3 ms·
I think Matz or some well known and respected "rubyist" needs to write a Ruby equivalent of Python's Pep 8 (there are some style guides out there on the interne
by benofsky 17y ago
I think Matz or some well known and respected "rubyist" needs to write a Ruby equivalent of Python's Pep 8 (there are some style guides out there on the internet but are mostly written in the "someone might disagree with me so here are 5 options for doing x" style) as there are a lot of stylistic things which ruby beginners always get slammed with.
For example, blocks or pseudo named paramaters with hashes are in no official documentation (that I've found) recommended (or discouraged) over other methods but a "rubyist" will often question a beginner over their use of x, y or z.
Edit: clarification, spelling and grammar.
- thenduks 17y agoWhile I'm not against having some of this stuff written down, Ruby purposely adopts Perl's TMTOWTDI philosophy. So, using the while-loop approach is perfectly valid. Ruby beginners should use whichever way they find most agreeable and evolve their view of the language as they go. Reading code written by other people (respected rubyists, as you say) is a great (and, the recommended) way to pick up new tricks to improve your code with. IMO, that's the way it should be. There's no reason to list every single little tip ('use inject instead of an external accumulator') somewhere since I wouldn't expect a beginner to read through all that anyway. When I learned Python several years ago I didn't know PEP's existed for ages, I figured it out myself and I think I'm a better programmer for it.
- mechanical_fish 17y agoThere's no reason to list every single little tip ('use inject instead of an external accumulator') somewhere since I wouldn't expect a beginner to read through all that anyway. They might not read it on day one. But they will find themselves reading it via Google after they read a line of code (written, perhaps, by a respected Rubyist) that uses inject and are trying to figure out how the idiom works and where it should be used. And, if they're lucky and they've found some fairly clear and concise docs, they might bookmark that page, or even read the rest of the page while they're there, thus saving themselves anywhere from 20 to 100 future trips to Stack Overflow. ("What is this thing with the hash that we use to pass options? What is this oddball "names.map(&:upcase)" syntax? What does "class << self" mean? How come my colleagues laugh bitterly when I try to use Rails fixtures?")
- benofsky 17y agoMy point exactly.
- jamesbritt 17y agoThere was a fairly decent style guide on the rubygarden wiki, but it was incinerated by spam. There's also this: http://github.com/chneukirchen/styleguide http://github.com/chneukirchen/styleguide But the best path may be to read a lot of (good) code and see what people do.
- percept 17y agoThis might be of interest: What are real-world prime examples of good Ruby code? http://www.rubyflow.com/items/1817 http://www.rubyflow.com/items/1817