In interpreted programming languages, such as PHP and JavaScript, what are the repercussions of going with an Object Oriented approach over a Procedural approach?

Specifically what I am looking for is a checklist of things to consider when creating a web application and choosing between Procedural and Object Oriented approaches, to optimize not only for speed, but maintainability as well. Cited research and test cases would be helpful as well if you know of any articles exploring this further.

Bottom line: how big (if any) is the performance hit really, when going with OO vs. Procedural in an interpreted language?

+3  A: 

Bottom line: no, because the overhead of interpretation overwhelms the overhead of method dispatching.

Mark Harrison
+9  A: 

Maybe I'm crazy but worrying about speed in cases like this using an interpretive language is like trying to figure out what color to paint the shed. Let's not even get into the idea that this kind of optimization is entirely pre-mature.

You hit the nail on the head when you said 'maintainability'. I'd choose the approach that is the most productive and most maintainable. If you need speed later, it ain't gonna come from switching between procedural versus object oriented coding paradigms inside an interpreted language.

I had the boss from hell. He knew nothing about programming, but thought he knew everything (he lectured me on Unix timestamps once, telling me that, "Unix timestamps are like European timestamps. They do it weird, they put the day first and then the month like this: dd/mm/yyyy" ROFL, what an idiot). So when he found out I was doing OO PHP, he flipped out and said it would "slow down our site". I was looking for any sort of study I could find to prove he was full of it so that I could continue programming OO...
sounds like a
+1  A: 

If you are using an interpreted language, the difference is irrelevant. You should not be using an interpreted language if performance is an issue. Both will perform about the same.

Justin Standard

I've actually done a small test like this in python on a website I maintain and found that they are almost equivalent in speed, with the procedural approach winning by something like ten-thousandths of a second, but that the OO code was so significantly cleaner I didn't continue the exercise any longer than one iteration.

So really, it doesn't matter (in my experience anyway).


Your performance will be characterized by the implementation, not the language. You could use the slowest language and it could scale to be the biggest site in the world as long as you design it to scale.

Just remember the first rule of optimiztion.



Jon Clegg