5
2013
Dev Confessions (And lessons learned the hard way!)
I’ve learned a lot through the years as a web programmer/engineer/developer (pick and choose the term you prefer). I’ve so too many thousands of lines of code to count, I’ve seen so many errors and warnings and server outages that I just don’t care to describe, and looking back at my past work is often pretty horrifying!
Let’s get those confessions out of the way
Forgive me oh holy purveyors of code, for I have sinned (in the past, but hopefully no more!).
- I have failed to indent my code properly
- I have done a terrible job of commenting code that makes little to no sense, even to me
- I have if/else’d without thine holy curly brackets
- I have suppressed errors without fixing them
- And I have done a terrible job of organizing files and directories
Now onto the finger wagging!
Now that you know I haven’t ‘always’ been perfect, I can get into holier-than-thou bit that is actually the larger picture here (visualize a winking face!).
After teaching, and rewriting, and yelling at, and fixing LOTS AND LOTS of code (my own included sadly), there are a few things that I’ve come to notice, hate, and feel very strongly about.
- CAMELCASE. $ThisShouldNoteVer_Be_a_VAriaBle. There is NO reason for this. I see LOTS of camelcase, and though it is accepted in jQuery, Javascript, and PHP Classes (end. ONLY class names), it has no purpose or use other than:
- Breaking things. PHP IS CASE SENSITIVE. All it takes is one tiny little slip of the space bar and BAM. Your variable doesn’t exist. Guess why? Oh, right- CAMELCASE.
- Giving the gift of a massive headache to any other developer who is ever unfortunate enough to inherit, or even look at your code.
- Giving the gift of a very large bill to your former clients when I am contracted to fix what the camelcase has broken and I see that the codebase is a bumpy ride on an irregular space bar.
- COMMENTING. Though I’ve never gone on the camelride before, I was historically terrible at commenting my code. This is not good. When even YOU (where “you” means “person who coded it”) don’t know what you’ve done, imagine how frustrating it is to inherit someone else’s (or a blast from your own code past [see bullet #2 in confessions above]) codebase and see things like…
function xy( $yes = false ){ if( $no == 'green' ) { echo 'WHYYYYYYY?!!!!!!!'; } }
- APPROPRIATE LINE SPACING AND BRACKET USAGE. Even I have been guilty of this one until recently when I discovered the epic fail of my ways. What I refer to is fun stuff like:
if( $one == $one ) echo 'What we all knew was true has been proven'; else echo "Apparently we can't do basic mathematics"; echo 'But then again, who knows!';
Which is problematic since the last line is always going to be executed, no matter what. Couple that with the fact that at a quick glance, I am not going to see that a conditional ever existed (no one is, don’t get all high and mighty on me now 😉 ). The example above should be:
if( $one == $one ) { echo 'What we all knew was true has been proven'; } else { echo "Apparently we can't do basic mathematics"; echo 'But then again, who knows!'; }
See, it’s not rocket science- just a couple extra key presses and we all have a very clear understanding of what is supposed to happen!
- CODE INDENTATION! Do I need to say more? I probably do actually.
' ' != 'proper indent'; //Aka, NO GOOD '2 spaces' != 'proper indent'; //Aka, NO GOOD '3 spaces' != 'proper indent'; //Aka, NO GOOD '1 tab stop (4 spaces)' == 'proper indent!'; //Sigh of relief. GOOD.
That’s it for today folks!
Not that there aren’t more things that make me curse and wave my fists wildly in the air, but I’m getting worn out just thinking about it!
Anything I forgot that makes you want to scream at the code?
5 Comments + Add Comment
Leave a comment
Recent Snippets
- htaccess : Only allow access to specific wordpress upload types if logged in
- MySQL : Query WordPress Database for Invalid Media Filenames
- PHP : Get Actual IP Address with PHP
- JavaScript : Allow Tab in Textarea
- PHP : Clean sanitized database contents on output
- htaccess : Force www. prefix in URIs
- PHP : Force File Download with Correct Content Type
- Wordpress : Disable upgrade notification
echo ‘some people don\’t alternate quotes.’;
echo “some people don’t do this. It’s easier to read.”;
Escaping unnecessarily annoys me. Just alternate your quotes.
Completely valid! (Though I personally find it easier to use single quote encapsulation when mixing HTML and PHP as I then do not have to escape all of the double quotes, but you’re still completely right Chris and I’ve amended the article!)
In HTML I personally prefer using the former…
echo “Link”
echo “Link”
echo ‘Link‘
Damn WordPress.
echo "Link"
echo "Link"
echo 'Link'