HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 140017 thumbnail
User 306333 avatar

By daveschinkel
via codezest.com
Published: Dec 09 2008 / 12:22

There are two major annoyances when it comes to good code and readable code. Here are 2 things that really every team should ensure happens (at least in my opinion ).
  • 7
  • 22
  • 1486
  • 0

Comments

Add your comment
User 209464 avatar

willcode4beer replied ago:

1 votes Vote down Vote up Reply

1 & 3 I agree strongly with.
#2 I could care less, as long as placement is consistent with the entire group.

I voted down because this looks like the start of a pointless curlybrace war, and I'm sick of 'em

User 217678 avatar

mostlyharmless replied ago:

1 votes Vote down Vote up Reply

coding standards say... same line

http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html

Read more about industry standards at

http://www.dzone.com/links/software_development_standards.html

And I know those are java standards not javascript, but if I am working in a java shop, then we're going to follow through, especially since javascript does not have established industry standards.

User 217374 avatar

senfo replied ago:

3 votes Vote down Vote up Reply

Java coding standards have always put the curly braces on the same line. I've always disagreed with that format. Luckily, C# coding standards place the curly brace on the next line.

Actually, come to think of it, Java and JavaScript are the only two languages that I know of where it's preferred that you place the curly brace on the same line. Coding standards for C, C++ and C# all say to put it on the next line.

User 217678 avatar

mostlyharmless replied ago:

0 votes Vote down Vote up Reply

That's fair. The point is that there are established standards for your languages and that you follow them and no makup your own for arbitrary, and subjective reasons.

User 256617 avatar

dragmire replied ago:

0 votes Vote down Vote up Reply

Does it really matter what Sun/Java says?

Put the curly wherever it looks good for your team. Don't rely on the "industry standard" for defining where the damn curly goes.

User 326209 avatar

jkirstein replied ago:

-1 votes Vote down Vote up Reply

rubbish

User 239201 avatar

amphi replied ago:

0 votes Vote down Vote up Reply

http://en.wikipedia.org/wiki/Indent_style

I started with Whitesmiths style, then switched to Allman/BSD style, and finally to K&R 1TBS aka hugging brackets. I don't put brackets around single line conditionals though, since that *never* has been a source of errors for me. I also omit all those fluff spaces unless there is a comma. Additionally, I add empty lines here and there to break up bigger code chunks into separate logical blocks (e.g. AAAA B CC DDD - where A/B/D are methods of individual objects and C is an if+method call). If necessary I'll also prefix those blocks with a comment. (Well, that's my private style. Of course I do use the company's/project's style if there is any. It's easy enough with auto formatting. ;))

I used each of these 3 styles for a few years and in my experience it doesn't matter at all which one you're using. Each one offers enough visual hooks.

User 288015 avatar

noahz replied ago:

0 votes Vote down Vote up Reply

Why is this on the front page? Don't we have better things to think about than curly-brace religious wars?

User 240244 avatar

eric32 replied ago:

0 votes Vote down Vote up Reply

Maybe we should all write hungarian notation too!

User 218789 avatar

eelmore replied ago:

1 votes Vote down Vote up Reply

You argue that long methods are unequivocally bad. Then, you argue that people should waste lines of code with braces that stand on a line by themselves. This argument against the One-True-Brace-Style is worse than most....

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.