4 ms·
This seems like surprising behavior because we expect compilers will make wise choices. Beginning programmers do the same: for example I've seen something like:
by vsbuffalo 13y ago
This seems like surprising behavior because we expect compilers will make wise choices. Beginning programmers do the same: for example I've seen something like:
for x in stuff_list:
print other_list_of_stuff.count(x)
This is intuitive to beginning programmers and uses Python's methods. But there's hidden complexity behind it. C is no worse a language for not moving strlen out of the loop than Python is for not optimizing this. Languages work at their level, and it's essential the programmer understand the precise bounds of this level.
- smsm42 13y agoNobody who tried to write some code compiling something (I'm not even talking about optimizing C compiler, but parsing or processing any sufficiently rich format that humans can touch) wouldn't expect compilers to make too much of the wise choices. Making code that behaves correctly, in a predictable manner according to what people expect and be "wise" too is very hard. It's easy to say "oh, it's clear I meant foo when I wrote bar" but try to make a code that identifies cases where "bar" means "foo" with 100% accuracy and you'll get why compilers aren't as wise as some think they could be.