[–]▶ No.998889>>998890 >>998923 >>999210 >>1000161 >>1000340 [Watch Thread][Show All Posts]
Zig is an open-source programming language designed for robustness, optimality, and clarity. It is intended to directly compete with C.
Key Features:
- Potential for developer awareness for every memory allocation happening; AKA the potential for perfect software with correct memory management in mind (EDGE CASES MATTER)
- Stress on compilation-time computations and heavy optimizations
- Syntactic additions are heavily discouraged -- no adding random bits of syntactic "sugar" just because it satisfies your eyes
- Cross-compilation from any OS
- Seamless usage of C code; NO bindings needed
Links:
https://ziglang.org/
https://github.com/ziglang/zig
https://www.youtube.com/watch?v=Z4oYSByyRak
▶ No.998890>>999828
>>998889 (OP)
Hello World
const std = @import("std");
pub fn main() !void {
// If this program is run without stdout attached, exit with an error.
var stdout_file = try std.io.getStdOut();
// If this program encounters pipe failure when printing to stdout, exit
// with an error.
try stdout_file.write("Hello, world!\n");
}
But typically you don't want to just print to STDOUT, so for a simpler interface for debugging warnings...
const warn = @import("std").debug.warn;
pub fn main() void {
warn("Hello, world!\n");
}
▶ No.998891
Importing and using C header files is as simple as:
const c = @cImport({
@cInclude("stdio.h");
});
▶ No.998893
▶ No.998896>>998897 >>998899
Your own dupe:
>>998888 (checked)
▶ No.998897>>998899
>>998896
Shit, didn't realize it did that. :/
▶ No.998899
>>998897
>>998896
Won't let me delete, pretty sure I'm using the same pw too. Rip
▶ No.998923>>998984 >>999003 >>999142
>>998889 (OP)
Wait 1.5 years for JAI
▶ No.998940
Looks like even more retarded ECMAScript
▶ No.998941
▶ No.998942>>998945
I want to like it but every time I look at it I like the syntax less or find another piece of ugliness in it. Like the switch statements.
▶ No.998945>>998946 >>998966
>>998942
>muh syntax
spotted the LARPer
▶ No.998946>>998947
>>998945
If you think Brainfuck is a bad language then you're a hypocrite.
▶ No.998947
>>998946
>if you think Brainfuck is a bad language it HAS to be because of its syntax
Protip: Brainfucks syntax is fine. There are other issues with it.
Kill yourself, LARPer.
▶ No.998966>>998967
>>998945
Double LARPer detected. Syntax can be a real issue. Look at Scala or C++.
▶ No.998967
>>998966
>muh syntax
LARPer spotted
▶ No.998970
▶ No.998984
>>998923
Currently doing this.
▶ No.999003>>999005
>>998923
They don't really have the same goals, for example Jonathan Blowe loves implicit calls while zig purposefully avoids anything not explicit
▶ No.999005>>999142
>>999003
An JAI doesn't look like Perl.
▶ No.999012>>999048 >>999060 >>999061 >>999533 >>999539 >>999972
I'm still waiting for a language that is actually safe, that has NO edge cases where it crashes (unlike Rust). I have yet to see a language that handles stack overflows properly without crashing. Zig doesn't have that yet, but in the video that OP linked the language's author says he's working on it.
▶ No.999048>>999057
>>999012
Why wouldn't you want it to crash when you fuck up?
▶ No.999057>>999062 >>999539
>>999048
I'd my software be able to clean up after itself if it fucks up. Or even better, to recover from the error and continue in a well-defined and consistent state instead of relying on the operating system to simply restart my application.
▶ No.999060
>>999012
Stop using computers with finite memory. Leave the real world and join the world of academia.
▶ No.999061>>999064
>>999012
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Smash is
procedure Smashit (N : in Integer) is
begin
Put (N, Width => 0);
New_Line;
Smashit (N + 1);
end Smashit;
begin
Smashit (0);
end Smash;
$ ./smash
...
174474
174475
174476
174477
raised STORAGE_ERROR : stack overflow or erroneous memory access
how's that?
60% of the time that same program dumps core
▶ No.999062>>999064 >>999105
>>999057
How about doing your job correctly? How about taking some responsibility and having some kind of quality control instead of wasting system resources because your software is shit?
▶ No.999064>>999065
>>999062
Show me your quality control that checks stack usage.
>>999061
Looks like guard pages, which requires paging. You automatically have those in your C programs, too. But that's not what I'm talking about. Crashing with a message is not "recovery".
▶ No.999065>>999066
>>999064
That's an exception, so you can catch it:
174534
174535
shit's fucked, trying to recover...done
from:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Smash is
procedure Smashit (N : in Integer) is
begin
Put (N, Width => 0);
New_Line;
Smashit (N + 1);
end Smashit;
Running : Boolean := False;
begin
Running := True;
Smashit (0);
Running := False;
exception
when Storage_Error =>
Put ("shit's fucked, trying to recover...");
Running := False;
if Running then
Put_Line ("and we failed!");
else
Put_Line ("done");
end if;
end Smash;
realistically tho
since this still fails 60% of the time, do as Erlang does and have an architecture that expects failure. Which means having the OS deal with it. An OS that "simply restarts" a daemon is an OS that can do more than that.
▶ No.999066>>999080 >>999199
>>999065
How would one write an OS that recovers from kernel stack overflows?
Also how can you be sure that your stack overflow never overwrites any of your application's other data? I think your stack-allocated objects would have to never be larger than your OS' guard page size, whatever size that may be. Imagine you were to put a large (multiple megabytes) object on the stack on a platform where the stack grows downwards. If you start writing to that object, you could potentially start writing below the guard page where other application data might be.
▶ No.999080>>999722
>>999066
statically check stack sizes for kernel code
in case of non-tail recursion, have a hard limit on the number of calls which is proved statically to be impossible to exceed
problem solved
▶ No.999105
>>999062
you really don't understand manual memory management
▶ No.999142
>>999005
>>998923
What?
Zig looks nothing like perl, and that's coming from someone who has used perl for years (I don't recommend it). Zig is practically the antithesis of perl
▶ No.999199>>999722
>>999066
Place the stack in a separate segment, like in the good old DOS days. Enjoy the return of near and far pointers.
More realistically, we have 64 bits of address space now. Make the guard page gigabyte large. Problem solved.
▶ No.999210
>>998889 (OP)
You forgot the most important feature: IT MOVES FOR GREAT JUSTICE
▶ No.999494
▶ No.999533
>>999012
It does already offer the possibility for smart developers to make crash-less code in ways that C didn't.
▶ No.999539>>999542 >>999543
>>999012
>>999057
it crashing your shitty code is a good thing. buggy code is a security hole, forcing you to work it out is a good thing. shitty software should crash more, like it does when you try to run it on openbsd
▶ No.999542>>999543
>>999539
that is what happens with zig, just the compiler commonly calls you a retard if it detects shitty code ontop of that
▶ No.999543
>>999539
>>999542
it's the POSSIBILITY of making bug-free software while retaining its low-level eyesight that zig is aiming to achieve
▶ No.999574
>hurr replaces C guyz!
Yeah yeah, alright then OP.
▶ No.999581>>999630
>>999577
Is this meme vaporware edition of Jai
▶ No.999630>>999663 >>999715
>>999581
Isn't zig exactly the same thing
▶ No.999663>>999665
>>999577
slower activity than a bag of rocks, looks shit
>>999630
no
▶ No.999665>>999667 >>999775
>>999663
Let's say I wanted to start a project in either Odin or Zig.
Which language should I choose and why ?
So far all I can see is Odin works and has third party libs, while Zig only compiles on x64 and has a ton of issues. But I didn't actually use either.
▶ No.999667
>>999665
>wanting to start a project in an unstable language maintained by only one developer
I wonder what happens when that one's developers money runs out?
▶ No.999715
>>999577
>>999664
>Odin dumps core after compilation
>Myrddin doesn't even compile; build system doesn't notice early failures
>>999630
>Jai doesn't exist
yeah it's a real puzzle
why is this thread here about this language that actually works?
▶ No.999722>>999747
>>999080
What happens if it hits the maximum recursion depth?
>>999199
>Place the stack in a separate segment
That's very architecture specific.
>Make the guard page gigabyte large.
Sounds kinda arbitrary.
▶ No.999747>>1000254
>>999722
read:
>have a hard limit on the number of calls which is proved statically to be impossible to exceed
what happens is that compilation fails due to the failure to prove, statically, that the program won't exceed the limit.
▶ No.999775
>>999665
You can use any C/C++ library in zig, and it is more stable than Odin in my experience (despite being so young).
▶ No.999828
>>998890
Absolute shit syntax, just like C. It's garbage.
▶ No.999829>>999832 >>1000017
>ctrl+f
>no aybabtu posting
The internet is truly fucked.
▶ No.999832
>>999829
times have changed
▶ No.999972>>1000156
>>999012
Choke on this, nigger.
sudo apt-get remove rust* libstd-rust* cargo*
sudo apt-get remove snapd* libsnapd*
▶ No.1000017
▶ No.1000156>>1000230
>>999972
he'd never do that with the amount of soy he's ingesting
▶ No.1000161>>1000230
>>998889 (OP)
Rust made Zig obsolete before it was even created.
▶ No.1000230
▶ No.1000254>>1000255 >>1000273
>>999747
You can't really limit recursion depth statically if it depends on user input. Whether or not it depends on user input is going to be difficult to check. Unless maybe you use a pure language that makes you consider all kinds of side effects, like Haskell, but at least that one has its own downsides.
▶ No.1000255>>1000453
>>1000254
>You can't really limit recursion depth statically if it depends on user input.
No but you can detect when it is dependent on user input and then require the error to be manually handled.
▶ No.1000273>>1000453
>>1000254
you can, by passing along a number of recursive calls and end the recursion if that number reaches a limit.
▶ No.1000340>>1000362 >>1005230
>>998889 (OP)
Why not just use Crystal?
▶ No.1000361
Why is the syntax so ugly tho?
▶ No.1000362
>>1000340
>garbage collected
unusable for the same things
▶ No.1000453>>1000693
>>1000255
How do I manually handle stack overflows that may or may not hit the guard page? Also if recursion depth did not depend on user input then I could compute its value at compile time.
>>1000273
How do I know that number?
▶ No.1000481>>1000626
I'm going to fork this language and call it "Zag". LOL REKT
▶ No.1000626
>>1000481
wtf Haha bro epic
▶ No.1000693
>>1000453
>How do I know that number?
def op_dick(*some_shit, recursive_calls=0):
if recursive_calls > 10:
return 'deal with it'
# do some shit
a = op_dick(*some_shit, recursive_calls=1+recursive_calls)
b = op_dick(*some_shit, recursive_calls=1+recursive_calls)
return a + b
A hypothetic compiler can verify that:
1) the recursion ends on a simple condition depending only on arguments
2) the initial value of the argument has a sufficient lower bound (at every call site)
3) with each step the value goes strictly towards the condition which terminates
Of course there will be some cases where it's not obvious for compiler, then you need to either make it obvious or don't use recursion if possible.
▶ No.1005230
>>1000340
not the same at all
▶ No.1005239>>1005255
>directly compete with C
repost this thread when it gets any microcontroller support or other low level chip support from manufacturers till then there is no chance for it to compete. it will just be a hipster language.
▶ No.1005255>>1005263
>>1005239
what are you talking about?
there has already been a thing that the main guy made where he booted directly into a written-in-zig kernel
look at all of the architectures zig directly supports
▶ No.1005263>>1005274 >>1005830
>>1005255
i said manufacture support. how development works in the real world for bare metal programming on micro controllers and the like is that manufactures both try to sell to companies with their chips specs and their development software/kit for the chip. the IDEs the compilers and maybe emulators they give out for free. so lets say your company you work for wants to development some chip, are you going to use ZIG because some guy says it fully supports your chip on the internet? or are you just going to use the C compiler the company that makes the chip gives you which you will get support for and you know is fully compatible. then think about the fact your engineer staff only knows C and the new people to come in also know C and not ZIG. and lets say you arent a larper talking about a hipster tier language and you want to get a job. is it worth learning ZIG? no fuck off nigger larper.
▶ No.1005274
>>1005263
You have no comprehension capabilities.
▶ No.1005830
>>1005263
>how development works in the real world for bare metal programming on micro controllers and the like is that manufactures both try to sell to companies with their chips specs and their development software/kit for the chip.
I hate these shitty IDE's that each tries to sell, and I refuse to work with any microcontroller that does not have a working gcc toolchain ala the MSP's / STM's. Theoretically, for any platform where there's a FOSS compiler, there's no reason zig could not support these systems.