News for hackers. Stuff that matters.
Re:Python with Braces by RHSeeger on Monday July 08, 2024 @09:24AM (#40905203)
I tend to prefer the former, but it suffers from the indentation being way to large if the method name is really long.

That being said, there are other cases where I want to align things and "a specific size indent" doesn't work

SQL

    SELECT this_column,
           that_column
    FROM tablename
    WHERE this_column = 1
      AND that_column IS NOT NULL
Comments

    /* 
     * Blah blah blah
     * Note: this is interesting because (enough text to want newline)
     *       and also that blah blah
     */
There's lots of places where "alignment" makes sense.
Re:Python with Braces by MrJohz on Monday July 08, 2024 @09:41AM (#40905360)
For the SQL case, you can just use a different formatting that puts aligned items into blocks, something like:

    SELECT
      this_column, 
      that_column
    FROM tablename 
    WHERE
      this_column = 1
      AND that_column IS NOT NULL
(The AND token could go either where it is, or at the end of the previous line, depending on your preferences - I prefer the clarity of putting the operator first here over the alignment of the column names, but I can see both sides.)

It might not be your preference, but that's always going to be the case with formatting.

With the comments, that's a good point. I'd generally prefer to use double comments for anything that spans multiple lines, but if you're creating a formatter you need to handle any syntax thrown your way. You could try formatting it without the leading space, but that would be very unusual, or keep the leading space and have it as the one exception to the rule. Or just not format comments, I guess.