When we talk about coding standards or code/programming style,
we're talking about how your code looks - proper indentation and
spacing, self-documenting identifiers, an appropriate amount of
documentation, etc. Sticking with programming standards is important
for any professional programmer. Writing code that doesn't follow
industry standard is considered amateurish, or what some call
"Mickey Mouse" programming (no offense to famous rodents). That
kind of bad programming has a negative effect: it makes it difficult
for you to go back and find errors, make changes, see how you solved
a difficult algorithm; it makes it difficult for other programmers
to do the same things. This costs a company/client more money and
time. Following good programming style and standards prevents you
from wasting your client's valuable time and money.
A program that is syntactically and logically correct will run and
function just fine, but a program that does not follow industry standards
when it comes to coding and UI design is just as bad! Why?
Programs that follow industry standard are:
Easier to read.
Many times you or another programmer will
have to go back and review
code you wrote a while ago. Code that is difficult to read will
take longer to decipher, even if you wrote it yourself. It's
even more difficult to read someone else's code that doesn't
follow industry standard.
Easier to maintain.
Clients frequently require changes to existing
programs. Whether you wrote the program or someone else did,
it's difficult to modify and maintain code that violates
standard practices: it can be difficult to find the module
you need to change or the values that need to be updated.
Easier to debug and avoid coding errors.
As you're coding, if you're not using
proper standards like good indentation, spacing, documentation,
self-documenting identifiers, etc. it can be very difficult to
locate problems with your code. One of the biggest problems I
see in class is when a student has a missing brace or semi-colon
and can't find it because their indentation is all over the place.
If you follow standards properly, you will rarely make mistakes
like forgetting a brace or semi-colon. If you name variables
properly, you're less likely to type a variable name incorrectly.
If you document well, it will be easy to find the complicated
section of code that contains a logic error.
More robust and reliable.
Code that follows industry standards tends to
run better and is
more reliable. It tends to be cleaner (e.g. no unused variables,
unnecessary program structures, statements, etc) and more efficient.
Additionally, be sure you read the
Coding
Standards for this course. It is expected that all work you
submit will follow these standards.
You should become familiar with these guidelines, not just for this course,
but also for later courses, and eventually for any professional work you
do outside the college.
The standards and guidelines include:
Documentation: using appropriate amounts of internal
program documentation (comments)
Using proper indentation and spacing.
Using Next-Line or End-Of-Line block style.
Using self-documenting identifiers and following a
language's standard naming conventions.
Exercises
1. Reformat the following code segments by hand so that they follow
proper standards:
a)
public class BadCode { public static void main(String[]
args){ System.out.println("Flowers for Algernon");}}
b)
public class
BadCode { public static void main(String[]
args){ System.out.print("6/4*2 is ");System.
out.println(6/4*2);}}
2. Add documentation to each of the corrected code segments
above.