Live data from Hacker News

Zig 0.8.0 Release Notes

ziglang.org

81–82 of 82 posts

Re: Zig 0.8.0 Release Notes

#81
post #41

Earlier quoted context omitted.

What alternative doesn’t add failure opportunities and require additional work by the developer where they will crop up? Both defer (and more generally scope guards) and context managers certainly do, to say nothing of try/finally.

True, but also does RAII for heap allocated objects unless one makes use of smart pointers. Outside HN, CppCon and C++Now bubbles not all C++ codebases are as clean as we would wish them to be.

unique_ptr is simple and and easy to use for individually managed memory. shared_ptr can dramatically simplify some concurrent code, as well.

For arena allocated memory, you have to manage the lifetimes manually just as you would for C -- except that the arena itself can be lexically scoped, at least.

C++ is not a perfect language by any means, but destructors are not a mistake IMO. I too find having to manually "defer" cleanup annoying. I'm still interested in zig for the comptime features, though.

Re: Zig 0.8.0 Release Notes

#82
post #77

Earlier quoted context omitted.

What do you imagine is typologically wrong with new std::string("pjmlp") ? Yes, new is itself too low-level, so std::make_unique("pjmlp"s) is the modern idiom; and std::string is limited (expect unicode-aware strings in '23). But a heap-allocated string object is a thing equally easy and useful to express in Rust. (Dunno about Ada: does it have any analog of destructors, yet?)

> What do you imagine is typologically wrong with new std::string("pjmlp")? You have to remember to `free` the string explicitely. > Yes, new is itself too low-level, so std::make_unique("pjmlp"s) is the modern idiom Is it? Isn't that going to create an `unique_ptr `?

Nope: https://en.cppreference.com/w/cpp/string/basic_string/operat...

> You have to remember to `free` the string explicitly

That is not a type problem. It is far from clear what pjmlp means here. unique_ptr should have been invented in 1985? Time machines have their own problems.

Post reply on HN