Live data from Hacker News

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

youtube.com

31–40 of 56 posts

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

#31

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.

C has a generic: "void *". It just doesn't have any type safety.

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

#32
post #2

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

I've spent most of my career writing C++ in the "C with classes and containers" style. Apart from the compile times and library issues, this really is better than just standard C. You can automate much of the memory management.

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

#33
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 tha…

I went the other way. I was introduced to programming at university, although not in a computer science degree. The professor believed in the hard way, so using some old Unix machines (it was in the 2000s), writing C++ in the equivalent of a notepad, and "debugging by printf".

Though I was keen on getting into coding, I was like many other students put off by this approach and only went back to programming many years later with visual basic.

I appreciate that one gets a better understanding of computer science by going really low level (assembler, etc) but I question whether this is the right approach if one wants coding to be more mainstream.

I think coding should be taught in high school like latin or physics, not because kids will all become programmers, or historians or scientists, but because having a basic understanding and culture will help in everyone's life and it gives kids a taste for what a career in that field may look like. And I don't think C++ is the right tool for that.

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

#34
post #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. In…

https://xkcd.com/927/

I'd rather see greater interoperability to enable parts of a project to be written in different languages. The C# ecosystem (F# etc) is closest to this, although see also Scala.

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

#35

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…

Have you tried Haxe?

http://haxe.org/

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

#36

Earlier quoted context omitted.

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.

Typeof is not standard and many DSP compilers do not implement that. Secondly I meant max search in array, not between to scalar values which is trivial. I really don't want to have for(...) inlined everywhere.

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

#37

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.

We could call it cfront: https://en.wikipedia.org/wiki/Cfront

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

#38
post #30

Earlier quoted context omitted.

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?

Template metaprograming is nonsense, not simple type substitution. C++ templates are just too much, especially when mixed with substandard developers.

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

#39

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.

You only get ABIstab in C if you never change the size or layout of your structs, or completely hide everything behind pointers and allocate everything on the heap (maybe a little on the stack if your library is amenable to using callbacks - blargk!). The rules[0] for C++ aren't really any different, you just notice it more. When you start shooting for ABIstab, without putting in a lot of extra work, you start losing the nice semantics and APIs you're used to. In the C world, because of the limited capabilities of the language, library developers have never been able to do better, so application developers are used to suffering crappy APIs and working extra hard to get stuff done.

C++98 code out of GCC has been ABI stable for over 10 years now btw, and we also have some pretty great tools for detecting ABI breakage now, like abi-compliance-checker[1]

[0] https://techbase.kde.org/Policies/Binary_Compatibility_Issue... [1] http://ispras.linuxbase.org/index.php/ABI_compliance_checker

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

#40

Earlier quoted context omitted.

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

You cannot implement cache efficient data structures using void pointers.
Post reply on HN