StyleGuide - GameRevision/GWLP-R GitHub Wiki

Java Code Style

Java Classes

When reading through that example class make sure you also look at stuff like number of empty lines between blocks (e.g. before methods: 2 empty lines always) or the LICENSE notice, or the author(s), or the indentation of JavaDoc annotations (I've adopted the following format: The param or exception name begins on the 21st row (meaning you can 'tab' there) and any description of the param begins on the 45th row (you can also 'tab' there). Return descriptions begin on the 21st row), or the general use of comments. JavaDoc is MANDATORY and you should always write comments explaining what you do before you write the code doing it.

Also, when you don't use that general style, be aware that we might reformat your code when we think it's safe to edit it and you'r not actively working on it. Also, bad coding style is an issue and it's also treated that way, especially when the project gets larger (Meaning we may create official project-related-issues concerning your code if we cannot talk to you any other way)

A simple SampleClass

    /**
     * For copyright information see the LICENSE document.
     */
    
    package com.example.package;
    
    import com.example.wtf.SomeConcreteThing;
    import com.example.wtf.SomeThing;
    import com.example.wtf.SomeThingElse;
    
    
    /**
     * This class is a sample class for the general code style.
     * It tries to explain how things should look inside your classes and why.
     * 
     * @author mr-nobody
     */
    public final class SampleClass
    {
        
        private final SomeThing thing;
        private SomeThingElse thingElse;
        
        
        /**
         * Constructor.
         * 
         * @param       whatEver                A string that is not of interested and has
         *                                      absolutely no meaning
         * @param       neverMind               The number of wtf's per minute
         * @throws      Exception               If there was a fatal error with handling the
         *                                      whatEver String
         */
        public SampleClass(String whatEver, int neverMind) 
                throws Exception
        {
            // this is some sample description of what is happening here:
            // it has proven to be of great benefit when creating comments
            // before writing any line of code, or at the same time
            // it has also proven to be of great benefit when your comments
            // tell a little story of what is the problem that your methods
            // or classes try to solve, how you choose to solve it and why

            // also, we have some attributes within this class, and it would be
            // a shame if we forget to create them here

            // because of the statements above, we'll try to adopt that coding style
            // so, when it comes to the whatEver parameter we need to save it,
            // because it is used inside the getWhatEver() method later on
            thing = new SomeThing(whatEver);

            // well, surprise surprise, it turns out SomeThingElse was an interface or
            // at least some base class of SomeConcreteThingElse ;D
            thingElse = new SomeConcreteThingElse();
            
            
            // additionally it is essential to leave some lines free between stuff that
            // has nothing to do with each other
            // thats why i, mr-nobody, choose to introduce a new paragraph for doing my
            // fancy stuff with the second parameter
            // you can see that it handles the wt.'s per minute, but additionally to that
            // we've chosen the parameter to be called "neverMind"
            // thats why all i do is check whether the wt.'s per minute have reached a 
            // critical state and then simply do nothing against it:
            if (neverMind > 60)
            {
                // oh f*** we have one wtf per second!
                // well, we can't do anything against it
            }
            
            // TODO: add some more stuff to this constructor
        }
        
        
        /**
         * Getter.
         *
         * This method returns the whatEver string, that is handled by thing.
         * It also changes thingElse's state.
         * 
         * @return      The whatEver string. We do not yet know what that string is actually used for. 
         */
        public String getWhatEver(ShardletAction action)
        {
            return thing.info();
            
            // the first line does not need comments, because it won't be of any benefit
            // there
            // now, when it comes to the state change, its better we tell the other devs why
            // we need to do that
            // it turns out, we simply need to do it to kind of make this a reasonable example
            // also note that interfaces like SomeThingElse can have static values:
            thingElse.newState(SomeThingElse.FUNNYSTATE);
        }
    }