News for hackers. Stuff that matters.
Re:How I write SQL by ebbv on Wednesday May 01, 2013 @01:16PM (#5639263)
No, no, no. Comma first variable listing is the worst thing ever in the history of the world.

Having the comma in the proper place has such a negligible cost (oh no I might have to delete the comma on the last element and add it to the formerly-last element!), and having it like this looks so god awful and doesn't really save you anything if you're swapping the first element instead of the last one.

Re:How I write SQL by unoti on Wednesday May 01, 2013 @01:26PM (#5639345)
The sensibilities for everything you just said are entirely subjective, and change as you are exposed to them. If you spend all day every day writing SQL, it is different than if you do it a little here and there. The entire codebase of Oracle Apps looks like this, so I found I grew accustomed to it over time and saw the benefits. Editing commas actually can be significant in terms of time and drag (this is even more apparent when edit Erlang).

Being very dogmatic, and in a discussion of ideas saying "that's the worst thing in the world" is easily worse than comma placement. So surely commas as indentation isn't the worst thing in the world.

Re:How I write SQL by genwin on Wednesday May 01, 2013 @02:16PM (#5639768)
I do SQL most days. Commas at the end of the line is more advantageous than not, in my book. I find this best:

  select
      Field1,
      Field2,
      AnotherField
  from
      Table1
So clean, so consistent! No all-uppercase that adds almost no benefit at significant cost. Fields lined up for easy reading and editing.

The comma controversy could be eliminated if the SQL standard was like Go's, where even the last line would have a comma.

Re:How I write SQL by ebbv on Wednesday May 01, 2013 @02:02PM (#5639661)
It's not the worst thing in the world. It's the worst thing in the history of the world. Get it right, gosh.

Seriously, though, hideous syntax is bad. It makes life miserable for everyone who has to work on your code after you. Don't do it, no matter what good reasons you think you have.

Re:How I write SQL by rosser on Wednesday May 01, 2013 @02:09PM (#5639712)
"Ugly" is a subjective judgement. "Worst thing in the history of the world" is a subjective judgement, and egregious hyperbole, to boot. Saying that mitigates pretty much all the credibility of any rational, non-hyperbolic argument you might also have offered in support of your point.

I find having to re-run my query because I forgot to delete the comma following the penultimate item in the SELECT list when I commented the ultimate one out "ugly".

Additionally, everyone I have ever explained this concept to has said some variation of, "Wow, that's a great idea. Thanks!" No one has ever said, "That's the worst thing in the history of the world" ... until you.

I've been doing database work professionally for a decade now. I've explained this concept to a lot of people.

Re:How I write SQL by ebbv on Wednesday May 01, 2013 @02:26PM (#5639842)
Chances are if you're explaining this to someone they have less experience than you so they wouldn't be in a position to tell you that this is a bad practice.

Like I said, objectively, you're just moving the extra work from moving around the last element to moving around the first element. You're not really saving any time. Plus even if you accept the argument that you are saving time (pretend you live in a world where you never move the first element) the time you save is negligible.

If you hadn't resorted to this ugly syntax, you should have developed habits that lead you to fix your commas whenever you move the last element around.

Obviously you can do what you want, but if you were on my team, I would not allow this syntax.

Re:How I write SQL by btilly on Wednesday May 01, 2013 @02:48PM (#5639995)
Like I said, objectively, you're just moving the extra work from moving around the last element to moving around the first element.

Except that moving the last element (more specifically appending after it) is by far the more common operation. And when you mess up on the first element, it is visually obvious that you have done so.

If you hadn't resorted to this ugly syntax, you should have developed habits that lead you to fix your commas whenever you move the last element around.

I worked with SQL for years, and never developed the habit reliably enough. Once I was introduced to the idea of the leading comma, I noticed the difference.

Obviously you can do what you want, but if you were on my team, I would not allow this syntax.

Then let's both be glad that I'm not on your team, because there are some co-workers that I don't want to have to put up with.

Re:How I write SQL by rosser on Wednesday May 01, 2013 @02:49PM (#5640005)
To speak frankly, you seem pretty belligerent in your crusade against the comma-firsters. For whatever reason, this is apparently holy war territory for you, and you're willing to make assumptions about me as a person, and my abilities as a technologist, based on where I put a goddamned comma.

Thanks for that.

Re:How I write SQL by btilly on Wednesday May 01, 2013 @01:43PM (#5639483)
My experience.

Changed formatting is a shock the first time. But it does not take long to retrain yourself to find it aesthetically more pleasing.

When you're making a quick fix to a batch job that does not hit the problematic query for 30 minutes, the cost of messing up the comma is 30 minutes. (Yeah, I know, it all should be properly factored out, and unit tested. But there is a lot of lightly tested code in the real world that behaves just like I said.) Because SQL is stored as plain text, there is real value in making your mental compiler have to do no work to notice stupid syntactical stuff.

Re:How I write SQL by garblegarble on Wednesday May 01, 2013 @02:09PM (#5639705)
Couldn't you use an IDE that understands SQL? IntelliJ does this - it recognises the SQL dialect you're using and can even validate against the tables & columns in your schema
Re:How I write SQL by btilly on Wednesday May 01, 2013 @02:57PM (#5640057)
Discussing IDEs is a different religious war. Outside of the Java world, people are not so wedded to IDEs.

Going back to my last job that was mostly SQL, I was working in Perl, with SQL embedded in TT templates. Good luck finding an IDE that understands that.

In that job the comma placement was critical. Which column would be the last column would depend on what options the report was being generated with. The point is that people would ask for many variations on the same report. One person would want a top level view, another would want to break out event type, another would want to break it out by which type of advertising campaign was thrown at it - and all were being generated out of the same templated SQL so I didn't have to maintain code in parallel. But the result is that in the code I couldn't make assumptions about which column was going to wind up being last.

Thanks to leading comma formatting, it was sufficient to require that the FIRST field stayed the same. Which proved to never be a problem.

Re:How I write SQL by ebbv on Wednesday May 01, 2013 @02:01PM (#5639649)
That's a methodology problem you're describing.

The solution should not be hideous syntax.

Re:How I write SQL by btilly on Wednesday May 01, 2013 @03:02PM (#5640091)
There are a ton of companies out there doing interesting things that are willing to pay well for working on code that has that methodology problem. But they are not willing to undertake a full rewrite of their system at the outset before you can start doing anything useful.

At that point you can choose which is more important - the religious war or getting on with your life. When I encounter things like that my vote is a bit of both. I bring habits that allow me to cope with the methodological problem, and incrementally try to create a space where I don't have a problem.

In the process I've found that my preference for trailing commas was a useless idiosyncrasy that I could live without. When I tried living without it, I quickly found that leading commas made my life more pleasant, and I learned to like that formatting style.

Re:How I write SQL by jradakov on Wednesday May 01, 2013 @01:28PM (#5639358)
I don't like having comma first listings, but it makes it incredibly easy to comment out parts of a query. I find commenting out parts of a query essential when trying to debug really long, complex queries.
Re:How I write SQL by mmsimanga on Wednesday May 01, 2013 @02:14PM (#5639745)
Not sure why the strenuous objection to the comma first. I too code that way and a couple of SQL formatting tools such as http://poorsql.com/ have the comma first as the default setting. An added advantage to the one mentioned by the original comment is being able to utilise column editing features.
Re:How I write SQL by hdctambien on Wednesday May 01, 2013 @01:21PM (#5639307)
Why is "after the element" the proper place for a comma?
Re:How I write SQL by jkeel on Wednesday May 01, 2013 @01:30PM (#5639387)
That's what I was wondering. The comma is just a separator. Plus it's only really needed BEFORE each field not after the preceding field.
Re:How I write SQL by rtfeldman on Wednesday May 01, 2013 @01:29PM (#5639366)
That's where it goes in English.
Re:How I write SQL by noblethrasher on Wednesday May 01, 2013 @01:26PM (#5639341)
It's probably more pleasent and easier to read for the next person.
Re:How I write SQL by hdctambien on Wednesday May 01, 2013 @01:35PM (#5639420)
(I can't reply to my reply)

Comma first seems more consistent to me.... unless you write your WHERE clauses like this:

WHERE a=b AND

a=d AND

e=f

Re:How I write SQL by ebbv on Wednesday May 01, 2013 @02:04PM (#5639674)
The same reason that you should put spaces before and after your logical operators. The same reason you should use consistent spacing on the left and right parenthesis. The same reason you should use caps for the SQL and lower case for all table and field names.

Because it makes your SQL more legible.

In english, commas go after the previous word, not before the next word. The syntax is the same for all programming languages. The fact that most compilers and interpreters don't require it is not an excuse for abusing it.

Re:How I write SQL by cptskippy on Wednesday May 01, 2013 @02:34PM (#5639907)
I disagree with you regarding legibility. I've been using commas like this in SQL for 10 years and I find it to be much more legible and functional this way.

Besides the subjective argument of legibility, what other benefits does it have?

Having a comma preceding something is an indicator that it is one of many. When debugging you can easily comment out the column, or table from a query.

Re:How I write SQL by ebbv on Wednesday May 01, 2013 @03:03PM (#5640092)
Again, you can comment out lines with the normal syntax too. There's no reason for this gimmick syntax. In theory it makes the last 2 elements easier to deal with but it makes the first two harder. It's silly, and it's ugly.
Re:How I write SQL by dennisgorelik on Wednesday May 01, 2013 @08:22PM (#5641709)
Lowercase for table names? I think table names should be in PascalCase.

And I personally prefer the rest of SQL to be in lowercase, so it does not attract too much attention. Usually in SQL table names and column names is the most important information.