Coding For Violent Psychopaths

But its more cool to see how concise I can make my code, not how readable and maintainable it is! :wink:

Hmmā€¦ Iā€™ve use the Pseudocode Programming Process since before I read about it in Code Complete (Good book, Thanks Jeff!). And it generally works really well for me. I leave the Pseudocode in comments to tell future programmers what is going on. This process also helps keep the code and comments in sync because I even write the pseudocode for new features or changes to a function/procedure.

Iā€™ve never really worked on a big programming team, generally there are no more than 3-7 programmers on the projects Iā€™ve worked on. And a lot of times it was just me. I am an insecure programmer, so I comment just in case I did something that seemed brillinat to me, but is actually bad, bad, bad. That way if someone that is better comes along while I am still there and they see it, they can say, ā€œHey, you know you can just do ā€¦ā€ Then I learn and they get their ego fed.

But then again, I also code for readability over putting in the slick ā€œI can write the entire function in 1 line C approachā€.

My favorite comment Iā€™ve come across while bug fixing someone elseā€™s code - (* This entire function is commented out in case the b!tch changes her mindā€¦ again! *)

ASDKLJAASKJ GRRRRRRrrrrrrrrRRRR

YOU KNOW WHO DIS IS? jbarthalomewe?

WHER I FIND?
G
asdkj
qweSDJJJJJJ!!!

The absolute worst crap Iā€™ve seen is not just checking in code thatā€™s logically wrong but also doesnā€™t even compile! In college if the code didnā€™t compile you got a zero but dang the folks in industry are supposed to be pros! Unbelievable! I try not to think of the craptastic code and all of the total rewrites that need to be done and then I can sleep well at night.

You canā€™t understand my code because itā€™s so well written.

@KM You donā€™t write documentation and code like theyā€™re just a different form of representation of the same knowledge. DRY.

Write documentation for high-level knowledge, not low-level knowledge.

The Pragmatic Programmer book mentions this too: ā€¦ā€œThe comments will inevitably become out of date, and untrustworthy comments are worse than no comments at all.ā€ā€¦

Jeff that photo is pretty scary !!

Iā€™m surprised no oneā€™s pointed to a href="http://www.web-hits.org/txt/codingunmaintainable.html"How to Write Unmaintainable Code/a

Comments are fine, but maintainable code is so much more than just documentation.

Iā€™ve had two sizable, heavily used codebases under my jurisdiciton, in my career so far. Lucky for me, the first was the very maintainable one. I learned a lot about the SDLC from that job.

Needless to say, the second codebase had several 1500 line sprocs that outputā€¦ (wait for it)ā€¦ html!

Also, I canā€™t believe no oneā€™s mentioned Brian Kernighanā€™s famous quote, ā€œEveryone knows that debugging is twice as hard as writing a program in the first place. So if youā€™re as clever as you can be when you write it, how will you ever debug it?ā€

@Tips: this is the funniest comment Iā€™ve read here in a while:

ā€œIā€™m not really understanding your post or what itā€™s aiming to!
I think you have to review some of the articles your are publishing hereā€

Jeff, I certainly appreciate when you press the idea of best practices. However, letā€™s all keep in mind that sometimes best practices have to take a hit from deadlines, stress, and bad management. Donā€™t be so quick to curse the developer of the code youā€™re struggling to maintain until youā€™ve coded several thousand lines in his/her shoes.

Granted sometimes even under the most favorable of conditions people churn out bad code. But even the best and brightest might produce code thatā€™s not up to their usual standard under certain circumstances.

Additionally, not everyone has really good peer mentorship. Some are learning as they code, developing best practices along the way (thatā€™s certainly the story for me!) Code they produced even six months ago isnā€™t as pretty as the code they are producing today.

More blame is surely earned by the guy thatā€™s been programming for years and still produces sloppy code.

Just keep an open mind.

My first job in college was doing tech support on a small commerial product. Being a small consulting firm, I was able to teach myself VB and work my way into development there. My first few assignments were maintenance work on existing client projects. Unfortunately, I learned more about how not to program and how painful unclear code can be to someone not familiar with it. To this day, I code with that pain in mind. As I code, I think about holding myself accountable to some imaginary maintenance programmer sitting next to me to whom Iā€™m explaining the very code/comments Iā€™ve just written.

That was priceless experience. Some of my coleagues have not had such experience and I can see it in the code they write; their whole approach to coding a solution.

In classic French kitchens, cooks didnā€™t go to school to attain their position, they worked their way up from dishwashing, to prep cooking (cutting vegetables, etc.), to cook, to chef. Along the way they learned every detail, both good and bad, of every aspect of a functional kitchen. That depth of knowledge and wisdom can only be gained through personal experience.

In school they always preached to write good code and comment your code so the next person could maintain it.

Of course, if you want job security, write your code so the next person canā€™t :slight_smile:

Acctually that doesnā€™t work so wellā€¦ when you write something and then donā€™t look at it for a few months, you might as well be that next person. And then youā€™ll be kicking yourself for coding that way.

Iā€™ve never gotten angry because of code that I had to maintain but Iā€™ve been profoundly saddened many times.

I believe being able to read code is as great if not greater skill than being able to write it. Having been a team lead, Iā€™ve given legacy code that is still in production to programmers to be modified. Sometimes the programmer will come back after a cursory examination and declare the code to all be crap and that it needs to be re-written, even for code that was well written and had been peer reviewed. What I learned over time is that some programmers are really good at reading code and others are not.

I always do this for code Iā€™ll maintain. Because itā€™s true.

Jeff: Not entirely related to this post, but in the last two months, you had a post that discussed error handling on ASP.Net apps. (It might also have been on the stackoverflow blog.) You noted how it was the first thing you setup on a project, and it sounded like a neat tool.

I didnā€™t note that open-source project with a horrible name at the time, and Iā€™ve been trying to find it - but I canā€™t find the post now, and canā€™t recall the name.

Am I going mad?

ā€œAny of your code that you havenā€™t looked at for 6 or more months may as well have been written by someone elseā€ (canā€™t remember the name of the person who wrote it but its true in my experience)

And I agree with the sentiment that well written code should be fairly self-documenting. What I like to see in the comments is an explanation of any dependencies and business rules relating to WHY the code is implemented in that fashion. Your code tells me what you did, comments should explain the non-obvious.

You should make one of those motivational posters out of this image (with the bold text included of course). Thatā€™s the best line Iā€™ve read in a long long time!!!

Picture scared the crap out of me. Thatā€™s all I have to say.