#Zag: C++ but its Zig++
1 messages · Page 1 of 1 (latest)
kristoff is aware of it btw as this was discussed in a stream where kristoff was present too
Generally, you'd post something in #1024381264213594242 if you actually have something to show.
this can also be like a project discussion area and also a showcase area too
That said, how would you change Zig to have guaranteed memory safety?
by having automatic memory management instead of manual
and the compiler would get rid of the surprises you get too
But my allocators 
or what i can do is make the compiler fix the allocators when compiling the code for the specific machine
without changing it in the code
if you have any suggestions make sure to drop them here
:)
Automatic in what way
const std = @import("std");
fn doStuff(allocator: std.mem.Allocator) ![]u8 {
var buffer = try allocator.alloc(u8, 10);
defer allocator.free(buffer);
return buffer;
}
instead of this it can be
fn doStuff() []u8 {
return new u8[10]; // automatic allocation (e.g., ref-counted)
}
```and it would be automatically freed when unused
This is a good troll
Ok well the first one is just UB
You are returning freed memory
It also doesn’t answer my question
How will it know memory is unused
hmmmmmmmmmm
more like a 12y kid
yeah well im 13 years 2 months old i recently turned 13
my thinking will change soon
I don't understand what part of this remains zig. Just call it new language and move on, otherwise this is just a caricature of zig
im also looking for what it can improve so that we can call it zig++ (zag)
my keyboard
gboard is so good
you can easily make a GC'd allocator in zig and forget about freeing shit
(but you shouldnt)
One of the points of zig is that memory management is manual
So idk why you would make an extension of zig that doesn’t have manual memory management
At that point you've almost recreated Go
zig will improve itself, there is a still long way to 1.0.0.
if you strip zig of it's main features it's not zig.
It's like redesigning car into boat and calling it car 2.0
:0
Was a joke, but my thoughts for a Zig++:
And the only one I was half-way serious about was a stable ABI
Oh god the ++ operator
Zig doesn't want its own stable ABI, because it likes being able to rearrange memory layout and stuff automatically, for optimization reasons.
How would operator overloading work with allocators
Yeah, passing an allocator into x += 42; seems awkward, lol. Only option would be to use a global allocator there, or at least pass it in through some other means (meaning any type with overloaded operators would need to embed the allocator ahead of time)
to get operator overload to work with allocators you would probably have to do a nono and set up some implicit behavior.
so inside a function you'd have to do something like have a matrix state that implements the operators in scope and you would give the matrix state some allocator or something like that.
i can't think of any other way off hand to do it nicely, or perhaps put the expressions inside some call like Matrix.op(allocator, mata + matb * matc);
although it might be some comptimes already do this by passin the expression as a comptime string: Matrix.op(allocator, "mata + matb * matc");
A lot of people here probably won't see a need for a Zig++. All the features that you say are missing were intentionally excluded, and Zig users generally understand the reasoning and are happy without those features (which is why they use Zig)
this will make it fundamentally different language and everything needs to be rewritten in compiler to support it
you better off making a rust fork or something similar to vale