3 ms·
Because there are places where indentation signifying intention breaks down. The classic example being the arbitrary restrictions on the Python lambda syntax.
by jimbokun 5y ago
Because there are places where indentation signifying intention breaks down.
The classic example being the arbitrary restrictions on the Python lambda syntax.
Ruby is more orthogonal and systematic. Everything is an object, and you call methods on those objects. And sending a block as a method parameter gives you something that very much resembles functional programming (minus the immutability).
There are a few other constructs (it's not quite so dogmatic about object orientation as Smalltalk), but Ruby is very regular and so you can understand how everything works with a small number of syntactic constructs.
- wizzwizz4 5y ago> The classic example being the arbitrary restrictions on the Python lambda syntax. That's actually because Guido thinks multi-line expressions are messy to parse, rather than because they can't be done. Consider: f = lambda x: return x + 5 Or, perhaps: print(sum(map(lambda n, b: while n: b.append(n) n -= 1 return b , range(3), [[], [], []]), [])) You can see why this was never added to the language, though.
- larkost 5y agoThe lambda thing is not about whitespace indentation. It is a purposeful decision that if you need more than one line to do it, it should have a name. At first I disliked this, but it does nudge you towards readability, which winds up to be a good thing. And if you look at it, there is very little space difference between an unnamed lambda and an embedded function: def lambda_version(): a = lambda x: line one line two # note: this sort-of requires the idea of implicit return, which Python does not have outside of lambda a() def named_version(): def lambda_replacement(): line one return line two lambda_replacement()