| Ruby, another language in the Smalltalk lineage, did without the [ ] at the cost of the "end" keyword to terminate blocks, but there is also the equivalent {} notation, recommended for one liners. A Python indented Ruby would probably able to do without [ ] but I should think about whether there are some unresolvable ambiguities with that approach. I won't recommend that personally because syntactical spaces introduce bugs. I run into one a few days ago when I moved code around a file and forgot to fix the indentation of a few lines. Luckily this one cost me only five minutes. Many people like Python though. Overall I like the terseness of 1 to: 5 do: [echo :x]
instead of the more verbose loop(1, 5, lambda x: echo x) # Python
(1..5).each do { |x| echo x } # Ruby
(1..5).each do |x| # Ruby again
echo x
end
But all those : are annoying: they increase the noise/signal ratio. I'd even do without the | | in the multi line Ruby version. I wonder if the compiler could add the : automatically by matching what it sees with the signatures of the defined function. 1 to 5 do [echo :x]
Then, why you need :x and couldn't use x without the : ?
Furthermore, how do I know how the name of the block argument if I didn't write the function. Isn't that an unnecessary coupling between the name chosen by the developer of the library and my code? I probably didn't understand everything is going on here. Edit: it has been explained in another comment in the parent's thread.And there are so many commonly used languages that use { } to define code blocks and [ ] for arrays. I'd stick with the majority for an easier onboarding of developers. The possibility of defining pseudo keywords thanks to the infix/suffix arguments is great. That's probably anathema in the Python world (only one way of doing things) and also in Go's. It should be acceptable in Ruby's. I'd prefer something like this func (n)to(m)do(blk) {
x = n
...
do blk x
...
}
The order of arguments and function names is clear because you read them from left to right without going through two different lists.Is anybody using Spry for real world programs? |