Live data from Hacker News

Problems of C, and how Zig addresses them

avestura.dev

171–180 of 290 posts

Re: Problems of C, and how Zig addresses them

#171
For me as a high level application developer, I liked C but felt that it needed a rational module system, generics and structural types. The addition of methods on structs would be nice too (no need for inheritance).

The only reason I thought about it is because I have been trying (and failing) to contribute to open source Linux projects - which are practically all written in C and the C++ projects are impossible to read.

Re: Problems of C, and how Zig addresses them

#173

Tangentially... I'm grateful that these new batches of systems languages have chosen to use the u8, i32, etc, style integer types. Rather than the uint8_t and int32_t style. First thing I do in any of my low level embedded C projects is put in the various uNN/iNN types.

D uses byte, short, int, long for i8, i16, i32, i64, and ubyte, ushort, uint, and ulong for the unsigned versions. After 5 minutes with the language there is no longer any point to emphasizing the number of bits. Besides, they're just easier to touch type.

Not sure if I parse your argument right, but there's lot of cases when one would care how wide specific integer type is. Especially in the code that works with data in bulk (as in millions/billions of data objects), where not wasting bits really pays off.

Re: Problems of C, and how Zig addresses them

#174

Earlier quoted context omitted.

The most frequently given reason is that a core principle for Zig is ‘No implicit control flow’ or just the more general ‘Explicit is always better’. RAII, both for constructors and destructors are inherently implicit control flow constructs, also they usually involve access to allocation primitives, which Zig also rejects when implicit. You can disagree with the language principles if that is one’s position. However…

I assume that zig requires the programmer to also manually allocate and free stack frames? And it eschews functions as they can hide allocations and control flows?

I would assume "allocation primitives" is referring to the heap.

Re: Problems of C, and how Zig addresses them

#175

For me as a high level application developer, I liked C but felt that it needed a rational module system, generics and structural types. The addition of methods on structs would be nice too (no need for inheritance). The only reason I thought about it is because I have been trying (and failing) to contribute to open source Linux projects - which are practically all written in C and the C++ projects are impossible to…

C++ has all the things you "felt that C needed". So there must be something more that you dislike.

Re: Problems of C, and how Zig addresses them

#176

For me as a high level application developer, I liked C but felt that it needed a rational module system, generics and structural types. The addition of methods on structs would be nice too (no need for inheritance). The only reason I thought about it is because I have been trying (and failing) to contribute to open source Linux projects - which are practically all written in C and the C++ projects are impossible to…

C++ has all the things you "felt that C needed". So there must be something more that you dislike.

The problem with C++ isn't too few features, it's too many.

Re: Problems of C, and how Zig addresses them

#177

Earlier quoted context omitted.

C doesn't have namespaces. The only sane way to deal with name collisions is either to use C stdlib types in library APIs (e.g. uint8_t), or use a library specific prefix (e.g. mylib_u8) - which is of course even more awkward than just using the standard uint8_t.

A prefix and a namespace aren't really that different in practice.

They are different. Namespaces are syntactically enforced and you can opt-in or out to names. To have syntactically validated qualified access.

Naming might go well and have the same utility, but you never know what evil things are going on in all those headers, redefining each other's symbols and yours.

Re: Problems of C, and how Zig addresses them

#178

Tangentially... I'm grateful that these new batches of systems languages have chosen to use the u8, i32, etc, style integer types. Rather than the uint8_t and int32_t style. First thing I do in any of my low level embedded C projects is put in the various uNN/iNN types.

Having spent a lot of time porting 32bit system code to 64bit, I developed a dislike for these explicit types. It's a slippery slope to hard code your bitness with people making assumptions where size_t or pointers fit. Now maybe if you're already 64bit that's fine (it's unlikely that we'll ever need 128bit, and code is unlikely to grow down), but for anything starting smaller it's a pain.

The sizes of floating point are growing "apart" in the AI space. Who's to say what might happen with sizes of types. Maybe it's great to use mostly u8 if you're controlling a worldwide asynchronous networked megacomputer.

Re: Problems of C, and how Zig addresses them

#179

Earlier quoted context omitted.

I can't answer you why Zig keeps showing up on HN (except for the surface-level answer that people keep submitting and upvoting it) but in terms of not being used in production, the Bun project, a Node/Deno alternative, is seeing a good deal of momentum by the people who like JavaScript a bit too much. It's probably the most widely used Zig project so far, including in production. https://bun.sh

Who uses bun in production? Seems totally insane to me to use a pre-1.0 application written in a pre-1.0 language in production considering Node and Deno basically do the same thing.

When the company you work for is burning VC money with no hope or intention of profitability, the only rational technology choice you can make as an engineer is to pick a promising but unproven technology which could boost your resume and help you land your next gig more easily. Or you simply pick it because you like and want to work with it and there is no one to stop you.

I'd be very happy to hear I am wrong about this and see a profitable company with an established product using it.

Re: Problems of C, and how Zig addresses them

#180
post #176

Earlier quoted context omitted.

C++ has all the things you "felt that C needed". So there must be something more that you dislike.

The problem with C++ isn't too few features, it's too many.

Agreed. However, my point about GP stands.
Post reply on HN