Live data from Hacker News

C++ and the Culture of Complexity (2013)

blog.greaterthanzero.com

261–270 of 285 posts

Re: C++ and the Culture of Complexity (2013)

#261
post #240

Earlier quoted context omitted.

A simple case is hiding the implementation and exposing a public API. Let's use objects to make it something C++ ought to be good at and C ought to be bad at. In C, you write a header file adder.h: struct Adder; struct Adder *adder_create(void); void adder_setup(struct Adder *, int, int); int adder_operate(struct Adder *); void adder_delete(struct Adder *); You can easily imagine how one would trivially implement the…

About your two realizations: 1. I've "exposed" parts of the private implementation in that they were in the header file, yes. They were also labeled "private". That means that someone can read that and gain more information about my implementation then they could from just public information, I suppose. It also means that nobody can actually use them in code, because they're private . So you can think of that as "exp…

Maybe I just don't have your problems, but I'm still not seeing this as much of an issue at all.

Surely problems are always personal, this all did start with the term "pet peeve".

For me, one of the peeves that comes back over and over is indeed that it seems that's near impossible to write a separation between the API and the implementation in C++ that is clean and beautiful. That's one of the first things in any project, drafting out the interfaces. And things get ugly quick there.

There are others but I drafted this particular case as an example that you requested. I don't want to go too deep into the discussion here but I'll reply to the two points below:

1) Exposing fields and functions under the private label is just a matter of principle. It doesn't matter if the private parts cannot technically be used outside the class: it still means there is information in the public API that shouldn't have to be there in the first place. That's just a stupid restriction of quirky language. A header file is mainly about the interface and its documentation: the last thing I want in it is to have cluttering bits of internal crap there only to be skipped over.

I could also cram all the code in a single source file and use global variables because hey, it can be made to work and it's easier to write a linker that way. The same applies with the public interface issue here.

2) Check back my C header file again. The struct layout is only visible to the implementation. As long as the ABI stays the same we can even use a different compiler to build the private implementation into a binary and the interface still works with all existing code.

Yet this is still about the fact that the private bits do not have to be visible to the public, just the implementation. So the language that forces me to do just that for the sake of convenience for the language designer and compiler writers is just plain stupid.

Re: C++ and the Culture of Complexity (2013)

#262

Earlier quoted context omitted.

THIS is the reason IMO too. C++ has taken on the very difficult task of remaining broadly compatible with C and with legacy features while at the same time has continuously evolved over the decades, incorporating whatever was the state of the art at that time, without new features breaking old code. That is not an easy task without increasing complexity.

> incorporating whatever was the state of the art at that time State of the art or flavor of the month? For instance, the features from functional programming that C++ and Java recently (in the last decade) added weren't anything new. When functional programming started to become more popular was when their features started showing up in C++ and Java. If people are concerned that your language is already to large tha…

Eh, C++ can hardly be criticized to pandering to the flavor of the month.

For example, lambdas were finally added only in C++11 even though while the STL had a functional flavor since the late '90s and sorely needed lambda expressions. Only after people went out of their way to build lambdas on top of macros, expression templates and whatnot, they were finally added to the language.

Re: C++ and the Culture of Complexity (2013)

#263
post #130

Earlier quoted context omitted.

> C++ is designed by its standards committee... When it comes to design, C++ is a good example of why having a benevolent dictator is better than a committee. I still think it's a huge mistake to not have a standard ABI and rely on C's ABI.

Definitely agree about the ABI. In C# it's a pleasure to write libraries for others and use other libraries whereas in C++ it's almost always a pain.

Standard ABI only makes sense if you are targeting a single system (.NET for C#). That's not the case for C++.

Re: C++ and the Culture of Complexity (2013)

#264
C++ is the only language that is compiled to binary, compatible with many compilers and OS, and can do both low and high level constructs.

It is true that it is a complex language, but this is true for every tool that allows you to do so many different things.

The complexity is not a goal in itself, it's just that it can do all of those things if you need them.

Simple tools are great and will save you a lot of time, but the truth is that you won't always be able to do everything with them. C++ allows you to do everything, and it is true that the cost can be very high and requires a lot of thorough knowledge and expert learning of what happens, but there are projects and cases where you just need to use C++ because that's the only choice you have left.

I agree that an alternatives like rust or D would be great as replacements, but the problem remains: if compilers are not mature on most platform, and if you don't have a large programmer base because the basics of the language are not simple enough, the language won't grow.

Re: C++ and the Culture of Complexity (2013)

#265
post #40
post #37

Part of the problem here is that OO sits nicely with references, but C++ (like C) is a value based language. This can be seen clearly in most of the design of the standard library -- it's all value semantics, and as such relatively simple and obvious to use (so long as you're not trying to cram OO into it). A line like if ( a == b ) In C++ is pretty obvious what it does. It'll always be a value comparison, and if a a…

Object Pascal, Eiffel, Ada, Mesa/Cedar, Oberon, Modula-2, Modula-3, Oberon, Oberon-2, Oberon07, Active Oberon, Component Pascal, Sather, Swift, D, Go, Rust are OO languages[1] and value based as well. [1] - As usual, there are many ways of doing OO, not just C++/Java style.

Interestingly half of those are Wirth or Wirth derived languages. He seems to like value based programming.

Re: C++ and the Culture of Complexity (2013)

#266

Earlier quoted context omitted.

Definitely agree about the ABI. In C# it's a pleasure to write libraries for others and use other libraries whereas in C++ it's almost always a pain.

Standard ABI only makes sense if you are targeting a single system (.NET for C#). That's not the case for C++.

It would definitely making interop between C# and C++ much easier. It would make interop between C++ and any language much easier. The only way to do it today is to extern "C" everything. It's ugly.

Re: C++ and the Culture of Complexity (2013)

#267
post #266

Earlier quoted context omitted.

Standard ABI only makes sense if you are targeting a single system (.NET for C#). That's not the case for C++.

It would definitely making interop between C# and C++ much easier. It would make interop between C++ and any language much easier. The only way to do it today is to extern "C" everything. It's ugly.

How would exactly an library compiled for 32 bit big endian POWER interoperate with a program written for 64 bit little endian ARM?

Re: C++ and the Culture of Complexity (2013)

#268
post #80

Earlier quoted context omitted.

C++ is a mess but it's one of the few languages that gives you low-level control of memory and fast code with zero or near zero cost abstractions. So for a certain class of application it's still the best choice. Music software, for example, is pretty much exclusively written in C++. I don't enjoy C++ the language very much but you can build some very cool things with it. Personally I'm hoping Rust displaces it from…

Very very slowly. Only now embedded development is starting to accept C++, and C still rules there anyway. Which means it took about 20 years to reach this point. And still Rust will need to go through the same certification processes that C, C++, Ada and Java enjoy for such scenarios.

The embedded world has accepted c++ for all but the smallest microcontrollers. I was using c++ for embedded development 6 years ago and I was late to the party. All that prevented adoption be me before that was the cost of RAM.

Re: C++ and the Culture of Complexity (2013)

#269
post #264

C++ is the only language that is compiled to binary, compatible with many compilers and OS, and can do both low and high level constructs. It is true that it is a complex language, but this is true for every tool that allows you to do so many different things. The complexity is not a goal in itself, it's just that it can do all of those things if you need them. Simple tools are great and will save you a lot of time,…

Rust uses LLVM, so we share the same characteristics here as clang does.

Re: C++ and the Culture of Complexity (2013)

#270
post #266

Earlier quoted context omitted.

It would definitely making interop between C# and C++ much easier. It would make interop between C++ and any language much easier. The only way to do it today is to extern "C" everything. It's ugly.

How would exactly an library compiled for 32 bit big endian POWER interoperate with a program written for 64 bit little endian ARM?

This doesn't work with C either or does it? C has a reasonable ABI so maybe we should get to the point where exchanging C++ libraries is as easy as doing this with C
Post reply on HN