5 ms·
This criticism echoes what E. W. Dijkstra said before, As long as programs are regarded as linear strings of basic symbols of a programming language and accord
by omouse 17y ago
This criticism echoes what E. W. Dijkstra said before,
As long as programs are regarded as linear strings of basic symbols of a programming language and accordingly, program modification is treated as text manipulation on that level, then each program modification must be understood in the universe of all programs (right or wrong!) that can be written in that programming language. No wonder that program modification is then a most risky operation! The basic symbol is too small and meaningless a unit in terms of which to describe this.
Using global variables in C is still rearchitecting the data flow. It's just a really obvious way to do it.
You basically have 4 things here: functions A and B and variables a and b. Calling A increases a, calling B increases b. Function A depends on a, b. Function B depends on a, b.
In FP, you would probably pass those variables around. In C or some other language you could store them as global variables or pass them around. Global variables are a shortcut for passing them around. Just as you don't pass around all of the assembly code of the functions you want to use to the next function, you don't need to pass all variables around all the time.
To answer your edit: these two totally independent, low-level calculations are now dependent on each other.
This is normal, just look at any example of co-routines. It's like a two-player game where one player goes first but it doesn't matter which.
- foldr 17y ago>In FP, you would probably pass those variables around. The point is that you might have to rewrite every part of the program in order to "pass around" those variables, where as in an impure language with global variables, this sort of major rearchitecting is not going to be necessary.
- omouse 17y agoThe pure vs. impure stuff is a red herring. It's meant to throw you off the scientific trail. If there are merits to the FP approach, as there are, then one or two drawbacks in a few of the languages aren't a problem. If there are multiple problems with the FP approach, then we discard it and toss out the languages that use it or modify them to only use the useful subset of that approach. With what little information we have in this example, it would be best to modify the language so that it includes those two low-level functions in its specifications and make those global variables they require. Modifying the language spec...is that pure or impure I wonder?
- ajross 17y agoRemember that the "FP approach" can be used in so-called "imperative" languages too. The reverse isn't as true.
- omouse 17y agoThe reverse is true. Just modify the language. I don't see why people are insisting on this "purity" in approaches. It's obviously leading to difficulties.
- foldr 17y agoPure has a specific technical meaning here relating to the absence of side effects. http://en.wikipedia.org/wiki/Pure_function http://en.wikipedia.org/wiki/Pure_function
- foldr 17y ago>Modifying the language spec...is that pure or impure I wonder? Neither, it's completely orthogonal to the pure/impure distinction.