3 ms·
This article makes it sound more complicated than it is, collecting all those edge cases. Many of them can be simply ignored, as in being no-op. Which is also w
by gnatolf 2y ago
This article makes it sound more complicated than it is, collecting all those edge cases. Many of them can be simply ignored, as in being no-op. Which is also what most cheap calculators do...
- mazambazz 2y agoI, too, have been caught in the trap of trying to accommodate all possible user flows. Sometimes you just have to put your foot down and just say "No, that is not how you use this tool".
- jansan 2y agoTraditionally this would be solved by inserting a comment into the code that insults the user (for example the classic "The user is a wanker" comment [1]). [1] https://www.theregister.com/2006/10/13/code_outrage/ https://www.theregister.com/2006/10/13/code_outrage/
- BlueTemplar 2y agoThe site linked in comments is gold. > Shit. I was just about to launch into an explanation of our code review procedures. Every week we sit around a table and carefully and dispassionately analyse and constructively criticise each others code. And it works. We sit there and listen and take it all in. It works really well and team morale is excellent. One day we're even planning to do one when we're sober.
- mrbombastic 2y agoI think there is a lesson here. Don’t let edge cases define your complexity whenever possible. Check if it is in fits your valid expressions and if it doesn’t do nothing, otherwise you get a mess of if x then y
- userbinator 2y agoThose "edge cases" actually aren't; they're simply "emergent behaviour" of how the state machine in the ASIC works.
- the__alchemist 2y agoYou don't need an ASIC in the way the article's challenge described the lunch problem. Do it with an MCU. The article goes into how the author did it at the register level, but that is not how a modern audience would do it. If you're doing registers, it's probably for your MCU's CORDIC peripheral etc for trig! You can even go fancy with floating point if you want (Probably elims the $0.30 MCUs). Tiny, cheap, and you can model it using appropriately expressive data structures (like rust enums) that handle the edge cases at the CPU level. I don't mean to dismiss your comment; it's important. I think this article is skirting a gray area of which constraints are applied. Then the conclusion is altered. Is it saying making a 4-function calculator is complicated!, or is it saying making a 4-function calculator is complicated if you add a number of specific restrictions and requirements (No modern CPU code, exact behavior replication to all combinations of user input etc). The latter is less interesting.