7

I was just wondering whether it would be worth sticking to non-OOP code for the sake of speed. Also, In commercial web-applications, is OOP generally used or avoided? Which is the standard?

Many Thanks,

Ed

Edward
  • 95
  • 1
  • 1
  • 9

4 Answers4

10

The standard is to favor readable code over efficiency, because most of the time "more efficient code" runs faster by a single millisecond. Object-oriented programming is generally more readable than a non-object-oriented counterpart.

See also this question: Why are so many web languages interpreted rather than compiled?. The majority of a page's load time is spent sending and receiving data or doing database things.

Community
  • 1
  • 1
Waleed Khan
  • 11,426
  • 6
  • 39
  • 70
  • So would it not make a significant difference to the user? – Edward Nov 18 '12 at 00:09
  • 2
    @Edward In most cases, no. You shouldn't concern yourself about efficiency unless your code is actually running slow — and remember, [premature optimization is the root of all evil](http://c2.com/cgi/wiki?PrematureOptimization). – Waleed Khan Nov 18 '12 at 00:10
4

OOP is generally used in commercial webapps, and is turning to be the standard. The reason for it is not efficiency - it's code re-usability, code readability, easy documentation, structure, and more importantly modularity!

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
3

Object-Oriented code is the standard, but not for performance reasons. It is really about maintainability.

Code speed is seldom of any real consequence in web applications. I/O is much more relevant, and most of the optimization people engage in is ultimately designed to reduce I/O:

  • Persistent database connections
  • Data fragment caching
  • Page caching
  • Client-side cache headers

Any significant CPU-intensive tasks are usually handled by compiled plug-ins, and made accessible to the interpreted language. Some common examples:

  • PDF Generation
  • Image manipulation (Imagik, GD)
  • Cryptography (OpenSSL)
slashingweapon
  • 11,007
  • 4
  • 31
  • 50
1

I think the OOP overhead is generally negligible for speed performance, and the code will gain much quality.

Commercial applications usually use OOP, if started after that was available (and stable!)

CapelliC
  • 59,646
  • 5
  • 47
  • 90