masteryoom
|
 |
«
Reply #30 - Posted
2012-11-23 06:57:16 » |
|
I *have* to have every single command in a method on the same line like so: 1 2 3 4 5 6 7 8 9 10 11 12 13
| public void method(){ if (thing == otherthing){ System.out.println("Yay!"); System.out.println("Cool!"); }else { System.out.println("No!!"); System.out.println("The world is about to die!!"); } } |
This excepts comments (which I don't really use anyway  ) I can't stand it being like this: 1 2 3 4 5 6 7 8 9 10 11 12 13
| public void method(){ if (thing == otherthing){ System.out.println("Yay!"); System.out.println("Cool!"); }else { System.out.println("No!!"); System.out.println("The world is about to die!!"); } } |
(I also like to have my } s indented (especially })  )
|
|
|
|
ra4king
|
 |
«
Reply #31 - Posted
2012-11-23 07:09:35 » |
|
Yeah that's called proper formatting. But "} else {"?!? No. NO. It has to be "}\n else {"
|
|
|
|
matheus23
|
 |
«
Reply #32 - Posted
2012-11-23 14:57:14 » |
|
Yeah that's called proper formatting. But "} else {"?!? No. NO. It has to be "}\n else {"
for me it's 1 2 3 4 5
| if (blah) { goAndEhhNaahForgetIt(); } else { whatElse("?"); } |
|
|
|
|
Games published by our own members! Check 'em out!
|
|
ra4king
|
 |
«
Reply #33 - Posted
2012-11-23 19:57:42 » |
|
Yeah that's called proper formatting. But "} else {"?!? No. NO. It has to be "}\n else {"
for me it's 1 2 3 4 5
| if (blah) { goAndEhhNaahForgetIt(); } else { whatElse("?"); } |
Heathen! Blasphemy! 
|
|
|
|
erikd
|
 |
«
Reply #34 - Posted
2012-11-23 20:33:56 » |
|
Well, I like things to be as consistent as possible, so I'd go with matheus23's way. No "//if body is only 1 line, *don't* use brackets" because imho that serves no purpose other than making the syntax less consistent/simple.
But hey, at the end of the day formatting rules are quite unimportant when it comes to code readability.
Clean, well written, easy to understand and consistent code goes way beyond things like formatting rules. As a simple example, if you look up "double checked locking" for singletons; there's no way any formatting can make that sort of gross uglyness even remotely readable (or good practice for that matter). If a singleton for some reason really makes sense (it usually doesn't), I'd use an enum. Or even just write static methods.
|
|
|
|
sproingie
|
 |
«
Reply #35 - Posted
2012-11-26 05:04:37 » |
|
cuddled-else is hardly "blasphemy", it's very traditional. However, I've gotten to like "compact control readability style" which uncuddles the else from the closing brace of the if, making all the control structures line up at the left column of the code.
As for double-checked locking, it works perfectly fine as of 1.5 ... but yeah it's still ugly. I always preferred the "initialization on demand holder idiom" anyway when I'm not using a proper DI container.
|
|
|
|
princec
|
 |
«
Reply #36 - Posted
2012-11-26 10:32:07 » |
|
Cuddly code is nice, and wants to be your friend. Personally I just went with the Sun Java standards way back whenever they were defined and now all it is is a matter of brain-pattern-matching for me. If something doesn't immediately instantly match the pattern I am expecting just by literally glancing at it - totally subconsciously - it looks wrong and my OCD forces me to fix it. Or rather Eclipse's autoformatter. This is all part of programming; seeing recognisable patterns in the shape of code at a glance helps us know that it is written correctly, in our own minds; a missing bracket for example, and the indentation goes mental. What is especially annoying in this day and age is that code is still basically uniquely text-file based and designed to work with version control systems that work on the concept of "lines" rather than ASTs. In a sensible world, all code would look exactly as we want it to look while we're editing it, in much the same way as the syntax colouring in my editor is mine and mine alone. Code would always be autoformatted, and autoformatted exactly in the way we like, with a learning system that learns formats from us. And then when it went into version control it would be compared semantically rather than purely syntactically; or at the very least, compared simply with all whitespace stripped. Cas 
|
|
|
|
Best Username Ever
|
 |
«
Reply #37 - Posted
2012-11-26 21:45:10 » |
|
cuddled-else is hardly "blasphemy", it's very traditional. If you have to describe something about coding as "traditional," then...  compared simply with all whitespace stripped.
publicclassLikeThis? 
|
|
|
|
BoBear2681
|
 |
«
Reply #38 - Posted
2012-11-26 22:22:54 » |
|
compared simply with all whitespace stripped.
publicclassLikeThis?  Not to mention that for some languages, whitespace is significant, meaning such a VCS would be useless for those languages. Really slick idea though. Eclipse already does a "Java structure compare" out of the box when committing to CVS (which for some reason my eyes always glaze right over), so it does seem others have attempted to bolt on such ideas to existing version control, in one form or another.
|
|
|
|
princec
|
 |
«
Reply #39 - Posted
2012-11-26 23:02:03 » |
|
Yup - so "all it needs" is a version control system designed to work after whitespace is removed. I have a funny feeling it might actually be a lot better than the crap we deal with right now. Cas 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
sproingie
|
 |
«
Reply #40 - Posted
2012-11-27 01:51:53 » |
|
For all its other colossal failings, ClearCase is capable of understanding code structure. It just takes a $200/hr Certified ClearCase Admin to do anything with that functionality. Another IBM tool, the ancestor to Eclipse, Visual Age for Java, had the right idea, which was to store the code in a database, much as Smalltalk stored it in the system image.
Of course, only IBM could name a product "VAJ"
|
|
|
|
deepthought
|
 |
«
Reply #41 - Posted
2012-11-27 02:45:56 » |
|
I end up with tons of white space between things like if statements or loops
|
Mad Scientist
|
|
|
JESTERRRRRR
|
 |
«
Reply #42 - Posted
2012-11-27 03:06:48 » |
|
}else {
VOMIT
everything needs new lines.. perhaps this is why my razers scroll wheel has died so young
|
|
|
|
ra4king
|
 |
«
Reply #43 - Posted
2012-11-27 22:02:30 » |
|
}else {
VOMIT
everything needs new lines.. perhaps this is why my razers scroll wheel has died so young
Be my new best friend.
|
|
|
|
Sickan
|
 |
«
Reply #44 - Posted
2012-11-28 15:38:15 » |
|
Compact code is best code. Spare your return keys and scrolling wheels, write proper code! 1 2 3 4 5
| if(condition) { System.out.println("Steve Jobs is dead!"); } else { System.out.println("Rick Astley is dead!"); } |
|
|
|
|
deepthought
|
 |
«
Reply #45 - Posted
2012-11-28 21:12:11 » |
|
Compact code is best code. Spare your return keys and scrolling wheels, write proper code!
my return key is fine. my WASD keys, however have the letters worn off.
|
Mad Scientist
|
|
|
Cero
|
 |
«
Reply #46 - Posted
2012-11-28 22:07:05 » |
|
Im quite strict about that stuff and hate the java usual way readability is of the up most importance 1 2 3 4 5 6 7 8 9 10 11
| public void method() { if (thing == otherthing) { System.out.println("Yay!"); } else { System.out.println("No!!"); } } |
|
|
|
|
ra4king
|
 |
«
Reply #47 - Posted
2012-11-28 23:10:11 » |
|
Im quite strict about that stuff and hate the java usual way readability is of the up most importance 1 2 3 4 5 6 7 8 9 10 11
| public void method() { if (thing == otherthing) { System.out.println("Yay!"); } else { System.out.println("No!!"); } } |
I think I just threw up in my mouth a bit. 1 2 3 4 5 6
| public void method() { if(thing == otherthing) System.out.println("Yay!"); else System.out.println("No!!"); } |
|
|
|
|
Riven
|
 |
«
Reply #48 - Posted
2012-11-28 23:13:10 » |
|
Agreeing to disagree is actually a nice thing.
Shall we end this mindless discussion?
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Best Username Ever
|
 |
«
Reply #49 - Posted
2012-11-28 23:17:33 » |
|
Nope. 1
| System.out.println(thing == otherThing ? "Yay!" : "No!!"); |
|
|
|
|
sproingie
|
 |
«
Reply #50 - Posted
2012-11-28 23:18:32 » |
|
1
| find . -name '*.java' | xargs perl -pi -e 's/^\s*/" " x rand(40)/e' |
|
|
|
|
deepthought
|
 |
«
Reply #51 - Posted
2012-11-29 02:16:25 » |
|
1
| System.out.println(thing == otherThing ? "Yay!" : "No!!"); |
ugh! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| player p=serv.getplayer(clientnum); commandmodule e = (commandmodule) serv.getentity(p.myship); if(e!=null) { camx=e.x;camy=e.y; System.out.println(e.dx+" "+e.dy); } camera2d.set(camx, camy, zoom); drawgrid(camx,camy); |
|
Mad Scientist
|
|
|
princec
|
 |
«
Reply #52 - Posted
2012-11-29 11:06:19 » |
|
Riven could "easily" render the entire discussion totally moot by allowing people to select different formatters for the code tags in SMF. Then you'd all see code formatted in the way you wanted it and the arguments would look rather silly  Which is sort of the point I was making about version control systems. Why the formatting of an ASCII file has any bearing on modern day programming is beyond me. And f**k Python. Cas 
|
|
|
|
DrHalfway
|
 |
«
Reply #53 - Posted
2012-11-29 11:14:46 » |
|
I always like to use brackets 1 2 3 4 5 6
| if (val) { System.out.println(val); } else { System.out.println(val); } |
I actually don't mind all of the styles presented here, If I were just reading code its fine. What I don't like is when people FORCE me to use something else. I think I've had a comment once that the above example is "unreadable" and should be converted into this. 1 2 3 4 5 6 7 8
| if (val == true) { System.out.println(val); } else { System.out.println(val); } |
ugh 
|
|
|
|
Roquen
|
 |
«
Reply #54 - Posted
2012-11-29 12:53:52 » |
|
Back when dinosaurs roamed the earth and folks (other than me) used CVS, we had per-user/per-file-type formatting on in/out operations. Surely stock new-jack VCS allow for these kinds of hooks.
|
|
|
|
deepthought
|
 |
«
Reply #55 - Posted
2012-11-29 18:38:10 » |
|
I actually don't mind all of the styles presented here, If I were just reading code its fine. What I don't like is when people FORCE me to use something else. I think I've had a comment once that the above example is "unreadable" and should be converted into this.
people just need to learn how to read code in general. I read in some programming tips book that this one guy's employer made everyone comment every single line. Ridiculous. 
|
Mad Scientist
|
|
|
Best Username Ever
|
 |
«
Reply #56 - Posted
2012-11-29 19:44:53 » |
|
Reading code is easy. Even more primitive languages like C++ and assembly code or files with minimal whitespace and no newlines. At worst you can just start in the main source file and mechanically parse the source file top to bottom like a compiler. Though that could take ages. The hard part is doing it efficiently, which is only possible when the code is well written for people and computers. Programmers (should) know that they can't count on faster hardware to fix slowdowns due to naive algorithms or data structures. A programmer shouldn't rely on other smarter programmers to fix personal failings.
|
|
|
|
|