Chapter 1: Java Programming Style

There are many different styles for writing Java code. Depending on the book you’re reading or the company you’re working for, you may be asked to put opening braces on a line by themselves, or, as in the book we’re using, put the braces at the end of the line. You may be told that when you indent code, you should use four spaces… or two spaces. When you indent, do you set the development environment to insert a tab character or to insert spaces? These choices and more are part of what’s called a *style guide.* For this course, ask me if I care about which style you use. [voice chorus] Do you care? No, I don’t. Choose the style you like best and use it consistently. There are some things I will insist on. First, your programs must be indented properly, no matter which spacing you decide upon. Your programs must have comments at the beginning that tell what the program does and that give your name and the date. One thing almost all style guides agree on is that each line in a multi-line comment begins with an asterisk. Most development environments will insert this asterisk for you automatically. Again, you must indent properly. Don’t mix styles, and whatever you do, don’t throw all the rules out the window and go for “artistic effect.“ Choose an indentation style, and use it consistently.

Leave a Reply

Your email address will not be published. Required fields are marked *