Friday, February 27, 2015

BEST PRACTICE

BEST PRACTICE

JANUARY 2015. The holidays have come and gone. We can add another day to all our Christmases past and New Years past.

It is also the beginning of another semester in college for me. The spring semester started on this month and I started taking Advanced Java. This might be the last programming course I'll take because I intend to learn more about programming languages by myself.

Here are some of the best practices in programming I've learned so far.

1. Use modular programming by dividing the problem into subproblems, and even into more subproblems, if necessary. In this way, you can see the forest from the trees and the trees from the forest.

2. Always write good documentation for your code, for your own sake and for the programmers who are going to look on your code down the line.

3. Always follow a consistent and good programming style. If you work for a company that follows their own style, follow that style.

Here are some best practices on good programming style.

Start your code with a heading comment like this one:
/*
 * Student: John Sindayen
 * Course: CIT 230 Advanced Java Spring 2015
 * Homework: 1
 * Date Due: 2/5/2015
 * Source file: Soldier.java
 * Version: 1
 * Date: 2/5/2015
 * Copyright (c) 2015 John Sindayen
*/

If writing a class that has javadoc comments, follow this style:
/**
 * Soldier class is a subclass that extends the Person class by adding Rank,
 * Military Unit, Monthly Salary, Marital Profile, Education Profile, and Race
 * properties.
 *
 * @author   John Sindayen
 * @version  1.0
 */
public class Soldier extends Person {

When initializing values for instance fields, use the default values for that type, as in the following:
        rank = null;
        militaryUnit = null;
        monthlySalary = 0.0;

As far as indentation is concerned, indent four spaces to begin a block, whether it is explicit or not, like this:
    public Soldier(String fn, String ln, int a, String g)
    {
        super(fn, ln, a, g);

Indent eight spaces if it is a continuation of a line, like this one:
        if (rk.equals("PVT") || rk.equals("CPL") || rk.equals("SGT")
                || rk.equals("2LT") || rk.equals("1LT") || rk.equals("CPT")

CYK:
What kind of class is an abstract method define in?
What key word is needed to use an interface in Java?
What is the proper term for a function that is a member of a class?

Follow your dreams!

John Sindayen

1 comment: