badlogicgames
|
 |
«
Reply #30 - Posted
2012-04-25 00:09:01 » |
|
I converted from to about a year ago, due to having to code extensively in Javascript. It's madness. I know. this is my story as well.
|
|
|
|
gouessej
|
 |
«
Reply #31 - Posted
2012-04-25 00: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 
|
|
|
|
sproingie
|
 |
«
Reply #32 - Posted
2012-04-25 01: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 
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
UprightPath
|
 |
«
Reply #33 - Posted
2012-04-25 01:11:04 » |
|
Tabs.
Easier to delete/insert.
|
|
|
|
Nate
|
 |
«
Reply #34 - Posted
2012-04-25 01: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!  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.  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(;; ).
|
|
|
|
sproingie
|
 |
«
Reply #35 - Posted
2012-04-25 01: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); } |
Though these days I haven't been working in a language with checked exceptions, so I haven't really needed that...
|
|
|
|
|
ReBirth
|
 |
«
Reply #36 - Posted
2012-04-25 04:44:14 » |
|
@theagentd I'm Yuki-ism, problem?
|
|
|
|
theagentd
|
 |
«
Reply #37 - Posted
2012-04-25 05:29:06 » |
|
@theagentd I'm Yuki-ism, problem?
You like my landlady? O_o
|
Myomyomyo.
|
|
|
R.D.
|
 |
«
Reply #38 - Posted
2012-04-25 09:43:15 » |
|
Oh that's really funny  Sun made some code conventions and I use them, that said: Eclipse -> CTRL + SHIFT + F 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 .____.)
|
|
|
|
Riven
|
 |
«
Reply #39 - Posted
2012-04-25 16: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.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Roquen
|
 |
«
Reply #40 - Posted
2012-04-25 16: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.
|
|
|
|
|
sproingie
|
 |
«
Reply #41 - Posted
2012-04-25 17: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.
|
|
|
|
|
UprightPath
|
 |
«
Reply #42 - Posted
2012-04-25 22: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.
|
|
|
|
ra4king
|
 |
«
Reply #43 - Posted
2012-04-25 23: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  - There must be a space between parenthesis and curly braces. - NEVER use curly braces for 1 line statements - TABS, NEVER SPACES  I never comment my code :/
|
|
|
|
UprightPath
|
 |
«
Reply #44 - Posted
2012-04-25 23:16:44 » |
|
- ELSE, CATCH, and FINALLY, MUST BE ON THEIR OWN LINE OR YOU SHALL DIE  - There must be a space between parenthesis and curly braces. - ALWAYS use curly braces for 1 line statements - TABS, NEVER SPACES  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
|
|
|
|
sproingie
|
 |
«
Reply #45 - Posted
2012-04-25 23:21:10 » |
|
Does anyone know why that convention/syntax is allowed/where it came from?
C, of course.
|
|
|
|
|
UprightPath
|
 |
«
Reply #46 - Posted
2012-04-25 23:29:06 » |
|
Oh yes, of course it did.
What about the why for it?
|
|
|
|
|
|
gimbal
|
 |
«
Reply #48 - Posted
2012-04-26 10: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.
|
|
|
|
|
princec
|
 |
«
Reply #49 - Posted
2012-04-26 12: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; |
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 
|
|
|
|
Riven
|
 |
«
Reply #50 - Posted
2012-04-26 12:53:07 » |
|
That actually is a 'bug': the variable name is misleading and therefore requires a comment.
|
|
|
|
princec
|
 |
«
Reply #51 - Posted
2012-04-26 13: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 
|
|
|
|
Riven
|
 |
«
Reply #52 - Posted
2012-04-26 13:16:14 » |
|
Triggering curiosity beats confusion any time.
Self-documenting (low level) code ftw.
Die, comments, die.
|
|
|
|
65K
|
 |
«
Reply #53 - Posted
2012-04-26 13:43:56 » |
|
Self documenting code is a myth.
Very true.
|
|
|
|
Riven
|
 |
«
Reply #54 - Posted
2012-04-26 13:45:16 » |
|
Self documenting code is a myth.
Very true. 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.
|
|
|
|
Z-Man
|
 |
«
Reply #55 - Posted
2012-04-26 13:52:47 » |
|
- TABS, NEVER SPACES  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.
|
|
|
|
|
gimbal
|
 |
«
Reply #56 - Posted
2012-04-26 14: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  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 
|
|
|
|
|
ReBirth
|
 |
«
Reply #57 - Posted
2012-04-26 15:22:52 » |
|
because my CS teacher would not accept programs written any other way -_-
Huh, take them here 
|
|
|
|
BoBear2681
|
 |
«
Reply #58 - Posted
2012-04-26 16:31:29 » |
|
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
| public Foo getFoo(String name) { ... }
|
Either do it right, or don't do it at all!
|
|
|
|
|
ReBirth
|
 |
«
Reply #59 - Posted
2012-04-26 16:49:22 » |
|
1 2 3 4 5 6 7 8 9 10
| public Foo getFoo(String name) { ... }
|
"You don't say?" Comments only work out when you're making a lib.
|
|
|
|
|