266
you are viewing a single comment's thread
view the rest of the comments
[-] HelloRoot@lemy.lol 19 points 4 days ago* (last edited 3 days ago)

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.

[-] beyond@linkage.ds8.zone 20 points 4 days ago* (last edited 4 days ago)

Aaah so a backtick is for strings? WRONG!!! IT EXECUTES THE FUCKING COMMAND!!!

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.

[-] HelloRoot@lemy.lol 8 points 3 days ago* (last edited 3 days ago)

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.

[-] Tanoh@lemmy.world 8 points 4 days ago

Yeah, you could very well argue that JS and others that use it for weird interpolated strings are the weird ones here.

[-] Feathercrown@lemmy.world 1 points 3 days ago

On the other hand, interpolated strings are fucking awesome and you need them every 5 seconds for UI work

[-] Tanoh@lemmy.world 2 points 3 days ago

Sure, but in Perl and other languages there is a difference between "$foo" and '$foo'. In that the first expands the value of foo, while the other doesn't.

But usually if you need to write stuff in noisy strings, just use printf/sprintf. Or a <<HERE block.

[-] barubary@infosec.exchange 4 points 4 days ago

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+a b c+ and qw;a b c;.

this post was submitted on 24 Aug 2025
266 points (100.0% liked)

Programmer Humor

37993 readers
80 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS