4 ms·
The first one is only necessary in languages where functions can have side effects. Otherwise the compiler can easily deduplicate that for you. In most cases y
by thomasahle 11y ago
The first one is only necessary in languages where functions can have side effects. Otherwise the compiler can easily deduplicate that for you.
In most cases you would of course still name the result yourself, as to indicate that the function call indeed is the same. However for something very semantic, such as `sum(list)`, maybe the only name you could give it, would be something like `list_sum` anyway.
- sspiff 11y ago> The first one is only necessary in languages where functions can have side effects To be more precise, it is only necessary in language where all functions can have side effects. Some language (like D) have the ability to mark a function as "pure" (without side effects), which allow the compiler to perform additional optimizations (and purity validation).
- coldtea 11y ago>The first one is only necessary in languages where functions can have side effects. Which makes it, practically speaking, almost all of them...