4 ms·
The most voted Ruby question on Stack Overflow
- eliot_sykes 13y agoLeads to "How can I write a switch statement in Ruby?"
- izietto 13y agoYes, it seems to me quite ironic (and weird) that the most voted Ruby question on StackOverflow asks for how to write a switch!
- dasil003 13y agoWhat's ironic about it? What would you expect to be the most voted ruby question?
- izietto 13y agoSurely not a question which could be easily answered with a LMGTFY like this http://lmgtfy.com/?q=switch+statement+in+ruby http://lmgtfy.com/?q=switch+statement+in+ruby
- chrismonsanto 13y agoThat's exactly why it would be the most voted question. It's a common thing to Google, and the Google search leads to the StackOverflow page linked, which leads to lots of upvotes.
- izietto 13y agoYes, but if I want informations about Ruby switch statements it means you are a newbie that should refer to a whole language syntax reference; you could say that Ruby has not an official language syntax reference (this is the most "official": http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/syntax.html http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/synt... ) so newbies are forced to google for syntax explanations, which is true, but it seems too little to make it the first Ruby question. And I think Ruby management has its negligence; it's weird that a so popular and mature language has so much lack of informations about its behaviour.
- sebastialonso 13y agoThat question was...unexpected to me, to say the least. I was expecting something obscure, maybe related to meta programming, certainly not something about flow structures!
- dasil003 13y agoYou were expecting something obscure to be the most voted question?
- pgsandstrom 13y agoJust compare it to other languages, there is a clear difference. Java: http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array http://stackoverflow.com/questions/11227809/why-is-processin... Php: http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php http://stackoverflow.com/questions/60174/how-can-i-prevent-s... Javascript: http://stackoverflow.com/questions/111102/how-do-javascript-closures-work http://stackoverflow.com/questions/111102/how-do-javascript-...
- Shish2k 13y agoLooking at the top few questions for several languages, I note some trends: Ruby, Python, Javascript: unique-ish language features Java: general comp-sci corner cases C, C++: what does this obscure operator mean Erlang, Haskell, Node: how to get started Go: how to live without features that were intentionally not included PHP: How to avoid the security pitfalls that the standard library encourages Seems about right... (Though I'm surprised to see Node alongside Erlang and Haskell in terms of people not knowing where to start)
- x3ro 13y agoHow on earth did this get to the front page? :D
- stef25 13y agoIs there no equivalent of php.net that explains this simple control structure?
- masklinn 13y agoThe ruby community does not really believe in documentation, so you have to go for third-party sources[0] or books Also, it's not a simple control structure, Ruby's case/when does not do equality checks (via ==) it does match checks (via ===) so you can match integers to ranges: > (1..3) === 2 => true or instances to classes > String === "foo" => true But `===` is not commutative: > 2 === (1..3) => false and the matches can seem somewhat arbitrary: > (1..5) === (2..3) => false [0] http://www.techotopia.com/index.php/The_Ruby_case_Statement http://www.techotopia.com/index.php/The_Ruby_case_Statement
- k__ 13y ago> The ruby community does not really believe in documentation made my day, thanks.
- edoloughlin 13y agoThe lack of documentation, especially when you want to do something non-standard, made me give up on RoR a few years ago. I got sick of getting lost when looking at the source, which seemed to consist of 5-10 line methods with a call hierarchy that was usually over 10 methods deep.
- k__ 13y agoNever tried Ruby or RoR. But "I don't believe in ..." or "She doesn't believe in ..." is a running gag in my circle of friends. "He got rather bad teeth so he had to pay much money for getting them done..." - "Didn't his insurance cover this?" - "He doesn't believe in insurance!"
- deleted 13y ago[deleted]
- achivetta 13y agoIs this perhaps because ruby calls it a case statement instead of a switch statement?
- matthewmacleod 13y agoRuby's case statements are super-awesome, and I constantly find myself longing for similar sugar elsewhere. Obviously it's more useful in a duck-typed language. RubySpec, for those who aren't familiar with it, is an attempt to write an executable specification for the language. Ruby's definitely suffered from not having this in the past. https://github.com/rubyspec/rubyspec/ https://github.com/rubyspec/rubyspec/ and specifically case statement spec at https://github.com/rubyspec/rubyspec/blob/master/language/case_spec.rb https://github.com/rubyspec/rubyspec/blob/master/language/ca...
- masklinn 13y ago> Ruby's case statements are super-awesome Most functional languages have, I think, somewhat better systems in that there's less magic[0], you can unwrap/extract values and you can add further conditions on values (guards)[1][2][3]. Some modern multiparadigm languages have lifted this style e.g. Scala or Rust. [0] because case/when relies on the non-commutative `===` its behavior can be surprising [1] http://learnyouahaskell.com/syntax-in-functions#case-expressions http://learnyouahaskell.com/syntax-in-functions#case-express... [2] http://learnyousomeerlang.com/syntax-in-functions#in-case-of http://learnyousomeerlang.com/syntax-in-functions#in-case-of [3] http://en.wikibooks.org/wiki/F_Sharp_Programming/Pattern_Matching_Basics http://en.wikibooks.org/wiki/F_Sharp_Programming/Pattern_Mat...
- ddd1600 13y agoI think the poster was trying to be snarky but so far this has been unacknowledged