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?
Procedural programming languages are not as faster as object-oriented. The object-oriented programming languages are faster and more effective. Procedural uses procedures, modules, procedure calls. Object-oriented uses objects, classes, messages.
Procedural programming is used for designing medium-sized programs. Object-oriented programming is used for designing large and complex programs. Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction.
program size: OOP will mean more lines of code than procedural projects. Performance: OOP programs are normally slower than procedural programs.
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.
Unfortunately, I've done my tests too. I did test speed, and it's about the same, but when testing for memory usage getting memory_get_usage() in PHP, I saw an overwhelmingly larger number on the OOP side.
116,576 bytes for OOP to 18,856 bytes for procedural. I know "Hardware is cheap", but come on! 1,000% increase in usage? Sorry, that's not optimal. And having so many users hitting your website at once, I'm sure your RAM would just burn, or run out. Am I wrong?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With