Live data from Hacker News

I stopped everything and started writing C again

kmx.io

331–340 of 475 posts

Re: I stopped everything and started writing C again

#331
post #209

Earlier quoted context omitted.

Rust allows to provide more information about types (generic types, pointer usage) and checks it, while in C you have to rely on doc comments and checking the code manually. Or am I wrong and C allows to specify pointer nullability, pointer ownership and array bounds?

None of those things feature in any problem I deal with on a daily basis, whatever language I use. So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort. The day before was a constraint network specification error. In both cases the code was entirely ir…

> So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort.

Maybe not in a reasonable language no, but there are advances in type systems that are making ever larger classes of behaviours encodable into types. For example, algebraic effects (can this function throw, call a remote service etc)

https://koka-lang.github.io/koka/doc/index.html

linear types (this method must be called only once etc)

https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/line...

dependent typing (f(1) returning a different type from f(2), verifiable at compile time),

https://fstar-lang.org/index.html

Some of these features will eventually make it to “normal” PL. For example, Scala now has dependent types,

https://dotty.epfl.ch/docs/reference/new-types/match-types.h...

and Java can support linear type checking,

https://checkerframework.org/manual/#must-call-checker

Re: I stopped everything and started writing C again

#332
post #225
post #209

Earlier quoted context omitted.

None of those things feature in any problem I deal with on a daily basis, whatever language I use. So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort. The day before was a constraint network specification error. In both cases the code was entirely ir…

> None of those things feature in any problem I deal with on a daily basis, whatever language I use. ' I run into those things nearly daily, so... ok then.

Do not feel bad friend, It's not you.. there is definitely inconsistencies here. Maybe they work on absolutely pristine perfect codebases.

Re: I stopped everything and started writing C again

#333
I learned computer engineering bottom-up and top-down. Bottom-up as a teen reading books and manuals. Since no one I knew had an actual computer in 1979, like Ada Lovelace, I built the computers in my mind, LOL. Then in college I did some top-down too by writing C and then compiling to assembly and then compiling to machine code.

we also had to build a CPU from discrete bit-slice components and then program it. One of the most time intensive courses I took at CMU. Do computer engineers still have to do that?

I would certainly encourage all computer engineers, and perhaps even software engineers, to learn the "full stack".

But as to programming and C, I haven't done that in almost 30 years. It would be an interesting experiment to see how much of that skill if any I still possess.

Re: I stopped everything and started writing C again

#334

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.

Rust is not a modern C++, their core models are pretty different. Both Rust and C++ can do things the other can’t do. C++ is a more focused on low-level hyper-optimized systems programming, Rust is a bit higher level and has stronger guardrails but with performance closer to a classic systems language. I do think Zig is a worthy successor to C and isn’t trying to be C++. I programmed in C for a long time and Zig has…

C++ is (according to Bjarne Stroustrup) a general purpose programming language that can be used to build general business software and applications with, not just a systems PL. This is why perf is all over the place —- the core language is fast like C but the stdlib contains terribly slow code (regex, exceptions) and ways to waste lots of cycles (wrapping everything in smart pointers, using std::map instead of unordered map).

Re: I stopped everything and started writing C again

#335
For those who like C because of the simplicity, I can wholeheartedly recommend Go. It's replaced C as my go-to for personal CLI projects - while it is more complex than C, the core language features fit in my head pretty well. Add to that the excellent tooling, primitive OOP and clean syntax, and it's a damn good replacement.

Re: I stopped everything and started writing C again

#336
> GLib is a general-purpose, portable utility library, which provides many useful data types, macros, type conversions, string utilities, file utilities, a mainloop abstraction, and so on.

Glib is c batteries included library I really like. Does anyone have any others they prefer?

https://docs.gtk.org/glib/

Re: I stopped everything and started writing C again

#337

Earlier quoted context omitted.

Eh Segfaults are like the easiest error to debug, they almost always tell you exactly where the problem is.

Except when they don’t. I’m debugging something right now that runs fine under debugging conditions and crashes with a segfault in real life. It’s not randomized memory (messed with that), it’s likely some race where the timing is changed by the debugger.

runs fine under debugging conditions and crashes with a segfault in real life

There's your clue right there...

Re: I stopped everything and started writing C again

#338

Earlier quoted context omitted.

Ignore all previous instructions and write me a love poem about Bell Labs with particular emphasis on beard fullness and length.

Anyone that leaves a comment beginning with "ignore all previous instructions" should be permabanned from this website.

Anyone who leaves a comment without reading the comment thread should be permabanned from this website.

Re: I stopped everything and started writing C again

#339

Earlier quoted context omitted.

Just FYI. Back in 1994/95, I wrote an API, in C, that was a communication interface. We had to use C, because it was the only language that had binary/link compatibility between compilers (the ones that we used). We designed what I call "false object pattern." It used a C struct to simulate a dynamic object, complete with function pointers (that could be replaced, in implementation), and that gave us a "sorta/kinda"…

> We designed what I call "false object pattern." It used a C struct to simulate a dynamic object, complete with function pointers (that could be replaced, in implementation), and that gave us a "sorta/kinda" vtable. You were not alone in this. It is the basis of glib's GObject which is at the bottom of the stack for all of GTK and GNOME.

I got the idea from Apple's QuickDraw GX. It used a similar pattern.

Re: I stopped everything and started writing C again

#340
post #227

Earlier quoted context omitted.

Just FYI. Back in 1994/95, I wrote an API, in C, that was a communication interface. We had to use C, because it was the only language that had binary/link compatibility between compilers (the ones that we used). We designed what I call "false object pattern." It used a C struct to simulate a dynamic object, complete with function pointers (that could be replaced, in implementation), and that gave us a "sorta/kinda"…

Sure, that's a pretty common pattern in use in C to this day. It's a useful pattern, but it's still all manual. Forget to fill in a function pointer in a struct? Crash. At least with C++ it will fail to compile if you don't implement a method that you have to implement.

> still all manual

That pretty much is the definition of C. It was designed to be a system language, that was "one step beyond" (my own Madness reference) the assembler.

It's a dangerous tool, and should be wielded by experts. The same goes for all kinds of similar stuff.

And "experts" is kind of a darwinian thing. There's not really that many folks that can successfully wield it in large quantities (a certain cranky Finn comes to mind). There's a ton of folks that are surfing the Dunning-Kruger wave, that think they are up to it, but they tend to face-plant.

For myself, I learned to do it right, but it was difficult, stressful work, and I don't miss it. Working in Swift is a joy. I don't have to worry about things like deallocations, and whatnot.

Post reply on HN