Live data from Hacker News

I stopped everything and started writing C again

kmx.io

431–440 of 475 posts

Re: I stopped everything and started writing C again

#431
post #160
post #61

Earlier quoted context omitted.

When Ada was first announced, I rushed to read about it -- sounded good. But so far, never had access to it. So, now, after a long time, Ada is starting to catch on??? When Ada was first announced, back then, my favorite language was PL/I, mostly on CP67/CMS, i.e., IBM's first effort at interactive computing with a virtual machine on an IBM 360 instruction set. Wrote a little code to illustrate digital Fourier calcul…

I recently started re-reading "Programming in Ada" by J.G.P. Barnes about the original Ada. In my opinion, it was not that good of a language. Plenty of ways to trigger undefined behavior. Where C was clearly designed to be a practical language with feedback from implementing an operating system in C. Ada lacked that kind of practical experience. And it shows. I don't know anything about modern day Ada, but I can see…

I recall watching a presentation about C++20. During the presentation, the presenter said there were about 163 undefined behaviors in the C language (note: I think it was C99) which implied there were many more in C++ since it’s a much more complex language. Unfortunately, I don’t have a link to that presentation.

You might have heard about the SPARK variant of Ada. I recall reading in an article many years ago that the original version of SPARK was based on Ada83 because it is a very safe language with a lot less undefined behaviors, which is key to trying to statically prove the correctness of a program.

Re: I stopped everything and started writing C again

#432

Earlier quoted context omitted.

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 unorde…

What's slow about regex? A properly optimised regex engine ought to be very efficient (if used sensibly, at least).

std::regex in C++ cannot be "properly optimized" due to various factors: https://stackoverflow.com/questions/70583395/why-is-stdregex...

Re: I stopped everything and started writing C again

#433

What's the best way to learn C? Any good modern book recommendations, or sites?

I second "Modern C" by Jen Gustedt.

- Get the `cdecl` tool to build intuition about function signatures. What does "int( * ( *foo)(void))[3]" mean?

- Write it yourself.

- Be disciplined. Develop good hygiene with compiler flags, memory/address checks, and even fuzzing.

- Read good source code such as the linux kernel. This is an amusing header file from the git source code that defines some banned functions. This is wisdom if you choose to follow it: https://github.com/git/git/blob/master/banned.h

- Push the language to its limits. Play with memory and data structures. Inspect everything. This book "Data-Oriented Design" by Richard Fabien is a great to explore as well. It's about organizing your data for efficient processing.

Re: I stopped everything and started writing C again

#434

Earlier quoted context omitted.

What's slow about regex? A properly optimised regex engine ought to be very efficient (if used sensibly, at least).

std::regex in C++ cannot be "properly optimized" due to various factors: https://stackoverflow.com/questions/70583395/why-is-stdregex...

The answer there [0] doesn't support this. From the answer:

> There is no question that libstdc++'s implementation of is not well optimized. But there is more to it than that. It's not that the standard requirements inhibit optimizations so much as the standard requirements inhibit changes.

The answer's one comment expands on this, it sounds like they're not able to add a sophisticated optimising regex engine into the libstd++ shared library (i.e. non-inline) as this would be an ABI break.

Perhaps other implementations of the C++ standard library perform better.

[0] https://stackoverflow.com/a/70587711/

Re: I stopped everything and started writing C again

#435

Earlier quoted context omitted.

If it looks anything like what I read in "Modern C++ Design" 20+ years ago then I'll pass. That book made me realize the language wasn't for me anymore.

It looks nothing like C++ decades ago, it is effectively a completely different language. I found C++ unusable before C++11, and even C++11 feels archaic these days. Idiomatic C++20 and later is almost a decent language.

"Modern C++ Design" was the first book that highlighted template metaprogramming and showed you ways to use it as a Turing complete programming language in itself. Even a decade+ after it was printed my friend said it was recommended reading for employees within Google so I gave him mine - but I'm not sure about these days.

Talking about how much you can do with C++ templates made me think of that.

Re: I stopped everything and started writing C again

#436

Earlier quoted context omitted.

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

Yes. Did you read what I wrote?

Re: I stopped everything and started writing C again

#437

Earlier quoted context omitted.

std::regex in C++ cannot be "properly optimized" due to various factors: https://stackoverflow.com/questions/70583395/why-is-stdregex...

The answer there [0] doesn't support this. From the answer: > There is no question that libstdc++'s implementation of is not well optimized. But there is more to it than that. It's not that the standard requirements inhibit optimizations so much as the standard requirements inhibit changes . The answer's one comment expands on this, it sounds like they're not able to add a sophisticated optimising regex engine into t…

In my understanding, other implementations cannot perform better, because the root cause is how it is defined in the standard. Basically, any better implementation would be non-conforming. It’s not the kind of ABI issue where simply choosing a different one would help; the flaw comes directly from the definition, which cannot be changed.

Of course, non-std implementations of regexes in C++ don’t have this issue. Were strictly talking about the standard library one.

Re: I stopped everything and started writing C again

#438
post #251

Earlier quoted context omitted.

Simplify. If you try to write the same complicated mess in C as you would in any other language it's going to hurt. Not having a package manager can be a blessing, depends on your perspective.

There's no amount of simplification that'll free you from the need to manually check and handle/propagate errors or deallocate resources in C. You might be able to reduce the amount of code you need to write, but it's still several lines of C versus one line of something else - and if you make a mistake or even forget something in those several lines, things will often compile and run fine, but you'll have memory lea…

I don't have these issues in C, you're projecting.

Not that I write bug free software by any means; no one does, though some like to pretend.

Re: I stopped everything and started writing C again

#439
post #430
post #249

Earlier quoted context omitted.

I love Common Lisp, but I would definitely think twice before implementing anything I want other people to use on their machines in it. A tiny C executable is pretty nimble in comparison to anything you'll get out of Common Lisp.

Eh, you can just distribute a .lisp file as though it were a ruby or perl script. CL is faster than the usual scripting languages, but admittedly not as fast as C or Rust.

'Just' is overdoing it a tiny bit :)

Assuming everyone has a CL installed is going to limit the audience pretty drastically.

And what about dependencies? Assume they have quicklisp installed as well?

Like I said, I love Common Lisp, but every language is some kind of compromise.

Re: I stopped everything and started writing C again

#440
post #256

Earlier quoted context omitted.

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.

No, but that tends to gradually happen all by itself from my experience, even in solo projects. Because it feels stupid writing something yourself when you have access to stdlib. Also, I feel rolling your own stuff in C++ is a major pita in comparison to C, too many rules to memorize for me.
Post reply on HN