3 ms·
goto/if/switch have their uses (especially in C) but I consider them low level and deprecated in favor of pattern matching, expression-based loops, and fmap / m
by throwaway2j94 4y ago
goto/if/switch have their uses (especially in C) but I consider them low level and deprecated in favor of pattern matching, expression-based loops, and fmap / map/reduce combinators.
- twawaaay 4y agoOf course, I do prefer higher level constructs. Even then goto/if/switch are effective, readable solution especially if you use them within idioms. The problem is when people start replacing low level statements with other low level equivalents. Or low level equivalents that are masquerading as high level. Which means they did not understand why you may want to get rid of the low level construct and only caused loss of readability for no structural benefit.
- ok_dad 4y ago> 2022: "If/else considered dangerous." I never thought this would happen, does this mean I should quit programming? I feel like you can't get much done in a computer without branching in a CPU, but maybe I misunderstand modern CPU architecture.
- moffkalast 4y agoNah, if I understand the guy correctly it's not about the low level stuff. That's hardly going to change any time soon. But in terms of a logic development perspective I guess it may be clearer to set up something like instead of your average while(true) if (boolean) callback_function() put an async on(boolean,callback_function) or something and let the language deal with the low level implementation of it. Not sure why it would be "dangerous" to use the explicit definition, but we can maybe do a bit better in terms of clarity by removing the optimizable boilerplate?
- anikom15 4y agoAt least with the while version I have complete control over the loop. With the async version I have to figure out what the timing model is by reading documentation and assume it’s accurate. Async can make things easier but it’s not going to magically make code more maintainable. It’s hard to debug async problems. With a loop I can debug it on a sheet of paper. Choose abstractions and higher-order expressions when it makes sense to do so, not just to avoid low-level or ‘deprecated’ ones. I believe arithmetic ifs are higher-level than boolean ifs from the computer’s perspective, but you wouldn’t prefer that over a boolean if, would you?
- lmm 4y ago> I never thought this would happen, does this mean I should quit programming? Yes. > I feel like you can't get much done in a computer without branching in a CPU, but maybe I misunderstand modern CPU architecture. Most CPUs have jump instructions, that doesn't mean it's a good idea to have gotos in your programming language.
- ok_dad 4y ago> > I never thought this would happen, does this mean I should quit programming? > Yes. Not sure what I expected, I'll turn in my resignation effective immediately.
- rep_lodsb 4y agoAll CPUs have jump instructions. General purpose computation isn't possible without it. Even 'if' / 'while' / etc. are syntactic sugar for 'goto'.
- lmm 4y ago> All CPUs have jump instructions. General purpose computation isn't possible without it. Technically not true, a Turing machine in the original sense only moves its head one position at a time (and I can imagine some early drum memory CPUs might have operated like that in real life). Of course one can emulate a processor that has jumps on a machine like that. > Even 'if' / 'while' / etc. are syntactic sugar for 'goto'. Structured programming is not just syntactic sugar; it gives you important properties that you can't get from using goto directly, hence why so many languages discourage or ban goto.