4 ms·
What'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 c
by tiglionabbit 10y ago
What'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.
- MaulingMonkey 10y ago> This gives the false impression that the variables are all related. If they are related, they should probably be encapsulated in some kind of structure. The true impression. If they're actually unrelated, they're more likely to be in different files outright, than immediately sequential. "Encapsulating" in a struct is pointless/potentially obfuscatory if they're related local temps - but I'll use the same style for initializing structs. > 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. I align those comments too. > If you add another long line, you have to realign the whole list The one drawback.
- coliveira 10y agoAgreed. Nowadays I am a true believer in aligned code, I think it improves readability more than almost anything you can find in modern coding styles.
- JoshTriplett 10y agoI find the first of those two examples far more readable than the second; the unnecessary spacing requires scanning from the name across the gulf of spaces to the corresponding value, rather than placing the values near the names. Also, alignment like that produces an excessive amount of diff noise: when you add or remove an entry, every entry changes.
- stouset 10y ago> Also, alignment like that produces an excessive amount of diff noise: when you add or remove an entry, every entry changes. I absolutely agree that this is a drawback — no approach is without some flaw. This is the flaw in mine. That said, I'm utterly convinced that it is worth this drawback.