+826

A Helpful Coding Tip

A lot of people know that it is a good practice to comment your code.But there is something else that is more helpful.In Zed Shaw's 'Learn python the hard way' book he advised to comment each line of a code you don't understand.By that I mean is if you don't understand a code, go through each line and explain what that line does.That way you would easily know where the problem lies.I've tried it and it really helped.Just to let you people know something useful.

6/8/2017 6:54:50 PM

Asif

455 Answers

New Answer

+111

it's nice to comment a code but there are some drawbacks as well. Like if developer updates logic and forget to update comments. or some times logic is not explainable in comments, so we should keep this in mind while putting comments in code.

+85

@ASIF Thank you, for sharing the tip!

+68

Learn Python theHard Way was one of the first books I read about programming, many years ago. That is definitelyy one practice I've taken the heart and you're right that it helps. I'm generally the kind of person who spends a lot of time on organization, taking notes, creating documentation and commenting my code. Some people place more focus on getting as much coding done as possible, and of while that is also vital, I think a solid foundation for learning and working that you can apply to anything is what will eventually help out rise above the the rest. Whether I'm learning a new language, a library or a framework, using new tech or simply reading about better practices to improve myself, I always work in a similarly obsessive fashion. I try to pay attention to how every little line of code works and a write extensively. Some of it ends up on my blog, but most of it is just for my own use and will likely never see the light of day. As an example, I'm learning to use Mongoose (MongoDB for NodeJS) right now. Also, as a more general goal, I'm trying to make use of ES6 and functional programming wherever possible, while avoiding only doing some things out of habit (like using jQuery and SQL databases). The basics of Mongoose are easy to get a hang of and it's possible to get started fast if you know Node.JS. But I've still rather been writing a long Markdown document detailing its usage, API and how ES6/functional programming can be used with. I've saved related Gists (I LOVE using Gist for learning and random snippets) and bookmarked several dozen bookmarks, with tags and all. I don't want to to just know ABOUT NoSQL databases - I want to be able to say with confidence that I'm skilled in their usage. A lot of time, all these tutorials and and the possibilities the languages, their hundreds of libraries and all the other technology offer, can feel overwhelming. But when you get down to individual lines of code, the big picture gets a lot clearer.

+54

Good tip. I usually say it out loud as I talk to myselves a lot.

+50

Search for 'rubber duck debugging'.

+46

Great tip 👍

+43

"It's not at all important to get it right the first time. its virtually important to get it right the last time." -by Andrew Hunt & David Thomas

+40

Another great tip for debugging is adding sensible print statements inside function/method's body where the issue is or inside many functions/methods to find the problematic function/method printing values of variables etc. But be sure to print clear statements, e.g: "Now in destructor", etc. this way u can watch variables and program flow and know when and why values changed. This can be also be done in IDEs using their "Watch" window.

+35

IMHO, it is just like verbalize what you doing when you doing something complicated. It is very useful for tracking your menthal point and moving to the aimed result.

+35

Don't forget to eat.

+34

pay attention to capitalization, also instead of coding, write out your programs on paper then plug them in and see if they work, doing this will force you to be more aware and notice little details better without having to go back and figure out why there is an error as often

+28

Useful information and observation As well 👍👍👍👌👌

+26

That actually is a good tip

+26

thnx..nice tip!

+25

really very helpful tip

+25

thanku for your useful tip for coding. A true coder wants to know than he can achieve anything in programming world and he can automatically mind thinks no one can try the coding for getting likes or comments .any one want to try the coding for useful in any part of life than that coding wants to used in any part of everyone life. in that aspect every programmer must think about the coding. from that automatically the likes and comments are get across u.all the best to all

+24

great thank you

+23

Good ol' 'Rubber Duck'

+23

+22

That's very true, the comment helps a lot