5 ms·
I'm curious, why would you ever want to align something like that? I've only ever seen "but it breaks my alignment" as the only argument from the spaces people
by jdrek1 5y ago
I'm curious, why would you ever want to align something like that? I've only ever seen "but it breaks my alignment" as the only argument from the spaces people but so far I have not yet seen a good reason as to why that alignment is desired in the first place. Comments like that seem extremely unlikely to me, comments are for explaining a non-obvious "but why" and that's better in a paragraph above the code, especially if you use tools like doxygen who expect them there.
And in the function example I assume you do it because the args don't 'fit' on one line but then why not just have your editor wrap the line (and optionally indent by one level)? To spot the function name better? Why not use syntax highlighting for that?
And even then just use tabs for indentation and spaces for alignment, what would be the reason to force spaces on everyone else and make them suffer from an indentation width they don't like?
- kazinator 5y ago> I have not yet seen a good reason as to why that alignment is desired in the first place Alignment is desired because it enhances readability. All good visual design incorporates elements of alignment, grouping, separation and so on. > why not just have your editor wrap the line We could write function calls, no matter how many arguments they have or how large the expressions, on one line. That will result in an excessive line length. Generally, you want to avoid code wider than about 100 columns. You may find yourself working with a prescribed coding convention which imposes such a constraint. If you rely on an editor wrapping the line in a clever way, that's good for you. But you don't now how other tools will react to the long lines. E.g. someone wanting a print out of the code may find that the lines are getting truncated. > what would be the reason to force spaces on everyone else and make them suffer from an indentation width they don't like? Using tabs for indentation and spaces for alignment requires extra care, and a carefully tuned editor setup which understands the semantic difference between the tabs and the spaces which follow. In any sizeable team, deviations in formatting will creep in. Enforcing it will just be a big waste of time, compared to the simplicity of banishing tabs. People who suffer from an indentation width they don't like have a psychological problem that perhaps makes them unsuitable for this line of work. The professional developer can happily work with any indentation format and maintain it as-is. The only halfway valid argument here is regarding people with severe visual disabilities. Everything else is whiny primadonna fluff. Tabs are still not the right tool here; accessibility has to be solved in such a way that the visually disabled developer is able to work equally well with any code that is thrown their way, tabs or spaces. You don't get to work on nothing but code that was developed in-house with accessibility in mind. Third-party code happens. Also, you are overlooking that indentation isn't necessarily aligned to an absolute grid of tab stops. Nested indentation can start at a misaligned position. (let ((fun (lambda (arg) (indented-two-spaces)))) (also-two-spaces)) The indentation within the lambda is relative to the (lambda ... form in the previous line. If we change the variable name from fun to func, the entire lambda moves to the right by one character. (let ((func (lambda (arg) (indented-two-spaces)))) (also-two-spaces)) "Tabs for indentation" is not a generally valid principle. It could work if tabs actually expanded to a fixed number of spaces, rather than advancing to an aligned tab stop. (let ((fun (lambda (arg) [TAB](indented-by-simply-expanding-tab)))) [TAB](also-indented-by-tab with [TAB] split arguments)) Now suppose the whole thing above is at some nesting level: [TAB](let ((fun (lambda (arg) [TAB] [TAB](indented-by-naive-tab)))) [TAB][TAB](also-indented-by-tab with [TAB][TAB] split arguments)) As you can see, we need a more general mixture of tabs and spaces to have resizeable tabs such that alignment is preserved. Furthermore, tabs have to just expand to a given number of spaces (acting as a kind of variable-width "superspace"), rather than forward to the next aligned tab stop. (I don't think my editor can do this and don't know of any which can). The code will not look right except on such an editor.
- jdrek1 5y ago> Alignment is desired because it enhances readability. While that's true I was asking specifically about those examples of yours. What would be the reason to have a weird L shaped comment around the code like that? Right now I can only see two situations in which something is aligned in code, the first one being something like this int foo; double a; because for some reason people like to have variables like that. Personally I don't see why anyone would want to do that but if they want to insert extra spaces they can do that, it's trivial to clang format before the commit and absolutely nobody even has the idea of using tabs there. The second one are function arguments over multiple lines. Personally again I find it a bit ridiculous that someone absolutely needs to have void foo(arg, arg arg, arg) { ... } when void foo( arg, arg, arg, arg) { ... } is just as readable and even saves you keystrokes because you can use an indent level for the alignment of the arguments and just have one tab (well two, since it's two lines) there instead of the 9 spaces you otherwise need. But again if they prefer the other style then that's fine, but it's no reason to force them to do the indentation with spaces too. Your example is flawed, you should never mix tabs and spaces like that, tabs never follow spaces. You use tabs to indent to whatever level you're currently on and then if you really want that alignment for whatever reasons you use spaces for the rest. > Enforcing it will just be a big waste of time, compared to the simplicity of banishing tabs. I don't think a clang format commit hook is that hard to enforce. Not to mention that you are enforcing formatting anyway, otherwise you end up with one person using 2 spaces and the other 8. And if you already enforce that then there is no reason to not just enforce using tabs for indentation since they are objectively superior. > People who suffer from an indentation width they don't like have a psychological problem that perhaps makes them unsuitable for this line of work. The professional developer can happily work with any indentation format and maintain it as-is. > The only halfway valid argument here is regarding people with severe visual disabilities. Everything else is whiny primadonna fluff. Do you really think that dismissing people's preferences as psychological disorders is a good idea? Especially in a community that likes to customize the shit out of everything? Why shouldn't they be allowed to see the code however they like? That's literally the idea of using tabs, you can see them as 37 spaces if you like but for me it's 4. If you want to do any extra alignment after the indentation then use spaces, sure. But who are you to decide how far right on my screen the body of the loop appears? Tbh if you ask me I find your proposal straightup draconic, you rather ban tabs completely rather than using the available tooling and/or properly training your people to enable everyone to work as they see fit. Yeah sure most people can work with a 8 spaces codebase if forced to but that doesn't mean it's a good idea. And since you brought up disabilities: I've worked with someone who had only one eye, he didn't do any indentation because otherwise he'd have to constantly move his head around. Set tabwidth to 0 in his editor and you don't need to do any reformatting on commits if you indent using tabs. Force spaces on everyone and he needs to do a reformat all the time. > (I don't think my editor can do this and don't know of any which can). I'm not sure I follow why this is necessary. They already act like that, the only tabs not being as wide as X spaces are the ones that follow a non-tab character and at that point you are no longer doing indentation anyway so a tab should not even exist there. Though I don't see a reason to not have this, should be a simple setting in any editor.