A Squeak Smalltalk Development Example

Stephan Wessels has put up a very large tutorial showing the complete test driven development of a game in Squeak. It covers quite a few things new Squeakers will want to know such as using SUnit to do test driven development, using Morphic to create Squeak widgets, using the debugger, and packaging the code with Monticello. It’s a great tutorial and I’m sure will become a popular resource.

However, despite the awesome effort (which I do appreciate), I have some problems with it. As with many other Squeak tutorials, it makes the mistake of using a standard Squeak image as you’d find on Squeak.org. This only helps further propagate the impression among newbies that Squeak is ugly, old fashioned, and lacking in all the features they expect from a more modern IDE. What you see in the screenshots is not a Squeak I’d use. Plain black code, ugly fonts, no intellisense, no use of the Refactoring Browser, no Shout Workspace.

Most developers who use Squeak would have a plethora of extra tools and utilities installed that make developing a much nicer experience than what you see in this tutorial. Do yourself a favor and start your Squeaking with a real developer’s image loaded with all the proper goodies like the SqueakDev image maintained by Damien Cassou.

Squeak.org still hasn’t figured out that its core audience should be developers, not children. They don’t seem to realize the base image they distribute actually scares away more people than it encourages to join the community. Though they do have a link to Damien’s SqueakDev image, they don’t encourage it like they do the base image, a mistake that leads new developers to open up Squeak for the first time, browser a tutorial or two, and toss it aside as a silly toy, never having seen the real power or beauty that is Smalltalk.

So all you developers out there using Squeak, please, stop showing people ugly images. Marketing matters, looks matter, and that stuff scares people away. Load up some decent fonts, setup the minimum *required* goodies like Shout, the Refactoring Browser, and ECompletion. And if you aren’t using these goodies, you should be, and you shouldn’t be making tutorials without them because it gives people a false impression of what Squeak is. Squeak is an awesome development environment that sadly doesn’t come out of the box that way, you have to start with the right box or learn to build your own.

Squeak.org could learn a lot about marketing Squeak by looking at how rubyonrails.org markets Rails. If there’s one thing Ruby does vastly better than Smalltalk, it’s marketing. Smalltalk continues to languish not because of technical merits, but because of bad marketing. Beaten by Java, and now beaten by Ruby, by marketing alone.

Related posts
    at: "Seaside 2.8 Released";
    at: "Better Web Application Development, a Comparison of Frameworks";
    at: "22 February 2007 > Squeak Image Updated";

On the Smalltalk Browser

Some of the comments in a the Barrier To Entry post bring up the point that maybe the Smalltalk IDE itself is one of those barriers.

It’s an interesting thing, the Smalltalk browser. Unlike most IDEs, it’s optimized for reading code rather than writing code. Other IDEs allow you to see any number of methods all at once, cutting and pasting text giant chunks at a time, they sure make you feel like you’re working. They don’t however, allow you to navigate the semantic structure of the code very well nor do they encourage the writing of well organized code.

Modern IDEs are getting better at this, but they’re doing it by copying Smalltalk. Smalltalk’s various code browsers (hierarchy, method, inheritance, senders, implementors, protocol, category, package, refactoring) let you explore the structure and relationships between existing code and its tools (transcript, workspace, method finder, message names) make finding and using existing code, or understanding existing APIs vastly easier than any other language I know of. Seeing the structure of code is always but a context menu or hotkey away.

Smalltalk’s browser is rather opinionated, luckily, thanks to Rails, opinionated software seems to be having somewhat of a revival. When it comes to writing code, the browser forces you into a certain mindset, one that other languages don’t force you into. When I create a method in Java/C#/Ruby, I have to choose little more than what file and class it belongs in. I *can* organize the code well, but there’s little incentive to do so and my unit of work is rather undefined, I could be slicing and dicing methods, classes, namespaces, etc., usually with the full screen devoted to code across various files or even god forbid in one giant file. This encourages a code now and organize later approach. Sadly, later often never comes, and the code is left functional but messy.

Smalltalk on the other hand, defines my unit of work as *the method* and by doing so forces me at every turn, to continually organize my code in semantically meaningful ways. When I create a method, I have to choose a class category, a class, and a method category to put the method in. If I don’t, Smalltalk kindly categorizes the method for me in a protocol called “as yet unclassified”. It’s almost an insult, but it’s also a not so subtle reminder than I’m writing code sloppily, faster than I’m thinking. It reminds me to slow down, think for a second, where does this thing belong.

It only takes a second to pick a meaningful category name, and these names are idiomatic, I see them all the time when I’m looking for code. Aha, we’ve linked writing code to reading code. By taking the time to properly categorize my methods I also learn where to look for code later, when I’m in reading mode. It’s a feedback loop, the more I read the better I write and the better I write the more I learn to read with accuracy, looking only where necessary. It’s as if the code itself *is* a concise form of documentation hyperlinked by semantic meaning using things that Smalltalkers call browsers. Browsers and hyperlinks, bah, that’ll never work!

And RDoc, what the fuck is that, looks curiously like a Smalltalk browser to me, but why should class comments be anywhere except on the class itself? Oh that’s right, Ruby doesn’t have a Smalltalk browser, they code in files, how quaint.

As for editing the method itself, I work on and view only one method at a time, and only the lower half of the browser is for editing code which punishes me if I write long methods that can’t fit into that tiny pane. Smalltalk at every turn encourages me to read more code than I write, reuse more code than I otherwise might, and write smaller simpler methods than I likely would in a text editor.

Writing smaller methods forces me to give them meaningful names. Giving them meaningful names and putting them in meaningful places makes the code easier to read and easier to find. Code that is easier to read and easier to find, is easier to reuse, easier to understand, and easier to compose into new solutions. It’s called bottom up programming, the foundation of which is small composeable methods.

I keep using the word small, maybe that’s a mistake on my part, what I really mean is concise. Methods with a single purpose that is clearly summed up by their name. These kinds of methods happen to be short in general, but that’s a side effect of their being focused on a single task. The Smalltalk browser encourages these kinds of methods by making writing long methods or paying attention to too many methods painful. Text editors are general purpose editor aimed at text, that could be anything from a blog post to a novel. Surely an editor intended only for code, and only for a particular style of code, can be made much more *domain specific*.

The Smalltalk browser is such an editor, its domain is highly factored heavily structured bottom up style object oriented code. If that’s the style of code you like to write, you’ll find the Smalltalk browser wonderful, if not, you’ll find it painfully opinionated and rude.

Take a peek at decompiled .Net framework sources, or Ruby sources and what you’ll find, are average line per method counts in the 50+ to even 100+ ranges. In Smalltalk, around 10 or so. To me, this is a clear indication that text editors are the wrong interface for writing clean simple well factored reusable code. Sure, I just pulled these numbers out of my ass, but they reflect my experiences and even then, I’m being polite, 1000 line methods are not at all uncommon in .Net.

Maybe adjusting to the Smalltalk browser is similar to adjusting to Lisp’s parenthesis. It’s something you desperately want to fix as a newbie and make it work like other languages. In Lisp’s case, trying to design an infix Lisp while in Smalltalk it’s a text and file based editor. In both cases, once you stop fighting the language and realize the difference is actually a great strength of the language rather than something that needs fixed. You realize it’s you that needs to change, you open your mind, accept that sometimes different is good, and take advantage of the new power these tools give you.

Experienced Lispers love their parenthesis and experienced Smalltalkers love their browsers. Rather than seeing the Smalltalk browser as a barrier, maybe, just maybe, you’d be better off seeing it as a new toy to play with. Something new to learn.

UPDATE: Here’s a few admitidly cramped screenshots of the various browsers. They do of course look much better maximized on your monitor.

browser8.jpg

browser7.jpg

browser6.jpg

browser5.jpg

browser4.jpg

browser3.jpg

browser2.jpg

browser1

Related posts
    at: "05 Dec 2006 > Squeak Image Updated";
    at: "A Squeak Smalltalk Development Example";
    at: "Popular Posts";

Functional Programming in Smalltalk

Smalltalk is generally considered to be an object oriented language but it’s actually a mixture of object oriented and functional techniques that made it so great. It’s the functional stuff, closures, anonymous functions, and higher order functions that make Smalltalk code so terse and easy to read. The objects provide the overall structure, but the functional stuff glues them all together and makes Smalltalk what it is.

I was considering writing more about it but a quick Google search turned up this great reference Smalltalk for Lispers from the Smalltalk/X Programmers Guide that gives an excellent introduction from a more functional point of view.

If you mix object oriented programming, manifest types, and procedural programming, you get Java or C#, not exactly a fun or flexible combination of language features. Mix object oriented programming, dynamic types, and light functional programming and you get Smalltalk and Ruby, much more fun and much more flexible and productive.

People often seem to forget “object” is meant as an abstract term that means “thing”. Object oriented programming is about programming with “things”. In that sense, functions are objects too. Not all objects need be created with named classes, and all too often people who complain about OO are really complaining about their misguided view of OO and the often made newbie mistake of trying to model everything with a class. It’s not called class oriented programming, it’s called object oriented programming. Maybe approaching Smalltalk from a more functional point of view will shed some light on more interesting ways to solve problems.

Related posts
    at: "On Simple Functional Idioms";
    at: "My Journey to Linux";
    at: "Popular Posts";

What are the Barriers to Entry for Smalltalk and Seaside?

It’s been two or three years since I began using Smalltalk and Seaside and I’m so comfortable in the environment I think I’ve forgotten how difficult it was to get going. By the time I started this blog, I was already quite comfortable using both Smalltalk and Seaside that I think a bunch of the little things I could have written about have been overlooked.

I’ve been so busy with work lately that I haven’t felt much like writing but I think it’s about time I give the blog a little more love. So those of you looking to get into Smalltalk, or Seaside, where’s your pain? What things are tripping you up that you can’t find answers to? What things are getting in your way that keep you from getting into the flow and really doing something in Seaside?

I’m just looking for some ideas for some bite sized yet useful articles covering topics I haven’t already covered that’ll help ease someone’s pain just a bit and get me back into the writing mood.

Related posts
    at: "Small Reddit, A Seaside Sample Application";
    at: "On the Smalltalk Browser";
    at: "Great Moments in Modern Computer History";

« Previous PageNext Page »