Yes, switch would cut some duplicate lines. I would still propose the lookup array pattern as recommended in this extra comment as it is a lot easier to add and cut arguments and is super easy to read.
Yes, but there still would be lots of repetitions even in short-form. Maybe I can write an own article soon about possible refactorings so that people can learn and compare. The original poster went with the simple if solution but there are multiple ways to make it shorter and easier to maintain.
What about switch statement?
Yes,
switch
would cut some duplicate lines. I would still propose the lookup array pattern as recommended in this extra comment as it is a lot easier to add and cut arguments and is super easy to read.These if statements could also be one-liners to save some more characters and space.
Yes, but there still would be lots of repetitions even in short-form. Maybe I can write an own article soon about possible refactorings so that people can learn and compare. The original poster went with the simple
if
solution but there are multiple ways to make it shorter and easier to maintain.Indeed.
Tell me where can I start a new discussion?
Just put a comment on the root of this article: dev.to/kaperskyguru/multiple-role-...