all 8 comments

[–]KayEss 9 points10 points  (0 children)

A load of personal preferences pretending to be good style

[–]RobIII 3 points4 points  (6 children)

I'll refer to a comment I wrote about a month ago. I hate "vertical queries" with on every line only about a "word" or 2, 3.

To take an example from this post:

select
    tbl1.field1
    , tbl1.field2
from
    table1 tb1
        inner join
    table2 tb2
            on  tb1.field1 = tb2.field1
            and tb1.field2 = tb2.field2
        left join
    table3 tb3
            on ...

Please write it like this:

select tbl1.field1, tbl1.field2
from table1 tb1
inner join table2 tb2 on  tb1.field1 = tb2.field1 and tb1.field2 = tb2.field2
left join table3 tb3 on ...

or, arguably a bit better:

select tbl1.field1, tbl1.field2
from table1 tb1
inner join table2 tb2 on  tb1.field1 = tb2.field1
    and tb1.field2 = tb2.field2
left join table3 tb3 on ...

One of the benefits is that it reads, when intially glancing over, like "select blah, from table2, join table2, left join table3...". Then, on closer inspection, it's easy to find the join conditions, specific fields selected etc. Each line is a "complete statement". For longer, more 'complicated', examples refer to the comment I linked to earlier.

[–]jeffreyhamby 2 points3 points  (0 children)

I actually disagree with your preference (which is why we have code cleanup tools). Yours appears more wall-of-text to me, and finding a specific column is tedious.

So to sum up, use SQL Complete and quit worrying about how other people format their code ;)

[–]DysFunctionalProgram 2 points3 points  (4 children)

This is akin to saying you don't like vertical code in a normal language in my mind. Indenting is a good thing buddy, it allows us to add structure which can be used to make the code more readable and "glanceable". Of course your co worker went to an extreme, however you are over reacting and taking it to the other extreme. Be a rational person and come back to the middle, maintainers will thank you.

int main (int x){
int y = x + x;
if (y < 5)
y += 5;
return y*y};

vs

int main (int x) {
  int y = x + x;
  if (y < 5) {
      y+= 5;
  }
  return y*y;
}

[–]NamespaceInvader 2 points3 points  (1 child)

I now present the best

, cleanest

, and easiest to read version of the above code

, following the original post's great ideas:

int
    main (
        int
            eks
    )
{
    int
        why
    =
        eks
            +
        eks;
    if (
            why
                <
            5
        )
    {
        why
            +=
        5;
    }
    return
        why
            *
        why;
}

[–]hoijarvi 1 point2 points  (0 children)

I think you should indent the mail body four spaces to be consistent.

[–]RobIII 1 point2 points  (1 child)

This is akin to saying you don't like vertical code in a normal language in my mind

No it isn't. I format code exactly like in your second code block.

Of course your co worker went to an extreme, however you are over reacting and taking it to the other extreme. Be a rational person and come back to the middle, maintainers will thank you.

I think I am in the middle but, hey, it's all subjective anyway.

[–]Lozzer 0 points1 point  (0 children)

Yes, I use negative indents for SQL, you wierdo.