interview questions

Top 6 best practices every coding newbie should know

Abraham Lincoln once said

Give me six hours to chop down a tree and I will spend the first four hours sharpening the axe

Programmers are highly enthusiastic people. They love to take challenge in any coding assignment, and start working till the program get solved. Coding is fun and challenging for them. Unfortunately they spend low amount of time planning things, and more time in writing code, hacking things, rewriting, streamlining, till they achieve their goal. But the end result which they get is work stress, wasted time and spaghetti code.

coding-best-practices-1

Image: Illustration of spaghetti code. Source: wikimedia

As a programmer, you can avoid the most common mistakes by planning things better, before writing your first line of code. These are global best practices followed by lead tech managers and devs.

Important things to do before writing your code

Understand the requirement clearly

One of the most common problems faced by newbie coders/students are that they jump into problem solving too early, before even understanding the requirement clearly. The requirement is originated by their boss/client/business or product team/teacher. As a programmer who is going to solve this problem, you need to understand the requirement in details. What exactly is needed in the assignment, how should end product looks like, etc.  For this, have multiple sitting/calls with your client, ask them to provide the detailed requirement document, get the final output samples/design from them.

Knowing existing code

Programmers are very eager to code everything. It is very important to understand existing code (if the product is already existing). There may be lots of existing code (like classes/functions) which can be reused. Reusing code and properly maintaining the code directory are always going to help in programming process, and help save lots of programming hours.

 Define use cases

coding-best-practices-2

Figure: Use cases of an ecommerce website.

When reading the requirement or discussing with client regarding the programming assignment, work on the use cases of possible scenarios. For example an online shopping website would have some of the following cases

  1. User search his/her preferred product (search flow)
  2. User compares between similar product (comparison/filtering flow)
  3. User fill his/her shopping cart with multiple products (building a shopping cart flow)
  4. User checkout and made payment (payment flow)
  5. User get his/her delivery (delivery flow)

Likewise, there are lots of other important process flow/use cases which user can experience while using this website. These are defining on very higher term, you can drill down, and break into smaller cases too.

Now this use cases step can have problem, if your understanding of requirement is not clear. For example- Lets say, you have a use case where you are 2 inputs and performing division and then printing output.

Now following fail cases you can expect, if you don’t plan well for this A divide by B problem.

  1. Ignoring B=0, you will get error
  2. A/B=C. C is returned as float
  3. Any of the input number is not integer. Lets say it is string. You will get an error.

When you are writing the use cases, make sure to have clear discussions with stakeholders/clients on the requirement, and the kind of cases you need to handle. Show your plan to clients, so that both you and clients are in sync beforehand.

Make a functional specification

coding-best-practices-3

Figure: Functional specification (Source- Wikimedia)

Functional specification will help you understand the complete overview of code, how different blocks are connected, what the shared methods, variable in each blocks . Make sure to get this functional specifications checked and confirmed by client or product stakeholders.

Make a technical specification

coding-best-practices-4

Figure: Technical specification (Source- Wikimedia)

A technical specification will contain details like technical structure, programming languages to be used, whether hardware/servers need to be upgraded. It includes following features.

  • Individual screens
  • List of items on the screens
  • Whether database activity is happening (select, update, delete)
  • How is code structure in classes. How is it communicating with back end and front end
  • UML/ETL diagram
  • flowchart
  • List of technology used

coding-best-practices-5

Figure: UML diagram (Source- Wikimedia)

coding-best-practices-6

Figure: ETL diagram (Source- Wikimedia)

 

coding-best-practices-7

Figure: Flowchart example of calculating BMI

Use a project management tool

Use project management tool, so that all the agreed features are in sync with you and client/stakeholder. Even tools like Excel and Google Spreadsheet are good for recording scope of project, features, deadlines etc.

Lot of times, devs misses this important aspect of recording the features/requirement, and start working with just discussion with stakeholder/clients. This often lead to missing clarity in understanding and not in sync with client/stakeholder. Also, if the client/stakeholder is adding/modifying any feature, your project management tracker will help maintain the change record, and justify your time with respect to development.

Once you are done with all this, you can now start coding.

Happy Coding!!!

End note

This article explains you best practices to follow before you start coding project. Following these practices will make your work more efficient, code reusable, save time and shorten delivery time. We hope that you like the article. Please feel free to share your comment, suggestion or doubt to us. You can comment below, or you can write us to info@xamnation.com

Leave a Comment

Your email address will not be published. Required fields are marked *