StumpyStrust
|
 |
«
Posted
2012-04-24 08:10:33 » |
|
So I was once told that there is something that is religious for coders. Something that some do one way and others another. Something that for some can not be changed. What is it? The curly brace/bracket. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void method(args....){ }
for(int j = 0; j <= i; j++){ }
public void method(args....) { }
for(int j = 0; j <= i; j++) { } |
Which religion are you? Before? or after? I like after....more white space means easier for me to read.
|
|
|
|
|
Riven
|
 |
«
Reply #1 - Posted
2012-04-24 08:41:19 » |
|
I converted from to about a year ago, due to having to code extensively in Javascript. It's madness. I know.
|
|
|
|
MrDodo
Senior Newbie 
|
 |
«
Reply #2 - Posted
2012-04-24 09:24:56 » |
|
Before! Always before!!!!
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Roquen
|
 |
«
Reply #3 - Posted
2012-04-24 09:37:52 » |
|
I'm totally fickle. Some constructs on same line, other after and my rules are fluid depending on my mood and the overall look.
|
|
|
|
|
princec
|
 |
«
Reply #4 - Posted
2012-04-24 09:46:26 » |
|
I've always used the Sun convention because it makes for slightly more compact code and vertical space is always at a premium. The more I can squeeze onto the screen at a time the better. Also all the example code and the default formatter in IDEs all use the Sun conventions. Don't be telling me to break my methods into smaller chunks now  Cas 
|
|
|
|
Regenuluz
|
 |
«
Reply #5 - Posted
2012-04-24 09:50:46 » |
|
I'm the first type of guy too ^_^ Just looks better, imo 
|
|
|
|
|
Scarzzurs
|
 |
«
Reply #6 - Posted
2012-04-24 10:11:36 » |
|
It's like brushing teeth or using the mouse with the other hand. I've always wanted to try using brackets on new line. I tried it for some time, really wanted it to work out. But in the end I went completely mad and switched back.
However, brackets on new line is really the best choice from an objective point of view, in my opinion, as it is more consistent and separate code from signature, giving a better view of the program structure. Currently, I will on rare occasions, if argument list is very long or lots of exceptions are being declared to be thrown, switch to bracket on a new line.
It does really seem like a religious question. Interestingly, some "atheists" have removed the brackets from their language entirely. However, it does seem to bring new problems and well, I've become religious I guess XD
- Scarzzurs
|
|
|
|
gimbal
|
 |
«
Reply #7 - Posted
2012-04-24 10:37:19 » |
|
I converted from to about a year ago, due to having to code extensively in Javascript. It's madness. I know. I switched too (only my change was a few years ago) - not because of any tool but just to comply. When everyone around you does it differently, it doesn't really pay to pigheadedly keep doing it the other way. Also I kept having to reconfigure source formatters. I used to prefer the "bracket under the code" way because I reasoned that with proper indenting it made it only too clear which two brackets make a pair. But now that I use the other way the argument has become quite feeble even to myself; the closing bracket shows which statement that it belongs too. Same difference really, but more compact.
|
|
|
|
|
princec
|
 |
«
Reply #8 - Posted
2012-04-24 10:42:48 » |
|
It's a shame that in this day and age auto-formatted source code editors (and concurrent source version control systems) have not become the standard. It should simply not matter where the whitespace is. It should look exactly like you like it to look, whoever wrote it. Cas 
|
|
|
|
Scarzzurs
|
 |
«
Reply #9 - Posted
2012-04-24 11:16:32 » |
|
@princec: Fair point. However most attempts at doing something like that I've seen has other downsides. For example Maple makes it very unintuitive to edit the otherwise beautifully formatted math expressions. Sometimes pressing the left arrow 3 or more times are required for moving one math character XD
- Scarzzurs
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Riven
|
 |
«
Reply #10 - Posted
2012-04-24 11:32:06 » |
|
Seems like it's settled. Boring. or ?
|
|
|
|
SwampChicken
|
 |
«
Reply #11 - Posted
2012-04-24 11:35:37 » |
|
If I'm editing someone else's code, I follow their style. If it's mine then it's usually 'before'.
|
|
|
|
|
princec
|
 |
«
Reply #12 - Posted
2012-04-24 11:50:10 » |
|
Always } else [if] { GFA Basic had autoformatted editing back in the late 80s on the Atari ST, with 3 different presentation styles. Cas 
|
|
|
|
Roquen
|
 |
«
Reply #13 - Posted
2012-04-24 11:55:13 » |
|
Back in the days of pre-history when I was an employee I had CVS set-up to auto-convert to a standard format prior for repo compares and storage it would auto-change to the local person's preference when pulling updates. I'd assume that some newer VC would allow this.
|
|
|
|
|
ReBirth
|
 |
«
Reply #14 - Posted
2012-04-24 12:55:14 » |
|
I always 1 2 3 4 5 6
| if (){
}else if(){
}else{ } |
|
|
|
|
appel
|
 |
«
Reply #15 - Posted
2012-04-24 13:42:29 » |
|
It's a shame that in this day and age auto-formatted source code editors (and concurrent source version control systems) have not become the standard. It should simply not matter where the whitespace is. It should look exactly like you like it to look, whoever wrote it. Cas  Problem is that source code is pure text file, formatted using spaces, tabs, newlines etc. Perhaps source code requires its own standard file format, whereas display of the code can be personalized. And I prefer
|
|
|
|
Cero
|
 |
«
Reply #16 - Posted
2012-04-24 13:45:49 » |
|
Always this. 1 2 3 4 5 6 7 8 9 10 11 12
| if () { bla } else if() { bla } else { bla } |
Everthing else, especially standard java code convention, looks horrible to me
|
|
|
|
BoBear2681
|
 |
«
Reply #17 - Posted
2012-04-24 14:53:08 » |
|
Sun's style when writing Java, K&R style when writing C. At work, some folks take the "curly brace on a separate line" to what I believe to be extremes, leaving you with code like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| try { doSomething(); x = getFoo(); } catch (IOException e) { handleError(e); logIt(e); } finally { closeStreams(); } |
|
|
|
|
|
loom_weaver
|
 |
«
Reply #18 - Posted
2012-04-24 14:57:40 » |
|
As long as it's consistent I don't really care. If it's my own code I use the standard Java convention.
|
|
|
|
|
|
|
jonjava
|
 |
«
Reply #20 - Posted
2012-04-24 16:27:28 » |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| void method () { for (int i = 0; i < 10; i++) { } }
VS
void method() { for(int i=0; i<10; i++) { } }
if (), for (), while () VS
if(), for(), while()
|
I sometimes mix (omg), but I prefer A. Also } else if { And { }
|
|
|
|
sproingie
|
 |
«
Reply #21 - Posted
2012-04-24 17:14:30 » |
|
GNU style. 1 2 3 4 5
| public void foo(bar) { blah.blah() yadda.yadda() } |
No not really. I think we can all agree that the GNU style is a bane upon the world and vexatious to the spirit  What I actually use is K&R style. Because K&R. Amen. Seriously tho it just depends on how long the class or method declaration is whether I cuddle the opening brace or not. If it runs over many lines, I'll put the opening brace on its own line. I stopped cuddling close braces for even conditional structures, resulting in what they call the "compact control readability style": 1 2 3 4 5 6
| if (blah} { ... natter natter natter ... } else { ... gromish gromish gromish ... } |
Basically, K&R style for control structures.
|
|
|
|
|
theagentd
|
 |
«
Reply #22 - Posted
2012-04-24 19:43:17 » |
|
What Religion Are You? Haruhiism infused with Oyashiro-sama. More generally known as Animeism. My daily praying involves clawing at my own neck while fighting gigantic monsters together with an alien, a time-traveller, an esper and a girl who doesn´t know she´s God. After converting I moved to a small village far north-east of Tokyo for convenience, but people are weird here. Everyone seem to completely avoid talking about some guy who disappeared a few years ago, and they also act really weird at times, so I started carrying around a bat for self defence. I´m also stuck in a time loop and attend a school in which I am the sole male member of the student council, which I am trying to turn into my personal harem. Fighting off frequent terrorist attacks by orange haired girls and the earlier mentioned gigantic monsters, every day is an adventure. In my spare time I like to play Japanese dating sims. Online I am known as the Capturing God due to my unmatched skill playing these games, which have even been acknowledged by Hell, from which I met a demon who requested my help. I am also a decent inventor. My latest inventions include a mobile phone diary that shows the future and a device which turn feelings into raw energy. This town is pretty small so rumors travel fast. I met a guy who was dating this really cute girl in my school, but then I heard that he was actually two-timing her! Rumors sure travel fast here! Last time I heard of him he was going on a boat trip with his girlfriend, but that was some time ago... People in my class are really strange. There´s this guy who always just sits there looking depressed while listening to his cassette player and then a guy who always brings guns and stuff to school every day. We also have this girl who´s handing out wooden stars to everyone, but she really doesn´t seem to attend school that much. There´s also this... uh... person who´s always wrapped up in a futon. To be honest I don´t even know if there´s actually a person inside it. Oh, did I mention that my laptop broke? Ah, no, it´s not like I´m bored to death or anything. 1 2 3 4 5
| if(bored){ watchAnime(); }else if(laptop.getStatus() != Status.BROKEN){ program(); } |
|
Myomyomyo.
|
|
|
sproingie
|
 |
«
Reply #23 - Posted
2012-04-24 20:10:59 » |
|
1
| }else if(laptop.getStatus() != Status.BROKEN){ |
Damn man, your spacebar broken? Well, at least you put spaces around the != anyway 
|
|
|
|
|
EgonOlsen
|
 |
«
Reply #24 - Posted
2012-04-24 20:13:21 » |
|
Before at home, after at work. I can live with both....
|
|
|
|
Roquen
|
 |
«
Reply #25 - Posted
2012-04-24 21:32:31 » |
|
1 2 3
| if (obj instanceof Object) { evilnessLevel=~-evilnessLevel; } else evilnessLevel = -~ evilnessLevel; |
|
|
|
|
|
UprightPath
|
 |
«
Reply #26 - Posted
2012-04-24 21:44:21 » |
|
1 2 3
| if (obj instanceof Object) { evilnessLevel=~-evilnessLevel; } else evilnessLevel = -~ evilnessLevel; |
HERESY! BURN IN THE FIRES OF HOLY INQUISITION!-- And yes, I know that the else never gets called. Ugh, but seriously? I hate the no-bracket single line control statement thing to a degree that I cannot describe without resulting to mashing the top row of character keys. In one of the classes where I had to program as a team, one of my team mates used it all the time. I had to add some code to his, and wasn't paying attention to whether he used them or not (Since I always use brackets) and ended up f**king up the code until I went back and reread everything. It was highly frustrating. I mean, if there's even a chance that you'll end up having to add a second line of code (Which should be about 99.99% of the GD time) you should preemptively add the brackets, just so you don't forget to do so when you go back. xD Also... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public class Fuu extends Foo implements Bar { public static Type staticVariable; public static void staticOperation() { }
private final Type finalInstanceVariable; private final Type finalInstanceVariable2; private Type instanceVariable; private Type instanceVariable2;
public Fuu() { }
public void operation(Type parameter, Type2 parameter2) { if (condition) { } else if (other condition) { } else { } } } |
|
|
|
|
Roquen
|
 |
«
Reply #27 - Posted
2012-04-24 22:07:19 » |
|
HERESY! BURN IN THE FIRES OF HOLY INQUISITION!-- And yes, I know that the else never gets called.
Not quite. Mere mortals (a.k.a people that don't deserve a swift kick in the pants) would write that as: (ignoring differences in tabs, brace placement, brace inclusion and method of inc/dec)
if (obj != null) evilnessLevel++; else evilnessLevel--;
Mahna mahna, too too doo too tooo, mahna mahna, too-too-to-too
|
|
|
|
|
StumpyStrust
|
 |
«
Reply #28 - Posted
2012-04-24 22:38:32 » |
|
Haha woh some how I knew that most people here were the "on the same line" and not "on new line" why? Because as many have said, its the way Sun did it and this is a java forum. I for one do what makes sense for me. If there are nested loops and if statements I like new lines so I know whats going on. (maybe its the inexperience there) but if its something simple or a bunch of catch cases I put stuff on a single line.
Actually, my code I think is horribly ugly because I don't document much...
@theagentd The very scary thing is I knew all the anime you were referencing...
|
|
|
|
|
princec
|
 |
«
Reply #29 - Posted
2012-04-24 23:43:55 » |
|
I used to not use curlies in one liners but now I always do because it makes it very easy to add and remove statements between 'em without introducing odd hard-to-spot errors or having to fiddle around manually typing them or removing them etc. to maintain some sort of consistency. Nowadays Eclipse puts them in for me automatically if I forget anyway. Cas 
|
|
|
|
|