
On 10/20/05, Matt Calabrese <rivorus@gmail.com> wrote:
I'd say it's much more analogous to conversions in C++ from a short unsigned int to an unsigned int being implicit. You don't lose any information in the conversion and the conversion makes perfectly logical sense. Forcing users to always be explicit is just making them write more unecessary code.
Also, expanding on this analogy since I don't think you are understanding the point I'm trying to make -- one might have code which uses shorts and ints to represt two different high-level concepts in code. In that particular project, under your logic, you wouldn't want implicit conversion from short to int. This is literally exactly the same situation with units. The "problem" isn't because short to int conversions should be explicit, it's because you aren't representing the high-level concepts which actually use those types as implementation details in your code. You really should be encapsulating those values in two different types if that is the functionality you want. The same situation can occur if both values were represented with ints. The operation between the two ints still wouldn't make sense -- the problem is that you aren't representing the fact that they implementation details of higher level concepts in your code. Encapsulation is what you really want. Always making short int to int conversions be explicit is missing the point that the datatype isn't the reason why the two objects aren't addable. The reason is because there is a higher level of abstraction which you didn not represent. -- -Matt Calabrese