5 ms·
Using global variables is far easier in this case and may entail changing a whopping three lines of code: one for the declaration of the variable and one each i
by fhars 17y ago
Using global variables is far easier in this case and may entail changing a whopping three lines of code: one for the declaration of the variable and one each in the two functions using the new variable. The argument passing variant on the other hand requires changing almost every single function call in the whole program. In this sense, imperative programming is strictly more expressive than purely functional programming (in the sense of the word that IIRCgoes back to Felleisen: a paradigm is more expressive if expressing a construct that is localized in this paradigm requires a global program transform in another paradigm).
Of course this doesn't mean that a program will be easier to read after going the easier to write way too many times...
- ams6110 17y agoWell could you not write new A and B functions that invoke the original functions with state parameters added while also providing the state-handling mechanisms. Then all other existing calls remain unchanged. This really just introduces a namespace for what would otherwise be a "global" but it keeps the real "global" namespace unpolluted.