In: Computer Science
a. In your own words, explain what is meant by good programming practice. Give two examples, one with good programming practice and one without good programming practice
Note:java Programming Language
Good programming practice means your programme code will be in well manner means you have to follow all the programming conventions like :
1)- Using naming conventions
2)- Ordering Class Members by Scopes
3)- Class members should be private
4)- Using Underscores in Numeric Literals
5)- Avoid Empty Catch Blocks
6)- Using StringBuilder or StringBuffer instead of String Concatenation
7)- Using Enums or Constant class instead of constant Interface
8)- Avoid Redundant Initialization (0-false-null)
9)- Using Interface Reference to Collections
10)- avoid using for loops with indexes
Example of good programming practice
public class Employee_Details // Naming conventions
{
private int Employee_ID;
private String Employee_Name; // class members should be private and use underscore between two name
Employee_Details(int ID, String Name) //use a constructor for accesing the private data or use public function
{
Employee_ID=ID;
Employee_Name=Name;
}
public static void main(String args[])
{
Employee_Details ob=new Employee_Details(23,"Rohit");
}
Example of bad programming style
class Abc //without using a valuable name of the class
{
int a=5; // without using naming conventions
int b=3;
public static void mian(String args[])
{
int c=a+b;
System.out.println(c);
}
}
*Note=> Program will run in both conditon but by using conventions your program is understandable to your team member and they will continue your program in case of your absence