6 ms·
> 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
by 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.
- deleted 5y ago[deleted]
- kazinator 5y ago> there is no reason to not just enforce using tabs for indentation since they are objectively superior. I just demonstrated one. The semantics of tabs is that they move the printing position to the next tab stop position, which is absolutely determined, rather than relatively. This does not work for nested indentation in modern (or even not-so-modern) programming languages. If we re-imagine the tab as simply being a macro which expands to a configurable number of spaces, then tabs could be objectively superior. It makes sense to advocate for that, and I'm all for it; but I don't place a high probability on it happening. Though a simple idea, it would have to be in every editor, and other tools. You almost want to re-purpose some other control character for this purpose and leave tab alone. About: void foo(arg, arg arg, arg) { ... } Note that editor support this, so the only keystrokes you need to enter this from scratch, for instance in Vim, are: void foo(arg, arg[Enter]arg, arg)[Enter]{[Enter]...[Enter]} The important attribute here is that the parameter list, which is an independent element of the phrase structure of the language, is presented in such a way that a bounding rectangle can be imagined around it. That rectangle includes only tokens from that element, and not from any other element: +----------+ void foo|(arg, arg | | arg, arg)| +-----------+ { ... } Boxes help readability; that's why we use tables and grids for presenting information or laying out user interfaces. Ideally, this principle would be applied to every syntactic element. Looking at complex examples of Lisp code, I can't find a single counter-example: every sub-expression can be boxed in a rectangle which includes only that expression and its constituents: modulo a few closing parens that are written out to the right: )))). A big example of this is given below. Now in the descendants of C syntax, the predominant brace placements throw a monkey wrench into this idea. We usually cannot draw a bounding box around a multi-line compound statement or other braced element such that the braces are included, and no tokens of neighboring constructs are included. About that other style, for consistency, I would want this: void foo( arg, arg, arg, arg ) { ... } if the opening parenthesis is not on the same line as the arguments, the closing one should not be either. I work in a shop where the style closely resembles this one, except the parameter declarations are on separate lines: int put_bytes( int fd, // comment char *buffer, // comment size_t size, // comment ) { } Now I personally don't like this, but I can work with it, and can see the advantages. If you have to add, remove or reorder arguments you are not fiddling with the parentheses at all. When you take a unified diff of the edit, it does not include lines that only differ because of a parenthesis. The lines marked + or - are all "payload". The inner alignment of the parameter names is helpful, as is having the space for commenting the parameters. I still wouldn't do this in a side project where I dictate the coding convention, but I can respect that and work with it without grumbling. Now about that bounding box thing, here is a random example I picked from the SBCL compiler sources. The file is: https://github.com/sbcl/sbcl/blob/master/src/compiler/srctran.lisp https://github.com/sbcl/sbcl/blob/master/src/compiler/srctra... The macro bound-binop, with some ASCII rectangles inserted, looks like this. Only the closing parentheses at the end violate the principle: the rectangle includes more parentheses than are strictly part of that syntax, and this problem is minimized by closing the parentheses together on the same line. I suspect that the programmers who work with Lisp and find it readable all grok this bounding box model, whether consciouosly or not. (defmacro bound-binop (op x y) +-----------------------------------------------------------------------------------------------+ | (with-unique-names (xb yb res) | | +-------------------------------------------------------------------------------------------+ | | | `(and ,x ,y | | | | +-----------------------------------------------------------------------------------+ | | | | | (with-float-traps-masked (:underflow :overflow :inexact :divide-by-zero) | | | | | | +-------------------------------------------------------------------------------+ | | | | | | | +-------------------------------------+ | | | | | | | | (let* |((,xb (type-bound-number ,x)) | | | | | | | | | | (,yb (type-bound-number ,y)) | | | | | | | | | | (,res (safely-binop ,op ,xb ,yb))) | | | | | | | | | +-------------------------------------+ | | | | | | | | +---------------------------------------------------------------------------+ | | | | | | | | | (set-bound ,res | | | | | | | | | | +--------------------------------------------------------------+ | | | | | | | | | | | +----------------------------+ | | | | | | | | | | | | (and |(or (consp ,x) (consp ,y)) | | | | | | | | | | | | | +----------------------------+ | | | | | | | | | | | | ;; Open bounds can very easily be messed up | | | | | | | | | | | | ;; by FP rounding, so take care here. | | | | | | | | | | | | +-----------------------------------------------------+ | | | | | | | | | | | | |,(ecase op | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | | | (sb-xc:* | | | | | | | | | | | | | | | | ;; Multiplying a greater-than-zero with | | | | | | | | | | | | | | | | ;; less than one can round to zero. | | | | | | | | | | | | | | | | `(or (not (fp-zero-p ,res)) | | | | | | | | | | | | | | | | (cond ((and (consp ,x) (fp-zero-p ,xb)) | | | | | | | | | | | | | | | | (>= (abs ,yb) 1)) | | | | | | | | | | | | | | | | ((and (consp ,y) (fp-zero-p ,yb)) | | | | | | | | | | | | | | | | (>= (abs ,xb) 1))))) | | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | | | (sb-xc:/ | | | | | | | | | | | | | | | | ;; Dividing a greater-than-zero with | | | | | | | | | | | | | | | | ;; greater than one can round to zero. | | | | | | | | | | | | | | | | `(or (not (fp-zero-p ,res)) | | | | | | | | | | | | | | | | (cond ((and (consp ,x) (fp-zero-p ,xb)) | | | | | | | | | | | | | | | | (<= (abs ,yb) 1)) | | | | | | | | | | | | | | | | ((and (consp ,y) (fp-zero-p ,yb)) | | | | | | | | | | | | | | | | (<= (abs ,xb) 1))))) | | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | | | ((sb-xc:+ sb-xc:-) | | | | | | | | | | | | | | | | ;; Adding or subtracting greater-than-zero | | | | | | | | | | | | | | | | ;; can end up with identity. | | | | | | | | | | | | | | | | `(and (not (fp-zero-p ,xb)) | | | | | | | | | | | | | | | | (not (fp-zero-p ,yb)))))))))))) | | | | | | | | | | | | | | | +-------------------------------------------------+ | | | | | | | | | | | | | +-----------------------------------------------------+ | | | | | | | | | | | +--------------------------------------------------------------+ | | | | | | | | | +---------------------------------------------------------------------------+ | | | | | | | +-------------------------------------------------------------------------------+ | | | | | +-----------------------------------------------------------------------------------+ | | | +-------------------------------------------------------------------------------------------+ | +-----------------------------------------------------------------------------------------------+