Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3
  ignore  |  Print  
  What Religion Are You?  (Read 8608 times)
0 Members and 1 Guest are viewing this topic.
Offline 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....){    //<----- on the same line as the method

}

for(int j = 0; j <= i; j++){        //<------- same line as the loop

}

//The other way

public void method(args....)
{                                        //<------ After the method

}

for(int j = 0; j <= i; j++)
{                                        //<------- after the loop

}


Which religion are you? Before? or after?

I like after....more white space means easier for me to read.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-04-24 08:41:19 »

I converted from
1  
2  
3  
4  
for(...)
{

}
to
1  
2  
3  
for(...) {

}
about a year ago, due to having to code extensively in Javascript.

It's madness. I know.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline MrDodo

Senior Newbie





« Reply #2 - Posted 2012-04-24 09:24:56 »

Before! Always before!!!!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.
Offline princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« 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  Roll Eyes

Cas Smiley

Offline Regenuluz
« Reply #5 - Posted 2012-04-24 09:50:46 »

I'm the first type of guy too ^_^ Just looks better, imo Tongue
Offline 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

My games and Projects:
BlastingPixels.com,
Old website
Offline gimbal

JGO Knight


Medals: 25



« Reply #7 - Posted 2012-04-24 10:37:19 »

I converted from
1  
2  
3  
4  
for(...)
{

}
to
1  
2  
3  
for(...) {

}
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.
Offline princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« 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 Smiley

Offline 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

My games and Projects:
BlastingPixels.com,
Old website
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2012-04-24 11:32:06 »

Seems like it's settled. Boring.

1  
2  
}
else {
or
1  
} else {
?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline 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'.
Offline princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« 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 Smiley

Offline 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.
Offline ReBirth
« Reply #14 - Posted 2012-04-24 12:55:14 »

I always
1  
2  
3  
4  
5  
6  
if (){

}else if(){

}else{
}

Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« 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 Smiley

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
1  
2  
if() {
}

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline 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

Offline BoBear2681

JGO Coder


Medals: 18



« 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();
}

Offline loom_weaver

JGO Coder


Medals: 17



« 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.
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Reply #19 - Posted 2012-04-24 16:27:20 »

I follow the "Clean Code" principals.

If it's easy to read, then well, write like that.  Pointing

And fact is, new lines, curly braces, are just semantics that can clutter readability.

http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline 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  
// white space before braces or no?

void method () { // A
for (int i = 0; i < 10; i++) {
 }
}

VS

void method() { // B
for(int i=0; i<10; i++) {
 }
}

if (), for (), while () // A

VS

if(), for(), while() // B


I sometimes mix (omg), but I prefer A.

Also } else if {

And {

}

Offline sproingie

JGO Kernel


Medals: 201



« 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 Wink

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.


Offline theagentd
« Reply #22 - Posted 2012-04-24 19:43:17 »

Quote
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.
Offline sproingie

JGO Kernel


Medals: 201



« 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 Smiley
Offline EgonOlsen
« Reply #24 - Posted 2012-04-24 20:13:21 »

Before at home, after at work. I can live with both....

Offline Roquen
« Reply #25 - Posted 2012-04-24 21:32:31 »

1  
2  
3  
if (obj instanceof Object) {
   evilnessLevel=~-evilnessLevel;
} else evilnessLevel = -~ evilnessLevel;

Offline 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() {
        //statement
   }

    private final Type finalInstanceVariable;
    private final Type finalInstanceVariable2;
    private Type instanceVariable;
    private Type instanceVariable2;

    public Fuu() {
        //statement
   }

    public void operation(Type parameter, Type2 parameter2) {
        if (condition) {
            //statement
       } else if (other condition) {
            //statement
       } else {
            //statement
       }
    }
}

Offline 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
Offline 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...

Offline princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« 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 Smiley

Pages: [1] 2 3
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (33 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!