Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  What are your java conventions?  (Read 1991 times)
0 Members and 1 Guest are viewing this topic.
Offline Archive
« Posted 2015-11-04 02:31:20 »

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  
32  
33  
34  
public class NameSpace {

   private static final int NAME_SPACE = 0;

   private static int name_space;

   private int nameSpace;
   
   private float floatTest = 0.1f; // some people put a capital 'f' like 0.1F
   private double doubleTest = 0.1D; // some people put a lowercase 'd' like 0.1d
   
   private void nameSpace(int nameSpace) {
      this.nameSpace = nameSpace;
   }
   
   public static int nameSpace(boolean nameSpaceBool) {
      return nameSpaceBool ? 1 : name_space;
   }
   
   public void lotsOfIfs() {
      if (nameSpace < 1) {
         nameSpace = 1;
      } else if (nameSpace > 1) {
         nameSpace = 2;
      } else {
         nameSpace = 0;
      }
   }
   
   private int someMath(int a, int b) {
      return (a * b) + (a / b) - (a * a); // some people don't put those parenthesis
   }
   
}


These are my conventions, i'm not sure if I covered all convention issues however so if you think of another convention please include it in your reply Smiley

Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #1 - Posted 2015-11-04 04:30:59 »

I like to separate static members and put them on top.

1  
2  
3  
4  
private static final int NAME_SPACE = 0;
private static int name_space;

private int nameSpace;

Offline Archive
« Reply #2 - Posted 2015-11-04 05:39:25 »

I like to separate static members and put them on top.

1  
2  
3  
4  
private static final int NAME_SPACE = 0;
private static int name_space;

private int nameSpace;


Haha whoops i totally forgot that I do that as well. I edited my main post hahaha

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Varkas
« Reply #3 - Posted 2015-11-04 13:53:00 »

I like braces on their own lines. My brain needs a lower information density on screen.

Other than that I try to stick to what Sun had defined long ago. I hope Oracle hasn't changed too much of those in the meantime ... if you work with other people it's best to have some sort of official standartd.

http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #4 - Posted 2015-11-04 16:38:49 »

Prepare for your java eyes to bleed, I feel that I should be able to tell what something is based off my convention, so I don't camelCase everything. I also dislike writing "this", but for inheritance I make sure to use "super" for clarity. However, I also don't go so far as to define the data type in variable names. Anyway bring on the hate.


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  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
public class NameSpace 
{

   private static final int NAME_SPACE = 0;//Not really sure what I do here, I'd have to look, but I think this is it...

   private static int sm_name_space;

   private int m_name_space;
   
   private float m_float_test = 0.1f;
   private double m_double_test = 0.1;
   
   private void nameSpace(int name_space)
   {
      sm_name_space = name_space;
   }
   
   public static int nameSpace(boolean name_space_bool)
   {
      return name_space_bool ? 1 : m_name_space;
   }
   
   public void lotsOfIfs()
   {
      if(m_name_space < 1)
      {
        m_name_space = 1;
      }
      else if(m_name_space > 1)
      {
         m_name_space = 2;
      }
      else
      {
         m_name_space = 0;
      }
   }
   
   private int someMath(int a, int b)
   {
      return (a * b) + (a / b) - (a * a);//I wouldn't always add parenthesis, just when the formula is difficult to read without them.
   }
   
}

Every village needs an idiot Cool
Offline SHC
« Reply #5 - Posted 2015-11-04 17:01:03 »

Mine are a mix from C/C++, Java and C#.

  • Use only 4 SPACES to indent code
  • Keep braces on their own line
  • Indent names of variables so equals signs are at same level
  • Lower camel case for methods and variables (Upper camel case in C++/C#)
  • No m_ prefix for variables (Only in except C++)
  • Spaces after keywords if/else/do/while
  • Short hand syntax of if will have the statement on next line
  • Indent the case statements in switch
  • Don't use blocks for case statements.
  • In OpenGL, add a block for statements between a glBegin and glEnd (I simulate them)

Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1674 views)
2018-06-10 19:43:48

EgonOlsen (1722 views)
2018-06-10 19:43:44

EgonOlsen (1161 views)
2018-06-10 19:43:20

DesertCoockie (1588 views)
2018-05-13 18:23:11

nelsongames (1188 views)
2018-04-24 18:15:36

nelsongames (1717 views)
2018-04-24 18:14:32

ivj94 (2542 views)
2018-03-24 14:47:39

ivj94 (1767 views)
2018-03-24 14:46:31

ivj94 (2847 views)
2018-03-24 14:43:53

Solater (972 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!