3 ms·
This is clearly not as bad as Perl, but it's still raving a bit. My key complaints are the complete lack of clarity as to what kind of thing split is, as well a
by swolchok 16y ago
This is clearly not as bad as Perl, but it's still raving a bit. My key complaints are the complete lack of clarity as to what kind of thing split is, as well as what exactly is going on with select. (I'm assuming it's getting passed a predicate in the form of a lambda or block or whatever the cool kids are calling it these days, and it's obvious to the Perl programmer what the block does after that.)
The equivalent Python is something like
import sys
for line in sys.stdin:
print '\n'.join(filter(line.split(), lambda word: word.endswith('ing'))
which I would argue is more readable to a layperson because function calls look like function calls. (By the way, does Ruby's puts automatically do the join with newlines, or what?)
- petercooper 16y agoMy key complaints are the complete lack of clarity as to what kind of thing split is The post seems to be about language independent readability. Rather than "functions should be called with () - that is clearly not a function - can not compute!!", the question is "can this code be understood even ignoring unfamiliar syntax?" Most developers familiar with languages like Java, JavaScript, Python, Perl, C# or Ruby could correctly guess what "split" refers to and that it is unlikely to be used as a variable name. Further, if a developer is familiar with the idea of method calls, it will be inferred that "whatever.split.whatever" is a sequence of method calls.. much as if it were, in some fictional languages, whatever->split->whatever or whatever:split:whatever. Similarly, a(b(c())) and a[b[c[]]] could both be easily inferred to be a set of nested function calls. "import sys" is not exactly clear either, but again, the meaning of this could be accurately inferred by most developers. print '\n'.join(filter(line.split(), lambda word: word.endswith('ing')) I want to join the array's elements together, not join the string. Joining together an array's elements by calling a method on the delimiter is no less raving than any Ruby I may cook up. Your example is both longer and has more syntax.
- jules 16y agoDoes it matter what kind of thing split is? There is no difference between properties and methods in Ruby. Yes, puts joins newlines.