4 ms·
>Python/Ruby, then no, they are good at prototyping but have all the pitfalls of Javascript when used on large teams. No, they absolutely don't. >>> "1" + 1
by crdoconnor 10y ago
>Python/Ruby, then no, they are good at prototyping but have all the pitfalls of Javascript when used on large teams.
No, they absolutely don't.
>>> "1" + 1
Javascript: 11
Perl: 2
This is the kind of approach works ok for small programs. Where the code that does these implicit type casts isn't too buried.
When it's buried 3 layers down in a dependency used by a dependency used by a dependency, you want this to happen instead:
Python/Ruby: Type error
- Terr_ 10y ago... And? That's simply "not having unpredictable type-juggling." It does nothing to communicate invariants or guide API usage at design-time. Consider PHP, which does have some of those bizarre and frustrating conversions, yet at the same time it also has stuff like type-hints and interfaces that can be used for design-time checking.
- crdoconnor 10y ago>... And? That's simply "not having unpredictable type-juggling." Literally what this entire thread is all about. Lots of languages have this issue and it manifests in the instability and indeterminacy of large scale applications in Perl and PHP much as it does in javascript. Type hinting is, honestly, a pretty poor way of dealing with the problem of turning "1" + 1 into 2, but that's a separate issue.
- Terr_ 10y ago> [type juggling is] Literally what this entire thread is all about. No it isn't, that's just what you've been fixated on. Please re-read nostrademons' post, because you aren't actually addressing the issues they brought up, namely: > It's dynamic typing with a prototype-based object model. This type system [...] tends to be pretty bad at communicating invariants to other programmers or nailing down APIs for other subsystems to build off. While it's true that Python "fails nicer" than JS, it addresses neither of those two issues about preventing failures.
- nostrademons 10y agoWhile I think that JS's loose typing is a little annoying and certainly isn't what I'd build if I were designing the language from scratch, it just isn't much of a problem for me in practice. Type errors in general (either of the implicit coercion variety or the dynamic typing variety) aren't much of a problem. They rarely happen, and when they do, they usually take all of 5 minutes to track down and fix. I find that the big benefit of types are in documentation. They are executable, explicit, compiler-checked documentation of the programmer's intended usage. Without this, it becomes much harder to read through and comprehend a large codebase that was mostly written by other people. It becomes even harder to change it. I like Python, I like Javascript - but they have their uses, and those uses don't include large-scale mature software engineering. I actually argued otherwise for my first couple years at Google (where both are used extensively, though the JS is largely statically typed), but eventually saw the wisdom of more experienced engineers in this, and relegated my Python to exploratory coding.
- oliverkyss 10y agoJava: 11 I guess companies should stop using Java for big enterprise applications with tons of dependencies. Or this isn't a problem because programmers usually know the basics of the language they are using. And if they don't, then that is the problem, not the language. btw, Python: '1' * 3 -> '111'
- Ar-Curunir 10y agoThe python example is not an issue; you're going from string to a longer string, not to an integer.
- oliverkyss 10y agoThat's not true, you're going from string _and_ an integer, because '*' is a binary operator. (And it isn't communicative as shown here, which is another 'problem') But that's not really the point, crdoconnor seems to think that languages should throw an error in cases like this, not just keep the type of the first argument.
- crdoconnor 10y agoMain.java:17: error: incompatible types: String cannot be converted to int int z = x + y; >btw, Python: '1' * 3 -> '111' In theory I agree with this but in practise I see this so rarely used it barely matters.
- oliverkyss 10y agoSorry, I meant "11" (String), same result as with JS. see here: https://repl.it/Cqeq/0 https://repl.it/Cqeq/0