Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

[ "foo", "bar", "baz" ] * ", " => "foo, bar, baz"

It's pretty bad.



I agree with you that many of these shortcuts are obnoxiously read-only, but that was probably the worst example you could have picked. That notation is nicer than Python's standard ", ".join(["foo", "bar", "baz"])


I'm not picking on Ruby, I'm picking on the article. The worst example? No, that'd be:

does = is = { true => 'Yes', false => 'No' }

does[10 == 50] => “No”


Somewhat like this way (in Perl) of finding the larger of two numbers:

  [$a => $b]->[$a <= $b]
I tend to just say max($a, $b) though.


I love Ruby for it's expressiveness even more so than Python. But the author's code examples tend to make me hesitate for the reasons that bad Perl code makes my eyes fall out.


But the author's code examples tend to make me hesitate for the reasons that bad Perl code makes my eyes fall out.

It's nice to read the article for that reason. Hopefully people will realize that you can write horrifyingly bad code in any language. I'm looking forward to the Python edition ;)

Maybe we can start approaching language design rationally when people start realizing that all languages suck big time. Even Ruby. Even Lisp.


It's been written. Look for the articles on how to mimic Ruby "case" statements with Python dicts.


By "worst example", I meant that I thought it was a poor example of your point, because the notation you quoted is okay. A lot of the other ones were worse code (and better examples of your point).


It's a common operation. You should see how many people have to code it/get it wrong in topcoder. So it overloads * -- how often are you going to multiply a string?


Yeah. I never divide strings, either. I think I'll override :/ to form filesystem paths! x = "var". x/"log"/"messages". Awesome!


We have different opinions on what's important in a language. I want something that's as fast to write as prose, so that my mind can focus on other things in the problem domain. This may mean that my code is rather unreadable to people used to coding in specific idioms. But functionality is commented at a higher level, so then what are they doing reading individual statements from my code anyway?

This means that, sometimes, I find myself in opposition to the python community for its goals of readability and regularity, but it's a powerful language chalk full of good ideas and one of the most important tribes on the net, so I still use it.


> But functionality is commented at a higher level, so then what are they doing reading individual statements from my code anyway?

(1) Because it's not doing what I expected. (2) Because I want to do something with it that you didn't forsee.


It sounds like you just said, "my code is unmaintainable, but that doesn't matter because it's commented".


why is that bad?


Because multiplication has a tenuous relationship with Array#join, because Array#join shares none of the "other" mathematical properties of multiplication, because :* is overloaded in other, conflicting ways for other object types, and because the resulting code is needlessly terse and no easier to read as a result of this hack.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: