views:

157

answers:

8

I believe, I program good, at least my code produces results...

But I feel I have drawback... I hardly follow any naming conventions... neither for variables.. nor for methods... nor for classes... nor for tables, columns, SPs... Further to this, I hardly comment anything while programming...

I always think that, Let me first see the results and then I will come and correct the var names and other things later... (Thanks to visual studio's reflection here)... But the later does not come...

So, I need tips, to force myself to adopt to the practice of following naming conventions, and commenting...

Edit : I totally understand the ill effects of my practice, and I also know, that it is bad... My question is how do I force myself to follow the discipline...

+10  A: 

Are you able to ask others for code reviews? Or even try pair programming? Both of those can really help you to do things you know you really should do.

Also, depending on your language/platform, there may well be lint-like tools you can run to check your code's health.

Jon Skeet
A: 

This is a matter of coding discipline. If you want to prototype something and then throw the code away, this is acceptable. However, the instant you need to reuse or debug your code, you will regret having no comments and poor method/variable name choices.

While you are working with the code now, you know what it is doing. In a few months to a year, you will not remember everything so clearly. Then, you will likely regret not commenting your code and not choosing good names.

Consider, too, if someone else were to read your code, how easy would it be to understand?

Paul Williams
+1  A: 

My gut tells me that your code is probably not as good as you think if you have no standards. You really just have to pick something, and stick to it. Being haphazard in coding style probably means you are haphazard in logic, which probably means you have a lot of bugs, and unexpected results in your code that will be hard to deduce later. Good luck.

sabshire
+1  A: 

Just remember the general coding guidelines you need to follow. And as you write the code write as per the guidelines with proper variable naming conventions for variables and methods and have function headers. Dont think whether your code will work or not, and code as per the guidelines.
Comments can be added later, but the naming conventions has to be followed even while doing a proof of concept. Write your code with a confidence that its going to work.

Have your code reviewed by your peers, and also you can use Fxcop for static code findings.

KhanS
+1  A: 

Best of all, your code should work and should do what it's supposed to. It's what you get paid for.

However, if it is not readable, then it will fade into existence, because in time you will not remember what it does. To avoid this, refactor and document your code as soon as it works. As a rule of thumb, you should not be satisfied with your work before it is documented properly. For each method you write, this should not take too much time. But the longer you wait, the more time it will consume to figure out what your code was supposed to be doing.

I know the best way of all is to document before writing, but that won't work with cowboy coders. The other way around might be a good alternative, because readable and good documented code shows off a developer's skills.

Prutswonder
A: 

Running something like StyleCop (if you're writing C#) can go some way towards this. It won't warn you about everything, but you can use it to make sure your methods have documentation comments etc.

However, as others have said coding discipline is something that has to come from within, not without.

ChrisF
+2  A: 

I hope you get to spend a few years working on code produced by someone else that has the same poor coding practices that you have. Only then will you truly understand how poor your code really is. Code that "works" is the bare minimum, writing code so that it is easy to to support, extend and maintain is where the genius of a good programmer is.

KM
I figured that the OP wouldn't accept this as the "answer" to the question ;-o
KM
Hi KM... It is not that your answer was not useful.. But as I stated, I already know the ill effects of this habit of mine... Your answer was just re-emphazing the same...
The King
if you do work for a few years on code produced by someone else that has the same poor coding practices that you have, I think you will be cured. You'll hate it so much, you'll then change.
KM
A: 

If you want to change something about yourself, you need to motivate yourself to change it. That's one of the "rules of life."

This isn't really something Stack Overflow can help you with. I suppose that a good suggestion to build up some motivation is finding yourself a job as a developer and see how far your development habits lead you...

-Carlos Nunez

Carlos Nunez