Thursday, September 29, 2005

Closures in Ruby and Smalltalk

Matz's talk on Blocksin Ruby

and Memoranda's comparison Smalltalkvs Ruby

You may want to work with some aspect of selected employees;
for example, to collect the spouse names of all managers.
In other words, select the managers from the employees and collect their spouse name


(employees select: [:each | each isManager])
collect: [:each | each spouseName]

foreach(Employee employee in employees) {
if (employee.IsManager) {

Which is closer to "english", which represents better our intention (mentally)?
I find the C# solution a little bit low level: we have to many implementation details.
Smalltalk is more abstract, it says exactly what it does.

Anothe nice approach is the Smalltalk project: where:
project: [:each | each spouseName]
where: [:each | each isManager]

Credits to RichardA. Demers

No comments: