Programming tip of the day – 3 Step Process

Follow this 3 step process in each of your code piece!!

3 steps
3 steps

1.  Make the code work (Working code please)

2.  Make the code right and better (Refactor)

3.  Make the code fast (Optimize)

This is a good way to improve your programming skills.  If you start doing this way, sooner or later, all 3 steps will get integrated for you to provide a more beautiful flowing experience.

 

Subscribe to GUVI Blogs to get regular updates about all the latest blog posts and tips!!!

Programming tip of the day – DRY principle

Hello Programmers,

Day in and Day out, Rajesh was writing code.  He was hard working, so he wrote code all the time.  But whenever his manager asks him to change some functionality, he takes a long time.  Manager becomes frustrated because he was not getting the output fast enough.  As days passed by, outputs became that much longer and the quality also reduced.  Rajesh was also frustrated.  He was always hard working, but had to work more and more harder as days passed by even to make small changes.  What was the reason?  Rajesh’s friend Vaibav came to help.  He found that Rajesh was not reusing the code that he wrote earlier, thereby duplicating code across the project.  Over a period of time, maintenance became difficult for Rajesh.  Then Vaibav suggested “Rajesh, always follow the DRY principle“.  Rajesh didn’t know what it was.  Vaibav suggested “Don’t Repeat Yourself 🙂 Always try to reuse code you or someone wrote earlier, because if you don’t, it is a waste of time for everyone”

DRY
Image: Courtesy deepubalan.com

 

MORAL: DON’T REPEAT YOURSELF.

What I learnt from my first real WORKING CODE?

Hi Friends, Welcome to GUVI Blogs again!!  It’s story time and rewind to my college days!!

That was my first reasonable project in programming.  I had written a parser for 2-pass macro assembler using C.  It was around 2500 lines of code, I was happy that my code worked in my machine.  Better yet, my code worked during the demo as well. 🙂 That’s a miracle..  So I had a great milestone to brag about – THE WORKING CODE.  But after I finished the project, I sat after a few weeks to just review the beautiful art that I had created (hehe, I am talking about the code that I had written).  I was hardly able to understand anything in my own code !!!!!!!! 😦  That’s when I learnt some important lessons in programming.

Modules please

My working code contained 2500 lines of C code in the main function.  Wow… What an achievement, I thought.  But when I reviewed it, I realized that things should not have been this way!!

Lesson Learnt: I should have split the code into nice modules, that would have saved a lot of time during maintenance.

Comments please

I didn’t put comments wherever necessary, so I was caught trying to figure out what each and every line or piece of code did.  It was difficult as hell and I wasted a lot of time literally trying to find out what the code did.  Remember, this was just few weeks after I wrote the code.

Lesson Learnt: I should have added enough comments for even myself to understand the code in the future 🙂 Continue reading