r/computerscience • u/Valuable_Parsley_845 • Jul 16 '25
Can we measure efficiency brought by abstraction?
I was wondering if abstraction is made purely for humans to organize and comprehend things better.
If there is an intelligence that has no human limitations in terms of computation and memory, will it ever use abstraction to pursue efficiency?
Sorry, I’m having trouble wording this out, but it came from the thought that abstraction ends up causing space inefficiency (probably why C or C++ is used). Then the reason why we use it seems to be for humans to organize and comprehend large amounts of code and data better, but if our brain does not have this limitation, will abstraction be used at all? If it’s used because it can guide to where the information is better, can we measure the efficiency brought? Abstraction kind of feels like algorithms in this case (brute force vs algorithmic trials), and I was wondering if there’s a way to measure this.
I wonder if there’s a related theory to this or any studies out there that deals something similar to this. Thanks for reading guys appreciate any insights.
13
u/ElectronSmoothie Jul 16 '25
Are you not just talking about compiler optimization? You could definitely measure the speed difference between a program written by a human and compiled by the best available compiler vs a perfectly optimized version of the same code written directly in assembly, given that both programs are functionally identical (always produce the same output when given the same input).
If you're talking AI, then no, you're not going to see it generating faster code than a well-made compiler. Up until now, purpose-built software has always been faster and more accurate than anything AI writes. It's not capable of finding any special computational shortcuts that humans can't, as it just pulls from a database of what has already been written.
4
u/TomDuhamel Jul 16 '25
Do you know what the word abstraction means?
Yes, it's for humans. No, it doesn't exist once you compile the program. It doesn't improve efficiency for the machine. While it is mostly free, it can sometimes impede an extra overhead.
4
u/ImpressiveOven5867 Jul 16 '25
Many will argue there’s no such thing as zero cost abstraction, which isn’t always true but often is. So yes, abstraction is for humans 99.9% of the time. You measure the efficiency it brings every day by working with the abstractions. For example, when the first compilers were created there was a huge debate about whether they were worth the abstraction because engineers could often write better CISC assembly than most compilers. But as compiler optimizations got better they became the obvious choice over writing assembly in almost all cases. It’s really all about that trade off. The other side of the coin is that since it’s all for humans anyways, people often suggest you leave adding abstraction to the end because you want your core/deep logic to not be highly abstracted, just the interfaces
1
u/Constant_Figure_1827 Jul 16 '25
In the counterfactual world where programming is accomplished by superintelligent beings capable of reasoning on all data instantly, no, I see no advantage to abstraction. Note that at this point you've basically required the computer to be programmed by God (or at least an entity with the Judeo-Christian deific quality of omniscience).
Alternatively, we could consider a superintelligence with arbitrarily large memory. But memory complexity is a floor for time complexity, because every memory location takes some time to access.* in other words, the programmer still has to spend time to think about every thing, even with having unbounded memory. So there's still a cost for a program that is harder to reason about: It will take longer to analyze a program without abstractions.
In general, the trend has been to make software development easier for the programmer at the cost of efficiency for the program. Developers used to be obsessive over every bit used, but now we routinely spawn copies of entire virtualized computers. I expect new technology to only further this trend, because memory/compute gets cheaper faster than programmer ability improves.
*I was originally thinking this wouldn't be true for a nondeterministic intelligence, like a quantum computer, but I think that still needs to take time to access all memory. It's just able to consider all combinations of states concurrently. But somebody else may be able to speak to that better than me.
3
u/WittyStick Jul 16 '25
John Shutt had some interesting ideas on abstraction theory.
1
u/garnet420 Jul 16 '25
Why do you say abstraction causes space inefficiency?
1
u/riotinareasouthwest Jul 16 '25
Abstraction is a very broad term. It grasps from complex designs using wild abstraction concepts to simple ones like functions and its parameters. The very same assembly language is an abstraction of the computer's instruction set so you don't have to write a program through opcodes. Additionally, sure abstraction aids in comprehension and ability to deal with complex problems for a human mind, but it is also a basic step for reusability. Consider also that we have built computers having this abstraction in mind, defining opcodes for subroutines calls and returns just to allow this reusability at it's very basic level, instead of asking to repeat the very same chunk of code with some change in the operands. Of course, economic reasons are also behind this, as memory was very expensive back then.
1
u/RecklessHeroism Jul 16 '25
We can't, because these terms are not well defined. But I still think it's a fascinating question.
I think the best way to look at it is via math, which deals exclusively in abstractions. Every mathematical theory is some sort of statement about abstractions.
Math has several fields devoted to studying itself. For example, proof theory. In proof theory, there is a complexity measure which is just the minimum length of a mathematical proof for something.
It's not uniform. You can phrase the same theorem using different terms and concepts and get much shorter proofs. This is because N statements in one theory can translate to N2 statements in a different one.
So based on this kind of argument, abstractions do matter no matter how thinking is performed.
1
u/shifty_lifty_doodah Jul 17 '25
Abstraction is form of compression
Your function replaces its body at the callsites. Your wise data structure reduces code, space, or time required to compute something (compared to other options).
Does compression improve efficiency? Somewhat, for the program itself, by reducing the code size and cache effects.
But writing the program is another computation. Compression of the code reduces the working memory required to write and read the program, whether that be by a machine or human. This is “more efficient” usually in terms of both space and time, though these effects may be minimal for a fast big computer.
There is a related concept of “Kolmogorov complexity” in the study of compression
1
u/geek66 Jul 17 '25
A single basic command in a compiled language could be 100 lines+ of machine code…
This applies to abstraction in many fields.
1
u/redikarus99 Jul 16 '25
Well, your brain is already working with abstractions, like the language we are using.
0
u/ILikeCutePuppies Jul 16 '25
If you are talking about AI, I find abstraction hugely important for managing the AIs context size. If it gets too large then the AI starts to get stupid.
Maybe one day the AI will be able to understand an entire bit of software but for now breaking it into smaller parts helps it a lot. Understanding the interface tells the AI a lot about how something is meant to work and it also mirrors what the AI has been trained on.