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.

Comments (automatically disabled after 1 year)

[...] Functional Programming in Smalltalk (Ramon Leon) Link: Smalltalk/X Programmers [...]

hiren 3365 days ago

u use "#(1 2 3 4 5) collect:#odd" instead of "#(1 2 3 4 5) collect: [:x | x odd]" ? this is something i regularly use nowdays.

BTW Vassili have written nice entries about currying in Smalltalk : http://blog.3plus4.org/2007/03/23/currying-in-smalltalk/ http://blog.3plus4.org/2007/03/24/currying-in-smalltalk-part-2/

Functional programming with "small" objects in Smalltalk is most fun :)

I feel very disgusted when some morons(some OO industry biggies included) talk that OO is biggest thing after Procedural programming and even dnt mention tht some most advanced techniques in OO are borrowed from functional programming.

hiren 3365 days ago

my mistake, please replace collect with select (was in sleeping mod)

Jason 3365 days ago

Good post. I have been saying this for a while but I get a lot of disagreement from people. But as you say, it is the high order functions that really make Smalltalk Smalltalk.

OO is basically a means of organizing code in a sensible, logical manner. Mixed with procedural coding it does help, but mixed with functional programming.... now that's power.

Ramon Leon 3365 days ago

Yea, Vassili's blog is great, I wish he'd write more, I really enjoy his point of view on programming.

@hiren, that's called the symbol hack, it's pretty sweet, I use it as well, but it does have it's problems. Vassili explains what they are pretty well on his blog. Despites those rare issues, I dig and use that hack myself.

Most people don't realize how heavily inspired by Lisp Smalltalk was, that's too bad, they don't know what they're missing. On the other hand... I don't exactly mind having that competitive advantage.

If I see my competition using .Net or Java, I know I've got nothing to worry about. Ruby, Python, or Pearl, OK, maybe they could be a little dangerous. Smalltalk, Lisp, Haskell, or Erlang, OK, now that's real competition.

 3365 days ago

ha ha u sounds liek PG. But consequence of that advantage is as Gilad says [1] poor fellows like me are forced to work with bad technology.

yaa i know about problems with symbol hack, but for unary selectors "Symbol >> value:" is perfectly fine. I just read about sections in Vassili's blog, it seems pretty cool for keyword selectors.

[1] http://gbracha.blogspot.com/2007/05/message-based-programming.html last comment

hiren 3365 days ago

Its me as Anonymous

MCOM graduate student 3347 days ago

Please take a moment to help with a quick six question survey about programmers and blogs. http://www.surveymonkey.com/s.aspx?sm=H3Tk7Ho1186wC3taRdYZuw3d3d

about me|good books|popular posts|atom|rss