Tag: clean code

Commented-out Code is rotting code

One of the things I really hate, and programmers should really avoid is commenting-out code. Do NOT do this!

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
//curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
//curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_URL, 'http://www.testingsite.com');
$result1 = curl_exec($ch);

curl_close($ch);
?>

You all have seen code like this. Commented-out code you do not know why it is there and if it should be deleted.

IF you work in team or if you work on the code yourself and coming back to it after some while, you and others will not have the courage to delete it. Everybody thinks it is there for some reason and it should not be deleted, because of too important. In the end they all clutter up fine code and make it a rotting code.

Why are those lines of code commented? Are they important? Where they left as a reminder for a change at hand? Or is it just dead code nobody ever took the time to clean up? Aren’t cookies used anymore and why not? Should it be enabled again? Why was the decision made to comment it out. A million questions arise. Those questions make it harder for the reader of the code to understand the story clean code is trying to convey. Remember you are not just writing programs you are writing stories through code. You are not a programmer, you are a story teller. Stories should get better over time and changed to today’s thinking.

Keep your code clean, just delete the code, today we have source revision control systems as a reminder of old code. Use that. You will not loose the code, SVN remembers. Promise.

Warm winter greetings from Belgium
Nick Belhomme