one dour badger ([info]dour) wrote,
@ 2007-01-12 00:53:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
(Smalltalk > you) ifTrue: [self postTo: LiveJournal].
Been fiddling about with Dolphin Smalltalk. I'm really liking this language. I first figured objects out in Java, and they seemed like a great idea, but certain things just seemed more complex than they needed to be. Smalltalk has no such cruft. Most especially, writing a small class does not necessitate writing a header which is larger than the method code.

It took a little bit of getting used to, but building live classes in a browser is immensely superior to writing them in an arbitrary editor. There is no compile cycle! Testing code in a workspace makes debugging an instantaneous process. I wondered at first if the live image methodology would hurt collaboration (because with a monolithic image instead of individual source files for your classes, CVS is essentially impossible), but now I see that Smalltalk classes are so... well, small, that the ability to trade packages around is plenty.

The degree to which you can re-use code is unbelievable, even on a small scale. Block closures are my all-time favorite structure. In every other language I've used, there has always come a time when I've wanted to insert arbitrary code into a routine at runtime. Silly me, I was just using the wrong languages! Thinking back now, I wonder if it was Logo that put the idea in my head; Logo is simplified Lisp, and Lisp does similar things.

And where closures let you make a lot of your code highly generic, the way class inheritance works (and the speed with which you can build new classes) lets you also hone general tools into very specific ones just because they're easier to reference later. Case in point, I was building a very generic PolyhedralDie class; once I was done, it took about a minute to subclass it into a FixedPolyhedral abstract singleton (mirroring instance methods to class methods and disabling the #new method), and then mere seconds to subclass that into concrete singletons D4, D6, D8, etc., which I can now utilize with direct class calls (D4 roll) instead of building an appropriate-sized PolyhedralDie (PolyhedralDie new sides: 4; roll).

It's bedtime, or I'd ramble more. This language is so... fun! :D



(14 comments) - (Post a new comment)


[info]plogon
2007-01-12 11:22 am UTC (link)
it would be even more fun if you could extend your language with a keyword "singleton". and when you add it to a class definition, the language does all the work for you (mirror methods, disable new,..)

i bet that it is possible in lisp ( with macros or something?)

(Reply to this) (Thread)


[info]dour
2007-01-12 06:39 pm UTC (link)
While it's probably a bad idea—from what I've seen, you're generally not supposed to expose the instance methods through the class in a singleton for a couple of reasons—it's thoroughly possible.

Keywords mean something slightly different in Smalltalk than in other languages; they're not flags, they're method names which take arguments. Standard class extension is done by sending a message to an existing class (which is itself a live object). The method designated by this message is inherited from Class. By changing its implementation, you can cause your classes to have different subclassing behavior, or disable subclassing entirely. Class (maybe even Object?) also teaches classes how to tell you what methods they implement, so you can selectively disable or mirror them. It wouldn't be hard to build a second subclassing method, #makeSingleton: , which did all the basic work. It would take a little extra effort to properly integrate it with the class browser, but you could always just send the message in a workspace.

Smalltalk and Lisp have a lot in common, in terms of design philosophies. Neither has control structures in the language; both are fully introspective and mutable at runtime. I think if I were still primarily a commandline jockey, or (especially) if I were using Unix, I'd probably have picked Lisp—in fact, I was on the verge of doing exactly that when I found this blog and decided to follow along (because his goal is my goal, and he's far more experienced).

(Reply to this) (Parent)(Thread)


[info]plogon
2007-01-14 08:41 pm UTC (link)
are you making a game too?

(Reply to this) (Parent)(Thread)


[info]dour
2007-01-15 01:36 am UTC (link)
By fits and starts, yes.

(Reply to this) (Parent)


[info]tilton
2007-01-12 05:16 pm UTC (link)
Yay Smalltalk! I used to do a bit of it back in the day, but it's been a long, long time.

If You Like Smalltalk, You Might Also Like(tm): Ruby. It rifled through Smalltalk's pockets and made off with its block closures, then broke into LISP's house and took some other bits. I'm finding it to be really fun to do things like

    # Print "hello, world!" five times
    5.times.do { puts "Hello, world!" }

and

    # Reverse each name in the list
    names.map { |n| n.reverse }

where the things in {}'s are block closures being passed to the 'do' method and the 'each' method, respectively. These are just small built-in toy examples.

And Ruby objects are infinitely extensible at runtime. You can open them, poke them, prod them, define new methods, rename old methods, intercept messages and do highly inappropriate things. It's wonderful.

Of course it loses out by not having the integrated workspace system that Smalltalk has, but it does have a reasonable interactive shell called irb that lets you spit arbitrary Ruby into your system to see what happens.



P.S.: If you're into web development, be sure to check out Seaside, probably the best web app development framework in the world, and unfortunately nobody uses it. It's pure Smalltalk, and it lets you do crazy things in a snap.

(Reply to this) (Thread)


[info]dour
2007-01-12 06:01 pm UTC (link)
You're not the only person who's suggested that I check out Ruby. Thing is, Ruby is an interpreted language; Smalltalk runs on a JIT VM, and these days you can package the whole deal in an executable, not to mention that all the Windows APIs have been packaged for Smalltalk. (Including DirectX. Vista's nearly done, even.) Also, Ruby cleaves to C/Java-ish syntax (curly braces, dots for message designation, etc.) which I'm really getting happy about not having to deal with! :D

All of your examples are identically short in Smalltalk, too. :)

(Reply to this) (Parent)(Thread)


[info]tilton
2007-01-12 06:20 pm UTC (link)
Oh, I'm not implying it's better than smalltalk. I'm just saying it's useful to have in your toolkit :) They're both very fun languages!

(Reply to this) (Parent)(Thread)


[info]dour
2007-01-12 06:41 pm UTC (link)
I'm not implying it's worse, just explaining why I picked the one I picked. ;)

(Reply to this) (Parent)


[info]tilton
2007-01-12 07:00 pm UTC (link)
Also, dang I wish Dolphin were available for OS X. All we've got is Squeak, which is not very programmer friendly.

I guess I could fire up Parallels and see how it runs under that.

(Reply to this) (Parent)(Thread)


[info]dour
2007-01-12 07:25 pm UTC (link)
Isn't Cincom Smalltalk available for Mac? And I know I saw one Mac-specific one... ah! Ambrai.

Don't I remember Smalltalk being officially endorsed by Apple at some point?

(Reply to this) (Parent)


[info]dour
2007-01-12 07:28 pm UTC (link)
Addendum: Parallels is a Windows emulator? I'm running Dolphin on an old IBM server with dual 866MHz P3s. If you've got a smokin' new Core Duo Mac, it should run just peachy.

(Reply to this) (Parent)(Thread)


[info]tilton
2007-01-12 08:42 pm UTC (link)
It turns out it runs very well indeed! I'm quite pleased. (Parallels in general has about a 5% to 10% slowdown over native system performance, which really ain't bad if you think about it. I love the modern age.)

(Reply to this) (Parent)(Thread)


[info]dour
2007-01-12 10:45 pm UTC (link)
Hooray for convergent hardware!

(Reply to this) (Parent)


[info]zaimoni
2007-01-13 03:15 am UTC (link)
Not to mention Smalltalk is what spawned Extreme Programming.

(Reply to this)


(14 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…