开发者

Overuse of redefining primitive data types?

My current project code base has every unit and its friend refined.

Extract :-

...
typedef int m; // meter
typedef int htz;
typedef int s; // 开发者_如何学Csecond
...

Good or Bad?

I hate it! Its a pain, there is no benefit, and "m" globally defined, omg!

But I want to state the reason why I hate it, in a bit more of technical/articulate manor... hello readers!

Can people list For/Against arguments for this pattern? Many thanks.


Better to make them custom types, as then you can control conversions and overload operators. Right now, I can do meaningless things like multiply a metre by a hertz. Ideally, m / s would yield a velocity- but it won't. It's meaningless to just typedef them like that.


Presumably they are trying to document intent, but without type safety there is no enforcing it. It is just clutter that increases the barrier of entry for reasoning about the code.

Even if they did try and create type safety, trying to abstract data at low levels just adds complexity. It doesn't make solving problems easier. The variable name describes the contents well enough anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜