Hacker News new | ask | show | jobs
by 0xdeadbeefbabe 2958 days ago
Since the FP crowd is here, why is loading a program into memory, writing a register, or calling a function not seen as a side effect, but writing to disk is seen as a side effect? Or have I got it wrong?
4 comments

I'm not really part of the FP crowd, but I'll take a stab at it. Note well, however, that what I say here could well be wrong.

On one level, there is no such thing as FP. All there is, is assembly-language (or binary) instructions being executed in a CPU that has access to some memory. (Almost) every instruction creates some kind of side effect (including changing the flags).

But nobody wants to program at that level, so we build abstractions on top of it. All higher-level languages create an abstraction. Even C creates an abstract machine, even though it's very close to the hardware. If the abstraction doesn't leak, you can just think about the abstraction, and ignore what's going on at the level(s) below it.

FP creates an abstraction that's at a higher level than many other abstractions. Within that abstraction, (almost) all you have are functions and values. Memory and registers are below that level. The changes to the call stack when you call a function are below that level. Those things are therefore not seen as side effects, because they are below the level of abstraction you're working at.

But disk is not. Therefore writing to disk is seen as a side effect, and those other things are not.

Loading a program into memory is part of runtime(it happens before your program starts executing; so how is that useful to model that?); Why would calling a function be a side-effect?

Not sure what exactly you mean by writing a register; if you directly mutate a location, it is considered side-effect. Otherwise any register rewrites that happen are just implementation details and if you have a different architecture than von-neumann than it could also be implemented without writing to a register.

Because it's outside the scope of how you interface with the language.

Calling these side affects is like calling Python a low level language because programs you write still use registers and raw memory access.

As long as software is executed in the real world you have side effects, including "side effects" coming in from the outside, like bits flipped in RAM. Yes. So let's just be practical. We can have the equivalent of a middle ages theological discussion or one rooted in this world :-)