Live data from Hacker News

Modern C and What We Can Learn from It [video]

youtube.com

81–90 of 132 posts

Re: Modern C and What We Can Learn from It [video]

#81

Earlier quoted context omitted.

I would argue that you pay a harder mental cost in C because each project has to reinvent its own convention to emulate C++ features, and also because C allow for less abstraction which makes reasoning about the whole program more difficult I don't see the relation with the fact that msvc and GCC have chosen different c++ ABI. That's not telling anything about the complexity of the language.

If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset. Getting back to the "C way" takes a couple of months to get C++ out of your system first ;) Of course for some types of problems, C++ is indeed the better language than C, but very often other languages are even better suited (e.g. I turn to Python for most problem where C doesn't work well, for instance munching tex…

> If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset.

Ah, classic no true scotsman'ism. No real C programmer would emulate classes, an object system, virtual dispatch, templates, ...

Re: Modern C and What We Can Learn from It [video]

#82

What book would you suggest for someone who started on the K&R 2nd Ed. then didn't write a line in C for about 15 years? I would appreciate something near the K&R style, but updated with the latest changes to the language, security related caveats etc.

Modern C, https://modernc.gforge.inria.fr/

Re: Modern C and What We Can Learn from It [video]

#83

Earlier quoted context omitted.

> C++ just has so many features that makes the development of programs and libraries easier, for almost no extra costs. I respect your opinion, but mine is the exact opposite (I don't know how representative mine is, but I'm sure I'm not alone). The problem with C++ is that many of those "features" are actually "anti-features". From the top of my head: operator overloading, copy-constructors, constructors, destructor…

> The problem with C++ is that many of those "features" are actually "anti-features". From the top of my head: operator overloading, copy-constructors, constructors, destructors, function overloading. While these "features" may make correct code easier to write, they always make incorrect code much, much harder to understand. > For example, you find a simple line of C++ that says "y=f(x);", and it can do anything: ha…

>I have yet to see any of this be an actual problem in real-world projects

Just on Monday, I was bitten by a bug caused by operator overloading. I'm building a static analysis tool in C++. There's a method `getType()` that returns the qualified type of an expression. I had a call to `getType()` nested in some other calls, e.g. `expr->asAssignmentExpr()->getRHS()->getType()->getSomeQualifiedTypeProperty()`.

The creators of the `QualifiedType` type that's returned by `getType()` had overridden the class member access operator to return an UnqualifiedType. This problem took me an embarrassingly long amount of time to diagnose. The compiler error messages told me that `UnqualifiedType` doesn't have a property `getSomeQualifiedTypeProperty`, but I couldn't see why I was getting an unqualified type from a method that is supposed to return a qualified type. I searched the documentation online, searched the header files, tried reinstalling the library, nothing made sense.

Then, I learned this operator had been overloaded. So, I just needed to write `expr->asAssignmentExpr()->getRHS()->getType().getSomeQualifiedTypeProperty()`.

Ouch.

Re: Modern C and What We Can Learn from It [video]

#84
post #10
post #9

Earlier quoted context omitted.

In my experience, I have to qualify I program "ANSI C", otherwise people assume that I am really talking about C++. I list ANSI C and no C++ in my professional experience and yet I have had a bunch of people call me to seriously talk about me helping in their C++ project. Maybe I shouldn't fault recruiters too much, though they should probably understand what language they are hiring for. But some of these guys were…

If you can program C well, C++ isn't going to be too much of a problem for you. The reverse is not necessarily true. If I were hiring on a C++ project I'd definitely want to talk to someone who is genuinely good at C - they may not want to talk of course.

Absolutely not. I program C well - very well, I'd even brag - and I've used C++ long ago as well. I've programmed in many other languages besides. I am not adverse to picking up new languages.

But when I look at a modern C++ project, I get instantly overwhelmed. There is so much going on. So many weird features interacting with each other. So much you have to be aware of and familiar with. It is massively painful to work with. I would not be comfortable with working any kind of C++ codebase without years of experience with this absolute beast of a language.

Re: Modern C and What We Can Learn from It [video]

#85
post #9

Earlier quoted context omitted.

In my experience, I have to qualify I program "ANSI C", otherwise people assume that I am really talking about C++. I list ANSI C and no C++ in my professional experience and yet I have had a bunch of people call me to seriously talk about me helping in their C++ project. Maybe I shouldn't fault recruiters too much, though they should probably understand what language they are hiring for. But some of these guys were…

> C died and C++ is newer and better version of it That's kind of my opinion. C didn't die for legacy reasons, but starting new project in C seems a nonsense to me. C++ just has so many features that makes the development of programs and libraries easier, for almost no extra costs.

You probably work with ultra high level stuff, which is the tip of the iceberg when it comes to programming. More than half of what is written around comes from drivers, embedded, engines, robots, controllers and kernel. And for those, you have nowhere to run but to use C down to its bottom. You might use some C++ to enforce some abstraction, iterate in a more fashionable way, but in the end, it's just C

Re: Modern C and What We Can Learn from It [video]

#86

Earlier quoted context omitted.

I would argue that you pay a harder mental cost in C because each project has to reinvent its own convention to emulate C++ features, and also because C allow for less abstraction which makes reasoning about the whole program more difficult I don't see the relation with the fact that msvc and GCC have chosen different c++ ABI. That's not telling anything about the complexity of the language.

If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset. Getting back to the "C way" takes a couple of months to get C++ out of your system first ;) Of course for some types of problems, C++ is indeed the better language than C, but very often other languages are even better suited (e.g. I turn to Python for most problem where C doesn't work well, for instance munching tex…

> If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset.

So you need a C++ mindset to have a use for a dynamic array, a hash table, threads or namespaces, all cross platform? (Yes windows is a platform too)

That's without considering raii! (which does admittedly have some baggage wrt the functions you need to implement.)

Re: Modern C and What We Can Learn from It [video]

#87
post #82

What book would you suggest for someone who started on the K&R 2nd Ed. then didn't write a line in C for about 15 years? I would appreciate something near the K&R style, but updated with the latest changes to the language, security related caveats etc.

Modern C, https://modernc.gforge.inria.fr/

Thanks, looks interesting. I would order the dead tree book if it wasn't from Manning, which uses a layout that is almost unreadable to me: thin fonts and no bold text where it should be. just take a look at the difference from the CC licensed .pdf and the livebook at Manning's site, and on paper it'll be even worse (been burned before with the otherwise excellent Nim book which is hardly readable as well).

Why is it still so hard to replicate the readability of the K&R after so many years? Please stop using thin fonts!

Re: Modern C and What We Can Learn from It [video]

#88
post #3

The presenter has discovered the Result / Either monad at 00:24:16, but their proposed C implementation sounds like a really bad idea: - The flag needs to be manually inlined into every type, thus bloating the type even after the value has been successfully created. ie every instance of `file_contents_t` in your program has become the equivalent of `Result ` and you have to check it for validity every time you use it…

> thus bloating the type

Mildly off-topic, but as of Rust 1.50 [0], Option is now the same size as File, as "-1" can be used to represent no-file. You're completely right though about how it would be good to unwrap it as soon as possible once it is successfully created...

[0] https://blog.rust-lang.org/2021/02/11/Rust-1.50.0.html#a-nic...

Re: Modern C and What We Can Learn from It [video]

#89
post #86

Earlier quoted context omitted.

If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset. Getting back to the "C way" takes a couple of months to get C++ out of your system first ;) Of course for some types of problems, C++ is indeed the better language than C, but very often other languages are even better suited (e.g. I turn to Python for most problem where C doesn't work well, for instance munching tex…

> If you feel the need to emulate C++ features in C then you're just writing C code with a C++ mindset. So you need a C++ mindset to have a use for a dynamic array, a hash table, threads or namespaces, all cross platform? (Yes windows is a platform too) That's without considering raii! (which does admittedly have some baggage wrt the functions you need to implement.)

Dynamic arrays, hash tables, threads: C++ doesn't have those either as language constructs, they are only implemented in the standard library.

Namespaces: prefixes work just fine in C and don't require name mangling.

RAII makes no sense with C's concept of "dumb data" instead of C++'s "smart objects".

Re: Modern C and What We Can Learn from It [video]

#90

Anyone who wants a very good modern C book that's only 272 pages, take a look at 'Effective C - An Introduction to Professional C Programming by Robert C. Seacord. [1]. It's from 2020. Robert Seacord is a Technical Director at NCC Group where he develops and delivers secure coding training in C, C++, and other languages. Seacord is an expert on the C Standards committee. > That's some solid credentials. He focuses on…

I believe it's important to always mention in conjunction with this book that, after decades of existence, the No Starch finally discovered C's natural mascot: Cthulhu. Cthulhu is powerful, to be respected and feared and, if malignantly unleashed, will be the end of the world. Just like C.
Post reply on HN