5 ms·
That's because C and C++ are not static languages. Only people who leaned C and C++ first think they are.
by spitfire 14y ago
That's because C and C++ are not static languages. Only people who leaned C and C++ first think they are.
- josephlord 14y agoThey are statically typed but only weakly typed (casts, void etc.) as is Java. Python is dynamically typed but again weakly. ML is strongly and dynamically typed. Anything that treats anything as a string or automatically casts from strings fills me with terror for general programming.
- abdulhaq 14y agoNo, python is strongly typed.
- masklinn 14y agoYou should avoid using those words, it merely marks you as somebody without a clue. I'm guessing your grandparent is already lost so there's no point in warning him.
- prodigal_erik 14y agoC and C++ are weakly typed because you can do things like int x = 42; printf("%c\n", *(char *) &x); that is, access the underlying bits which represent a value as if they were of some completely different type. The results are deliberately not standardized and vary with your machine. Python doesn't provide any way to do this; at worst you get a TypeError for a conversion that isn't implemented, or AttributeError for a slot that an object doesn't have. Implicitly parsing strings to produce numbers isn't weak typing, merely reckless and prone to mistakes. Weak typing can corrupt the state of your program so severely that even correct code begins to malfunction.
- masklinn 14y ago> C and C++ are weakly typed This, in and of itself, means absolutely nothing. And neither does: > Implicitly parsing strings to produce numbers isn't weak typing There is no such thing as a widely accepted, let alone formal, definition for a strong/weak axis, every other guy out there has his own personal definition. What the bloody hell is the point of words for which no two persons share the same definition? No point. None at all. See comment above, it merely marks you as a guy without a clue.
- gizmo686 14y agoBut, python is strongly typed, it just isn't dynamically typed. For example, javascript is a weakly typed language, because things such as "a"+1, and Math.floor("a") are all valid; while they would result in a type error in python. What makes python seem weakly typed to many people is its implicit variable shadowing. So when you do a="hello", a is a str, and can only be used where a str is expected. However, python lets you do: >a="hello" >a=1 at which point a is shadowed to an int. Dynamic typing has some (not all) of the problems weak typing has, but they are not the same thing
- masklinn 14y ago> But, python is strongly typed These words, they don't mean jack shit. > Dynamic typing has some (not all) of the problems weak typing has, but they are not the same thing Well of course they aren't, for starters "dynamic typing" actually means something.
- gizmo686 14y ago"In a weakly typed language a compiler / interpreter will sometimes change the type of a variable. For example, in some languages (like JavaScript) you can add strings to numbers 'x' + 3 becomes 'x3'. This can be a problem because if you have made a mistake in your program, instead of raising an exception execution will continue but your variables now have wrong and unexpected values. In a strongly typed language (like Python) you can't perform operations inappropriate to the type of the object - attempting to add numbers to strings will fail. Problems like these are easier to diagnose because the exception is raised at the point where the error occurs rather than at some other, potentially far removed, place. In a statically typed language, the type of variables must be known (and usually declared) at the point at which it is used. Attempting to use it will be an error. In a dynamically typed language, objects still have a type, but it is determined at runtime. You are free to bind names (variables) to different objects with a different type. So long as you only perform operations valid for the type the interpreter doesn't care what type they actually are." [0] It might help you to do research, ask clarifying questions, or explain why you think someone is wrong; instead of assuming that anyone saying something you disagree with has no idea what they are talking about. [0]http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%...
- abdulhaq 14y agoI suggest you start to prefer learning from people instead of insulting them - you'll do much better in life. At least learn to either be polite or keep quiet.
- olavk 14y agoThere is no agreed-upon definition for the terms strong and weakly typed. Even then, your categorization are unconventional. Python is typically categorized as strongly typed since silent type coercion does not happen. Also I've never heard Java categorized as weak. You can cast, but there is still a runtime check that the cast is valid.