News for hackers. Stuff that matters.
Re:When are enums not a code smell? by masklinn on Monday November 22, 2021 @11:09AM (#29307925)
A C# enum is, like a C enum (as they were explicitly introduced to be compatible with those), just a bunch of constants for integers.

So when you have an enum-typed value, odds are good that it’s one of the named ones but there’s no mechanism anywhere preventing it to be any other integer of the underlying type.

Re:When are enums not a code smell? by Semaphor on Monday November 22, 2021 @11:44AM (#29308423)
But how is that an issue? I guess when you are casting random integer to the enum-type without any checks?
Re:When are enums not a code smell? by masklinn on Monday November 22, 2021 @12:00PM (#29308616)
> But how is that an issue? I guess when you are casting random integer to the enum-type without any checks?

Any caller can send any garbage (if you're publishing a package / API), likewise a dependency can return any garbage, etc... C#'s enums are entirely indicative.

Re:When are enums not a code smell? by Semaphor on Tuesday November 23, 2021 @02:30AM (#29315444)
Then you have the default path, throwing an exception. I don’t see how that is different from accessing an array with an OOB index.