Timeline for Avoiding the goto voodoo?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 23, 2019 at 1:08 | comment | added | user949300 | I love this answer, especially "If 1024 is too many, 8 is also too many". But it is essentially "use polymorphism", isn't it? And my (weaker) answer is getting a lot of crap for saying that. Can I hire your P.R. person? :-) | |
| Jan 22, 2019 at 22:39 | comment | added | user91988 | So much this. The other answers don't really improve on what's in the question. This code needs a rewrite. There's nothing wrong with writing more functions. | |
| Jan 22, 2019 at 18:06 | comment | added | Justin Time - Reinstate Monica | As presented, it appears to be an interrupt handler, in which case the single responsibility is "interpret generic flag and dispatch to appropriate handler." Although certain branches having multiple statements does shed a little doubt on that interpretation, IMO... | |
| Jan 22, 2019 at 12:48 | comment | added | Taco | @user949300 The 1,2, and 3 are placeholders here. They mean nothing other than to show that order of execution doesn’t matter. | |
| Jan 22, 2019 at 9:45 | comment | added | Deduplicator | @user949300 The code doesn't have any meaningful names, so we cannot say why some combinations are special. There can be perfetly good reasons why some aren't (generally) used, or others get a more convenient label. We simply cannot say. | |
| Jan 22, 2019 at 5:39 | comment | added | user949300 | @Deduplicator One look at this mishmash of some but not all combinations of 1,2&3 shows that this is not a "well designed API". | |
| Jan 22, 2019 at 5:04 | comment | added | user326452 | Upvoted this answer. If you just want to debate GOTO, that's a different question than the one you asked. Based on the evidence presented, you have three disjoint requirements, which should not be aggregated. From a SE standpoint, I submit that alephzero's is the correct answer. | |
| Jan 22, 2019 at 2:30 | comment | added | Deduplicator | As a point of fact, there are many well-designed APIs which have all kinds of flags, options, and assorted other parameters. Some may be passed on, some have direct effects, and yet others potentially be ignored, without breaking SRP. Anyway, the function could even be decoding some external input, who knows? Also, reductio ad absurdum often leads to absurd results, especially if the starting-point isn't even all that solid. | |
| Jan 22, 2019 at 2:02 | comment | added | Taco | So grateful for this answer! In my opinion the code is perfectly valid and genericized for this particular post. The question is in relation to the goto statement and not the concept of single responsibility. I have refactored the code to handle everything with four simple if statements. More to the point on your answer, there is nothing wrong with multiple if statements in the same method so long as they achieve a related goal to the method and simply alter the execution path. In my actual code each piece isn't actually a method call, but a single line execution. | |
| Jan 22, 2019 at 1:54 | history | edited | alephzero | CC BY-SA 4.0 | added 73 characters in body |
| Jan 22, 2019 at 1:48 | history | answered | alephzero | CC BY-SA 4.0 |