Is self-documenting code worth potential performance issues?
-
24-06-2021 - |
문제
I created small class that allows me to use enumerators of strongly-typed enums as flags (in combination). I'm using type_traits for underlying type detection so it should be also slightly type safe and mostly processed at compile time. However, i was wondering if it is really worth it.
I can now write something like
void Foo(Flags<Mode> Value);
and the programmer will see that he can use only enumerators from Mode (e.g. Mode::Read) and also he can't combine any other enums with Mode. Do you think it is better way than
void Foo(int Mode);
, i'm not sure if people can appreciate it?
해결책
What you are suggesting is considered best practice.
With a modern optimizing compiler there should be no performance cost.
제휴하지 않습니다 StackOverflow