3 ms·
Thats the reason why assembly should be the first or the second language studied by beginner programmer. Thats the reason why Knuth use assembly in his TAOCP in
by ordu 9y ago
Thats the reason why assembly should be the first or the second language studied by beginner programmer. Thats the reason why Knuth use assembly in his TAOCP in code examples. Moreover if one wants to write fast programs he should be friend with -S compiler flag to know exactly what assembly compiler generates on this or that high-level code.
When you are familiar with asm you see that `obj->virt_func()` not just fancy and convenient but also there are some magic behind that which cannot be described by simple `call mangled_virt_func_addr`.
When you are familiar with asm you can see than calling function like
int foo(int a, int b) {
return a + b;
}
is way slower than just do `a+b`, and not just because of call/ret instuctions and possible cache misses, but because of compiler lacks ability to make some optimisations. And you write `inline` functions for such small tasks.
When you are familiar with asm you inevitable see all this quirks. Sometimes you do not want to see them, but nevertheless you notice them every time, and you need to make a consious decision to leave some code inefficient, due to (for example) "i'm writing program that will be run one or two times, and time spent to make it fast would be greater than time saved on faster program runs".
- virtualized 9y agoIf I write the foo function in assembler, it will also be slower than just a+b. The assembler won't be able to inline the function, which makes the C version possibly more efficient. You are comparing apples and oranges.
- ordu 9y agoYes, I agree. But I'm not trying to persuade anyone to use assembly instead of C. I'm trying to say that experience with asm greatly helps to to see a difference between `foo`, `inline foo` and `virual foo`.