5 ms·
> Weakly/dynamically typed. These terms do not mean the same thing, and the two languages you mention are not weakly typed. Strong typing means, roughly, that
by tom_mellior 8y ago
> Weakly/dynamically typed.
These terms do not mean the same thing, and the two languages you mention are not weakly typed.
Strong typing means, roughly, that type errors can be detected at some point. It is strong static typing if this detection is at compile time, and strong dynamic typing if it happens at runtime. Racket is strongly dynamically typed:
> (car 42)
car: contract violation
expected: pair?
given: 42
The type error is detected.
Weak typing is the opposite of strong typing. Assembly languages are weakly typed: you never know what's in a register. So is Forth. So is C, if you allow pointer casts. But dynamically typed programming languages are not weakly typed: They need dynamic type information at runtime to execute, and they do use that information to detect errors.
- Guthur 8y agoPretty sure javascript is weakly typed.
- tom_mellior 8y agoCan you show an example of a JavaScript type error that is not detected at any point? By "type error" I mean something like "applying integer add to a bit pattern representing an integer and a bit pattern representing a float", which you can do in assembly language or Forth or C, but not in any dynamically typed language I know of. Because you cannot take the bits that make up a float and pretend to the compiler that those bits actually represent an integer.
- gugagore 8y agoI have heard that languages like javascript are weakly typed because of the effort they go through to evaluate an expression instead of throwing a type error. >> "5" - 3 < 2 It doesn't fit your example of a type error. Quite the opposite, the interpreter intentionally has code to do the specific thing for the specific types. But this feature is why javascript is "weakly typed" in many posts.
- leshow 8y agoweak/strong typing has no formal definition. You can argue over it's meaning but neither of you will be right.
- deleted 8y ago[deleted]
- kazinator 8y agoFrom the console output you have shown, from that output alone, how do we know whether that's a static or dynamic type check?
- tom_mellior 8y agoFrom that output alone we don't know that. I assumed some background knowledge on the reader's part, namely, that Racket is not statically typed by default.
- igouy 8y ago> These terms do not mean the same thing What do they mean?
- kazinator 8y ago"Weakly typed" means that the type system doesn't detect and prevent all situations whereby a datum is misused as if it were of a different type. Programs may misbehave due to type confusion, running off with incorrect results. "Dynamic typing" means that run-time values carry type information. Dynamic typing that checks that type information everywhere and diagnoses misuses can be called strongly typed. Static and dynamic situations can be weakly or strongly typed. Ada is more strongly typed than C. Common Lisp is more strongly typed than someone's one-weekend project whose car function cheerfully accepts an integer-typed value and uses it as a cons cell.
- igouy 8y ago"Type safety is the property that no primitive operation ever applies to values of the wrong type." page 263 "Programming Languages: Application and Interpretation" Shriram Krishnamurthi 2003 ---- "Historically, people have sometimes used the phrase strong typing to reflect the kind of type-checking that ML and Java use, and weak typing for the other kinds. However, these phrases are at best poorly defined. … Indeed, the phrases are not only poorly defined, they are also wrong, because the problem is not with the “strength” of the type checker but rather with the nature of the run-time system that backs them. The phrases are even more wrong because they fail to account for whether or not a theorem backs the type system." https://papl.cs.brown.edu/2018/safety-soundness.html#%28part._.Types_.Versus_.Safety%29 https://papl.cs.brown.edu/2018/safety-soundness.html#%28part...
- deleted 8y ago[deleted]
- kazinator 8y agoAlso, there has been a use of "strongly typed" to denote the idea that alias names for types such as integers are incompatible. In this sense, Pascal family languages were called "strongly typed", whereas C isn't, because a typedef int user_id_t; isn't a new type, but just a name for int that can be passed everywhere an int can be passed. C character handling is also "weakly typed": characters are just kinds of integers: we don't need ord(ch) to get a character's code, or chr(n) to produce a character. C implicit arithmetic conversion behaviors are also weakly typed in this sense.