4 ms·
Python is actually strongly typed. For example, 1+"1" will fail in python. Type errors will (usually) make the program crash. I believe this is a major plus ove
by reycharles 14y ago
Python is actually strongly typed. For example, 1+"1" will fail in python. Type errors will (usually) make the program crash. I believe this is a major plus over javascript when writing and maintaining large programs.
- mickeyp 14y agoYes, crash at runtime. That's no good in a production environment when you can have hundreds of code paths and no real way of ensuring they are all correct. Mistakes happen, and code coverage tools are in my experience pretty useless at ensuring all code paths have been exercised (a theoretically futile task as well.) As for strongly typed- yes, that is true, but it is also dynamically typed, and combined with duck typing you're left with a philosophy that encourages interchangeable types provided the interface is similar. Strong typing come in many forms, and you can have strong types and still have a compiler there to help you out. But of course, no system is perfect. That's all well and good when you still have a complete, mental overview of the code and how it interacts at a macroscopic level. That's much harder to do when you go from 1 to many developers -- especially if you're developing code to be consumed by other developers.
- reycharles 14y ago> Yes, crash at runtime. That's no good in a production environments My point is that it's a lot better than trying to continue in an inconsistent state. I'm not saying dynamic typed languages are better than static typed languages. Right now I use coq. I write programs and their correctness proofs so I definitely get why you would want some static guarantees.
- mickeyp 14y agoOh, I know you weren't. It wasn't a criticism of your observation at all, but one of those "sigh, why can't I have my cake and eat it" moments :)
- illumen 14y agoPython has Abstract Base Classes, and also widely used zope.interfaces. These, along with simplicity, convention(pep8, frameworks), a stable base(stdlib), packages, a standard unittest framework, and a strong internet community help python code bases scale. JavaScript is missing a stable base, packages, ABCs and interfaces, and a shared testing framework. However many of these are available within separate communities like for example the jQuery community. jQuery provides a stable base, plugins, a good community to share code, a standard testing framework, a way to extend code (plugins) to make it reusable, and now it has a module system which can be shared with other JavaScript frameworks. I've been on 10+ JavaScript developer projects with 100+ developers over all. I've seen JavaScript code reused by one million+ developers. I've seen open source JavaScript projects with 100+ developers. So I have experienced myself that it can scale up to a certain point. As long as the team has the best practice skills to do it that is. JavaScript is the ultimate spaghetti making machine in the hands of newbies without direction.
- mickeyp 14y agoThey can scale, but not every code base is well written. Operating from the assumption that best practices is always implemented isn't necessarily true. Sometimes you work with sub-par code or code that was written by someone skilled but due to time pressure; misunderstanding the requirements; or a poorly planned architecture means that it does not lend itself to scalability. That's the problem. You can refactor it, but refactoring code in Python can be a nightmare compared with tools like Visual Studio that make it a breeze -- plus you get the benefit of having a compiler catch errors for you. Well-thought-out code will always trump bad code; but that's a truism.
- crazyowl 14y agoNo, not crash at runtime. Raise exception in runtime. You know, like NullPointerException in Java? Or ClassCastException? Or OutOfMemeoryException. You'll have more of the runtime errors in Python, but you're not free from them in other languages either, static typing or not.
- mickeyp 14y agoThat's true, as anybody in, say, Delphi would know, when they hard cast from one type to another. As for the semantics of crashing vs. not crashing, that is a different argument entirely. Do you want your code to suppress a SyntaxError or TypeError exception and "keep going" - probably not? But maybe? It all depends, I suppose. You'll let the unhandled and unexpected exceptions percolate to the top of the stack and then your "main" method will decide what to do next. But putting square pegs into round holes do happen, and the question then becomes: how do you ensure that does not happen as often? I never made the argument that languages like C#, Ada, Delphi, or Java were immune from runtime errors. Not at all.
- darkestkhan 14y agoYou call that strong typing ? IMHO it is natural that it fails - what did you want as a result? But 1 + 1.0 works in Python - and I just added float to integer (integer was implicitly converted to float (given sufficiently large integer such behavior will result in erroneous calculation)), which is contrary to what strong typing is about.
- crazyowl 14y agoThis is true, but if that means python isn't strongly typed, then neither is Java or c++, since they too will convert for you. So, what widely used language is strongly typed then?
- darkestkhan 14y agoAda and Haskell from top of my head.
- reycharles 14y agoYes I do. ()+[] fails too. In javascript: 1+"1" --> "11", []+1 --> "1", null+[] --> "null" etc.