Quora Feeds
Active Member
Barry Rountree
Adam Hartline said most of what needs to be said, but I do want to disagree with him slightly about C. In low-level languages such as C and Fortran, there’s a well-understood mapping from source code to assembly code and architecture. It’s not perfect — otherwise it turns into assembly — but if you set up a struct, you can trust the compiler to lay it out in memory in a specific way. If you make a function call, you can have high confidence where the flow of control will land.
C++ is a bit higher, and those conventions start breaking down. A struct may still look like a struct, but you really don’t have any intuition as to how a class is going to be laid out in memory, or how many function calls will be triggered by a constructor. If you’re trying to understand how a particular bit of code interacts with a particular processor, this situation can be intensely annoying. If you’re working at higher levels of generalization and the performance you’re getting is good enough, the additional abstraction can be a lifesaver.
And that, ultimately, is why we have lower-level languages. There’s a tradeoff between abstraction and performance, and if you’re writing performance-critical code, you end up expressing the problem in terms the machine can understand, rather than in terms that are convenient for you.
See Questions On Quora
Continue reading...
Adam Hartline said most of what needs to be said, but I do want to disagree with him slightly about C. In low-level languages such as C and Fortran, there’s a well-understood mapping from source code to assembly code and architecture. It’s not perfect — otherwise it turns into assembly — but if you set up a struct, you can trust the compiler to lay it out in memory in a specific way. If you make a function call, you can have high confidence where the flow of control will land.
C++ is a bit higher, and those conventions start breaking down. A struct may still look like a struct, but you really don’t have any intuition as to how a class is going to be laid out in memory, or how many function calls will be triggered by a constructor. If you’re trying to understand how a particular bit of code interacts with a particular processor, this situation can be intensely annoying. If you’re working at higher levels of generalization and the performance you’re getting is good enough, the additional abstraction can be a lifesaver.
And that, ultimately, is why we have lower-level languages. There’s a tradeoff between abstraction and performance, and if you’re writing performance-critical code, you end up expressing the problem in terms the machine can understand, rather than in terms that are convenient for you.
See Questions On Quora
Continue reading...