C++ is a strongly-typed language. It enforces strict restrictions on intermixing values with different data types. On the other hand, Javascript (created in C++) resembles C++ closely in syntax but is an untyped language, meaning its variables can hold any type of value.
A strongly typed language is different that a untyped language, so you can't really compare the two. I think you're referring to:
Weak: types can be easily converted to other types (JS) Strong: types can not be easily converted to other types (Java) Dynamic/Untyped: variables can be assigned to any value, regardless of it's type (Python) Static: variable types are known at compile time and can not change (C++)
There isn't one set definition for these, so different people might say different things, but this is just the jist of it
Merlin's beard, your right! Operations in "untyped" languages happen directly on bits, with no observation of the type. In Javascript, each operation is bound to a specific type, so you cannot divide an integer by a string. So "weakly-typed" would be a much better description. You rock Squid.
Python is not untyped. It is dynamically and strongly typed.
Example:
>>>s="hello">>>type(s)<class'str'>
>>> s + 3
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
s + 3
TypeError: can only concatenate str (not "int") to str
>>> s = 3
>>> type(s)
<class 'int'>
We can change the type of s -> dynamic typing
We cannot add a string and a number -> strong typing
I thought untyped meant the same as dynamically typed? Like "untyped" not in the sense that there are no types, but "untyped" in the sense that variables aren't bound to a certain type
In that way, I agree. This discussion is interesting: stackoverflow.com/questions/915438... It validates this usage, but it also says that it is a not-so-accurate shortcut.
In my opinion, "untyped" can also refer to cases where there is really "no type". In C++, it is often the case when deal with raw bytes (they are untyped on their own, you can interpret then the way you want) or when you use assembly code (a register simply holds a number, it could be either an int or an enum that fits in an int).
That's why I prefer to use "dynamically typed" when types are actually checked by the language : )
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A strongly typed language is different that a untyped language, so you can't really compare the two. I think you're referring to:
Weak: types can be easily converted to other types (JS)
Strong: types can not be easily converted to other types (Java)
Dynamic/Untyped: variables can be assigned to any value, regardless of it's type (Python)
Static: variable types are known at compile time and can not change (C++)
There isn't one set definition for these, so different people might say different things, but this is just the jist of it
Merlin's beard, your right! Operations in "untyped" languages happen directly on bits, with no observation of the type. In Javascript, each operation is bound to a specific type, so you cannot divide an integer by a string. So "weakly-typed" would be a much better description. You rock Squid.
Python is not untyped. It is dynamically and strongly typed.
Example:
We can change the type of
s
-> dynamic typingWe cannot add a string and a number -> strong typing
I thought untyped meant the same as dynamically typed? Like "untyped" not in the sense that there are no types, but "untyped" in the sense that variables aren't bound to a certain type
In that way, I agree. This discussion is interesting: stackoverflow.com/questions/915438... It validates this usage, but it also says that it is a not-so-accurate shortcut.
In my opinion, "untyped" can also refer to cases where there is really "no type". In C++, it is often the case when deal with raw bytes (they are untyped on their own, you can interpret then the way you want) or when you use assembly code (a register simply holds a number, it could be either an
int
or an enum that fits in anint
).That's why I prefer to use "dynamically typed" when types are actually checked by the language : )