4 ms·
I've always had a hard time because I was thinking.. why would I carry the performance hit of instantiating objects for a bunch of stuff?
by sureglymop 4y ago
I've always had a hard time because I was thinking.. why would I carry the performance hit of instantiating objects for a bunch of stuff?
- rolenthedeep 4y agoWhy accept the performance hit of copying structs when you could use a reference type? It's a tradeoff. OOP makes sense for certain types of problems, and functional programming solves other problems. It's very much a case of selecting the right tool for the job. I recently transitioned from C# game programming to C++ embedded system firmware. Objects don't make much sense for what I'm doing now, and I'm coming to see the elegance of functional programming. There is no one answer, just a box of tools. What makes a good programmer is understanding each of your tools well enough to decide which one will solve your problem in the way you want.
- zabzonk 4y agoyou have to instantiate variables anyway. grouping those variables in objects simply makes your code more understandable - there is really no extra cost.
- intelVISA 4y agoCould be wrong but, at least in C++, there's realistically no overhead to creating a trivial object that you wouldn't have by manually instantiating the variables anyway. (Ignoring virtual stuff, lengthy constructors -- code run is code run but a raw object I think is by itself relatively harmless.)
- zabzonk 4y agoyou are right - in c++ (and in most other languages that support oo) there is no overhead on instantiating a structure, or variables, that you would not have to pay anyhow.