4 ms·
>Yes, Python is safer than C++. C++ makes no pretence of being a safe language. Static typing is not the same thing as safety. I'm just addressing the posters
by deltaonefour 4y ago
>Yes, Python is safer than C++. C++ makes no pretence of being a safe language. Static typing is not the same thing as safety.
I'm just addressing the posters comment on statically typed langauges. Not saying anything about "pretenses".
>Out-of-bounds array access is undefined behaviour in C++, but that isn't a result of C++ being statically typed. If you want a statically typed language with bounds-checked arrays, look at Java, Ada, or Rust.
Yeah I know.
>Again this doesn't generalise to all statically typed languages.
I never said this. I am just commenting on the opposite generalization the poster I'm replying to made. In general statically typed is safer the dynamically typed but this doesn't apply to all actual languages with these properties. There are actual statically typed languages like C++ that are less safe then a dynamically typed language like python.
>Also, Python isn't untyped, it's dynamically typed.
This is just a semantic mistake. Clearly I meant dynamically typed. Not untyped. But I hope people get the meaning.
>How is JavaScript different from Python here?
Javascript doesn't crash as much as python. For example Calling someHashTable[nonexistentKey] in javascript returns a value that can actually be propagated far along into the datapath before throwing an error. IN python that's an instant crash. This makes python much easier to debug then js. I use the words less error prone, because python in the long run ends up having less errors due to creators implementing failures that happen quickly and early.
>I'm not sure I follow, what doesn't depend?
Statically typed languages prevent run time errors related to types. I am saying that while this is great this property isn't that important then errors that are easily traceable.
What's by far more important is that even if the programming language has many holes where run time errors can occur it is better just to have those runtime errors easily traceable to the source of the error. The existence of errors that are hard to trace in C++ actually makes it much much less safe then python despite the extensive type system. It indicates that type safety is much less important.
- MaxBarraclough 4y ago> Statically typed languages prevent run time errors related to types. I am saying that while this is great this property isn't that important then errors that are easily traceable. I don't think I agree, it's very beneficial to catch a bug at compile time (or at least 'type-check time') rather than at runtime. It's particularly valuable for refactoring. Even if it's easy to trace a runtime error, it's still a win to transform it into a compile-time error, or a bright red line in an IDE. > Statically typed languages prevent run time errors related to types. The upper-limit on what can be done with type-systems isn't terribly clear, as sophisticated type systems (of the kind we don't see in today's mainstream languages) can prevent errors which aren't simply passing the wrong kind of data. An old Rust example: [0]. > What's by far more important is that even if the programming language has many holes where run time errors can occur it is better just to have those runtime errors easily traceable to the source of the error. An error might be very rare or might only occur when a malicious action is taken, so it's important for a language to be helpful in writing correct code. Consider a buffer-overflow in a C codebase that only happens when a malicious packet is received. Of course, type systems aren't the only way for a language to help the programmer write correct/safe/secure code. For example GCC has a flag to have the compiler insert code to explode noisily if the program tries to dereference NULL. That's an improvement in safety when compared to what standard C gives you (undefined behaviour of course), but doesn't relate at all to type systems. [0] https://yoric.github.io/post/rust-typestate/ https://yoric.github.io/post/rust-typestate/ (although typestates were since removed from the Rust language)
- deltaonefour 4y ago>I don't think I agree, it's very beneficial to catch a bug at compile time (or at least 'type-check time') rather than at runtime. It's particularly valuable for refactoring. Even if it's easy to trace a runtime error, it's still a win to transform it into a compile-time error, or a bright red line in an IDE. Well explain python then. Why is python easier to work with then C++? There is literally so much raw data to back up my statement on how python is "easier" then C++. Anyone who has worked extensively with both languages, and I mean very extensively, knows how painful C++ is compared with python. I think you may not agree. But that's just your own unique opinion. In general, I'm the one who's right. >An error might be very rare or might only occur when a malicious action is taken, so it's important for a language to be helpful in writing correct code. Consider a buffer-overflow in a C codebase that only happens when a malicious packet is received. So what's your point? Your stating this because of what? >Of course, type systems aren't the only way for a language to help the programmer write correct/safe/secure code. Why are you telling me this? Did I say type systems were the only way? >That's an improvement in safety when compared to what standard C gives you (undefined behaviour of course), but doesn't relate at all to type systems. Another improvement is to make a programming language that is impossible to crash. Several languages already have this ability. But this is a tangent. Again I really don't want to dive to deep into this. The point remains this: Python is more safe then C++ despite having more holes for crashing and no type system. Can you prove otherwise or not?
- MaxBarraclough 4y ago> explain python then. Why is python easier to work with then C++? This isn't an apples-to-apples comparison. They're very different languages, in terms of everything from memory management to build models to type systems to concurrency to historical baggage. Python is certainly more writeable than C++, for countless reasons. In terms of maintainability, Python's dynamic types are a disadvantage, but Python is also a much simpler and safer language than C++, which is very beneficial. > I think you may not agree. But that's just your own unique opinion. In general, I'm the one who's right. Please refrain from this kind of thing on HackerNews. > what's your point? Traceability of errors isn't everything. It's also important for a language to help the programmer avoid introducing defects in the first place. Neither Python nor C++ do this particularly well. Neither is anywhere near, say, Ada or Haskell. > Why are you telling me this? Did I say type systems were the only way? There's no reason to be defensive. Not everything is a refutation. > Another improvement is to make a programming language that is impossible to crash. Several languages already have this ability. I'm not certain what you mean here. Which languages are you thinking of? It's very often useful for a language to have runtime checks that may result in immediate termination, rather than continue with unaddressed erroneous execution. Examples are when Java throws on an out-of-bounds array access, or on divide-by-zero, or on dereferencing null. > Python is more safe then C++ despite having more holes for crashing and no type system. We're agreed on this point, although I'm not sure I'd say Python has more holes for crashing. Python is the safer of the two languages. [0] C++ is a minefield of undefined behaviour, [1] Python is not. Our discussion has not been limited to safety. [0] https://news.ycombinator.com/item?id=31223659 https://news.ycombinator.com/item?id=31223659 [1] https://news.ycombinator.com/item?id=31224310 https://news.ycombinator.com/item?id=31224310