4 ms·
Rails Development No-Nos
- teej 17y ago> Tabs instead of spaces Every editor on earth supports both. Why the hell do I have to use spaces if the choice has -no effect whatsoever-.
- deleted 17y ago[deleted]
- old-gregg 17y agoYou may be wondering why you're getting downmodded. That's because people disagree with you. I suspect the good reason is that different editors handle tabs differently. Some treat them as 2 spaces, some 4, some 8. I don't use tabs and frankly I don't even know what my tab width is set to in vim. Using tabs in the code shared between multiple people will produce annoying inconsistencies. Spaces will look identical everywhere.
- kscaldef 17y agoWell, I think the main argument for tabs is that they will look exactly how each individual wants them to look. If you like things compressed horizontally, set your tab width to 2. If you want things really spacious, set it to 8. Spaces don't give individuals the option to tailor for their preferences. There are two non-trivial issues in this debate though: 1) mixing spaces and tabs is undeniable evil. Everyone on your team needs to conform to one or the other. (And since I like spaces, everyone should use spaces ;-). ) 2) In a layout-based syntax like Haskell's, you cannot set your tab width willy-nilly. The syntax defines a tab as equivalent to 8 spaces. Vary this in your editor at your peril.
- gcv 17y agoI like your problem #1. Using tabs exclusively means that code cannot align nicely in common situations: multi-line function arguments, or parameter lists, or object initialization. So therefore you have to either mix tabs and spaces to achieve proper alignment, or just use spaces. (setq-default indent-tabs-mode nil)
- bkudria 17y agoWhat's wrong with mixing tabs and spaces? The proper way to code is to use tabs to indent, and spaces after to align. So, no spaces before tabs, only after, and tabs should only indent to the current indentation level of the code (obviously).
- kscaldef 17y agoThe problem is that you must adopt a standard tab width for this to approach. Otherwise when you mix this with team members who use only spaces, things with become inconsistent. Also, as I pointed out, with languages like Python & Haskell, it is required to fix the tab width. At this point, where you must dictate a fixed tab width that everyone must use, I fail to see any advantage to using tabs (other than a miniscule reduction in file size).
- old-gregg 17y agoindents per line of more than 2 spaces. drives me baddy I hate 2-space indentation. It's weird. It makes the code look less readable and every other more or less popular programming language uses 4. I see no reason why Ruby code needs to look like a narrow, dense spaghetti because of this stupid "rule". There is nothing in the language that justifies this awkward feature: Ruby isn't excessively nested and an average line length is short. This language looks beautiful when properly indented with 4 spaces. I've heard from a couple of Pythonista friends that Ruby looked to much Perl-like to them, I suspect some of it can be attributed to this tradition of fucked up indentation. Before reading open source Ruby code I always reformat it properly: just a hotkey in vim.
- jeroen 17y agoThe whole 2/4/8 spaces argument should be a reason to go for tabs. Then everyone could set their own tab size and have their code indented as they want. Unfortunately, I don't think all editors play nice.
- bkudria 17y agoAmen. And, don't inflict pain on others just because your editor sucks.
- ruby_roo 17y agoIt was weird for me at first, but I find it comfortable now. The eyes don't have to move as much while scanning code; small thing, I guess. Of course, if I didn't have a proper text editor that took care of the tab stops for me, it'd probably make me crazy to have to hit the space bar twice for indents. Still, it was never as off-putting as the significant whitespace in Python, which any pythonista can tell you becomes very easy to live with after an easy and brief acclimation period.
- erlanger 17y agoAlmost all of these "No-No's" apply equally to development on any platform. Adding "Rails" sorta makes it link-bait, since there's very little domain-specific knowledge here: * Write tests * Don't write obfuscated code * Consistent indentation, using spaces * Don't mix presentation with logic etc. etc.
- ConceptDog 17y agoHoly crap.. Articles that are almost entirely links to twitter need to burn in hell.
- bkudria 17y agoOK, I'll bite. What's wrong with Twitter?
- windsurfer 17y agoI know I probably shouldn't do this (for fear of getting down-voted), but... the basic problem with twitter is it's severe restriction on n
- umjames 17y agoI don't think I agree with no comments in methods and not much comments overall. What if the comments specify why you're taking a certain approach over another or something that was decided by other people? Comments are good for documenting not what the code says, but the reasoning behind that code. This is especially helpful if you haven't looked at it for awhile.