DEV Community

loading...

Discussion on: C++ Variables, Functions, Conditionals, and Logic. In VSCode.

Collapse
dynamicsquid profile image
DynamicSquid

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

Collapse
jerrymcdonald profile image
JerryMcDonald Author • Edited

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.

Collapse
pgradot profile image
Pierre Gradot

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'>
Enter fullscreen mode Exit fullscreen mode

We can change the type of s -> dynamic typing

We cannot add a string and a number -> strong typing

Collapse
dynamicsquid profile image
DynamicSquid

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

Thread Thread
pgradot profile image
Pierre Gradot • Edited

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 : )