You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As Message.type's value has only 7 candidates, it might be good to create enum, maybe.
here are pros and cons:
pros
better switch statement experience
enum enables exhaustive switch feature, which leads us less bugs
IDE's add missing switch cases feature will also be enabled with it
more readable
we can know what message is supported for now at a glance
less bugs
typo will be reported by the compiler and language servers
cons
destroys backward compatibility
changing Message.type's type from String to some enum will force us change lots of existing code
I think the disadvantage can be avoided if we create a new field like Message.concreteType with enum type, without changing Message.type's type from String.
However, it may confuse users, since it's hard to understand at a moment that why there're type and concreteType.
For PoC, I made a branch(see here) to see how it goes, and it passes all existing tests, at least.
I would like to hear your opinions. Thank you
The text was updated successfully, but these errors were encountered:
As
Message.type
's value has only 7 candidates, it might be good to create enum, maybe.here are pros and cons:
pros
switch
statement experienceadd missing switch cases
feature will also be enabled with itcons
Message.type
's type from String to some enum will force us change lots of existing codeI think the disadvantage can be avoided if we create a new field like
Message.concreteType
with enum type, without changingMessage.type
's type from String.However, it may confuse users, since it's hard to understand at a moment that why there're
type
andconcreteType
.For PoC, I made a branch(see here) to see how it goes, and it passes all existing tests, at least.
I would like to hear your opinions. Thank you
The text was updated successfully, but these errors were encountered: