Code Smell: Magic Numbers & How To Fix It #shorts

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

And you can replace whole switch case with a `return orientation.ToString();` with this implementation.

TheLatyos
Автор

It's also easier to convert from and to enum by using humanizer or automapper/mapster package, completely eliminating manual mapping compared to magic numbers.

With humanizer package, it's very easy to generate human readable string just by using .Humanize() extension. So we can just store the integer in the database, map it to enum with mapster, and render a human readable string with .Humanize().

dputra
Автор

The Problem with the enum is that you could cast an int to the enum type, pass it to the method and that leads to unexpected behavior. In this case it throws an exception. That is one reason why I try to stay away from C# enums as much as I can and use a SmartEnum instead where I could encapsulate the behavior inside, the string representation in this case.

lasttheroy
Автор

Ick I encountered a bash script that someone used file ID numbers to store a temporary message that was being built for a log message.

JohnWasinger
Автор

You sound an awful lot like Joy of code, is this a sister channel?

Hugos