What Religion Are You?


// 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 {

}

GNU style.


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”:


if (blah} {
  ... natter natter natter ...
}
else {
  ... gromish gromish gromish ...
}

Basically, K&R style for control structures.

[quote]What Religion Are You?
[/quote]
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.

if(bored){
    watchAnime();
}else if(laptop.getStatus() != Status.BROKEN){
     program();
}

}else if(laptop.getStatus() != Status.BROKEN){

Damn man, your spacebar broken? Well, at least you put spaces around the != anyway :slight_smile:

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


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 fucking 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…


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
        }
    }
}

Not quite. Mere mortals (a.k.a people that don’t deserve a swift kick in the pants) would write that as:
[spoiler]
(ignoring differences in tabs, brace placement, brace inclusion and method of inc/dec)
if (obj != null) evilnessLevel++; else evilnessLevel--;
[/spoiler]

Mahna mahna, too too doo too tooo, mahna mahna, too-too-to-too

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…

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 :slight_smile:

this is my story as well.

I do that:


for(...)
     {
     }

void method(){
      ...
}

if(...)
    {
    }
else
    {if(...)
           {
           }
    }

I thought you were really speaking about religion. Actually, I’m atheist :persecutioncomplex:

How about this one: spaces or tabs? I say it’s not really important which you use, it just reveals whether you’re a decent human being or not :wink:

Tabs.

Easier to delete/insert.

I use single line if/else/for/etc only if the content fits on a single line. For if, the else if and else get their own line. If a line wraps, I put in the braces for readability. People who say that they need braces “just in case” to avoid hard to find errors when editing code… if you are really paying such little attention, maybe you shouldn’t be editing the code! :slight_smile: The indentation is plenty readable.


if (something) go();
if (meow)
   print("cat");
else
   print("not cat!");
if (moo) {
   throw new RuntimeException("sdakjfnasjkfnkjsnfjkaasdf" +
      "more stuff");
}

What annoys me is Eclipse’s formatter does this, and there is no way to change it…


if (meow)
   print("cat");
else if (moo) print("cow");

In which case I either add braces (which I don’t like since it adds a line) or use an empty comment…


if (meow)
   print("cat");
else if (moo) //
   print("cow");

Tabs of course. The only reason to use spaces is ascii art, which is a dumb reason. :slight_smile:

I’ve taken to using “ignored” for empty catches, so it is obvious it is empty on purpose:


try {
   // ...
} catch (Exception ignored) {
}

What else do I like to be consistent with… I like using while(true) and an if to break when there is no counter variable, instead of a nasty hard to read for(;;).

What’s neat is IntelliJ has an inspection that warns you about empty catch blocks … unless the exception is named “ignored”.

What I find more useful is to replace the boilerplate that catches and ignores (or just prints) exceptions with something like this:


catch (SomeException ex) {
  throw new RuntimeException(ex); // XXX generated handler
}

Though these days I haven’t been working in a language with checked exceptions, so I haven’t really needed that…

@theagentd
I’m Yuki-ism, problem?

You like my landlady? O_o

Oh that’s really funny :smiley: Sun made some code conventions and I use them, that said: Eclipse -> CTRL + SHIFT + F :slight_smile:
I have some small modifications on may line width und empty lines but that’s it.

Something new, how about commenting?
Are you one of those types who comment everything or just what you really need?

I use both. For Engine stuff I just comment everything. Mostly because I have to :confused: But for my own code I don’t give a damn about it and jsut add comments when the method is really complicated (Tho my current game is commented because my Prof wanted it .____.)

I comment anything that is nonobvious. That is rather subjective, but as I hate to comment my code, it forces me to write code that is easy to grasp. Commenting getters and settters is out of the question.