Live data from Hacker News

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

youtube.com

101–110 of 132 posts

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

#101
post #98
post #45

Earlier quoted context omitted.

No upvote can tell how much I relate to this. The only way to get a good maintainable C++ code is to hire very mediocre programmers whose “C++” really means “Qt with some shared ptrs”. The reason (I believe) is that complex things are like hard drugs for smart people. Instead of solving business tasks, which honestly are often just boring, they long for an art in programming. In C++ this inevitably leads to solving n…

> The only way to get a good maintainable C++ code is to hire very mediocre programmers whose “C++” really means “Qt with some shared ptrs”. I feel like this is the most salient point in my mind. You can make an absolute mess of a code base in any language if you re-invent every wheel. I work in the embedded world and there's a definite trade-off between C and C++. C is very minimal and embedded developers are very r…

> At least in my domain I feel the problem is developers just throwing code at a problem until it compiles and exhibits the expected behavior in the happy path

I specialize in joining projects with "issues", specifically to help them deliver, improve reliability, performance, etc.

I have observed most projects with problems exhibit one of two "failure modes". I mean projects and not developers because projects tend to hire like developers and then developers mostly share same problematic quality. In the end it is not individual contributors who are at fault but management who allowed it to happen.

#1. Insufficient programming skills. This where developers don't use libraries because they don't even know they exist, can't recognize the problem they are solving as generic. This is where they can't structure the code because they haven't seen much code at all and/or are not interested in learning.

You can recognize this immediately as codebases with a lot of code duplication and very weak structure/abstractions.

#2. Too much programming ambition. This is where developers think so highly of themselves that they can't accept existing off the shelf components and will reinvent them because they can do better. They will write new everything because it will offer 10% performance increase in their specific case or just for the intelectual fun of doing it. They will obsess over ensuring there is no duplication of code at the cost of creating baroque structures that have no meaning and purpose other than ensure that every single component works in every single case supported by the application and in any possible future.

You can recognize this as codebases with no duplication but when you try to read the code it seems the structure is so complicated you need to have a huge map on entire wall and a guide to be able to travel the codebase. Most of the objects don't have any meaning in the domain of the problem and are just abstract "stuff" necessary to glue everything together.

I very much prefer working with case #1

The reason is that, as dumb as the code is, you can read it and understand what the author probably had in mind, what the application attempts to do. You can then work with the code, refactor functionality out, and so on.

In my experience case #2 is usually beyond repair (or at least beyond my abilities to repair). These developers become easily hostile -- because they think very highly of themselves they treat everybody as inferior and now I am trying to write some dumb unsophisticated code and so I must be dumb. They also tend to change jobs pretty easily so the only result of trying to fix that kind of project is people suddenly leaving it and management getting restless at the lack of progress.

And for some reason every single C++ team I worked with falls under case #2.

I think because, given so many options, you need to have ambition to willingly choose C++ as your main programming language and so the population is preselected.

Don't get me wrong, these are all highly intelligent people. But you can be very intelligent and still make a mess. I know because I was doing the same until I have acquired some wisdom based on my own mistakes and mistakes I have observed.

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

#102
post #76

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…

Well... What's the difference compared to C? f(x) can also do anything, including side-effects, changing mutable state, etc. Worse if it's a macro.

In C, n=f(x) plainly means the variable n is assigned the value returned from f(x). While you don't know what f(x) does, you can tell it is a function.

In c++, the = could be a function too, that does unexpected things. Critically, if you are unaware of the side effects of that = operator, you may be doing things you don't want to do. The most likely issue would be performance if you are repeatedly using the = operator thinking it is a simple operation. Like if someone is being clever and uses the Active Record model and you are unexpectedly doing database writes with what you thought was a local object with no side effects.

To not have this happen, of course, you could read the entire object definition, but then you need everyone working on the project to have 100% of the code committed to memory. This is why you will likely find rules in the coding style guide of whatever company banning such practice after someone is bitten by it.

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

#103
post #28

Earlier quoted context omitted.

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

I wish, althought C++ was born on the same building as C (kind of) and has enjoyed first class support on UNIX, it has hardly taken its place at the kernel level or syscalls. So most UNIX/POSIX projects, even new ones, will default to C. Then there is the embedded space where almost 40 years later trying to use C++ instead of C is still an uphill battle, between embedded development communities, tool vendors, debuggi…

This is a hope OT reply, but I just want you to know that I truly appreciate your commenting on HN. I find myself actively seeking out your comments when browsing. While I may disagree with some of your thoughts (violently in a few cases) I always find them well written and argued. I even find myself wondering what you would think of my pet language project. So, in sum, even if coming to HN is just a fun diversion for you, it actually makes a difference to some people, so thanks.

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

#104
post #45

Earlier quoted context omitted.

No upvote can tell how much I relate to this. The only way to get a good maintainable C++ code is to hire very mediocre programmers whose “C++” really means “Qt with some shared ptrs”. The reason (I believe) is that complex things are like hard drugs for smart people. Instead of solving business tasks, which honestly are often just boring, they long for an art in programming. In C++ this inevitably leads to solving n…

While this is mostly true, there are some (very limited) circumstances where modern language constructs are legitimately the best approach. Generic libraries are probably the most obvious case where you may need some fancy metaprogramming. Move semantics and other similar tricks for avoiding copies are often used for saving much more than a 24-byte copy. Unfortunately, a lot of C++ enthusiasts who write this kind of…

I strongly believe readability trumps everything when it comes to writing code for a lot of reasons.

I love modern language constructs when I can use them to help make the code more readable and verifiable.

What I dislike is using language features to make the code seem more intelligent and eloquent where there already exist simple, dumb, readable way to achieve same result.

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

#105
post #45

Earlier quoted context omitted.

No upvote can tell how much I relate to this. The only way to get a good maintainable C++ code is to hire very mediocre programmers whose “C++” really means “Qt with some shared ptrs”. The reason (I believe) is that complex things are like hard drugs for smart people. Instead of solving business tasks, which honestly are often just boring, they long for an art in programming. In C++ this inevitably leads to solving n…

While this is mostly true, there are some (very limited) circumstances where modern language constructs are legitimately the best approach. Generic libraries are probably the most obvious case where you may need some fancy metaprogramming. Move semantics and other similar tricks for avoiding copies are often used for saving much more than a 24-byte copy. Unfortunately, a lot of C++ enthusiasts who write this kind of…

The C answer to generics is void pointers, careful programmers, and CVEs. CVEs are the most important C language construct.

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

#106
post #56
post #44

Earlier quoted context omitted.

I think the basic issue is that C++ want to spend a lot of time focusing on C++ The Language, while C developers mostly want to focus on developing the logic of whatever they are doing. When I worked on C++ projects half of the discussion was on just the use of language or various consequences of it. On C projects that never happens. There is nothing to talk about so everybody focuses on making the project better. Th…

What I miss most when working in C instead of C++ is that although lint was created in 1979, most projects still avoid any kind of static analysis. Then there are the discussions on: - what warnings to turn on as errors - what ISO C says and what compiler XYZ does, with many not even aware to the differences - not clear understanding of the 200+ UB cases documented on the standard - in-house libraries for safer handl…

Almost all above applies to C++ too.

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

#107
post #64

Is it possible to translate C into (unsafe) Rust while maintaining both human readability and link-level compatibility?

There is also https://github.com/jameysharp/corrode

I have not used it, but I doubt it's possible to translate C into idiomatic Rust mechanically.

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

#108

What I really want, is a C++ book that lists the absolutely must-have features for a beginner-intermediate programmer, I don't want to be overloaded(no pun intended) with all those 2000 advanced features, I can read an advanced level book when I'm ready. Basic types, smart-pointers(how to use them and when to use them), basic OOD and template(but no advanced tricks), essential algorithms and containers, that's about…

"A Tour of C++" is only 256 pages and the 1st edition is what I used to get into modern C++ in the workplace years after a strange mix of C/C++ labs in college.

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

#109
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. 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".

Why do namespaces require name mangling? One could imagine just using :: in the symbol name.

Anyway, even C has name mangling: For example, on Windows, all C symbols gets prefixed by an underscore https://docs.microsoft.com/en-us/cpp/error-messages/tool-err... And even on macOS there is something about having symbols starting with \1

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

#110
post #66

An account of modern C should also note , which came with C99, and makes "sin()" and "cos()" do the right thing w.r.t. argument type (float, double, long double), something that has long been possible in Fortran. In C, this allows you to typedef a "real" type, set to either float or double at compile-time, in order to conveniently explore trade-offs associated with the different floating point precisions. The impleme…

Note that C11 added _Generic to the language, so things like the type-generic functions from tgmath.h can nowadays be implemented in user space.

Indeed; thanks. I do appreciate knowing that does this for all the math functions in one fell swoop.

speaking of FP-precision genericity, I really wish there was a format specification for printf that would reliably print a floating-point number with just enough digits to recover the bits of the given value (float or double), but the given value will already have been promoted to double since printf is variadic.

Post reply on HN