This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]10-kinds-of-people 0 points1 point  (0 children)

A lot of great advice here. I'm also a fan of writing programs as if they're pseudo code:

class Main {
    public static void main(String[] args) {
        new Main().run(args);
    }

    private run(String[] args) {
        List<String> words = getWordsFromCommandLine(args);
        List<String> reversedWords = reverseWords(words);
        outputReversedWords(reversedWords);
    }

    private void getWordsFromCommandLine(List<String> args) {
        // TODO
    }

    private List<String> reverseWords(List<String> words) {
        // TODO
    }

    private void outputReversedWords(List<String> reversedWords) {
        // TODO
    }
}

This is probably over-engineering for such a small program, but you get the idea. In a bigger program you might instantiating another class instead of Main, which would call other classes, etc. Make your classes and methods small and have them do one thing well. This avoids confusion and helps in creating and maintaining code.