lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



 
In simple terms, the length of a number is how that number would be represented if you were to print it out.  No complicated rules.  No super science.  If I can convert the number to a string and get its length, then that’s the number I’m looking for.
 

So why don’t you just do that? What is the purpose of trying to make numbers and strings interchangeable? A number, as an abstract idea, is totally different from an array of characters. The fact that they have similar representations in source code doesn’t in any way mean they are in some way the “same” concept, and more than a photo of an elephant and a photo of a pizza (as photos) makes them the “same”.

imho, trying to make “123” behave like 123 just confuses beginners; it lulls them into a false sense of security that strings are somehow “the same” as numbers when they are not. It’s not long before a student is writing, “1” + “2” all over the place and finally wonders why “1 + 2” doesn’t give him/her 3. And at that point you have to explain why and then comes the inevitable question: “If they aren’t the same why does “123” work then?”. Overlapping types in this way simply causes confusion for beginners and experienced developers alike imho.

—Tim