Timeline for Refactoring many else if, else if, else if, etc. statements
Current License: CC BY-SA 4.0
4 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 4, 2018 at 13:47 | comment | added | Flater |
[..] use a Func/Action here too, essentially pairing a Func<string,bool> (does the line match the condition?) and an Action<string> (then take this action). This makes the answer more universally applicable in cases where not every line is expected to begin with a predefined keyword.
|
|
May 4, 2018 at 13:43 | comment | added | Flater |
Not a fan of the "answer to your question". if(handler(line)) return; isn't really intuitive for a consumer of the underlying logic. There is also an inherent danger about conflicting lines (e.g. ones that match multiple criteria), but the proposed separate delegates make it less than easy to spot/maintain (compared to the if else example. It definitely has its issues, but it keeps the order of execution a bit more readable). Big fan of the "answer to your problem"; but I'd extend it further. Instead of assuming every line has the same structure, you could [..]
|
|
May 3, 2018 at 18:10 | history | edited | Kevin Fee | CC BY-SA 4.0 |
added 26 characters in body
|
May 3, 2018 at 15:54 | history | answered | Kevin Fee | CC BY-SA 4.0 |