News for hackers. Stuff that matters.
Re:"Useless syntax sugar": Numbered block parameters in Ruby by munificent on Wednesday October 11, 2023 @03:36PM (#37849244)
Tangential but:

> My homegrown theory is that the idea of array.each { ... } as the main syntax for cycles was the first “aha!” of the new language development for its author

> The style that flourishes with this new shortcut is representing computation as a chain of small blocks, declaratively describing transformations from inputs to outputs. The style that is native to Ruby, the first mainstream language to have enumerable.transformation { ... } as the main cycle construct, and, I believe, played a role in normalizing “map”, “reduce”, and “filter” as a way of thinking about how things are handled.

Matz got that from Smalltalk. That's why most of the enumeration methods in Ruby match the names of similar methods in Smalltalk ("collect", "reject", "select", etc.) and not the corresponding names in functional languages ("map", "reduce", "filter"). The "each" method is the odd one out because that's called "do" in Smalltalk and "do" is a reserved word in Ruby.

Smalltalk definitely isn't mainstream today, but it did have its day in the sun where it was one of the better-known languages.

Re:"Useless syntax sugar": Numbered block parameters in Ruby by zverok on Wednesday October 11, 2023 @03:48PM (#37849392)
Yeah, should've mentioned that probably (though a post is already a mess of footnotes, aside notes, and parenthicals).

I do believe though that a lot of modern languages got that from Ruby (or, via Ruby, from "JS that Rubyists wrote" and such), when it was a "hot new thing" for a brief moment in 2000s. Or maybe it is my skewed perspective.

Re:"Useless syntax sugar": Numbered block parameters in Ruby by dragonwriter on Thursday October 12, 2023 @04:11AM (#37854666)
>That's why most of the enumeration methods in Ruby match the names of similar methods in Smalltalk ("collect", "reject", "select", etc.) and not the corresponding names in functional languages ("map", "reduce", "filter").

Ruby has both, actually; "map" is a synonym for "collect", "reduce" is a synonym for "reject", and "filter" is a synonym for "select" (well, actually, they are both synonyms for "find_all"). And the non-Smalltalk names seem to have had more influence on newer methods, e.g., Enumerable has filter_map, but not select_collect, even as a synonym.

Re:"Useless syntax sugar": Numbered block parameters in Ruby by zverok on Thursday October 12, 2023 @04:33AM (#37854788)
Ruby didn't always had both. `reduce` as an alias for `inject` was introduced in Ruby 1.8.7; `filter` as late as in Ruby 2.6 (just a few years ago, and most of the codebases I saw are still preferring `select`).

Yes, the dictionary is normalized in the last years towards what became industry/mainstream standard names for the concepts, but the statement that initial names were derived from Smalltalk is correct.

Re:"Useless syntax sugar": Numbered block parameters in Ruby by spacechild1 on Thursday October 12, 2023 @04:39AM (#37854823)
Fun fact: "sclang" (the SuperCollider programming language) is mainly derived from Smalltalk and uses the same names. Definitely niche, but very much alive :) https://doc.sccode.org/Classes/Collection.html#Iteration