3 ms·
If you add a new value to an enum, or a new argument to a method, you have to know all the places where you do switches on the enum or call the method, which is
by jdm2212 6y ago
If you add a new value to an enum, or a new argument to a method, you have to know all the places where you do switches on the enum or call the method, which is hard to do without static types.
- archarios 6y agoWhy couldn't you just search for where that enum is referenced and add the cases?
- jdm2212 6y agoYou have to know when semantically it's an instance of the enum, and when it's just a string literal (e.g. in JavaScript, where enums are just a pre-defined set of allowed strings). Also, you might assign to it in one place, and then use the resulting variable in many other places farther down the call chain. Now you have to find all those usages. Static typing makes both of those trivial if your language (or linter) has enum-exhaustiveness checks for switch statements.
- hnick 6y agoYou can't always find everything with a search in a dynamic language. Some things are resolved at runtime. In our Perl code base, finding function calls is difficult for this reason (you can eval a string name to get a module or function and call it, based on a configuration setting in a file).