C++ Creator Wants To Solve 35-Year-Old Generic Programming Issues With Concepts (cio.com)
C++ creator Bjarne Stroustrup is arguing that we can improve code by grounding generic programming in concepts -- what's required by a template's arguments. An anonymous reader quotes Paul Krill's report on a new paper by Stroustrup:
In concepts, Stroustrup sees the solution to the interface specification problem that has long dogged C++, the language he founded more than 35 years ago. "The way we write generic code today is simply too different from the way we write other code," Stroustrup says... Currently an ISO technical specification, concepts provide well-specified interfaces to templates without runtime overhead. Concepts, Stroustrup writes, are intended to complete C++'s support for generic programming as initially envisioned. "The purpose of concepts is to fundamentally simplify and improve design. This leads to fewer bugs and clearer -- often shorter -- code"...
Concepts, Stroustrup believes, will greatly ease engineers' ability to write efficient, reliable C++ code... The most obvious effect will be a massive improvement in the quality of error messages, but the most important long-term effect will be found in the flexibility and clarity of code, Stroustrup says. "In particular, having well-specified interfaces allows for simple, general and zero-overhead overloading of templates. That simplifies much generic code"
Concepts are already available in GNU C Compiler 6.2, and Stroustrup wants them to be included in C++ 20. "In my opinion, concepts should have been part of C++ 17, but the committee couldn't reach consensus on that."
Concepts, Stroustrup believes, will greatly ease engineers' ability to write efficient, reliable C++ code... The most obvious effect will be a massive improvement in the quality of error messages, but the most important long-term effect will be found in the flexibility and clarity of code, Stroustrup says. "In particular, having well-specified interfaces allows for simple, general and zero-overhead overloading of templates. That simplifies much generic code"
Concepts are already available in GNU C Compiler 6.2, and Stroustrup wants them to be included in C++ 20. "In my opinion, concepts should have been part of C++ 17, but the committee couldn't reach consensus on that."
That's what C++ needs: More features! They had better introduce sidgils like in Perl so they can have room for more keywords.
Templates produce very bloated code. Most embedded programmers working in C++ use a very small subset of the language for a reason. But C++ has lots of other problems. It was nice when it saved you from having to hand-build vtables doing OOP in C. Now after the meta-programming fads have gotten into it the language seems all over the map.
You're obviously new at reading. t != r
The vagaries and complexities of C++ as it progresses in it's specification is reminiscent of efforts to get epicycles to explain motions of heavenly bodies. Geez, people are snide about Perl syntax. Now we have &ref, &&global_ref, [](args){my_lambda_code();}, copy constructors, move constructors, 'override' to fix virtual function breakage. This is just a mess of a language.
In a band? Use WheresTheGig for free.
I was just saying, "You know, C++ is too straightforward, and there are too few ways to get things done. It needs a few more keywords and paradigms to make it make it work."
What a freakin' mess.
Bjarne Stroustrup, Doug Lea, Knuth, etc... still make feel like a moron on a almost daily basis....
If someone makes you feel like a moron when they explain something, then maybe they are not as smart as you think they are. If you are a true master, you should be able to explain concepts in a way that even a child can understand. Richard Feynman was famous for this. So was Albert Einstein. Of course you can go too far, and simplify too much, so the children only think they understand. Donald Trump is a good example of that.
Well, when I was thinking about programming languages a long time ago, I have come to a grudging respect for Windows, and backwards compatibility. Really good compilers, IDEs and debuggers will take many man years before production code can be made. In order to get that fancy stuff, you need a really big market to justify all that expensive development. That god scripting languages don't require such complicated tooling, and one has choices. I'm looking at you Javascript!
I want him to roll in the additions from Cilk++, Aspect-Oriented C++ and FeatureC++, the mobility and personalisation capabilities of Occam Pi, the networking extensions provided by rtnet and GridRPC, full encryption and error correction code facilities, everything in Boost, and a pointless subset of features from PL/1.
If you're going to do it all, might as well do it in style.
Seriously, though, Aspects would be nice.
It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
I never saw that in the many years I was working primarily with C++ and a regular reader of the related newsgroups. When Bjarne did contribute in any forums I followed, he generally seemed direct and reasonable, and it was usually in the more advanced discussions about tricky areas or the future of the language.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
OK, thanks I will correct people spreading such rumors.
sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
How about first fixing something much more basic, like modules?
I used to be a C/C++ dev, and wrote a lot of COM objects for the financial space back in the day. The ten different ways to cast something was becoming a pain to deal with. .NET/C# for my company in about 2001, liked what I saw and moved over to C# with a short stint in Java along the way, and I have NEVER looked back.
Writing LOB applications is all about delivering functionality for the end user. In C# I've designed the most, developed the most and maintained the most applications I've ever managed to do in my 30 year career in software development.
I was tasked to evaluate
Beautiful generics, LINQ, clean looking code, interoperability with legacy code, ultra-rich APIs and a rock-solid dev environment, ECMA-standardised are clear winners for me and C#.
A greybeard trying to breathe new life onto a now 30 year old language he put together doesn't surprise me, but C++ is never going to get the attention it once had. Sorry Bjarne, I saw it all before with Bertrand Meyer trying his darndest to keep Eiffel relevant. Same thing's happening with your baby, sorrry to say.
The key difference between this and interfaces in Java seems to be push vs pull, does a class explicitly declare that it is say sortable or do you just check if it has functions that match something that's sortable. If you look at the example he does on page 8 with Shape.draw() and Cowboy.draw() sure you could be more explicit in the template requirements or you could demand that the cowboy explicitly has to say he's "drawable". To me Stroustrup's idea sounds a bit too much like the story about the blind man and the elephant, if you only touch it in enough places you can be sure it's an elephant. The obviously problem is that once you have a birth defect or amputee with only three legs, it all fails.
For example I might like to define a class "SequenceNumber" that has functions like setInitialValue(), getNextValue() etc. but lacks typical characteristics of a number like being able to add and subtract them, but I can still sort sequence numbers. If it's explicit I only have to declare it sortable and implement the necessary functions. If it looks at the "concept" number it'll say nope, you're not a real number because we can't add two of you together.
This could be trivially avoided by having the possibility to supplement class definitions as implementing additional interfaces, like here's a library with the Circle shape header and I say it's a drawable even though it doesn't say so itself. It'll still have to actually fulfill the interface, but that way you're not bound by the ones supplied by the library. Since that's purely a synthetic check on whether your code should be able to call that code I don't see how that should be a problem.
Live today, because you never know what tomorrow brings
Concepts lets you check that the parameters of a template instantiation satisfy the template's requirements. However, it doesn't let you check that the *definition* of a template is valid whenever the parameters satisfy the template's requirements. So it's really only solving half of the problem.
That's often the case - but sometimes, people really are morons :-)
Seems everyone I run into these days who says "I'm a software engineer" has zero CS instinct
That's because software engineering has very little to do with computer science. A software engineer solves real-world problem with software.
How many cops do you run into these days that have more than the strict minimum knowledge of the law needed to do their job? Does that make them incompetent cops, or is it possible that maybe a different skill set is required?
If you want to stick to academia and horse around in labs that depend on grant money and alumni, knock yourself out, nobody is stopping you - there will always be a need for abstract thinkers. But out there in the real world, people must build things on time and on budget, and while we all wish that the best algorithms and the most elegant code is the way to achieve that, when push comes to shove, shipping the product is what pays the bills and if that means ugly code, then ugly code it is. Do you think the POS software on the cash register that allowed you to buy grocery this week is a masterpiece, or that the algorithm that decides when and how to to take over your car brakes is flawless? No, it's probably full of bugs and hard-coded passwords and antipatterns. But guess what, you still got that food in your fridge and you've made it alive on the freeway. Good. Enough.
lucm, indeed.
you are a true master, you should be able to explain concepts in a way that even a child can understand. Richard Feynman was famous for this. So was Albert Einstein. Of course you can go too far, and simplify too much, so the children only think they understand.
Richard Feynman and Albert Einstein both did exactly this. You really can't understand quantum mechanics or general relativity without math. You can think you do, and both of them were great at providing simple explanations that gave the illusion of understanding... but it was only an illusion, which of course they knew perfectly well.
Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
Just because you never encountered the variant "learnt" in your small world doesn't make it wrong, idiot.
Those who do not learn from commit history are doomed to regress it.
Richard Feynman and Albert Einstein both did exactly this. You really can't understand quantum mechanics or general relativity without math. You can think you do, and both of them were great at providing simple explanations that gave the illusion of understanding... but it was only an illusion, which of course they knew perfectly well.
I don't know about Einstein, but Feynman was also good at explaining things using math in a way that gave a typical physics student the illusion that you understood it. But that was only an illusion, as when you got back to your dorm room to do the homework you realized that he explained it in a way that you could not replicate because to him the math (usually path integrals) was so intuitive that he could breeze through it on the chalkboard, but you would actually have to grunge out the calculus because of your relative ignorance. Even the TAs weren't able to help you understand it the way he explained, but they would usually also have to grunge out the math to explain it to you.
It was then you realized that not only was he good at explaining things at a high level that gave you the illusion of understanding, but he knew the stuff so thoroughly in a way that you only wish you could understood it, someday.
Even in Physics X, he always had a few mathematical gems that seemed completely unrecreatable outside the lecture room. And if you ever heard him describe his techniques to pickup women, well, those were also something you might think you understand, but were totally unable to replicate later either... ;^)
No, not a new fad.
Concepts have been coming in C++ since the 90s.
There are two parts of concepts. On the ideas side, Stapanov came up with the idea with the STL. A concept of X is anything X-like. So loosely speaking if you have an array concept, then anything giving [] and having indexable pointers/iterators matches. So, builtin arrays match, as does std::array and vectors from Eigen would match too.
This makes sense: they're semantically the same and if you wrote an algorithm (eg. sort) using any of them, it would look identical. In this way, it's like a specification. If your class matches the specified "array" concept, then any algorithm written against that spec (the array concept) will work correctly on your class.
It's a great idea.
The other bit is language support. So, much C++ code is written using the idea of concepts, but the language does not assist in any way. Templating is completely generic, you say essentially "accept any class", but if you've written against the array concept, and the class doesn't match, you'll get a compile error right in the guts of the algorithm where you try to use [] on an array.
It would be nice, instead of saying "this function accepts any class" to say "this function accepts any class matching the Array concept", or in short "this function accepts any Array". The compiler knows the types and can tell in advance if the class matches. That way if you try to sort a set with that function, for example, it would simply tell you that the set is not an Array.
You can kind of finesse and finagle something better by utterly abusing a different language feature. The language has a mechanism called SFINAE (substitution failure is not an error), which is designed to make function overloading in the presence of templates sane. When the compiler does overload resolution, it substitutes the current type into any templated functions which match the name in question. If that substitution yields a compiler error, the compiler ignores it and removes that option from the list of overloads. This prevents unrelated templated overloads from breaking builds in irrelevant places. It's supposed to be a hidden detail which makes templating "just work". Except you can abuse it to enable/disable functions based on compile time tests for features of a class. IOW you can use it to implement concepts. Accordding to Stroustrup this means "you know too much :(".
He's right: just because you can do it like that doesn't mean it makes life easy.
Putting concepts into the language gives explicit support, with clean, clear, consistent syntax, not using brittle SFINAE hacks. People have been working out how since the 90s, and there have been several major proposals. It's not actually that trivial. You have to avoid breaking any old code, no matter how perverse. It has to work and work cleanly with old, non concept aware code (otherwise it would get slow/no adoption) and it needs to make life simpler for language users and not be an expert only feature, etc etc.
It looks like the concepts TS is finally hitting enough of the targets to actually work.
So basically, no, concepts is not a fad. It's been a major part of the C++ world for 2 decades.
SJW n. One who posts facts.
So, a concept is just a fancy name for an interface or an abstract class?
Yes, AFAICT, it's an interface, but implicit - like a Go interface - not the explicit one you'd have to "implement" like in Java.
Yes, except with compile-time specialisation instead of run-time specialisation. One of the big problems that I have with C++ is that it has entirely separate mechanisms and syntax for implementing the same thing with compile-time and run-time specialisation and they don't always compose well. Languages such as Java sidestep this by providing only run-time specialisation and expecting the JIT compiler to generate the equivalent of compile-time specialisation.
With an abstract class in C++, you'd require that every method be called via a vtable, which makes inlining hard (though modern compiler can do devirtualisation to some extent). This often doesn't matter, but when it's something like an array access, which is 1-2 instructions, the cost of the method call adds up. In contrast, if you use a template then the compiler knows exactly which method implementation is called and will inline any trivial methods (at the cost of now having one version of each templated function for every data type, which can blow away your instruction cache if you're not careful). The down side of the template approach is that you have no (simple) way of saying 'this template argument must be a thing on which these operations are defined' and the error message when you get it wrong is often dozens of layers of template instantiation later and totally incomprehensible without a tool such as Templight.
I am TheRaven on Soylent News
Well, I heard an anecdote about Einstein many years ago - he was writing one of his articles about GR and wanted to make it understandable to the general public, so he read it to his granddaughter (or something like that), who was only about 5 years old, thinking, if she can understand it, then of course everybody else would as well. And, amazingly, this young child, who was playing happily with her stuff while listening to her nice graddad, would yes "Yes" every time he asked if she understood what had read out. I think it is a very sweet story ;-)
Another saying that I have seen attributed to Einsteing is, that you should always strive to make things as simple as possible, but no simpler. GR is a good example of this - it is a remarkably simple and elegant theory, and you really couldn't make it simpler; but it is still bloody complicated, not least because the toolset required (differential geometry on a smooth manifold with a Lorentzian metric as well as a volume form) is rather complicated in itself. C++, I suppose, compared to C, is like GR compared to Newtonian Mechanics; it gets really, really crinkly around the edges, not because the idea is unsound, but the subject just is that complicated, when you pursue it - and you can't make it simpler without losing important bits.
The man difference between a concept and an interface is in the time when the dispatching to some specific called code is resolved.
Concepts resolve the call during compile time. This can lead to binary code bloat since the calling code needs to be "cloned" for each called code.
Interfaces resolve the call during run time. It can reuse the caller code but imposes some call overhead (the run time dispatch).
And sometimes you just need the resolving in the run time. If it would not be available then one would be forced to simulate it ... e.g. using dispatch (switch) on e.g. an alternative type (discriminated union). Well, or you could implement vtable manually if the language gives you enough power (pointer arithmetic) to do it.
When a "high" level language require half a dozen or so ways to implement a cast, it's time to go.
Of all of the criticisms of C++, this one makes the least sense. Different casts in C++ have very different semantics and one of the worst things that a programming language can do (and which C++ does in many places) is give you the same syntax for different semantics. Are you taking the same set of bits and interpreting them as a different type (typesafe languages don't need this because they don't permit it)? Are you explicitly removing a const qualifier and thus declaring that you know what you're doing when you do something that might break the invariants of an interface (similarly, not permitted in typesafe languages)? Are you saying create a new instance of the target type initialised from this one?
Remember when a programming language was truly object-oriented?
I still use some that are, but C++ is not one of them. If you try to write Smalltalk-like code in C++, you will write almost as bad code as if you try to write C-like code in C++.
I am TheRaven on Soylent News
It's similar, but not entirely the same. It's mostly implicit interfaces at compile time. Implicit in that you never need to declare that you meet an interface, your class is tested to see if it matches. However, it's much more parametric. Underneath it all, those tests are arbitrary code, not simply a list of methods and signatures.
SJW n. One who posts facts.
If you are a true master, you should be able to explain concepts in a way that even a child can understand
This is, in a word, horse pucky. It's the same reasoning my niece uses to justify her anti-vaxxer beliefs: the quacks and charlatans she listens to are more credible than epidemiologists and immunologists because they're easier to understand. This is the real-life equivalent of the joke about searching for the $20 bill under the street light because where you actually lost it is inconveniently dark.
If it were true that a child could understand anything, there wouldn't be a need for education. You'd just find a "true expert" to explain, say, fluid dynamics to a random bunch of people off the street and then set those randos to work designing aircraft. Or cryptographic systems.
There's an unfortunate cultural trend to devalue anything that requires mental effort and dedication to understand as elitist bullshit. This is a dangerous development, especially when combined with our national vanity: ever since the Moon landing we see technological and scientific leadership as a birthright. It's not. It's something we have to earn, and continue earning every day by dint of hard labor.
The humbling truth is that real understanding in many things requires trekking a long and arduous road. It's a near certainty that you don't actually understand General Relativity; crude analogies about balls and rubber sheets notwithstanding. General Relativity is like a mountain that looks easy to tackle from a great distance, but the fact is it takes years of toil before you can even grasp how arduous the foothills of Mount Einstein are.
Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
Similar, but not exactly. The OP is pointing out why experts are frequently bad at imparting their knowledge to others, particularly laypeople. This is a valid hypothesis.
Trump supporters, OTOH, go much farther, and simply discount anything claimed by experts if it contradicts their "gut feeling" or what they "know" or what their preacher tells them.
"Good. Enough."
Ah, the cry of the "programmer" who churns out barely functional junk. Let us know how you get on after your non-job is automated.
"Good enough" means fit for purpose. If you go beyond that you're not solving a business problem, you're feeding your OCD on the company's dime, like an office manager that puts barcodes on office chairs.
lucm, indeed.