3 ms·
Not this again. Haskell, Prolog, CSS, SQL are classic examples of declarative programming, but really, what isn't? Everything except machine code is to a certai
by olooney 8y ago
Not this again. Haskell, Prolog, CSS, SQL are classic examples of declarative programming, but really, what isn't? Everything except machine code is to a certain extent declarative.
Obviously, even the C compiler is free to optimize and rewrite your code to a large extent. Maybe it will put everything in registers! Maybe it will shuffle variables out of memory! Maybe it will skip entire instructions, or unroll loops! Maybe it will completely eliminate code that it believes to be dead! Maybe it will use SIMD instructions to do four multiplications at once! Will it will pad your structs, or change byte order? Will it use 16, 32, or 64 bits for you integers? There's no way to know! Even if you figure it out for your own machine today, the code you write today may be compiled to target a different architecture in the future. Obviously, then, C is a declarative language because the programmer only provided a high-level outline of what he or she wanted and let the compiler figure out the details.
Even at run time, we find that many system calls are declarative for all intents and purposes. What happens when you call malloc()? Well, you tell it what you want, and a memory manager decides how to give it to you using a variety of memory management strategies: maybe they call mmap() or VirtualAlloc() or some other syscall, or maybe they just give you a pointer into a region of memory they allocated earlier and have been hanging onto.
Is even machine code fully imperative? Maybe once upon a time it was, but now with all these caches and pipelines and branch prediction, it seems like even the hardware is making decisions on our behalf about how to "best" run a program.
The way I see it, we can either acknowledge that these computer thingies are in fact to a large extend "doing what we mean" rather than following our explicit instructions and accept the corollary that we are never quite fully in control, or we can all go back to writing assembly for the 6502.
- tabtab 8y agoLaynes Law: Every debate is over the definition of a word. Or every debate eventually degenerates into debating the definition of a word. Or once a debate degenerates into debating the definition of a word, the debate is debatably over.
- wnmurphy 8y agoWhat do you mean by 'over'?
- tabtab 8y ago"Pointless to continue", I would assume. I've been in looong debates that end up being tied to the meaning of a word. Our worldviews often shape the way we use and apply language. For example, how one defines "type" may ultimately pivot on how a given person processes categories in their own mind. I've probably spent a novel's worth of text in online debates about "type".