Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Memory unsafety (by default without opt-in) is being treated like a feature in these newer languages.


I've replied to you before on this in other comments. (here is one such example: https://news.ycombinator.com/item?id=32629951)

Odin has numerous memory safety features enabled by default. Having manual memory management does not entail no "memory safety". You could easily have a language with GC or ARC and still have all of the unsafe features of C. Objective-C is a brilliant example of this.

Many memory safety can be achieved with many constructs such as:

* Bounds checking for array-like types

* Having no pointer arithmetic

* Having distinct typing (virtually no implicit type conversions)

* Having no array-to-pointer demotion like in C (combination of the above to problems)

* Having actually decent array types: fixed-length arrays, slices, dynamic arrays, #soa arrays, etc

* Have length-bound strings rather NUL-terminated strings

* `Maybe(^T)` type to allow for non-nil pointers to be explicitly checked

* Built-in discriminated `union`s (of which `Maybe` is just one of those)

* Virtual Memory Protects

* And many more!

Most of the unsafe features in C/C++ come from most of the above features, especially pointer-semantics and the lack of a decent array type.

What Odin does not offer is ownership semantics and lifetime semantics, which is an entire discuss to itself which I won't talk in this comment.


If Odin is memory-safe by default then my bad, I was wrong.


That's because memory safety has a price: either a GC (which creates interoperability issues if you have two languages with GCs..) or a complexity price like in Rust..

So these languages stay memory unsafe but tries to minimise the issues caused by the lack of safety.


That's not true. Memory safety could be free. Actually it would even outperform any memory unsafe language, when done right™.

The key would be hardware supported automatic memory management.

This tech exists since many years but nobody uses it (likely because our "good old friend": patents, which is a death sentence to any good idea).

https://researcher.watson.ibm.com/researcher/files/us-bacon/...

https://people.eecs.berkeley.edu/~kubitron/papers/holistic_r...

https://adept.eecs.berkeley.edu/wp-content/uploads/2018/06/A...


Making an effort in language design also has a price.


What other language takes this stance? (other than jai, which is not released)


Zig




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: