Live data from Hacker News

I stopped everything and started writing C again

kmx.io

211–220 of 475 posts

Re: I stopped everything and started writing C again

#211
post #46

Try zig, it is C with a bit of polish.

I saw mentions of Zig here often, so I decided to look at the docs to see what features it has. I had to scroll through all the docs only to find myself disappointed by the fact that Zig doesn't help with memory management in any way and advices to use comments and careful coding instead. And what adds to the disappointment is that its plus/minus operators do not catch overflow. If I wanted undefined behaviour, I could just use C/C++ as no language can compete with them in this regard.

Re: I stopped everything and started writing C again

#212
post #88

Earlier quoted context omitted.

Why zig and not Rust? Just to throw the question out there :-)

For me, where linked lists, graphs and other structures are a common need, zig gives me slices and deferred frees. Rust is double expensive in this case. You have to memorize the borrow checker and be responsible for all the potential undefined behavior with unsafe code. But I am not a super human systems programmer. Perhaps if I was the calculus would change. But personally when I have to drop down below a GC langua…

> You have to memorize the borrow checker

Correct me if I am wrong, but Rust at least has a borrow checker while in C (and Zig) one has to do the borrow checking in their head. If you read a documentation for C libraries, some of them mention things like "caller must free this memory" and others don't specify anything and you have to go to the source code to find out who is responsible for freeing the memory.

Re: I stopped everything and started writing C again

#213

Earlier quoted context omitted.

The compiler says "expected X, but found Y". I don't know how to interpret this: is the type of the thing underlined with "^^^" X or Y? "Expected" and "found" are just like "up" and "down" in space: they are meaningless if you don't know what the compiler expects (and why should it?). What it needs to say is something along the lines of "a function f is defined with type X, but is given an argument of type Y": maybe…

Since it's underlining code you wrote, it must be "found" that is highlighted, not "expected". Much like up and down, gravity exists to ground all of us in the same direction.

I'm over here with TTS: Underlining in a terminal rarely translates to audio. It isn't the only consideration that needs to be made, when making things clear.

Re: I stopped everything and started writing C again

#214

Earlier quoted context omitted.

Real projects get into the millions of lines of code, Rust will not scale to compile that quickly.

Not quickly, no. But neither does C++ (how long does it take to compile Clang?) and people manage fine. Faster would obviously be better, but it's not big enough of a deal to cancel out all the advantages compared to C.

I once moved a C++ project to C, and compile times went from 15 minutes to 5 seconds. It was a huge productivity boost. LLVM being slow to compile is also one of the reasons the Zig folk are looking to make it an optional dependency.

Re: I stopped everything and started writing C again

#215
post #203

Earlier quoted context omitted.

I'd say whether Rust helps you reduce bugs depends on how good you are at creating abstractions and/or encoding properties in the type system.

Most bugs are way above that level of abstraction and thought.

[Citation needed].

Re: I stopped everything and started writing C again

#216
post #112

Earlier quoted context omitted.

At first I really liked this idea, but then I realised the size of stack frames is quite limited, isn't it? So this would work for small data but perhaps not big data.

In theory, this is a compiler implementation detail. The compiler may chose to put large stacks in the heap, or to not even use a stack/heap system at all. The semantics of the language are independent of that. In practice, stack sizes used to be quite limited and system-dependent. A modern linux system will give you several megabites of stack by default (128MB in my case, just checked in my linux mint 22 wilma). You…

Its a giant peeve of mine that automatic memory management, in the C language sense of the resource being freed at the end of its lexical scope, is tied to the allocation being on the machine stack which in practice may have incredibly limited size. Gar! Why!?

Re: I stopped everything and started writing C again

#218
post #180

Earlier quoted context omitted.

I don't follow your first point—the compiler is pointing out exactly what the problem is (the argument has the incorrect type) and then telling you what you likely wanted to do (borrow the String). What would you see as a more helpful error message in this case?

The compiler says "expected X, but found Y". I don't know how to interpret this: is the type of the thing underlined with "^^^" X or Y? "Expected" and "found" are just like "up" and "down" in space: they are meaningless if you don't know what the compiler expects (and why should it?). What it needs to say is something along the lines of "a function f is defined with type X, but is given an argument of type Y": maybe…

I don't see any way that the use if expected and found can be ambiguous for a type conflict.

I buy a fruit mixer from Amazon.com ; I send it back along with a note: expected a 230VAC mixer, found a 110VAC mixer.

Re: I stopped everything and started writing C again

#219

Earlier quoted context omitted.

Have you looked at Zig? It is often termed a modern C where Rust is the modern C++. Seems like a good fit.

i never really understand why these get compared. i wouldn't expect that much overlap in the audiences zig seems like someone wanted something between C and "the good parts" of C++, with the generations of cruft scrubbed out rust seems like someone wanted a haskell-flavoured replacement for C++, and memory-safety i would expect "zig for C++" to look more like D or Carbon than rust. and i'd expect "rust for C" to have…

I would say OCaml more than Haskell, but yes.

Re: I stopped everything and started writing C again

#220
post #216

Earlier quoted context omitted.

In theory, this is a compiler implementation detail. The compiler may chose to put large stacks in the heap, or to not even use a stack/heap system at all. The semantics of the language are independent of that. In practice, stack sizes used to be quite limited and system-dependent. A modern linux system will give you several megabites of stack by default (128MB in my case, just checked in my linux mint 22 wilma). You…

Its a giant peeve of mine that automatic memory management, in the C language sense of the resource being freed at the end of its lexical scope, is tied to the allocation being on the machine stack which in practice may have incredibly limited size. Gar! Why!?

Ackshually, it has nothing to do with the C language. It's an implementation choice by some compilers. A conforming implementation could give you the whole RAM and swap to your stack.
Post reply on HN