4 ms·
> but Pascal’s type system was pretty solid To be honest, this is a matter of styles, coming from a dynamic type background I don’t appreciate strongly typed s
by pmelendez 3y ago
> but Pascal’s type system was pretty solid
To be honest, this is a matter of styles, coming from a dynamic type background I don’t appreciate strongly typed systems as an advantage.
- Jtsummers 3y agoStrongly typed is orthogonal to dynamic and static typing. Python and Common Lisp are both "strongly" typed and dynamically typed. There's no reason to shun strong typing if you also like dynamic typing.
- pmelendez 3y agoI would be curious to see references that claims that dynamic and static typing are orthogonal with strongly typed systems, as “strongly type” is rather ambiguous and the only reason I used the term was because that was how Pascal was promoted back in the day (or at least how was taught to me) From Wikipedia: In 1974, Liskov and S. Zilles defined a strongly-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function." Note that the definition refers to type declaration, both being optional in Python and Common Lisp, so I wouldn’t use either as an example of strongly type languages.
- Jtsummers 3y agoYou already found the wikipedia page, try reading it. See where it puts a lot of dynamically typed languages under the category of "strongly typed". You've decided it's a good enough source apparently. But really, I used "strongly" in quotes deliberately. It's a terrible phrase since it means nothing in practice because it can mean too many things (as that same page notes) that often are at odds with each other. > Note that the definition refers to type declaration, both being optional in Python and Common Lisp, so I wouldn’t use either as an example of strongly type languages. Even this definition would potentially exclude SML and OCaml where types are inferred, not declared. So according to you those two languages are weakly typed? I think a lot of people would be surprised to learn that.
- epolanski 3y agoDynamic and static merely point to the fact that type analysis is either done at runtime or at compilation time. It is an unrelated concept to which type rules will be applied by the software at runtime or compilation time.
- deleted 3y ago[deleted]
- kazinator 3y ago"whenever an object is passed" clearly refers to run-time. An object is not being passed when we are compiling the function call. "declared in the function" clearly means that the function has an internal type check. An interface declaration (Modula-2 interface file, C header file with prototypes) is not "in the function"; it's compile-time meta-data about a function. A function call between separately compiled translation units has no idea what is in a function.
- slt2021 3y agohow can Python be strongly typed if it doesn't enforce types for declared arguments? What is the value of this supposedly "strongly typed" Python's type system? class Object: pass def f(arg:int): print("type of arg = ", str(type(arg))) f(1) f(666.0) f("kek") f(Object()) type of arg = <class 'int'> type of arg = <class 'float'> type of arg = <class 'str'> type of arg = <class '__main__.Object'> and not a single error/warning thrown
- Jtsummers 3y agoHow is OCaml strongly typed if it doesn't have declared types?!?!? (EDIT: In case it's not obvious, I'm being sarcastic, I'm pretty sure some people in this discussion won't get that though.) let f x = x + 1;; (* What's the type?!?!? *) Turns out that "strong typing" is a shitty phrase that people should stop using because it means too many conflicting things, and, consequently, means nothing. Static and dynamic typing have well-defined meanings, stick with those terms instead of ones that mean nothing. But for a demonstration (compare to Perl) try this in your Python REPL: >>> 1 + "1" Does it work? Probably not unless you futzed with the language implementation. In Perl it does, though. So to the extent that "strong typing" means anything, Perl is "weakly typed", Python is "strongly typed", and both are dynamically typed. It's an orthogonal characteristic of the type system and language from when type checking occurs. ---------- EDIT: BTW, formatting code blocks on HN is really easy. Prefix each line of code with two space characters. __Replace those _'s with spaces The result is much cleaner than your comment: def foo(x): return x + x No extra newlines needed, more compact, easier for most people to read.
- slt2021 3y agopeople on HN often claim that Python is "strongly typed" while PHP is loosely-typed, but I don't see the difference honestly. both are pretty loose. re: 1 + "1" I didn't get your point really. My reply was to counter claim that Python is supposedly "strongly typed" and I don't understand how this strong typing helps developers. I know that languages can infer types, which is tangential subject. I dont know why you brought this up