5 ms·
People should just use actual tabs. Then you can make the indentation display however you want in your editor. And you never have to worry about deleting part
by tiglionabbit 10y ago
People should just use actual tabs. Then you can make the indentation display however you want in your editor. And you never have to worry about deleting part of an indent level, creating weird slightly offset indentations.
I know, everyone is going to downvote me for saying this. But if you're literally using 8 spaces to represent a tab, which is the default width tabs are rendered at, then what downside could there be to switching to actual tabs?
Edit: "spaces are never used for indentation" so do they actually use tab characters then?
- aanm1988 10y ago> In all cases, prefer spaces to tabs in source files. People have different preferred indentation levels, and different styles of indentation that they like; this is fine. What isn’t fine is that different editors/viewers expand tabs out to different tab stops. This can cause your code to look completely unreadable, and it is not worth dealing with. from the LLVM style guide.
- tiglionabbit 10y agoWhat's an example of some source code that becomes unreadable when you change the size of tabs? Are you editing code in Microsoft Word or something? Setting custom tabstops and shooting yourself in the foot? Don't mix tabs and spaces in indentation btw. That is the one thing you must never do.
- stouset 10y agoTabular alignment is practically the one thing of all these holy wars that actually improves readability. So no, that's not something funny — it's something that trivially and immediately improves readability of your source. foo = 1; this_value_is_not_foo = 8; another_int = 419; pi = 314159; versus: foo = 1; this_value_is_not_foo = 8; another_int = 419; pi = 314159;
- tiglionabbit 10y agoIt's fine to use spaces for your tabular alignment. Go ahead. But whether you have tabs or spaces as the indentation portion won't make any difference to the resulting alignment. The important thing is that you don't mix tabs and spaces in either portion. So, in my proposal, the indentation portion would be all tabs, and the tabular alignment part would be all spaces.
- stouset 10y agoThis works in theory. I've yet to see a project accomplish it in practice. There's always someone with an incorrect editor config that does indentation and alignment with tabs (because it's easier to configure your editor to just send a <TAB> than to have smart behavior, or copy-pasted code contains a tab rather than spaces, or a million other reasons), and nobody notices until two years later and everything is a mess for anyone trying to use a custom tab-depth.
- deleted 10y ago[deleted]
- mcbits 10y agoThis gives the false impression that the variables are all related. If they are related, they should probably be encapsulated in some kind of structure. And once you add the comments explaining what the first three variables are and how they should be used, and the comment explaining why pi doesn't have a decimal point, there is no benefit to alignment. If you add another long line, you have to realign the whole list (or leave it looking sloppy). Overall, this kind of alignment is a bad idea.
- stouset 10y agoCongratulations for taking my contrived example way too literally and missing the point entirely. Not every group of variable assignments warrants a comment for every line, nor is my argument relevant only to static constants, nor is there any reason why aligned assignments should be construed to be related any more than consecutive assignments should be, nor should that stop you from reaping the unarguable improved readability of aligning them anyway.
- paulryanrogers 10y agoWhen there are [line] width guidelines then the difference between 2 and 8 adds up
- tiglionabbit 10y agoI hate line length guidelines. People should just enable word wrap. I use Sublime Text and it wraps lines in a really readable way, maintaining the indentation from the start of the line.
- brudgers 10y agoProbably tabs because that's what makefiles require. That and having a standard allows people to speak a common language.