Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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]
  ignore  |  Print  
  What's your preference is spacing  (Read 5553 times)
0 Members and 1 Guest are viewing this topic.
Offline masteryoom

JGO Coder


Medals: 5
Projects: 2


If you look closely, you might see it turning...


« Reply #30 - Posted 2012-11-23 07: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!");
    //more code
   //blah blah blah
}else {
    System.out.println("No!!");
    System.out.println("The world is about to die!!");
    //more code
  //blah blah blah
}
}

This excepts comments (which I don't really use anyway  Grin )
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!");
        //more code
   //blah blah blah
}else {
   System.out.println("No!!");
     System.out.println("The world is about to die!!");
     //more code
  //blah blah blah
}
}

(I also like to have my } s indented (especially })  Grin)

Smiley
Online ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #31 - Posted 2012-11-23 08:09:35 »

Yeah that's called proper formatting. But "} else {"?!? No. NO. It has to be "}\n else {"

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #32 - Posted 2012-11-23 15: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("?");
}

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #33 - Posted 2012-11-23 20: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! Tongue

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #34 - Posted 2012-11-23 21: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.

Offline sproingie

JGO Kernel


Medals: 201



« Reply #35 - Posted 2012-11-26 06: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.
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #36 - Posted 2012-11-26 11: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 Smiley

Offline Best Username Ever

Junior Member





« Reply #37 - Posted 2012-11-26 22:45:10 »

cuddled-else is hardly "blasphemy", it's very traditional.
If you have to describe something about coding as "traditional," then... Cheesy

compared simply with all whitespace stripped.

publicclassLikeThis? Tongue
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #38 - Posted 2012-11-26 23:22:54 »


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

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #39 - Posted 2012-11-27 00: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 Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 201



« Reply #40 - Posted 2012-11-27 02: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"
Offline deepthought
« Reply #41 - Posted 2012-11-27 03:45:56 »

I end up with tons of white space between things like if statements or loops

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #42 - Posted 2012-11-27 04:06:48 »

}else {


VOMIT

everything needs new lines.. perhaps this is why my razers scroll wheel has died so young
Online ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #43 - Posted 2012-11-27 23: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.

Offline Sickan

Senior Member


Medals: 8



« Reply #44 - Posted 2012-11-28 16: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!");
}
Offline deepthought
« Reply #45 - Posted 2012-11-28 22: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.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Cero
« Reply #46 - Posted 2012-11-28 23: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!!");
     }
}

Online ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #47 - Posted 2012-11-29 00: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!!");
}

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #48 - Posted 2012-11-29 00: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
Offline Best Username Ever

Junior Member





« Reply #49 - Posted 2012-11-29 00:17:33 »

Nope.

1  
System.out.println(thing == otherThing ? "Yay!" : "No!!");
Offline sproingie

JGO Kernel


Medals: 201



« Reply #50 - Posted 2012-11-29 00:18:32 »

1  
find . -name '*.java' | xargs perl -pi -e 's/^\s*/" " x rand(40)/e'


Offline deepthought
« Reply #51 - Posted 2012-11-29 03: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);

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #52 - Posted 2012-11-29 12: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 Smiley 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 Smiley

Offline DrHalfway
« Reply #53 - Posted 2012-11-29 12: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  Lips Sealed

Offline Roquen
« Reply #54 - Posted 2012-11-29 13: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.
Offline deepthought
« Reply #55 - Posted 2012-11-29 19: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. Angry

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Best Username Ever

Junior Member





« Reply #56 - Posted 2012-11-29 20: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.
Pages: 1 [2]
  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.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (50 views)
2014-07-14 18:02:53
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!