Code it Right

09 Feb 2017

Writing good code has a lot to do with good communication not just to the machine, but to the programmer reading it. A couple days ago when I was having problems with my algorithm class, I went to my professor for help and I ended up writing pseudo code on the white board. After I rationalized and scribble some functions with for loops, I stood back and felt pretty embarrassed. My objective was to demonstrate what I knew and what I needed help on but based on what I wrote, it was hard for my professor to identify why I didn’t understand randomized algorithms. What could have taken ten minutes took an hour and thirty minutes trying to convey my point across because we spent most of the time fixing the notations of my code.

Thank god for integrated development environments(IDE), because if not for it, I would spend more time finding missing semi-colons rather than developing programs to solve problems. Trouble shooting includes making sure the logic made sense but when it turns out that I’m missing some brackets, the moment sometimes calls for pulling my hairs out.

Recently, I was introduced to IntelliJ. It is a Java developing environment for computer software. Professional software is frequently updated and maintained. In order to ease this process, a need for uniform coding conventions arises. Some of these issues cannot be explicitly stated, and there is often more than one good solution. Better ideas and discipline come with experience. In order for others to properly follow the flow of a program, a standard must be devised. IntelliJ deals with professional coding conventions that can help one become a successful programmer.

Different languages have different style of formatting, and choices are arbitrary. Having a style that is consistent is important but there are also exceptions to coding conventions. Here are examples of naming conventions and different code layouts.

Naming Conventions

Variables:   
   Not So Good 		Noun
   Round 		Wheel
   LoopTimes 		NumLoops
   Valid 		InputStatus
   Starting 		Source
   Ending 		Destination
   SetWaiting 		Listener

Classes: 
   Not So Good 		Collective Noun
   accounting 		bankAccount
   setPoint 		point
   nodeNetworking 	socket_info

Layout

One of the more important aspects of coding is the readability and appearance issue in coding of programs. The appearance of code should convey its organization and meaning and unlike English text, it’s more like math and tables.

char c1;
c1 = GetChoice();
switch (c1)
   {case 'a', case 'A':  ProcessOptionA();  break;
    case 'd', case 'D':  ProcessOptionB();  break;
    case 'r', case 'R':  ProcessOptionR();  break;
          default:             cout << "Not a valid choice\n";
}

Or..

private JTextArea  legendArea = new JTextArea (LEGEND, 2, TEXT_WIDTH);	
private JTextField fahrText   = new JTextField(TEXT_WIDTH);	
private JTextField windText   = new JTextField(TEXT_WIDTH);	
private JTextField chillText  = new JTextField(TEXT_WIDTH);	

The size of a project or program has a significant effect on error rates, programmer productivity, and the amount of management needed. The structure of any programming involves the design of functionality, brevity and efficient organization. This fact ensures that I continue practicing good coding conventions because I know that every program that I create needs to maintain longevity and won’t cause frustrations when trying to read it.