php[architect] Home

Programming: you're doing it wrong

Posted by on March 10, 2010

The year 2010 marks the twentieth anniversary of my professional involvement with the IT industry; in two decades, I have learned that programming, more than any other profession below “Keith Richards,” seems to attract people who have a certain ego. I don’t mean to say that we’re all megalomaniacs in search for a country to run, but there certainly is no lack of opinionated types in our industry.

The result is that a programmer who wants to make a name for herself soon finds out that it takes an extremely thick skin to survive in this world—even if you try your best to avoid being caustic, chances are that others around you won’t. In the world of computers, people have to volume settings: loud, and extra loud. To borrow lamely from pop culture, our amps all start at eleven.

The question is: why?

Critic’s Corner

One of the things that I have learned in twenty years of attempting to program is that we’re all doing it wrong. You. Me. Everybody.

No matter how advanced the techniques that we use, there is always something that we could be doing better. Do you think that static methods are convenient? Sure, they work—but His Holiness Martin Fowler has decreed that Singletons are the correct way of handling static data. Except, of course, that he also told us that dependency injection is a much better way of handling external dependencies.

Which one is right?

The real problem is that the answer to that question is, “yes.” That’s because it lacks a specific context in which it can be inserted. Dependency injection may be the correct answers in some situations, while singletons may be perfect for your needs in others. Without in-depth knowledge of the circumstances in which a particular problem presents itself, there is no particular way to offer a definitive solution.

Meanwhile, in the Bat Cave…

While we stand and argue the finer points of computer science, we often lose sight of our primary mission: enabling processes. A programmer is first of all an artisan: proud of her work, but most productive when she is making something.

Somewhere along the lines, we’ve somehow managed to convince ourselves that we are artists. We have stopped debating differences on their merits within the context of enabling us to get things done—instead, we argue them endlessly in the abstract, as if writing code were both means and end. Like the CIO who sets a company’s IT strategy based on what’s on the back cover of the latest issue of Information Week, we’re moving from fad to fad without stopping to consider that technology is a tool and not a substitute for our own responsibility to make choices.

Meanwhile, those who somehow manage to remember that software is a tool achieve great success even if their code leaves a lot to be desired. When I open a PHP file inside the WordPress codebase, I feel like I just boarded a time machine that’s taken me back to the way we used to write PHP code six or seven years ago—and don’t even get me started on what I think of Drupal.

Yet, despite the fact that their code looks like it was written by someone who has no idea who Martin Fowler is and probably thinks that dependency injection is a medical technique for weaning addicts off of opiates, both those products undeniably work, and work well—not to mention the fact that they are very widely used.

More than that, they’re actively maintained, updated and upgraded—despite the fact that, according to what the artists tell us, software written using less-than-optimal techniques should be unmaintainable, buggy and unreliable.

If you’re agonizing over whether you’re writing good code, let me spare you the anguish: you’re doing it wrong—except if your code works, in which case you most definitely are doing it right.

Image credit: Adam Swank


About the author—Marco is the keeper of keys and Chief Garbage Collector at Blue Parabola. He can be found on Twitter as @mtabini.

 

Responses and Pingbacks

Very true, although I can’t let go of the thought that programming is also an art. That’s what keeps the job interesting to me, creating better or more structural solutions, not reinventing the wheel so I can move on to new challenges instead of doing plain production work.

 

Very well put, Marco.

 

I could not agree more. While programming is an art form, let’s not lose sight of the fact that we are creating tools for everyday people and at the end of the day, people want things to just work.

I would even go so far to say that it all boils down to the UI. IOW, if the button does what it was supposed to, users don’t care about the “correctness” of the logic behind that button.

Of course I am over generalizing to a degree; there are always exceptions to the rules, not all software is for a broad audience and best practices are called best practices for a reason. However, the phrase “make it work” can mean the difference between success and failure.

 
Q_the_novice on March 11th, 2010 at 1:41 am

His Holiness Martin Fowler’s website is still using tables!

 

Amen! The most important words I have read in a long time, and it is good to read it on the php|architect site, as the magazine itself seemed to be losing this perspective a little of late.

Although authors / commentators mention: “technology is supposed to enable processes”. The echo chamber of bloggers and tweeters treat it almost as some sort of inconvenience in the way of their patterns, unit tests, orm, framework …

Don’t get me wrong these things all have a place and are important, not to mention interesting, but do you really think the client / organisation (person who pays you) cares one jot.

I would far rather work with someone that knew how to question a project and its goals (possessing business awareness), than someone who knew the ‘right’ answer to: singletons vs static methods vs dependency injection?

 

Absolutely right. As soon as programming becomes an art, it loses its relevance. Calling someone an artisan is not to deride; look at what stonemasons and carpenters have, and do, achieve. They make things of beauty, but they are not artists.

I have long experience as a profresional programmer, going back to PDPs (for those with long memories). The most important achievement of a programmer is to create software that delivers the desired functionality within budget and time. If it happens to be “pretty” also, then that is a bonus – provided that making it “pretty” didn’t add time or cost!

My first lesson along these lines came when developing a system for clerks to enter data; I was working out how to make an interface that looked good – until it was pointed out to me that they don’t look at the screen when working and never, ever, want to move their hand off the numeric keypad.

I also think that there are times when a GOTO statement makes code clearer – but that’s another long argument!

 

[…] an opinion piece posted to the php|architect site Marco Tabini suggests that we (as developers) are doing it wrong as we move further and further away from the pragmatic side of programming into the abstract. No […]

 

Right on. This is a great reminder of what we all tend to forget as we’re bombarded with new tools and techniques.
I think it’s worth calling out the difference between an artisan and an artist. From Wikipedia:


artisan –
#A skilled manual worker who uses tools and machinery in a particular craft.
#A person who displays great dexterity.

while. . .


artist –
#A person who creates art.
#A person who creates art as an occupation.
#A person who is skilled at some activity

The words have relatively broad meaning, but I read this as an artisan is one with technique and tools, while the artists make the art. For example, Jackson Pollock trained as an artist, but I’m pretty sure they didn’t show him how to throw paint at a canvas in art school. Regardless of your opinion on his art, many people like it- and like it enough to pay millions for it- and hundreds of thousands ‘use’ it by enjoying it at museums every year. In other words, he had the technique and the tools, but he had to put them aside to make the art that best reflected his dreams.

I think we should all consider ourselves artists when we’re working on apps, which are a form of art, after all.

,Wil

 

Great post. Food for thought. Thanks.
//Michael.
P.S. Who is Martin Fowler ??

 

“you’re doing it wrong—except if your code works, in which case you most definitely are doing it right”

I think an important thing to add would be – “your code works and continues to work for a reasonable length of time”

 

[…] Tuesday, Marco Tabini told us that we were doing it all wrong. He makes some fantastic points about software development overall, and about the state of our […]

 

Thank you – at last someone who shares my opinion, and has the time to tell the world about it

 

Uncle Bob Martin’s book Clean Code has really helped me create easier to understand, more maintainable, and more testable code. Design patterns help too. The end goal is to solve business problems as efficiently as possible while keeping maintainability in mind.

 

You won me at:
“When I open a PHP file inside the WordPress codebase, I feel like I just boarded a time machine that’s taken me back to the way we used to write PHP code six or seven years ago—and don’t even get me started on what I think of Drupal.”

Well said.

 

What makes that older code great is that is it simple and straight-forward. Coders sometimes get caught up in these crazy uber-complex ideas that ultimately aren’t added enough to offset their complexity. Others swing too far the other way, and just make the code as brutally specific as possible. Neither approach works; neither is right.

Still, just because someone’s managed to get something working doesn’t mean it is good. You really have to factor in the lifetime of the code, and it’s success or failure in making its user’s lives easier. There are great examples of really crappy code that is awful to use, yet extremely popular. The world would actually be a better place if these were replaced, but we cling to them out of habit.

 
Michele Mauro on March 12th, 2010 at 1:58 pm

Fowler wrote lots of clever and interesting stuff, and he is right most of the time. The problem you talk about is probably more related to the fact that Software Engineering is not Engineering at all (despite what my boss and my own Phd say 🙂 ), and that software is such a vast and endless space that different methods and opposite philosophies have still enough space to be true, in their own neighbourhood. Except that a neighbourhood can be a multimillion industry with hundreds of thousand of professionals. And there are many of them industries (just think embedded vs. web programming).
So, it’s not (only) that programming attracts egomaniacs: every field has them. Software Development is so big a jungle that many of them can shout at the same time, don’t hear one another, and be right at the same time.
By the way, don’t say His Holyness name in vain another time. Read at least twice “UML distilled” and you’ll be forgiven. 🙂

 

I don’t agree with everything. I think that code should be written to meet a few criteria besides just “working” to get the job done.

1. Make it easy to maintain. I hate searching through poorly written apps to extend/fix components that are failing or need to be improved because some brains upstairs want things to perform differently.

2. Write so people can read it. Don’t save yourself some time by writing unorganized hard to read code so someone else needs to spend longer to figure out what the code is suppose to do.

3. Reasarch the right way to do things, HTTP_POST_VARS isn’t used anymore, use $_POST and don’t forget to sanitize your input data with actual functions like mysqli_real_escape_string not add_slashes or your own custom function.

It does take longer to work with poorly written code after it’s written than to just take some extra time to write it correctly.

 

Many of the new things Martin Fowler advocates are to facilitate the creation of automated unit tests. Lots of programs in production don’t have unit tests; they work, but they are more rigid and resistant to change as a result.

 

[…] Tabini recently wrote on the php|architect blog that “programmers are doing it wrong.” He argues that many […]

 

Excellent posts. And John Kary’s points resonate also. Having read both posts, I have to agree with what is raised on both. While I am a big advocate of minimal, simplistic designs to get your release out in a quality driven manner, I can’t help but agree with Marco in the area of ego winning over pragmatism (if I interpret him correctly).

I have seen projects suffer in the past simply down to, imo, ego – on both sides of the fence. Ego encapsulated in the programmer who thinks half way through the project that we must start again because we should have implemented pattern x at the beginning, to the other end of the pole where senior programmers defend their borked designs and hence everyone suffers the maintenance headache / cost – and end up ‘hating their job’ … as I have come to do in the past.

Know your subject, remember the deadline, don’t leave a mess that you wouldn’t want to revisit.

 

Happy 20th anniversary!
I’ll have my 10th anniversary this October, it feels great! And I agree with you! Keep posting!

 

Its a bit sad to see that people fully agree with your post, as I doubt you mean it exactly the way its written. 😉
The best architecture won’t help if the product’s not working. On the other hand, if one writes code like, sadly, many PHP developers do, you will waste heaps of time on maintenance, because you break stuff all over, again and again.

I’d rather not use copy&paste and filesystem wide search and replace, but good architecture. 😉

 

[…] Tabini pointed out that architecture doesn’t matter as much as having code that works. This is a fine point, and often times is true. But if you ask the average PHP developer if they […]

 

it was pointed out to me that they don’t look at the screen when working.

 

Things may have changed lately but I see acceptable wordpress templates such as studiopress using the same naming conventions and following the same standards as wordpress which makes my point that you can’t just write code any way you want as long as it works because in the future it will be expected to work with other code or some poor coder will get stuck having to work with you code when you didn’t bother following any standards.

I do however, feel that we don’t have to jump on every new technology as soon as it’s available just to try to adhere to zend or php.net.

Oh and by the way, my first experience with phpunit and simpletest was getting false reports because someone didn’t unit test the unit testers when they built them. (Someone mentioned unit testing above)

 

Leave a comment

Use the form below to leave a comment: