-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nim is unsafe #4
Comments
It's also Reddit, where they criticize Java but downvote anyone else who dislikes it. Just tell 'em to suck an egg or something... |
Unfortunately, I do agree somewhat. Undefinable behavior aside (which can be fixed through the codegen) many of the basic types in the standard library easily allow unsafe and inefficient behavior. A large amount of the pain C/C++ programmers seem to face is from the constant mental modeling that needs to be done to write code that doesn't encounter some odd memory error or cause undefined behavior. Furthermore, the cycle of having to compile, run, and then test your code just to possibly find common mistakes is horribly tedious. This is what makes Rust so attractive, and Nim... not so attractive. Rust has all that familiarity of C++, coupled with the underlying idea that "anything unsafe should be explicitly approved of by the programmer". However one may feel about the extreme view Rust has taken on this, it nevertheless seems like something that relieves the biggest pain-point of C/C++ programming. Nim, on the other hand, feels at times a hode-podge of ideas that cater to few. Yes, it has a good GC, procedures, closures, and a compile-time evaluation system. Unfortunately, many of the 'killer features' are underdeveloped or were never subject to enough user feedback to make them really useful. I could go on, but this comment is ranty enough as it is. Make no mistake, I want to see Nim grow and become successful, but I fear that the current path it's heading on will make it turn into something akin to compiled PHP.. At some point backwards incompatible changes will need to be made, if only to correct design and efficiency flaws. |
These kind of arguments would be way more convincing if the example actually would not crash in release mode, but it does... Maybe the hacker news people need to actually hack something and look at the results rather than pretending they know everything. |
Sorry, but you're not speaking for the C/C++ programming community but from your own experiences and you dislike how Nim's strings work. Which is fine, but please don't pretend there is some consensus on this complex topic when there clearly is none. And again, COW can be introduced without breaking semantics make them as efficient as C++'s strings. And back in the days, I analysed a complex piece of software heavily doing string ops (it was a preprocessor not unlike C's) and decided that even COW is too expensive after a certain amount of optimizations has been applied. Java-like code full of accessors is punished by Nim's strings, but that doesn't mean Nim's strings are misdesigned. Add to this the fact that Nim's strings are really consistent with how the rest of the language works and you have the explanation of why Nim's strings are the way they are. That Python and Java do it differently never was a valid concern for me, if I want Python and Java I know where to find them. |
ptr, addr and cast are the keywords (and pointer/cstring/ unchecked arrays) which introduce unsafety, the rest is safe. The manual is actually pretty clear about it. The missing nil checking is a bug but rather a minor one because it just doesn't come up in practice. If you come up with real world examples where it does come up, it will get a higher priority. Opinions on reddit are not a replacement for actual real world examples. |
I think the whole point is that it doesn't crash. |
Would it be possible to get an |
Yes, and yet it DOES CRASH both with and without -d:release. |
What about on clang, without the address sanitizer option? |
The point of an effect is to prevent something at compile time. Can unsafe code call safe code? Yes. Can safe code call unsafe code? You better enable this too. So what's the point? The unsafe features already stick out and are already keywords. |
Here is an email exchange I initiated back in July when I needed to find a language to implement some code that needed to be fast and I was debating between Cython, Nim, and Go:
Here was his response:
So I used Nim in production (calling out from Ruby, where I do most of my non-systems and non-machine code) for a performance critical piece and everything has worked out just fine. Nim has a slower adoption curve for a couple of reasons. One is that it is so complete, that it is hard for some people to learn / justify the time commitment. The other is that it is still pre-V1, so people don't want to accept it and face breaking changes with a codebase. I haven't had any problems with nilable strings or safety, but then again, I haven't done that much with the language. I'm only a every-now-and-then user. I'm about 4x as productive with Ruby, at least half of which is because I'm so familiar with the language, but when I need to write performance critical code Nim is great. |
So what should we reply to something like this? https://news.ycombinator.com/item?id=10947761 |
My response:
|
Now that we have not-nil seqs and strings, can we close this? |
|
Yes we still have Of course there are still unsafe and/or dangerous parts of Nim. Or as the Quora answer said:
No more loud complaints about unsafety, combined with the recent not-nil seqs and strings (these were things where lots of beginners could easily trip and fall), are the reasons why I think this can be closed. |
(moreover
will crash in release mode, unless you know what you are doing and take appropriate steps like disabling ASLR, and even then only on Clang) |
That will also crash in debug mode. |
I still think |
Yes, and it is the intended behaviour. The complaint on HN was about this snippet not crashing, due undefined behaviour and optimizations |
Yes and that is still a (mostly theoretical) issue until we add some C compiler specific flags to the compilation process. |
|
We now have |
...or at least that's what I am told by Reddit/HN.
It seems that this is Nim's reputation now, every single time a discussion about Nim gets off the ground somebody comes along and says something like "Nim would be awesome but it has the same unsafe and undefined behaviour as C". Recent example here. Somebody even asked a question on Quora about this: https://www.quora.com/Is-Nim-really-that-unsafe.
The root of this criticism is here.
I think it's about time we do something about this. Either simply decide that Nim doesn't try to be safe, does try to be safe but provides features which allow it to be unsafe, does try to be safe but a bug causes it to be unsafe, or a combination of those statements. So which is it?
Is it for example fine that
Will not crash in release mode?
Possibly related: #2809
The text was updated successfully, but these errors were encountered: