Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does OOP compile?
#1
Suppose I want to be anti-OOP and
- use structs instead of classes
- external functions (that take the struct as a parameter) instead of member functions
- global variables instead of static member variables
- functions pointers instead of virtual functions
- manually call constructor/destructor
etc

Now here's my question, does OOP reduce to the above, or would converting to the above save space and make it faster?

It's just that we're almost finished covering OOP in my C++ class, and although I'm beginning to apreciate the benefits, and still can't shake an uneasy feeling about how much slowness/bloat I've heard it introduces.
Reply
#2
Why not try it for yourself, and see if it works for you. If you find that the benefits are greater than the slight slowdown you MIGHT get (some people like to whine about anything and everything) then you make that choice. These things are prolly better to experience for yourself rather than going on what everyone says. Smile
igitalblackie.com - Done! Smile Ask about our hosting Wink

-Goddess of the of the No More Religion Threads movement Smile
Reply
#3
AFAIK, from my works on the topic, OOP compiles to procedural (that's the way ASM is) code. OOP is just a high-level artifice to make coding more easy, reliable and robust.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#4
Quote:It's just that we're almost finished covering OOP in my C++ class, and although I'm beginning to apreciate the benefits, and still can't shake an uneasy feeling about how much slowness/bloat I've heard it introduces.
What you have heard about slowness and bloat has been greatly blown out of proportion. Such rhetoric is always started by old schoolers who didn't have the OOP convenience when they were first programming and they have yet to convert to the newer system. In this act, they concoct lies and myths about OOP. Although it is true that you can lose a very small amount of speed and give up a very small amount of size to OOP due to it being SO high level that more generic routines are written, the difference is so miniscule that it's not even worth mentioning. This holds doubly true for today's advanced optimizing compilers. As na_th_an said, OOP is reduced to procedural code anyways, so actually you're going to have to do more work to code in a way that you're already going to see the results of. You may gain back that 0.1% speed increase or that 32KB size difference. But is it really worth the headache? And as Rhiannon stated, try it for yourself and see which way you like. If you enjoy the hard work of procedural C++ and need the difference in speed and size, go that route. If you would prefer the ease of programming that OOP provides and don't mind if sometimes your programs might run a hair slower or be just a little larger, go with OOP. It's all personal preference. Just do yourself a favor and don't listen to the anti-OOP zealots because if given the chance, they'd tell you that Visual Studio .NET has "sekrit APIs that only Micro$oft has axx to!".
I'd knock on wood, but my desk is particle board.
Reply
#5
Well, my good-friend na_th_an is right when he says that OOP is just a high-level way of programming.

Some time ago, I began to programming a "Window handler" for a GUI. I designed a struct which contained relevant information of a window/container and some behaviour using function pointers. Then I stopped due to lack of time and so, and noticed that all i was designing where an object. So, the question is, why to program all that code when I can make use of OOP, which implements the idea I was developing? So the answer to your Sterling first question is: yes, OOP reduces to consider every thing in a Software development to have properties and behaviour (id est, attributes and methods). If you take a struct, consider the fields as attributes and function pointers as methods, you are programming an object. OOP languages provide you that.

Referring speed topic, well, it isn't a language class question (OOP, procedural, functional, declarative, whatever...) it's a optimizing question. You can't measure if OOP is faster than not OOP, you must compare the code it generates.

Another question about speed: OOP high-level programming doesn't introduce delays. What happens is that now that OOP is being very used, programmers use more and more external libraries, than may introduce delays with dinamic linking, procedure calls, etc.
ed: nothing better when you are tired.
Reply
#6
since I know you are trying to write a compiler (as am I Smile) I will suggest to you an idea. Get your copy of C++ (ive got GCC), code some OOP program, and compile to the asm source.

With GCC its: g++ source.c -S (I think)
then look at the source and decipher. Ive tried this a little, and the asm source is horrible and non-intel code but may be of some use.

And as phobeuos said, the only speed comparison you can make is of the executable code. If a compiler has good implimentation of OOP then it may be very good code. It could be bad, but dont worry I think.
Im also interested in OOP as to what it compiles to heh. If you find much out please tel me Smile
Reply
#7
OOP sucks.

End.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
Quote:AFAIK, from my works on the topic, OOP compiles to procedural (that's the way ASM is) code.
The original AT&T C++ compiler simply compiled down to C, then to get an executable you would just run the C compiler.

Quote:What you have heard about slowness and bloat has been greatly blown out of proportion. Such rhetoric is always started by old schoolers who didn't have the OOP convenience when they were first programming and they have yet to convert to the newer system.
OOP is not the new system, it has been around since the 70's, it is just a different style of programming. OOP will never replace structural programming, because different styles suit different projects, a good programmer knows when to pick what language and style.

Object orientated languages often do have some slowness/bloat because of the overhead of how objects work, its not a major problem these days because of the memory size and cpu speed of modern computers, but programs that need to be lightning fast (such as operating system kernels) are still often coded in structural languages.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#9
OOP doesnt suck, it's just another, higher, level of programming.

Why do you program in C over ASM? It's slower and bloats your code. Think of it that way. OOP is plenty useful when speed isnt an issue, just like higher-level math calculations are useful over ASM when you dont need lightning-fast speed.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#10
C/QB are one step removed from the actual commands that are inside a specific processor. ASM coding often means you can optimize with the specifics of the language.

OOP sucks because it's too removed. Some people don't even learn procedural programming and they start to overcomplicate things by using OOP. If you want to use OOP because it is easier to create a program with OOP for you, go ahead and use it. But, my superior intellect does not require the use of OOP.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)