5 ms·
> ...Optimizing memory accesses is hard because you don't know who's looking at the memory in a global sense...In a language like C, therefore, there's a tensio
by benlorenzetti 9y ago
> ...Optimizing memory accesses is hard because you don't know who's looking at the memory in a global sense...In a language like C, therefore, there's a tension between generating optimized code and generating predictable code, and that tension comes from the fact the compiler doesn't know which code could have side-effects and, therefore, invoke spooky action-at-a-distance if it's optimized too aggressively.
I get this argument for functional languages and Haoyi's description for functional style, by writing down the expression tree not just one possible serialization the expression tree, was excellent); both the freedom to access memory and the lack of richer information about possible execution orders makes it more difficult for automatic compiler optimizations. I have definitely bought into writing C in a functional way when using local variables.
However, the lack of some compiler optimizations due to memory aliasing guarantees is not always a disadvantage. Like bootstrapping a compiler, taking advantage of new processor features, doing an inherently sequential task like state machine parsing, or even if you just enjoy thinking about data and algorithms at a low level.
What imperative languages need to remain competitive is richer type systems regarding objects with pointers into the heap. And this is no secret; languages have been experimenting with this forever. C++'s attempt with object oriented programming was a good stab in the dark but clearly has limitations, with the explosion of type information regarding things like exceptions and wart covers like move semantics.
What I would like to see is a language with weak typing and free pointers like C, but with a more capable, generic type system with concepts, like that described by Alexander Stepanov in Elements of Programming. Also object orientation as a language feature should be replaced by [some syntactic sugar + generic functions + function overloading + linearish? types] to make OO style easier than it is in C.
Things like memory aliasing optimizations would be managed by generic functions and type concepts provided by STL like libraries.
Perhaps it makes me a slower, less productive programmer but I like imperative programming and access to memory. That is the part I enjoy.
- msla 9y agoI fully agree that there's a time and place for explicitly sequential code. I just think that it's safer for everyone if it's explicitly marked as being sequential, so compilers know that most optimizations are now off-limits.
- benlorenzetti 9y agoThis seems like a reasonable compromise if people are interested in a language that can do both. Using C's syntax, a language could modify the semantics of terminators , ; : to indicate strict/total ordering of statements.