Download presentation
1
Commenting and Naming Conventions
2
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!
3
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!
4
How to Comment in Java You can add comments in two ways:
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 You can create a block of comment starting with /* and ending with */ /* This will be commented This is also commented This line is also commented */ JCreator indicates a comment by turning it this green color
5
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!
6
Code Conventions Naming Conventions are part of Code conventions
These are guidelines to follow when coding in Java
7
Why Have Code Conventions
Why Have Code Conventions? (From Code Conventions for the JavaTM 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.
8
Use these conventions for naming in your program from now on
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: Use these conventions for naming in your program from now on
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.