It's Friday night. I'm writing code. Not good code, mind you. Crappy code. Completely self-serving code that serves only one purpose: to solve a problem I alone have. No one else will see this code. No one else will use this mini-app. I'm writing it for myself and myself alone.
I did not test this code.
I did not use a framework.
I mixed PHP and HTML in one file.
I'm sure there are numerous XSS and other wonderful security vulnerabilities present.
My code is not indented properly.
My code is procedural, poorly documented and hard to follow.
It is not scalable.
Hell, it probably won't even load in IE.
It looks like ass, too.
In fact, I think I may have broken every best practice I can think of, and probably even a few that escape me at the moment.
And you know what?
I. Don't. Care.
I'll tell you why I don't care.
The value of writing a crappy self-serving mini-app is akin to the value of journaling. Sometimes it feeds your soul to write stuff just for the heck of it. Writing for your own purpose, and for no one else to see. Just to get the ideas down on paper. To throw the rules of grammar and spelling to the wind. To throw the thesaurus and sentence structure right out the window. To write just for the sake of writing. In fact, that's what NaNoWriMo (that some of you may be familiar with) - is all about. To write for the sake of writing, not to write a masterpiece. It exists only to get your creative juices flowing.
How many times has our creativity been stifled by our own perfectionism? We have an idea for an app, and we try to do everything perfect from Step 1. This will be the app of the century, we tell ourselves. This code must be perfect. We must get everything right from the very beginning. Everyone will see this code. Everyone will use this app. Our reputation will be on the line!
Before we know it, the development of our app has stagnated. We get bored. We come up with another idea that is even more exciting, and we abandon the old for the new. Shampoo. Rinse. Repeat. The cycle never ends. Burnout is inevitable.
I say screw that. I challenge you to write a few lines of crap code that solves a problem you have. Be selfish. Break the rules. Stir it up a bit. Write some crappy code that serves a purpose for you and you alone. Just because we work in open source does not mean we have to always open our source. Make this code for your eyes only.
Of course, I'm not advocating actually deploying your crappy code, in the same manner I wouldn't recommend you sending your personal journal to Random House for potential publication. So don't expect to write shitty code, get sued or worse, suffer public humiliation, then blame me.
But for now, come on, get crazy. Change your files *right on the production server*. I won't tell.
It's liberating!
After spending all day worrying about complexity, code quality, unit testing, logic errors it's nice to come home to code that loves you and doesn't mind if you add on a few extra functions that don't really belong there.
Just like any other artists, we coders need to just let it all hang out sometimes and let the code take us where it wants - good or bad.
Don't think - just code. It's amazing how relaxing it can be.
Fight the power!!!!
Amen to this sister. Amen to this.
ACK and full ACK
"Change your files *right on the production server*" it is! And y'know, I'm even doing so as root!
(and the business my software runs hasn't even collapsed yet)
cheers
Completely agree!
You can still maintain the moral high ground however by calling it 'a prototype' ;-)
Fantastic Post!
Hah ! You just said aloud what I know I've been thinking for ages.
You're indeed supposed to spend your work time writing tested, re-usable, as-much-as-possible perfect code ×
And whatever happens, nothing you write ever gets lost for real. It's much easier to experiment with quick ?
Amen ;)
I was right with you until the irrelevant last line.
By definition. production is not private, except in very trivial cases.
Productions has nothing to do with the tools tricks and toys we perpetrate in the privacy of our own daily activities :)
I've got more than a couple of projects sitting on my hard drive just for this purpose :)
I can fully support the idea that sometimes you just need to code. Something has to break you out of your rut. Also, like a Seinfeld calendar, you need to code regularly or you lose your skill. Sometimes the high ceremony gets in the way of actually writing code. However, I do have concerns.
My old High School coach used to say, "Practice doesn't make perfect. Perfect practice makes perfect." His point was that if you practiced poorly, you'd also perform poorly. That's what this blog post reminds me of. Having been working in PHP lately, I can experientially say that the performance is as poor as this practice.
As a counter example, Uncle Bob wrote this blog post (today!) on Coding Katas (http://blog.objectmentor.com/articles/2009/11/21/whats-all-this-nonsense-about-katas). As usual, Uncle Bob nails it both with his writing and his performance. I encourage you to watch the video he links at the end of his post.
I know I'm going to come across as a Big Jerk in this comment. What I've found to be the case is that PHP needs more discipline, not less. edit "right on the production server"? Is that the norm? No testing? Again, seems like the norm. XSS and security problems? Every day I've worked in PHP I've found security problems; the norm.
Feel free to delete this comment if you think I'm being too jerky. Next time we meet up, I'll buy you a beer or two.
@Doug Alcorn:
Haha, no worries, my friend. I hope my post does not add to the stereotype that PHP devs are lazy or undisciplined. And of course I wouldn't advocate practicing to be crappy. I'm merely suggesting we let our hair down for a moment and not let our own perfectionism get in the way of our creativity. Kind of like singing in the shower and not using the proper breathing techniques. Or painting an abstract that doesn't follow the rules of perspective or form (and doesn't even *resemble* a bowl of fruit). Create just for the sake of creating.
Of course it's not the norm to change files right on the production server. Of course it's not the norm to not give a lick about testing or security vulnerabilities. To suggest people follow these practices on a regular basis would be ludicrous.
Believe me, I know there is a lot of crappy PHP code out there - but give Ruby some time. There will be a lot of crappy Ruby code out there some day. It's just easier to write crappy code in PHP. :)
Great post!
I think crappy code is where you learn. Over the past few nights, been writing crappy code, just to see what HTML5, and CSS3 are capable of, (and subsequently get a feel for which browsers support what.)
Not too concerned with the PHP code behind it, which does have some glaring security problems, as it uses file uploading.
Truth.
I wrote an exit(0); column in php|architect on a similar topic, a long time ago. I should dig it up and re-post.
Writing code that doesn't meet professional standards is the most fun code.
S
Great post!
This is a practice that I call "Code for fun" which I sometimes use on late Friday night programming.
Actually as I'm getting better with time, this crappy Friday night code becomes better, and sometimes even helps me sketch ideas which I eventually publish.
When I have a problem, I often write code to solve it, and I don't apply best practices either. I have a cron job that runs every day to send my fiancee a reminder email - it makes use of the mail() function and you know what? I don't care!
Software development isn't about (and shouldn't be about) never having fun. Writing scalable, clean code is critical for big projects, but not so important for personal solutions.
Thanks for validating something I've believed for a long time.
Hehe ... funny article.
Well once you have grown up a bit you can make this kind of decisions 'i just want to have it done'. I guess its fine. You cant polish and gold plate for hours every silly script you write.
Im just more cautious about that as its easy to reuse these disposable scripts and then it becomes a bad habbit ;-)
If you really know you will never use it again ... i cant see a problem with it, go ahead.
Art
I completely agree! On some (windows) servers I use some PHP scripts instead of batch files, because I can do more in less time with PHP. I want to get things done and I don't need a framework, I just need a powerful scripting language.
There is also some code you just throw away after it has completed it's job (think of singular data imports or migrations), doesn't make economic sense to waste time on that as long as it achieves results.
Have you no shame Elizabeth?
Ha ha, just teasing.