Live data from Hacker News

What if anything have we learned from C++? [video]

youtube.com

21–30 of 56 posts

Re: What if anything have we learned from C++? [video]

#22
post #2

After twenty years of using it? That I was wrong, that plain-old C really is better.

I hold the exact opposite opinion, and would never want to work on a plain C project. It is so low level that one has to write a lot of plumbing code to take care of error handling and resource management. It's also missing pretty much all higher-level concepts that are fast and can make code easier to write, read and less error-prone. Overall, it's simply not fun to write C code, there's a lot of tedious manual work, and even if you do everything according to the book you might oversee something and have problems. Well-written C++ completely eliminates some classes of problems, just like Rust's type system can eliminate even more issues.

C is so tedious to write that even if I didn't have access to C++ I would try something else first when the need to write cross-platform/performant code would come.

The point is: it's not appropriate to evangelise C (or any other language) without pointing out some of its major disadvantages. This is simply spreading misinformation.

Re: What if anything have we learned from C++? [video]

#23
post #9

I started programming in C++ in the late 90's and I used to be confused about what features to use and found it easy to make a mess. But I am happy I stuck with it as it opened up opportunities to work in a lot of different and interesting domains like games, mobile apps, interactive art installations, trading systems and video and film processing apps. Also, most of my code is platform independent and very efficient…

This is also something that I like. In my opinion, the programming languages environment is ridiculously fragmented, and one has to learn new tools constantly in order to keep up, without gaining any real benefits.

I would prefer it if we had several strong, open langauges that are complements to eachother and which would own the market so developers could focus on solving problems, not learning syntaxes and APIs. Instead we have C# and Java, Python and Ruby, etc.

Re: What if anything have we learned from C++? [video]

#24

Earlier quoted context omitted.

Coding in plain C99 with some discipline can actually get you most of the benefits of C++, without any of its quirks. The "object-orientedness" of C++ really boils down to implicitly passing the this pointer to member functions, inheritance + virtual functions, and namespaces. All of these can be emulated in what I would call "C with discipline". Just be consistent in your naming conventions, always use a common pref…

What about templates? For some reason, C programmers only seem to comment about the OO parts of C++ and never talk about templates. When you bring variadic templates into the mix, it's just more awesomeness. And, before you mention it, use clang to avoid getting the page long templates related errors.

I haven't seen much template wizardry in the C++ codebases I've worked on. It can generally be seen in the standard headers.

Type-generic data containers can still be implemented with void pointers and very little runtime overhead, for example: http://lxr.nginx.org/source/src/core/ngx_array.h

Re: What if anything have we learned from C++? [video]

#25
post #11

That introducing kids to programming using C++ will ensure they never want to try again.

I was introduced to C and then C++ when I was 10 years old. I found the book on C by Arthur Chapman very confusing, particularly pointers. I then started reading a book on Pascal in the same series and that was confusing too.

But I stuck with it and have found that learning C++ has meant that I think in C++, and transfer this to other languages when I have to write them.

Additionally, the second thing I found was that all other languages I have come across (Obj-C, Java, Swift, JavaScript, PHP, C#) all have enough commonalities in syntax and thought processes that working in them is easy. In some cases, you get to consider them "dumbed-down" C++, and it makes working in them easier (and means approaches to things are different).

So it isn't a bad language after all. Particularly with the changes in C++11, it feels like an entirely new language.

Re: What if anything have we learned from C++? [video]

#26

I really wish there was a "syntactic-sugar-on-top-of-C++" language that would compile down to C++ and have 100% compatibility with the existing C++ ecosystem (so that you can just directly use a class from any C++ library). Something like TypeScript is to JavaScript, or like Kotlin is to Java. Would make the experience much nicer without having to wait on the slow C++ standardization process or deal with all the back…

Compiling to C would be better. Using C++ libraries from anything outside C++ compiled by the same exact compiler and same exact version of it as the library was is a royal pain.

On the other hand using C libraries is super easy from any language and something compiled 10 years ago still works today.

Re: What if anything have we learned from C++? [video]

#27
post #8

Earlier quoted context omitted.

What I've learnt is that if you start writing C++ as a plan-old C, you quickly find yourself reaching for this and that feature from C++ that makes your job easier and your code more readable. Knowing where to stop is the tricky part.

Coding in plain C99 with some discipline can actually get you most of the benefits of C++, without any of its quirks. The "object-orientedness" of C++ really boils down to implicitly passing the this pointer to member functions, inheritance + virtual functions, and namespaces. All of these can be emulated in what I would call "C with discipline". Just be consistent in your naming conventions, always use a common pref…

C99 is nice, but C still lacks generic. I am not talking about C++ template nonsense, but not having to write max element search for every primitive type.

I am working in DSP project which was started with typical C++ OO BS, finally with ended up with C compiled as C++ + some simple templates for cases as above.

Re: What if anything have we learned from C++? [video]

#28

Earlier quoted context omitted.

Coding in plain C99 with some discipline can actually get you most of the benefits of C++, without any of its quirks. The "object-orientedness" of C++ really boils down to implicitly passing the this pointer to member functions, inheritance + virtual functions, and namespaces. All of these can be emulated in what I would call "C with discipline". Just be consistent in your naming conventions, always use a common pref…

C99 is nice, but C still lacks generic. I am not talking about C++ template nonsense, but not having to write max element search for every primitive type. I am working in DSP project which was started with typical C++ OO BS, finally with ended up with C compiled as C++ + some simple templates for cases as above.

Using statement expressions and the typeof extension, you are able to write function-like, type-generic, scope-insensitive macros like this one:

    #define MAX(a,b) ({ \
        typeof (a) _a = (a); \
        typeof (b) _b = (b); \
        _a > _b ? _a : _b; \
    })
The inability to write template functions can be compensated by designing your function so that it takes a function pointer where the type-specific action occurs.

Re: What if anything have we learned from C++? [video]

#29
post #22
post #2

After twenty years of using it? That I was wrong, that plain-old C really is better.

I hold the exact opposite opinion, and would never want to work on a plain C project. It is so low level that one has to write a lot of plumbing code to take care of error handling and resource management. It's also missing pretty much all higher-level concepts that are fast and can make code easier to write, read and less error-prone. Overall, it's simply not fun to write C code, there's a lot of tedious manual work…

Stroustrup gave talks where he explained how to cherry pick c++ elements to decorate simple C code with just enough abstraction to get done safe and fast. I find it's an old timer skill to be able to use languages as suggestions rather than law and to strip it using only the bits that will really bring value to the project.

Re: What if anything have we learned from C++? [video]

#30

Earlier quoted context omitted.

Coding in plain C99 with some discipline can actually get you most of the benefits of C++, without any of its quirks. The "object-orientedness" of C++ really boils down to implicitly passing the this pointer to member functions, inheritance + virtual functions, and namespaces. All of these can be emulated in what I would call "C with discipline". Just be consistent in your naming conventions, always use a common pref…

C99 is nice, but C still lacks generic. I am not talking about C++ template nonsense, but not having to write max element search for every primitive type. I am working in DSP project which was started with typical C++ OO BS, finally with ended up with C compiled as C++ + some simple templates for cases as above.

I am not talking about C++ template nonsense, but not having to write max element search for every primitive type

How is it template 'nonsense', when those templates do exactly that?

Post reply on HN