4 ms·
> Because you don't have to write a lot of boilerplate to tell the language things that it should be able to figure out for itself. This is exactly my point; c
by annnnd 13y ago
> Because you don't have to write a lot of boilerplate to tell the language things that it should be able to figure out for itself.
This is exactly my point; compiler can't figure out what kind of data I want, at least not in general. A good example is jQuery $.data() which tries to guess what kind of data you have in your HTML tag attribute. Guess what happens if you have a MongoDB ObjectId (as string), for instance "52259986890d6f24e9000000"? Exactly - it is a floating number. Believe me, it leads to some interesting debugging sessions... :)
I agree with you however that it is beneficial to have a way to set the var to None/null/..., indicating "not initialized". Win some, lose some I guess.
- pdonis 13y agoGuess what happens if you have a MongoDB ObjectId (as string) But that's a matter of semantics, not static typing. You're going to have to do type conversion on the string regardless, because "MongoDB Objectid" isn't a native type for the compiler. But with static typing, you need to tell the compiler the type of the variable in addition to telling it how to do the type conversion: for example, in C++, you might have to say... var MongoObjectid id = new MongoObjectid("somestring"); ..whereas in Python, for example, you could just say... id = MongoObjectid("somestring")
- mathias_10gen 13y agoActually in C++11 you can just say: auto id = mongo::OID("1234..."); This gives you much (not all) of the brevity and flexibility of dynamic typing, while maintaining the power and safety of static typing.
- annnnd 13y ago> You're going to have to do type conversion on the string regardless, because "MongoDB Objectid" isn't a native type for the compiler My point was that jQuery .data() tries to guess how to handle strings and misses in some cases, because the strings are too similar to numbers. The fact that this particular string was a MongoID is actually not relevant to the problem, it just illustrates that this is a real-world problem.