3 ms·
I once had someone try to tell me that python was "untyped" - I guess people assume a lot when they come from a first-class statically-typed language.
by solumos 6y ago
I once had someone try to tell me that python was "untyped" - I guess people assume a lot when they come from a first-class statically-typed language.
- kstrauser 6y agoIn Python, objects have types. Variables are best thought of as void* pointers to objects.
- dr_zoidberg 5y agoI've found over the years that people have an easier time understanding how Python manages variables when you tell them that, rather than "in-memory boxes with data" as is the case in other languages, Python variables are more like "name tags that you attach to an object".
- Spivak 5y agoPointers that also carry the underlying type information.
- kstrauser 5y agoI don’t remember what the CPython implementation looks like, but even if the information is there, it’s not really exposed to end users. “type(foo)” doesn’t return the type of the name “foo”, but of the object that “foo” points to.
- Spivak 5y agoI meant that it's a pointer that is aware of the type of object it's pointing to by virtue of all objects knowing their own type. Same difference I guess. Unlike void pointers or Object references in Java you can't "forget" an object's type.
- kstrauser 5y agoAh, I think I see what you mean. I still think it's more accurate to say that names are just pointers that don't have any typing info themselves (or if they do, it's an implementation detail that doesn't actually get surfaced and isn't a part of the language definition). In Python it doesn't quite make sense to talk about the type of a "name" or "variable" or "pointer" because, because it points to an object, and that's where the canonical type info actually lives.
- guram11 6y agoiirc untyped is not incorrect, untyped lambda calculus for instance is where your value type is unknown until your runtime like dynamic type, untyped doesn't mean you don't have type in your language
- pmontra 6y agoI wonder if my professor of the Programming Languages course at university would laugh or cry at such a definition. I expect that everybody doing this job has a CS or equivalent degree and knows the difference between strong / weak and static / dynamic typing. Reading other comments here demonstrates this is not the case. This is not a bad thing (luckily we only need a screen and a keyboard) but hopefully they'll have learned something new today. Btw, there is a lot I don't know despite my degree. No hard feelings.
- exdsq 6y ago“Untyped” is the phrase used in literature too https://www.sciencedirect.com/science/article/pii/S1474667016339969 https://www.sciencedirect.com/science/article/pii/S147466701... Practically, untyped languages would include asm and forth.