To clarify, I looked at existing online ruby code and gave it a small test for readability. It may be outdated, use uncommon syntax, bad practice or be full of individual developer quirks - I wouldn’t know. I did that because I wanted to highlight some weaknesses of the language design that turned me away from ruby years ago. https://en.wikipedia.org/wiki/Principle_of_least_astonishment
Yes, very nice. But here comes the ugly;
[1,2,3].map(&:to_s)
oh ok, a bit hieroglyphic, but I can figure it out, seems like ‘&’ means element and ‘:’ means what I do with it.
files = `ls -1`
Aaah so a backtick is for strings? WRONG!!! IT EXECUTES THE FUCKING COMMAND!!!
ARGF.each { |line| putslineif /BEGIN/ .. /END/ }
What the hell is | and / ? Oh but I guess .. is a range like in other languages, but what would be that range??? WRONG! I!!T’S A FLIP FLOP!!!
%w{a b c} # array of strings%i[foo bar] # array of symbols%r{https?://\w+} # regex%x(ls -1) # run shell command
Ah, just memorize which letter to use by heart and that % is for type and that [ = { sometimes. But { unequal to { other times.
if line =~ /ERROR/
warn $~.post_match
end
=~ neat!
$~ dafuq???
At this point I feel like ruby devs are just trolling us. There are always multiple ways to do the same thing. Every example from above also has a tidy and readable way to do it. But the alternative ways become progressively more shorthand, unreadable and unintuitive.
I’m way happier debugging “200 char wide class name + 50 line of boilerplate” code written in java that verbosely and expressively does the same thing compared to deciphering single symbol hieroglyphs in shell esque scripts where I have to pay attention which way the ticks are pointing.
Does Ruby require the use of [] and {} there? Because those %w/%i/etc things look like custom quoting operators and at least in Perl you can use any delimiter you want: qw(a b c) is a list of strings, but so are qw+ab c+ and qw;ab c;.
Edit:
To clarify, I looked at existing online ruby code and gave it a small test for readability. It may be outdated, use uncommon syntax, bad practice or be full of individual developer quirks - I wouldn’t know. I did that because I wanted to highlight some weaknesses of the language design that turned me away from ruby years ago. https://en.wikipedia.org/wiki/Principle_of_least_astonishment
Yes, very nice. But here comes the ugly;
[1,2,3].map(&:to_s)
oh ok, a bit hieroglyphic, but I can figure it out, seems like ‘&’ means element and ‘:’ means what I do with it.
files = `ls -1`
Aaah so a backtick is for strings? WRONG!!! IT EXECUTES THE FUCKING COMMAND!!!
ARGF.each { |line| puts line if /BEGIN/ .. /END/ }
What the hell is | and / ? Oh but I guess
..
is a range like in other languages, but what would be that range??? WRONG! I!!T’S A FLIP FLOP!!!%w{a b c} # array of strings %i[foo bar] # array of symbols %r{https?://\w+} # regex %x(ls -1) # run shell command
Ah, just memorize which letter to use by heart and that % is for type and that [ = { sometimes. But { unequal to { other times.
if line =~ /ERROR/ warn $~.post_match end
=~ neat!
$~ dafuq???
At this point I feel like ruby devs are just trolling us. There are always multiple ways to do the same thing. Every example from above also has a tidy and readable way to do it. But the alternative ways become progressively more shorthand, unreadable and unintuitive.
To be fair this is what they do in Perl and shell scripts (and in PHP too), so it’s not unexpected behavior in that world.
I’m way happier debugging “200 char wide class name + 50 line of boilerplate” code written in java that verbosely and expressively does the same thing compared to deciphering single symbol hieroglyphs in shell esque scripts where I have to pay attention which way the ticks are pointing.
Yeah, you could very well argue that JS and others that use it for weird interpolated strings are the weird ones here.
Does Ruby require the use of
[]
and{}
there? Because those%w
/%i
/etc things look like custom quoting operators and at least in Perl you can use any delimiter you want:qw(a b c)
is a list of strings, but so areqw+a b c+
andqw;a b c;
.Yes, but why?
https://en.wikipedia.org/wiki/Principle_of_least_astonishment