Re:Interview with Zig language creator Andrew Kelley [video]
by TinkersW on Thursday August 27, 2020 @09:40AM
(#24293563)
That is the same approach used in many C++ projects
[ Parent
| on HN ]
Re:Interview with Zig language creator Andrew Kelley [video]
by pron on Thursday August 27, 2020 @09:50AM
(#24293655)
But to do that you can only use a subset of C++ (e.g. you can't use arrays nor pointer arithmetic). This works for all of Zig, except for some very specific, clearly marked, "unsafe" operations.
Re:Interview with Zig language creator Andrew Kelley [video]
by TinkersW on Thursday August 27, 2020 @09:58AM
(#24293757)
It works with arrays if you stick with std::array & std::span like constructs.
It also works with iterators-generally by sticking some extra data in the iterator in dev builds, so it can check for out of bounds access.
If I do have some code that uses C pointers + size, I'll insert some dev build assertions.
Re:Interview with Zig language creator Andrew Kelley [video]
by pron on Thursday August 27, 2020 @10:05AM
(#24293820)
Sure, and then when you enforce that you address the third most bothersome thing for me in C++, leaving you only with the top two (for me): a complex language and slow compilation.
Re:Interview with Zig language creator Andrew Kelley [video]
by renaicirc on Thursday August 27, 2020 @09:42AM
(#24293585)
Then I guess the obvious question is: has it worked well for those projects?
Re:Interview with Zig language creator Andrew Kelley [video]
by TinkersW on Thursday August 27, 2020 @10:08AM
(#24293840)
It obviously isn't as safe as Rust, but I think it works well enough for something like gamedev(where absolute safety isn't required).
For memory related issues I find it sufficient.
One aspect where it is probably not as good as Rust is for threading related issues, as it relies on inserting runtime checks which may or may not trigger depending on the number of threads attempting access.