News for hackers. Stuff that matters.
Re:An intro to Zig's integer casting for C programmers by elcritch on Tuesday May 11, 2021 @12:46PM (#27120339)
From what I can tell, safety isn't a selling factor of Zig. From a "safety" perspective Zig seems like a step backwards compared to the latest generation of languages, and Rust in particular. Zig's ergonomics seem decent but its memory safety tact appears to basically be to include valgrind-like tools into debug builds with good PR.
Re:An intro to Zig's integer casting for C programmers by rslabbert on Tuesday May 11, 2021 @05:07PM (#27123535)
Not a Zig expert, but safety is a factor for Zig, it just treats it as less of an absolute than Rust. I think the thing to keep in mind is that something can be a priority without being an absolute priority. I'd make a comparison to OpenBSD vs Linux. Both have security as a priority, OpenBSD just has a more absolute focus on it.

For example, a couple of features come together really nicely to make memory safety easier to test in Zig: * You need a reference to an Allocator to be able to allocate memory, so as a general rule, the caller can control which allocator is used. * Unit testing is integrated well into the language. * Therefore, you can create an allocator for each unit test, and fail the test at the end if any memory was leaked. * This process can also happen at the application level with the General Purpose Allocator, which can let you print an error when the program exits if anything was leaked.

The above doesn't solve every memory safety problem (and there are other features like native bounds-checked slices that solve other kinds of issues), but it provides an extra layer that can probably get us quite far into the "quite safe" camp.

Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @09:21PM (#27125623)
This. AFAICT Memory leaks are not practical to test in rust (note this is not the same as detectable), but basically come for free in zig tests.
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @01:45AM (#27127030)
Except that level of security I could already do with Pascal dialects like Turbo Pascal or Modula-2, hence why I really don't see much value in Zig, other than being more appealing to younger generations.
Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @01:06PM (#27120569)
Putting valgrind into the stdlib is really clever, and also, I like memory safety being the carrot to get you to write tests. I worry having a 'safe' system like rust sometimes causes very smart (TM) developers, especially less experienced ones, to be complacent and write less tests.
Re:An intro to Zig's integer casting for C programmers by nicoburns on Tuesday May 11, 2021 @06:25PM (#27124371)
Writing fewer tests is somewhat justified when you can encode invariants in the type system. It depends on the level of reliability you require of course. But my Rust code without tests has been comparably reliable to my code in other lanaguages eith tests.
Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @07:50PM (#27125051)
No tests? How do you refactor while ensuring your business logic invariants?
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @09:40AM (#27130192)