Why int instead of named enums?

Started by
6 comments, last by dalleboy 20 years, 8 months ago
Why insist of using for example TurnLeft(int rate) instead of TurnLeft(TurnRate rate) where TurnRate would be an enum defined to the following:

enum TurnRate
{
   TURN_SLOW,
   TURN_FAST
};
[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
Well, if its in an interface which may be used by C or other languages, then ints are more standard.

Enums are generally a better solution, but in big systems can be problems because you can''t forward declare them -- they lead to twisted dependencies.

I would go with the enum as they are just simpler and less error prone, unless I had a really good reason not to.
Does it _really_ matter? This interface is not set in stone and is very susceptible to changes anyway. Besides, those particular enums are assigned values equivalent to int's.. (4 byte integer values).

Admin for GameDev.net.

quote:Original post by dalleboy
Why insist of using for example TurnLeft(int rate) instead of TurnLeft(TurnRate rate)


Why insist on using enum??

Just a curious thought!?



____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said.
I could be wrong or right but the ideas are mine.

No no no no! :)
Probably because intellisense will give you a drop-down of all the members of an enum?
quote:Original post by MichaelT
Why insist on using enum??

Just a curious thought!?

Type-safety.

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
quote:Original post by BrianL
Well, if its in an interface which may be used by C or other languages, then ints are more standard.

Perhaps true, but the GDArena uses C++ virtual member functions, so the interface is not really meant for any other language than C++.

(I know that virtual functions exist in other languages and can be implemented even in C, but ain''t that a bit harder than implementing enums?)

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
quote:Original post by dalleboy
Why insist of using for example TurnLeft(int rate) instead of TurnLeft(TurnRate rate)


Personnel preference. Usually the reason behind most things.
Beer - the love catalystgood ol' homepage

This topic is closed to new replies.

Advertisement