Live data from Hacker News

I stopped everything and started writing C again

kmx.io

371–380 of 475 posts

Re: I stopped everything and started writing C again

#371
post #11

I fully understand that sentiment. For several years now, I have also felt the strong urge to develop something in pure C. My main language is C++, but I have noticed over and over again that I really enjoy using the old C libraries - the interfaces are just so simple and basic, there is no fluff. When I develop methods in pure C, I always enjoy that I can concentrate 100% on algorithmic aspects instead of architectu…

About 16 years ago I started working with a tech company that used "C++ as C", meaning they used a C++ compiler but wrote pretty much everything in C, with the exception of using classes, but more like Python data classes, with no polymorphism or inheritance, only composition. Their classes were not to hide, but to encapsulate. Over time, some C++ features were allowed, like lambdas, but in general we wrote data clas…

Also fast to compile!

Re: I stopped everything and started writing C again

#372
love this sentiment. i tried a lot of languages after C, and am also back to C. it does force me to pencil out all kinds of stuff rather than relying on third party code or compiler error help, but i find that delightful. good upfront coding on a piece of paper, slowly (compared to other langs) implementing it, and diligently testing because you know its very needed in C. it forces you to do things right, and if you do you get an ultimate reward. blazin fast , well behaved code.

yes, my life is still full of segfaults as many segfaults as ignorance and impatience. so its delightful because it helps me overcome those 2 things, slowly and steadily =)

Re: I stopped everything and started writing C again

#373
post #150

Earlier quoted context omitted.

> Similar to C, but with much more help from the compiler with all sorts of things. Is that not the problem rust was created to solve?

Indeed. I'm still not entirely sure why Rust was created when we have Ada, but if I had to guess it's mainly because Rust has slightly more advanced tricks for safe memory management, and to some degree because Rust has curly braces.

Ada use was strongly tied to the US DoD, which put some people off it, for one.

Re: I stopped everything and started writing C again

#374
post #241

Earlier quoted context omitted.

Interesting use of the word 'objectively' there.

Not really. I have written a lot of C and Rust. The notion that identical projects written in both languages would have identical numbers of (or even severity of) bugs is laughable on its face. I mean, literally just not being able to deref a NULL pointer by itself is enormous.

You can dereference null pointers in Rust, it's also easy to make null pointers. The thing is I'm not surprised you didn't realise this is possible because you would never actually do this in Rust since it's obviously a bad idea.

  let p: *const i32 = std::ptr::null();  // Pointer to a signed 32-bit integer, but it's null
  unsafe { some_local = *p };            // Dereferencing the null pointer, bang
If we instead use references they're nicer to work with, don't need unsafe, perform the same, and are never null. So obviously that's what real Rust programmers almost always do.

Re: I stopped everything and started writing C again

#375
post #231

Earlier quoted context omitted.

> 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.

I've seen you make these kinds of comments before on other articles. Please stop. Not everyone is perfect and can forevermore avoid making any mistakes. I strongly suspect your opinion of your skill here is overinflated. Even if it isn't, and you really are that good, everyone cannot be in the top 0.00001% of all programmers out there, so your suggestion to "simply" learn not to make mistakes is useless. This all jus…

> This all just comes off incredibly arrogant

I know, but it's the truth. Consider another case. I worked in a machine shop in college trying to make my steam engine. The man who ran the shop, was kind enough to show me how to operate the machines.

Those machines were like C, built during WW2. They had no user friendly features. The milling machine was a particular nightmare. It was festooned with levers and gears and wheels to control every aspect. There was no logic to the "user interface". Nothing was labeled. The worst one was a random lever that would reverse the operation of all the other levers. My terror was wrecking the machine by feeding the tool mount into the cutting bit.

I would make a part, and it would come out awful - things like the surface finish was a mess. If he had some time, he'd come over and help me. He'd turn a wheel, "ting" the blade on a grinding wheel, adjust the feed, and make a perfect part (all by eyeball, I might add). The man was just incredible with those machines. I was just in awe. He never made a mistake. Have you ever tried to get a part centered properly in a 4-jaw chuck? Not me. He could on the first try every time.

But he'd been doing it every day for 40 years.

Re: I stopped everything and started writing C again

#376
post #256

Earlier quoted context omitted.

You still need to think about error handling, and it's not standardized because everyone else will also have to think about it ad hoc. You'll also still need to think about when to copy and move ownership, only without a type system to help you tell which is which, and good luck ensuring resources are disposed correctly (and only once) when you can't even represent scoped objects. `goto` is still the best way to deal…

But you have a choice, you don't have to implement all of C++/Rust. The beauty of C is that it allows you to pick your level of complexity.

You don't have to use the entirety of C++, either.

Re: I stopped everything and started writing C again

#377

Earlier quoted context omitted.

I think a more charitable interpretation of what he said was, "after sufficient practice, I became good enough to start avoiding those pitfalls." It's not all that different from learning any challenging task. I can't skateboard to save my life, but the fact that people can do it well is both admirable and the result of hundreds or thousands of hours of practice. Skilled people can sometimes forget how long it took t…

> after sufficient practice, I became good enough to start avoiding those pitfalls. You can only do that in code you control. You can not control the entire call stack of your functions in cooperative environments.

> You can not control the entire call stack of your functions in cooperative environments.

That's true. But I try by doing code reviews, and I try to lead the team by example and suggestion.

Re: I stopped everything and started writing C again

#378
post #231

Earlier quoted context omitted.

I've seen you make these kinds of comments before on other articles. Please stop. Not everyone is perfect and can forevermore avoid making any mistakes. I strongly suspect your opinion of your skill here is overinflated. Even if it isn't, and you really are that good, everyone cannot be in the top 0.00001% of all programmers out there, so your suggestion to "simply" learn not to make mistakes is useless. This all jus…

Surely it is better than yet another self-promoting mention of his programming language on every unrelated C, Rust or Zig post?

Every post on D attracts C, Rust, and Zig replies :-)

Feel free to downvote any and all posts I make.

Re: I stopped everything and started writing C again

#379
post #299

Earlier quoted context omitted.

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…

What do you consider the difference in their core models. Rust and C++ both use RAII, both have a strong emphasis on type safety, Rust just takes that to the extreme. I would like to even hope both believe in 0 cost abstractions, which contrary to popular belief isn't no cost, but no cost over doing the same thing yourself. In many cases it's not even 0 cost, it's negative cost since using declarative programming can…

Rust is basically what you get if you start with ML and then do enough to avoid having garbage collection.

Re: I stopped everything and started writing C again

#380

Earlier quoted context omitted.

He's not making a comment about everyone , it's a specific comment about how often long time C programmers make basic mistakes after a million SLOC or so. In this instance Walter is correct - the mistakes he listed are very rarely made by experienced C programmers, just as ballet dancers rarely trip over their own feet walking down a pavement. The problem of those errors being commonplace in those that are barely fiv…

> just as ballet dancers rarely trip over their own feet walking down a pavement What about about walking down a busy construction site? The most charitable and correct interpretation I can think of is "I'm a professional. Seatbelts and OSHA destroy my productivity."

> Seatbelts and OSHA destroy my productivity

D is designed with seatbelts (like array overflow protection), and they work. I regularly show how C could add them with only minor additions.

Post reply on HN