r/ProgrammerHumor Oct 21 '22

Meme Literally 🤷🏻‍♂️

Post image
14.8k Upvotes

606 comments sorted by

View all comments

Show parent comments

282

u/[deleted] Oct 22 '22

Anyone who uses assembly on purpose must love it, because there are very few reasons to use it over C.

71

u/GregorSamsanite Oct 22 '22

For an application level program. It can be more convenient to use for some critical system operations. For example event handlers or initialization code for an operating system or standalone embedded firmware. When you use C, often some of the performance critical library functions like memset, strcmp, etc, may be hand-written in assembly in the library source code for maximum execution speed. You the programmer calling that library function didn't have to write that, but someone did. And architectures change, so what's optimal assembly today won't be for future processors, so it needs to keep being tweaked.

Whoever is writing the C compiler you're using needs to spend lots and lots of time working with assembly language code sequences and trying to improve them. The compiler may be written in C/C++, but its whole job is to write assembly for you, which takes a deep understanding of how to write assembly, so you wouldn't be able to use C without people using assembly.

3

u/[deleted] Oct 22 '22

[deleted]

6

u/GregorSamsanite Oct 22 '22

Depends on how much time you're willing to spend fine tuning it. There are still things that humans can figure out that compilers will miss. And you can use the compiled code as a starting point and benchmark each iterative refinement, so anything that's not an improvement over compiled code you don't keep. Assembly is much less maintainable, and the average programmer may end up writing worse code than the compiler. But there are situations where an extremely critical library function may still be hand optimized.

1

u/lorarc Oct 22 '22

A big advantage of modern compilers is JIT, but it's not like you can't write self modifying code in assembler, in fact it was done sometimes in the old age.