Presentation on theme: "Commenting and Naming Conventions. Comment Your Code With small programs it may seem more trouble than it’s worth to add comments However, developing."— Presentation transcript:
Commenting and Naming Conventions
Comment Your Code With small programs it may seem more trouble than it’s worth to add comments However, developing the good habit of commenting your code will save you much grief in the future as your programs get more complex – I speak from experience!
Here are a few suggestions as to why you should comment your code: Finding errors and the flow of your program is more efficient. Software is often developed as a team where people work on only parts of a large program. Other team members should be able to understand what your part does and how it does it without having to ask you. You would want the same. If you change jobs, you may be responsible for a piece of software you created for your previous job. You don’t want your past to haunt you because the “new guy” doesn’t know how your code works It makes marking your code easier!
How to Comment in Java You can add comments in two ways: 1.Using two forward slashes will comment everything after them on that line only: Example: This is not commented // This will be commented This is not commented 2.You can create a block of comment starting with /* and ending with */ –Example: This is not commented /* This will be commented This is also commented This line is also commented */ This is not commented –JCreator indicates a comment by turning it this green color
What You Should Comment You should comment any part of your code that you feel may need some clarification on What I will be looking for in terms of commenting are: –The Header Section: Should include - This class, Name, Block, Project Name –Methods: What the method does –Variables and Constants: if name is not descriptive enough –Classes: What the class does (we’ll talk more about classes in the future) COMMENT YOUR CODE!
Code Conventions Naming Conventions are part of Code conventions These are guidelines to follow when coding in Java
Why Have Code Conventions? (From Code Conventions for the Java TM Programming Language / / Code conventions are important to programmers for a number of reasons: 80% of the lifetime cost of a piece of software goes to maintenance. Hardly any software is maintained for its whole life by the original author. Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.
Naming Conventions You should be familiar with the conventions for the following Java elements –Methods, Classes, Variables and Constants The information you need can be found at: nventions.doc8.html#367 nventions.doc8.html#367 Use these conventions for naming in your program from now on