13
Best Coding Practice Mukesh Lagadhir Swayam Tech Lab http://www.swayamtechlab.co m [email protected] Few rules every coder must know and follow.

Best coding practice by swayam techlab

Embed Size (px)

Citation preview

Page 1: Best coding practice by swayam techlab

Best Coding Practice

Mukesh LagadhirSwayam Tech Labhttp://[email protected]

Few rules every coder must know and follow.

Page 2: Best coding practice by swayam techlab

You already know

• Comment your code such that it is clear what your code does even if it is two line of code and 10 line of comment

• You should be able to figure out your code years after it’s written (that is where first step helps)

• A good programmer should be able to figure out what your code does from your comments.

Commenting

Proper Naming Convention• Use proper variable names even if it takes many

character for one name i.e. submitedValueAfterPurchaseCompleted

• That will help you to relate it with your comment and you can have basic of what that variable does.

• Naming also applies to your Class, Package(Namespace) and file name as well

Page 3: Best coding practice by swayam techlab

• Document everting in your project even plugin you used or code snippet you have taken from other website.

• Your comments on classes and methods can be helpful to do documentation, there are tools which can do documentation for you from code comments.

• Document will be more helpful when your project grows and you add more developers and you don't have time to explain each things to them.

• Generate Proper Document for Use Cases as well• And If possible include flow chart with each procedure

or module

Documenting

Page 4: Best coding practice by swayam techlab

• You must be in situation where you ended up with code like index, index2, indexNew

• Make your code human readable as much as you can, after all you are going to read this code next time :) not your computer

• Use proper naming convention as explained above• Formate your code properly

Make It Human Readable

You can read more about code formatting herehttps://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style

https://google.github.io/styleguide/javaguide.html

Page 5: Best coding practice by swayam techlab

This is all you know since your graduation, you might need to

revise it and you will have good grip above all things.

Page 6: Best coding practice by swayam techlab

NOW COMES THE SECRET 5 FORMULA WHICH YOU MIGHT NOT AWARE AND ALL THE GREAT PROGRAMMERS AROUND THE WORKS USES

THIS

#5

Page 7: Best coding practice by swayam techlab

1.Don’t Jump Over Code

• Never , Ever, Ever start coding directly when you have requirement

• First review requirement properly and have some plan in mind of how you can do this, this will be first solution

• Don’t Implement first solution , check for other solution. You can do search on Internet or in existing libraries. Second solution will be combination of your first solution and second thought of how you can do it better.

• This will make your idea clear about your code and will also identify possible loop holes

Yes I know I can finish this in 30mins, let me start - but WAIT

Page 8: Best coding practice by swayam techlab

2.Prepare CodeChart• Once you figure out #1 , start with paper or a sample text

file instead of direct code - this will be like CodeChart (similar to flow chart)

Step 1 : products = recent products from db Step 2 : perform logic on product Step 3 : iterate over products Step 4 : render template file Step 5 : finish

• Based on your CodeChart you can do your code easily.• This will reduce your errors by 40%• And you will have sort of confident on your code

{ }

Page 9: Best coding practice by swayam techlab

3.Compile CodeChart• You thought it is just a CodeChart and on text file, how can

it be compile right?• Let me explain, You need to run this code chart into your

mind and go over each step and add two things to CodeChart

{ }Easy ? In X Min

Step 1 : products = recent products from db 100% 5

Step 2 : perform logic on product 90% 30

Step 3 : iterate over products 100% 15

Step 4 : render template file 100% 30

Step 5 : finishIf you have noticed, your CodeChart is now a CodeMatrix which can tell you exactly that in how much time you can do code, what part is difficult for you and what can take some time like Step 2- this could be a dependency on other or anything

Dividing tasks in Minute Level will also help you in improving your estimation.

Page 10: Best coding practice by swayam techlab

4.Make Beautiful Code From CodeMatrix

• You have CodeMatrix, this is Exactly what you need to do a perfect code. you know each steps and you know how much time it can take and your confidence level

• Start building a code based CodeMatrix, do not allow your self to go out of this CodeMatrix, and if you wish you can add new column to code matrix and mark it as completed as well

{ }In X Min Done In

Step 1 : products = recent products from db 5 10

Step 2 : perform logic on product 30 15

Step 3 : iterate over products 15 20

Step 4 : render template file 30 40

80 85

Above analysis will explain you that what part took more time so you can be better sure next time to dedicate time to each steps.

Page 11: Best coding practice by swayam techlab

We are Still not finished. You need to know what biggest mistake you are doing

{ }In X Min Done In Let’s Test

Step 1 : products = recent products from db 5 10 5

Step 2 : perform logic on product 30 15 10

Step 3 : iterate over products 15 20 5

Step 4 : render template file 30 40 5

80 85 25

It’s a normal behaviour of developer to test everything they code

So if you have noticed, you took 85 minutes in development and 25 minute in testing your code - You are 30 minutes behind your schedule which is 180 minutes for your 8 Hours. So Either you are doing overwork for 3 Hours or you are behind your schedule by 3 hours daily.

All Agree?

But We have SOLUTION for you to save your valuable time

Page 12: Best coding practice by swayam techlab

5. CodeBunch• You never test the half cooked food right? Same applies to your code as

well. Never test half developed code. That is the secret for great coding practice. Let me explain you what and how you can do

• Based on CodeMatrix start developing code and finish till last step of CodeMatrix. Once you finish your CodeMatrix have a break of 5-10 minutes.

• This will allow you to move away from your code but your subconscious mind will be thinking of code for you.

• Once you finish your break come back and Test your entire code in once.• This will take less time compare to testing each developed line and running

it for testing.• You can start with 1hr CodeMatrix if you are not experience developer and

slowly increase size of your CodeMatrix. Over period of time you will be able to do entire Modules of your project based on CodeMatrix without testing, this will save huge time over testing.

We are practicing this Technics for years and seen the vast difference in productivity and quality of code a person can develop. Our Developers are now addicted to do only code for a day, then they leave and do testing next day morning with fresh mind.

Page 13: Best coding practice by swayam techlab

Let us know your thoughts by commenting below or you can write to us on [email protected]

Visit us @ http://www.swayamtechlab.com/

Thank you