Archive:Java/Programming tips: Difference between revisions

wikademia>Cremisis13
wikademia>Cremisis13
Line 22: Line 22:
'''Note''': Do NOT use arrays when the members have nothing to do with each other. This causes messy code!
'''Note''': Do NOT use arrays when the members have nothing to do with each other. This causes messy code!
=Basic Tips for Improving Code=
=Basic Tips for Improving Code=
==Tabbing==
Tabbing is necessary to understand your code more easily. For example, the following is very complicated to understand without any tabs:
<pre>
public class MessyCoding extends Coding {public
static void main(String
args[]
){System.out.println
("This is messy coding. Don't do this");System.exit(0);}}
</pre>
In much better format:
<pre>
public class CleanCoding extends Coding {
  public static void main(String args[])
  {
      System.out.println("This is clean coding. DO THIS!!");
      System.exit(0);
  }
}
</pre>
Notice that you actually can understand the code! Every single new block that has { and } should have contents that have an extra tab. Example:
<pre>
public class CleanCoding extends Coding {
  public static void main(String args[])
  {
      try{
        try{
            ...;
        }
        ...;
      }
      ...;
  }
  ...;
}
</pre>
==When to press Enter==