Live data from Hacker News

I stopped everything and started writing C again

kmx.io

191–200 of 475 posts

Re: I stopped everything and started writing C again

#191
post #176

Earlier quoted context omitted.

The biggest problem with C is that doesn't even have enough features to help you build the features and abstractions you need and want. For example with C++ the language offers enough functionality that you can create abstractions at any level, from low level bit manipulation to high level features such as automatic memory management, high level data objects etc. With C you can never escape the low level details. Cur…

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.

Re: I stopped everything and started writing C again

#192
post #88
post #46

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

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 language, it is pretty close to the hardware.

Zig simply solves more of my personal pain points... but if rust matures in ways that help those I'll consider it again.

Re: I stopped everything and started writing C again

#193
post #155

Earlier quoted context omitted.

I'd call it a while ago, but not a long time. Long time to me is more like 70s or 80s. I was born in 1996 so likely I'm biased: "before me=long time". It would be interesting to do a study on that. Give the words, request the years, correlate with birthyear, voila

Given how fast our field grows, you might want to consider anything beyond 13 years "a long time ago", since only a tenth of us were around back then[1]. [1]: https://entropicthoughts.com/python-programmers-experience

I don't think that's a good benchmark for a C discussion, though it probably is for JS.

Re: I stopped everything and started writing C again

#194
post #57

Earlier quoted context omitted.

> helping the cause Rust evangelism is probably the worst part of Rust. Shallow comments stating Rust’s superiority read to me like somebody who wants to tell me about Jesus.

it's not unique for Rust, C/C++ devs probably aren't just used to it, since there hasn't been anything major new for decades. If you already dislike this, I ask you to read C-evangelism with respect to the recent Linux drama about Rust in Linux.

every technology has proponents

but Rust evangelism is on another level

Re: I stopped everything and started writing C again

#195
post #46

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

> it is C with a bit of polish.

I am fast becoming a Zig zealot.

What I've discovered is that while it does regularize some of the syntax of C, the really noticeable thing about Zig is that it feels like C with all the stuff I (and everyone else) always end up building on my own built into the language: various allocators, error types, some basic safety guardrails, and so forth.

You can get clever with it if you want -- comptime is very, very powerful -- but it doesn't have strong opinions about how clever you should be. And as with C, you end up using most of the language most of the time.

I don't know if this is the actual criterion for feature inclusion and exclusion among the Zig devs, but it feels something like "Is this in C, or do C hackers regularly create this because C doesn't have it?" Allocators? Yes. Error unions? Yes. Pattern matching facilities? Not so much. ADTs? Uh, maybe really stupid ones? Generics, eh . . . sometimes people hack that together when it feels really necessary, but mostly they don't.

Something like this, it seems to me, results in features Zig has, features Zig will never have, and features that are enabled by comptime. And it's keeping the language small, elegant, and practical. I'm a big time C fan, and I love it.

Re: I stopped everything and started writing C again

#196
post #18

Earlier quoted context omitted.

That really depends what you want to do. All that security in Rust is only needed if there is a danger of hacks compromising the system. The moment you start building something that's not exposed to the internet and hacking it has no implications, C beats it due to simplicity and speed of development .

> All that security in Rust is only needed if there is a danger of hacks compromising the system. Rust's safety features help prevent a large class of bugs. Security issues are only one kind of bug. > C beats it due to simplicity and speed of development C being faster to develop than Rust is a ludicrous claim.

I don't think its ludicrous.

Rust is a complex language that is safe.

C is a simple language that is unsafe.

There are always compromises and it always depends on the project. Of course importing a dependency is faster in Rust.

But the best language ever imho is Golang. Its simple and safe with the compromise being the GC.

Re: I stopped everything and started writing C again

#197

Earlier quoted context omitted.

> C++'s stdlib contains a lot of convenient features, writing them myself and pretending they aren't there is very difficult. I've never understood the motivation behind writing something in C++, but avoiding the standard library. Sure, it's possible to do, but to me, they are inseparable. The basic data types and algorithms provided by the standard library are major reasons to choose the language. They are relativel…

Modern C++ has goodies like consteval that are supremely useful for embedded work. STL and the rest of the stdlib on the other hand depends on heap and exceptions for error reporting which are generally a no go zone for resource constrained targets. You can productively use C++ as C-with-classes (and templates, and namespaces, etc.) without depending on the library. That leaves you no worse off than rolling your own…

Can't you disable exceptions?

Re: I stopped everything and started writing C again

#198
post #188
post #146

Earlier quoted context omitted.

> I think Rust is harder to learn, but once you grok it, I don't think it's harder to use, or at least to use correctly. It's hard to write correct C because the standard tooling doesn't give you much help beyond `-Wall`. When I say Rust is harder to use (even after learning it decently well), what I mean is that it's still easier to write a pile of C code and get it to compile than it is to write a pile of Rust code…

I’d add that the Rust code and C code will probably have the same number of bugs. The C code will likely have some vulnerabilities on top of those. Rust doesn’t magically make the vast majority of bugs go away. Most of bugs are entirely portable!

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.

Re: I stopped everything and started writing C again

#199
post #127

I'm kinda in the opposite camp. After doing a bunch of VB in my tweens and teens, I learned Java, C, and C++ in college, settling on mostly C for personal and professional projects. I became a core developer of Xfce and worked on that for 5 years. Then I moved into backend development, where I was doing all Java, Scala, and Python. It was... dare I say... easy! Sure, these kinds of languages bring with them other pro…

> Memory leaks, NULL pointer dereferences, use-after-free

I suffered writing those for many years. I finally simply learned not to do them anymore. Sort of like there's a grain of sand on the bottom of my foot and the skin just sort of entombed it in a callous.

Re: I stopped everything and started writing C again

#200
post #127

I'm kinda in the opposite camp. After doing a bunch of VB in my tweens and teens, I learned Java, C, and C++ in college, settling on mostly C for personal and professional projects. I became a core developer of Xfce and worked on that for 5 years. Then I moved into backend development, where I was doing all Java, Scala, and Python. It was... dare I say... easy! Sure, these kinds of languages bring with them other pro…

Thank you for your work on XFCE. It's been the best WM/UI for me for over a decade.
Post reply on HN