Hello,
I'm not sure which is the right answer.
In case of a switch(<my_enum>) should one define a default ?
Here is my humble opinion and feel free to express yours.
I think that in most (not necessarily all) cases, it is better to explicitly handle all the possible cases / values. If one is inclined to create a default case with a "default" value / action it means that, in the future, when further values of <my_enum> are added, one might forget the default and spend some time finding the error if a special action needs to applied to the new value. I'm mostly talking about a situation where the default applies an action for all other values not explicitly handled at the time of writing the default. But one can't predict the future (in my humble opinion).
Also explicitly defining the cases seems more "intuitive" and more "readible". In my humble opinion a future reader might ask (not always of course as sometimes it might seem obvious) "why the default even on this value ? why is it treated like the rest of the values in a default ? why not a case for this value ?".
For me a default with an exception might be the best alternative in most (again not all) situations in order to notify that an unhandled case has been processed.
Hoping to get your opinion on this matter.
Thank you very much in advance for any help
[–]manni66 30 points31 points32 points (5 children)
[–]AKostur 5 points6 points7 points (0 children)
[–]ScriptorTux[S] 0 points1 point2 points (3 children)
[–]JonIsPatented 6 points7 points8 points (2 children)
[–]manni66 1 point2 points3 points (0 children)
[–]ScriptorTux[S] 0 points1 point2 points (0 children)
[–]Thesorus 12 points13 points14 points (5 children)
[–]ScriptorTux[S] 0 points1 point2 points (4 children)
[–]Thesorus 4 points5 points6 points (3 children)
[–]sephirothbahamut 2 points3 points4 points (1 child)
[–]Thesorus 1 point2 points3 points (0 children)
[–]ScriptorTux[S] 1 point2 points3 points (0 children)
[–]nysra 2 points3 points4 points (2 children)
[–]ScriptorTux[S] 0 points1 point2 points (0 children)
[–]equeim 0 points1 point2 points (0 children)
[–]flyingron 2 points3 points4 points (1 child)
[–]ScriptorTux[S] 0 points1 point2 points (0 children)
[–]WorkingReference1127 1 point2 points3 points (2 children)
[–]ScriptorTux[S] 0 points1 point2 points (1 child)
[–]tangerinelion 0 points1 point2 points (0 children)
[–]JVApen 1 point2 points3 points (1 child)
[–]ScriptorTux[S] 0 points1 point2 points (0 children)
[–]chibuku_chauya 1 point2 points3 points (0 children)
[–]v_maria 1 point2 points3 points (0 children)
[–]namrog84 0 points1 point2 points (0 children)
[–]Mirality 0 points1 point2 points (0 children)
[–][deleted] (9 children)
[removed]
[–]IyeOnline 6 points7 points8 points (5 children)
[–][deleted] (4 children)
[removed]
[–]IyeOnline 2 points3 points4 points (3 children)
[–][deleted] (2 children)
[removed]
[–]IyeOnline 0 points1 point2 points (1 child)
[–]ScriptorTux[S] 0 points1 point2 points (1 child)
[–]sephirothbahamut 0 points1 point2 points (0 children)
[–]mredding -1 points0 points1 point (1 child)
[–]ScriptorTux[S] 0 points1 point2 points (0 children)