News for hackers. Stuff that matters.
Re:Zig cc: A drop-in replacement for GCC/Clang by drfuchs on Tuesday March 24, 2020 @05:38PM (#22679294)
Zig (the language) is very appealing as a "better C than C". Check out https://ziglang.org (dis-disclaimer: I'm unaffiliated.)
Re:Zig cc: A drop-in replacement for GCC/Clang by ifreund on Tuesday March 24, 2020 @05:46PM (#22679395)
Aye, and it lives up to that claim as well in my opinion, despite being still relatively young and pre-1.0. My favorite thing about Zig is that it has managed to stay simple and solve many of the problems of C without resorting to greatly increased complexity like Rust (which is much more of a C++ replacement than a C replacement in my opinion).
Re:Zig cc: A drop-in replacement for GCC/Clang by d4mi3n on Tuesday March 24, 2020 @05:51PM (#22679449)
IMO the marketing as Rust as a C/C++ replacement is a bit misplaced. I think it's more accurate to consider it an alternative systems language. The tools/languages used in this space are a bit broader than C-family languages.
Re:Zig cc: A drop-in replacement for GCC/Clang by ifreund on Tuesday March 24, 2020 @06:04PM (#22679552)
That's true, though systems programming is in practice dominated by the C ABI (great post on that here by the way https://drewdevault.com/2020/03/03/Abiopause.html). Zig does something quite special that puts it ahead of the crowd in this space; It can import and use C libraries as easily as C does (no bindings required), and it can itself be built into a C library, auto-generating the required C headers.
Re:Zig cc: A drop-in replacement for GCC/Clang by d4mi3n on Tuesday March 24, 2020 @06:11PM (#22679619)
You are absolutely correct on the point of the C ABI. It's definitely the systems lingua franca.

Just finished reading the Zig cc article and I must say I'm also quite impressed. I'll be keeping an eye on the next Zig release--being able to eventually use it as a `cc` or `mvsc` replacement would be a big game changer. Having recently run the study of trying to cross compile a few C++ and GTK apps, I can really see the appeal.

Re:Zig cc: A drop-in replacement for GCC/Clang by LessDmesg on Wednesday March 25, 2020 @02:54AM (#22682528)
Rust is not a C++ replacement, nor a C replacement. It targets its own niche (embedded, realtime, correctness-oriented). It's a totally different development culture. Zig, OTOH, is absolutely a C replacement.
Re:Zig cc: A drop-in replacement for GCC/Clang by bregma on Wednesday March 25, 2020 @09:29AM (#22684298)
My day job is maintaining the toolchains for a popular safety-certified realtime embedded operating system. I have never once been asked to provide a Rust toolchain. Fortran, yes. Ada, yes. Python and Go, yes. By and large it's just C (and more and more C++).

Rust seems to be mostly something "full stack developers" and "back end developers" embrace for server-side toys and hobby projects.

Re:Zig cc: A drop-in replacement for GCC/Clang by nicoburns on Wednesday March 25, 2020 @09:59AM (#22684559)
Python, on a realtime embedded operating system? Rust isn't really there for embedded development yet. It's great for low-level code on full-blown processors/OSs though
Re:Zig cc: A drop-in replacement for GCC/Clang by bregma on Wednesday March 25, 2020 @11:27AM (#22685468)
Python: customers ask, I deliver.

Top-end embedded processors have GPUs and hypervisors these days and run AI algorithms to, say, detect lane changes and do parallel-parking maneuvers. These days AI means code written in Python and Fortran.

Re:Zig cc: A drop-in replacement for GCC/Clang by jfkebwjsbx on Wednesday March 25, 2020 @04:11AM (#22682815)
Rust does not target correctness-oriented code at all. Neither do standard C or C++, for that matter, but there are derivatives of C that can (and are) used for it.
Re:Zig cc: A drop-in replacement for GCC/Clang by otabdeveloper2 on Wednesday March 25, 2020 @03:10AM (#22682581)
> It targets its own niche (embedded, realtime, correctness-oriented).

I don't know of anyone who actually uses Rust in that niche.

Everyone who uses Rust is using it because of "C++ is hard, let's go shopping instead" syndrome.

I.e., at this point it's a language for beginners to ease themselves into programming without training wheels and eventually graduate to real big boy programming languages.

Re:Zig cc: A drop-in replacement for GCC/Clang by smolder on Wednesday March 25, 2020 @03:37AM (#22682677)
This is a strange sentiment. I think 99/100 people who know rust would not categorize it as "for beginners"
Re:Zig cc: A drop-in replacement for GCC/Clang by otabdeveloper2 on Wednesday March 25, 2020 @03:44AM (#22682703)
It's pretty much irrelevant what people feel emotionally about Rust.

The real-world fact is that Rust is, as of March 2020 at least, an entry-level systems programming language. It's used as a stepping stone by former PHP/Python/Go programmers, who are very intimidated by C++, to get into performance-oriented coding.

Nobody actually writing embedded or sensitive code (airplanes, nuclear power stations, etc.) is doing it in Rust.

Re:Zig cc: A drop-in replacement for GCC/Clang by dystroy on Wednesday March 25, 2020 @04:46AM (#22682949)
This makes zero sense and it's not about emotion.

The language is young and you don't certify a software solution every two days or don't rewrite your nuclear power station code every day.

Very experienced programmers switched to Rust because it makes it possible to build large scale industrial programs both efficient and reliable. They won't switch to C++ just because they think they're good enough to live dangerously.

(btw I work on plant control and yes I write parts in Rust)

Re:Zig cc: A drop-in replacement for GCC/Clang by otabdeveloper2 on Thursday March 26, 2020 @03:08PM (#22696777)
> Very experienced programmers switched to Rust because it makes it possible to build large scale industrial programs both efficient and reliable.

This never happens in the real world; not unless the 'very experienced' bit is experience only in languages like PHP or Python.

Re:Zig cc: A drop-in replacement for GCC/Clang by nicoburns on Wednesday March 25, 2020 @10:02AM (#22684578)
It's true that a lot of PHP/Python/Go programmers look to Rust rather than C++ when getting into performance-oriented code. But it's not really a stepping stone, because you never have to leave.

It's true that not a lot of people are using Rust for embedded software. That's a much harder nut to crack because so many of the toolchains are proprietary (and embedded support in Rust is still missing quite a few things).

Re:Zig cc: A drop-in replacement for GCC/Clang by otabdeveloper2 on Thursday March 26, 2020 @03:09PM (#22696788)
> ...because you never have to leave.

You kind of do if you ever want to work on anything other than pet personal one-man projects.

Re:Zig cc: A drop-in replacement for GCC/Clang by nicoburns on Thursday March 26, 2020 @03:52PM (#22697233)
Not for technical reasons though.

Also: I've used Rust at work. In fact, I learnt Rust because I was processing a lot of data at work, and needed a fast language to do so in a reasonable amount of time.

Re:Zig cc: A drop-in replacement for GCC/Clang by stjohnswarts on Tuesday March 24, 2020 @08:48PM (#22680798)
I know it's not as complicated as C++ but it sure seems like they're in a rush to get there :) . Modern (post c++14) covers most of my criticisms of c++ for my daily driver. I still poke at Rust because I really love statically typed languages :)
Re:Zig cc: A drop-in replacement for GCC/Clang by yarrel on Tuesday March 24, 2020 @09:51PM (#22681256)
I've been very surprised by Rust's complexity. Some of it seems to be being hidden over time (as well as adding new features) but its syntax at any given moment is generally more complex than C++.
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @11:50PM (#22681791)
Really? I would consider its syntax to be of similar complexity but of higher consistency. What parts of it do you find complex?
Re:Zig cc: A drop-in replacement for GCC/Clang by pjmlp on Wednesday March 25, 2020 @02:44AM (#22682494)
When you happen to have generics coupled with lifetime annotations for example.
Re:Zig cc: A drop-in replacement for GCC/Clang by throwaway17_17 on Wednesday March 25, 2020 @01:17AM (#22682125)
I’m not being contrarian, but I have only been following Zig in passing. Can you give a few example of the increase in complexity, I am genuinely curious. Zig seems, to my eyes at least, to have done an admirable job of remaining simple when compared to the behemoth that is C++, of any vintage (but especially post C++03).
Re:Zig cc: A drop-in replacement for GCC/Clang by jjnoakes on Tuesday March 24, 2020 @06:31PM (#22679782)
I wonder how much it would cost to sponsor compiles-via-c support. I'd love to use zig-the-language but I need to compile for platforms that LLVM does not support, so I would need to use the native C toolchain (assembler/linker at the least, but using the native C compiler seems easier).
Re:Zig cc: A drop-in replacement for GCC/Clang by ihnorton on Tuesday March 24, 2020 @06:42PM (#22679866)
There is a semi-maintained (perhaps more accurately “occasionally resurrected”) C backend for LLVM: https://github.com/JuliaComputing/llvm-cbe
Re:Zig cc: A drop-in replacement for GCC/Clang by jjnoakes on Tuesday March 24, 2020 @06:59PM (#22679982)
Thanks; I was aware of this but last I checked it only supports a subset of LLVM (whatever Julia needed).
Re:Zig cc: A drop-in replacement for GCC/Clang by pjmlp on Wednesday March 25, 2020 @02:40AM (#22682485)
I am still not sold on its security story, usage of @ and module imports.
Re:Zig cc: A drop-in replacement for GCC/Clang by skrebbel on Wednesday March 25, 2020 @03:01AM (#22682551)
Can you elaborate on the security story story?
Re:Zig cc: A drop-in replacement for GCC/Clang by pjmlp on Wednesday March 25, 2020 @03:11AM (#22682585)
Manual memory management, we have already learned that isn't the way to go, when security is part of the requirements in a connected world.

Still no way to catch use-after-free.

https://github.com/ziglang/zig/issues/3180

Re:Zig cc: A drop-in replacement for GCC/Clang by skrebbel on Wednesday March 25, 2020 @07:03AM (#22683456)
Clear, good point, thanks.
Re:Zig cc: A drop-in replacement for GCC/Clang by agapon on Tuesday March 24, 2020 @06:10PM (#22679610)
I don't know... To me, zig does not look like C at all. IMO, go and zig are as similar to each other as they are dissimilar to C.
Re:Zig cc: A drop-in replacement for GCC/Clang by agapon on Tuesday March 24, 2020 @06:12PM (#22679635)
I mean, is this C-like?

  fn add(a: i32, b: i32) i32 {
      return a + b;
  }
Re:Zig cc: A drop-in replacement for GCC/Clang by AndyKelley on Tuesday March 24, 2020 @06:17PM (#22679690)
Re:Zig cc: A drop-in replacement for GCC/Clang by iruoy on Tuesday March 24, 2020 @07:06PM (#22680021)
Simple stuff like this looks very similar to Rust: https://godbolt.org/z/spkKai

Rust quickly becomes harder though, while Zig is much easier to grasp.

Re:Zig cc: A drop-in replacement for GCC/Clang by tsimionescu on Tuesday March 24, 2020 @07:21PM (#22680129)
The fact that they compile to the same assembly instruction does not make them similar source code.
Re:Zig cc: A drop-in replacement for GCC/Clang by abainbridge on Wednesday March 25, 2020 @09:18AM (#22684216)
The languages are similar enough that the Zig tool-chain can translate C source into Zig source. There's mostly a one-to-one correspondence.
Re:Zig cc: A drop-in replacement for GCC/Clang by balfirevic on Tuesday March 24, 2020 @07:19PM (#22680113)
It could hardly be more C-like. Are you getting distracted by the syntax?
Re:Zig cc: A drop-in replacement for GCC/Clang by kelnos on Tuesday March 24, 2020 @07:30PM (#22680181)
When we talk about something being "C-like", the syntax is what we're talking about. Being "distracted by the syntax" doesn't make sense when the syntax is the entire point of the statement being made.
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @08:14PM (#22680519)
Admittedly it's been decades since I've done any C (literally since 1999, except for an LD_PRELOAD shim I wrote about 5 years ago) but being someone who prefers C and other ALGOL-syntax derivates I find the syntax to be relatively easy to grok. One advantage over C is that the confusing pointer/array/function pointer thing has a well-defined order in Zig, there's no "spiral order" nonsense going on.
Re:Zig cc: A drop-in replacement for GCC/Clang by naniwaduni on Tuesday March 24, 2020 @08:32PM (#22680688)
There is no spiral. C's pointer declaration syntax is arguably backwards ("declaration follows usage") but fundamentally follows normal precedence rules. The so-called spiral is total nonsense misinformation.
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @10:02PM (#22681322)
That's exactly my point. It's confusing enough that someone e made a bullshit claim that was totally wrong and confused noobs for years. That won't happen with zig.
Re:Zig cc: A drop-in replacement for GCC/Clang by pjmlp on Wednesday March 25, 2020 @02:59AM (#22682543)
That won't happen with any sane systems language all the way back to Algol dialects.

The only thing that C has taken from Algol, was structured control and data.

Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @09:57PM (#22681288)
What about this do you find disagreeable? http://c-faq.com/decl/spiral.anderson.html
Re:Zig cc: A drop-in replacement for GCC/Clang by palotasb on Wednesday March 25, 2020 @04:16AM (#22682832)
The spiral rule works if "pointer to" and "function returning"/"array of" alternate but it breaks if they don't, i.e., if you have arrays of arrays or pointers to pointers.

    int** arr1_of_arr2_of_arr3_of_ptr_to_ptr_to_int[1][2][3]
In this case, spiraling between [1], ×, [2], ×, [3], int is obviously wrong, the correct reading order is [1], [2], [3], ×, ×, int. (Edit: read × = *)

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

Re:Zig cc: A drop-in replacement for GCC/Clang by diegoperini on Wednesday March 25, 2020 @07:40AM (#22683650)
I would name that algorithm "inside-out" instead of "right-left" if my understanding of its behavior is correct.
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Wednesday March 25, 2020 @01:33PM (#22686698)
Aren't you supposed to treat multiple array or pointers as a group?
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @10:02PM (#22681327)
The fact that it's wrong if you try to generalize it beyond the examples given?
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @11:53PM (#22681807)
Does it? Here's one that I grabbed from cdecl.org:

  char * const (*(* const bar)[5])(int )
And its translation:

  declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char
This seems like what I'd get from the spiral technique.
Re:Zig cc: A drop-in replacement for GCC/Clang by ant6n on Wednesday March 25, 2020 @03:09AM (#22682575)
They are both close-to-the-metal, few-abstractions, procedural, imperative Systems programming languages with explicit memory management and layout.
Re:Zig cc: A drop-in replacement for GCC/Clang by balfirevic on Tuesday March 24, 2020 @07:38PM (#22680240)
When "we" talk? I suggest that in the future if you mean syntactically similar you say syntactically similar.

But then, of course, it wouldn't have much to do with Zig's "appeal as better C than C", which prompted this whole discussion.

Re:Zig cc: A drop-in replacement for GCC/Clang by agapon on Wednesday March 25, 2020 @07:36PM (#22689457)
Exactly. I would appreciate an explanation what makes zig c-like if its syntax is nothing like c? What does "c-like" even mean then?
Re:Zig cc: A drop-in replacement for GCC/Clang by yarrel on Tuesday March 24, 2020 @09:52PM (#22681263)
It's about 50% C-like. Which is giving people a That Dress experience answering yes or no to the question.
Re:Zig cc: A drop-in replacement for GCC/Clang by boltzmann_brain on Tuesday March 24, 2020 @09:20PM (#22681037)
On a first glance, it does look like a simpler version of Rust, and I say it without demeaning Zig. Looks very promising, I'll be keeping an eye for it.