Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 8813 times)
0 Members and 1 Guest are viewing this topic.
Offline badlogicgames
« Reply #30 - Posted 2012-04-24 22:09:01 »

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.

this is my story as well.

http://www.badlogicgames.com - musings on Android and Java game development
Offline gouessej
« Reply #31 - Posted 2012-04-24 22:49:31 »

I do that:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
for(...)
     {
     }

void method(){
      ...
}

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


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

Offline sproingie

JGO Kernel


Medals: 202



« Reply #32 - Posted 2012-04-24 23:04:28 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline UprightPath
« Reply #33 - Posted 2012-04-24 23:11:04 »

Tabs.

Easier to delete/insert.

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #34 - Posted 2012-04-24 23:20:21 »

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! Smiley The indentation is plenty readable.

1  
2  
3  
4  
5  
6  
7  
8  
9  
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...

1  
2  
3  
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...

1  
2  
3  
4  
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. Smiley

I've taken to using "ignored" for empty catches, so it is obvious it is empty on purpose:

1  
2  
3  
4  
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(;;).

Offline sproingie

JGO Kernel


Medals: 202



« Reply #35 - Posted 2012-04-24 23:48:59 »

I've taken to using "ignored" for empty catches, so it is obvious it is empty on purpose:

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:

1  
2  
3  
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...

Offline ReBirth
« Reply #36 - Posted 2012-04-25 02:44:14 »

@theagentd
I'm Yuki-ism, problem?

Online theagentd
« Reply #37 - Posted 2012-04-25 03:29:06 »

@theagentd
I'm Yuki-ism, problem?
You like my landlady? O_o

Myomyomyo.
Offline R.D.

Senior Duke


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #38 - Posted 2012-04-25 07:43:15 »

Oh that's really funny Cheesy Sun made some code conventions and I use them, that said: Eclipse -> CTRL + SHIFT + F Smiley
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 :/ 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 .____.)
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #39 - Posted 2012-04-25 14:07:19 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #40 - Posted 2012-04-25 14:13:21 »

I think of over commenting as harmful.  Not only are you wasting time doing it, but it's distracting when you looking at code.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #41 - Posted 2012-04-25 15:33:44 »

I only comment for myself, stuff like FIXME and HACK and WTF and so on.  I'm often told I should comment more, but mostly the one who tells me is someone who writes screen after screen of useless coments that I have to strip out to actually understand the code. 

I like using method and parameter names that make their function obvious.  If I have to comment a method just to generally explain what it does, it isn't a well-written one.
Offline UprightPath
« Reply #42 - Posted 2012-04-25 20:28:41 »

Most of my comments are of the "Using 1-based indexing because of <Insert reason here>" (PreparedStatements Y U NO use 0 based indexing!?), "Starting iterator at i instead of 0 because of <Insert reason here>" and "Ending iterator at j instead of list.length because of <Insert reason here>".

Of, if I'm doing something hackish that's overly complicated for whatever reason, I try to explain what I am doing and how I think it should be done when I come back to it.

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #43 - Posted 2012-04-25 21:06:30 »

I have super strict formatting rules on myself:
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  
26  
27  
28  
29  
30  
31  
public class MyClass {
    public static final int OVER_9000 = 9001;
   
    private int coolnessLevel = OVER_9000;

    public void myMethod(int value) {
        ...;
    }
}

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

try {
    ...
}
catch(Exception exc) {
    exc.printStackTrace();
}

do {
    ...;
} while(...);


- ELSE, CATCH, and FINALLY, MUST BE ON THEIR OWN LINE OR YOU SHALL DIE Smiley
- There must be a space between parenthesis and curly braces.
- NEVER use curly braces for 1 line statements
- TABS, NEVER SPACES Angry

I never comment my code :/

Offline UprightPath
« Reply #44 - Posted 2012-04-25 21:16:44 »

- ELSE, CATCH, and FINALLY, MUST BE ON THEIR OWN LINE OR YOU SHALL DIE Smiley
- There must be a space between parenthesis and curly braces.
- ALWAYS use curly braces for 1 line statements
- TABS, NEVER SPACES Angry

I never comment my code :/

There, I fixed it for you! Har har.

Does anyone know why that convention/syntax is allowed/where it came from? I assume that there was a reason for there being this construct in so many languages, but for the life of me I can't understand why they'd add this special case that seems there only to hinder readability/maintainability.

>.> Sorry, this is one of my biggest syntax pet-peeves ever. It feels like giving a person a gun so that they can use to shoot themselves in the foot. xD

Offline sproingie

JGO Kernel


Medals: 202



« Reply #45 - Posted 2012-04-25 21:21:10 »

Does anyone know why that convention/syntax is allowed/where it came from?

C, of course.
Offline UprightPath
« Reply #46 - Posted 2012-04-25 21:29:06 »

Oh yes, of course it did.

What about the why for it?

Offline sproingie

JGO Kernel


Medals: 202



« Reply #47 - Posted 2012-04-25 21:37:30 »

Why?  C, of course.  C is its own rationale now.

Quote
1936 - Alonzo Church also invents every language that will ever be but does it better. His lambda calculus is ignored because it is insufficiently C-like. This criticism occurs in spite of the fact that C has not yet been invented.

http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html
Offline gimbal

JGO Knight


Medals: 25



« Reply #48 - Posted 2012-04-26 08:51:57 »

I think of over commenting as harmful.  Not only are you wasting time doing it, but it's distracting when you looking at code.

I see over-commenting as a signal that something is terribly wrong. Apparently your code is far from self-documenting.
Online princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #49 - Posted 2012-04-26 10:14:06 »

Self documenting code is a myth. It presumes a vast amount of background context which most people won't have. If you're documenting code for the sake of yourself, that's fine; but if you're documenting it because you want other people to use it or work on it, I wouldn't presume to think they know what's in your head. Something as simple as:
1  
double dist = dx *dx + dy * dy; // Get distance to gidrah

Why is it not a sqrt? Looks like a bug. You would probably leave an explanation of why you aren't sqrting it if you were expecting someone else to take over maintenance of that algorithm.

Cas Smiley

Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #50 - Posted 2012-04-26 10:53:07 »

That actually is a 'bug': the variable name is misleading and therefore requires a comment.

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

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #51 - Posted 2012-04-26 11:05:44 »

If you put that in to the context of how a mathematician describes formulae though you'd think even "dist" was too many characters. But still, even renaming it "distanceSquared", you might be curious to know why it works with squared distances vs. real distances. Etc. I know it's a bit of a straw man but there are lots of subtle variations on this.

Cas Smiley

Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #52 - Posted 2012-04-26 11:16:14 »

Triggering curiosity beats confusion any time.

Self-documenting (low level) code ftw.

Die, comments, die.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline 65K
« Reply #53 - Posted 2012-04-26 11:43:56 »

Self documenting code is a myth.
Very true.

Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #54 - Posted 2012-04-26 11:45:16 »

100% self documenting code is a myth, just like world peace is a myth. That doesn't mean we shouldn't strive to reach that goal.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Z-Man
« Reply #55 - Posted 2012-04-26 11:52:47 »

- TABS, NEVER SPACES Angry
WHY?!? Expand tabs to spaces >_<

As for curly braces, always on a new line. Partly because it's what I'm used to reading and partly because my CS teacher would not accept programs written any other way -_-

EDIT:
Oh and, this
Die, comments, die.
Offline gimbal

JGO Knight


Medals: 25



« Reply #56 - Posted 2012-04-26 12:18:51 »

Self documenting code is a myth.
Depends on how far you think it should go. I define self-documenting code as "code which you can read and understand". Of course by just reading the code you are not going to magically understand the context of the problems it is solving and/or the process it is part of, unless the problems are really simple of course Smiley

But that kind of documentation you are not going to capture in code comments either.

100% self documenting code is a myth, just like world peace is a myth. That doesn't mean we shouldn't strive to reach that goal.

Ha, now that I can relate to Smiley
Offline ReBirth
« Reply #57 - Posted 2012-04-26 13:22:52 »

because my CS teacher would not accept programs written any other way -_-
Huh, take them here  Angry

Offline BoBear2681

JGO Coder


Medals: 19



« Reply #58 - Posted 2012-04-26 14:31:29 »

Quote
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.

In all seriousness, I'm guilty of over-commenting code.  I'm trying to scale it back. But one of my pet peeves is folks who use doc comment generators but don't actually edit the generated comments, leaving you with fun stuff like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
/**
 * Gets the foo.
 * @param name
 *      the name
 * @return
 *      the foo
 */

public Foo getFoo(String name) {
   ...
}


Either do it right, or don't do it at all!
Offline ReBirth
« Reply #59 - Posted 2012-04-26 14:49:22 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
/**
 * Gets the foo.
 * @param name
 *      the name
 * @return
 *      the foo
 */

public Foo getFoo(String name) {
   ...
}

"You don't say?"

Comments only work out when you're making a lib.

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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!