Archive
One Size Fits All
On Bjarne Stroustrup’s FAQ page, he state’s his opinion on the utility of object oriented programming:
The strength of OOP is that there are many problems that can be usefully expressed using class hierarchies – the main weakness of OOP is that too many people try to force too many problems into a hierarchical mould. Not every program should be object-oriented. As alternatives, consider plain classes, generic programming, and free-standing functions (as in math, C, and Fortran).
The same could be said of organizations of people, no? Of course, in a purposeful org of people and machines, the goal is to produce and distribute material wealth to all stakeholders: products/services to its customers and financial well-being to its employees and owners. Thus, some sort of controller-controllee structure is required to keep the org from deviating too far from its purpose. There are alternative structures to hierarchy but, as Bjarne sez, “too many people try to force too many problems into a hierarchical mould“. Bummer.
Unneeded And Unuseful
On Bjarne Stroustrup’s C++ Style and Technique FAQ web page, he answers the question of why C++ doesn’t have a “universal” Object class from which all user-defined C++ classes automatically inherit from:
I felt the need to post this here because I’m really tired of hearing Java programmers using the “lack of a universal Object class” as one reason to stake the claim that their language of choice is superior to C++. Of course, there are many other reasons in their arsenal that undoubtedly show the superiority of Java over C++.
21st Century Assembler
I love working in the malleable medium of C++, but I wonder if it is becoming, or has already become, the “assembly language” of the 21st century – powerful and fast, but hard to learn and easy to make hard-to-diagnose mistakes. I recently stumbled upon this 5 year old interview with C++ creator Bjarne Stroustrup. The interviewer opened with:
Mr. Stroustrup, the honest soul that he is, essentially validated the opening, but with a trailing caveat:
C++ has indeed become too “expert friendly” at a time where the degree of effective formal education of the average software developer has declined. – Bjarne Stroustrup
Since “experts” tend to be more narrow minded than the average Joe, they tend to look down upon newbies and non-experts in their area of expertise. And so it is with many a C++ programmer towards new age programmers who side step C++ for one of the newer, easier to learn, specialized programming languages. In the classic tit-for-tat response, new age programmers belittle C++ users as old timers that are out of touch with the 21st century and still clinging to the horse driven carriage in the era of the lamborghini.
So, who’s “right“? And if you do share your opinion with me, what language do you work with daily?
Hostile, Cruel, And Wasteful
From an interview with C++ creator Bjarne Stroustrup, I give you this:
Corporate practices can be directly hostile to individuals with exceptional skills and initiative in technical matters. I consider such management of technical people cruel and wasteful. – Bjarne Stroustrup
I think this may be the main reason why brilliant technical startup companies are born. In an ironically altruistic twist, the unconsciously idiotic ways in which DYSCO SCOLs treat their best human “resources” (sic) hurt themselves while simultaneously benefiting the world.
Idiomatic Idiot
Programming idioms are the language-specific, more concrete equivalent of design patterns. I remember watching a video interview with C++ creator Bjarne Stroustrup in which he recommended that programmers learn how to program idiomatically in 5, yes 5, different languages. WTF? I’ve been working in C++ for years now and it seemed like forever before I could comfortably program this way. There’s at least one whole book out there that teaches idiomatic programming in C++. Sheesh!
I think that to remain idiomatically competent in a language, one has got to work in the language almost daily for a long, sustained period of time. How can one do this with 5 languages? Maybe it’s just me – I am an Idiomatic Idiot.
How many languages could you confidently say you know how to program idiomatically in?
Moving, Initializing, And Hotdogging
In an interview with C++ creator Bjarne Stroustrup, Danny Kalev asked Bjarne several questions about the major features being incorporated into the venerable C++ language via the C++0x standardization effort. Here’s one such Q+A exchange:
I know, I know. The “*” should be a “+” in the free function declaration box above. But does the typo really detract from the message being conveyed?
So, how hard is it to write a move constructor implementation? It’s as hard as this:
Notice how the lower level reference-to-a-reference (i.e. rvalue reference) feature in the Matrix move constructor enables the higher level “move” feature to be easily written. This capability to move big stuff around instead of copying the behemoth will be a great addition to the language, especially to library writers, no?
Bjarne’s examples of the new “uniform and universal initialization” C++0x feature jacked me up too:
We can use the {…} notation for every initialization and wherever we initialize an X with {v} we get the same resulting value. That’s a major improvement over C++98’s non-uniform set of alternatives using the =v, ={v}, and (v) notations:
With any new and powerful tool, there’s always the danger of “hotdoggers” conniving to show how much smarter than you they are. Here’s a typically wise and insightful, and universal quote from Bjarne on the topic:
Before we get to benefit from the simplifications offered by C++0x, we may go through a period where too many people try to show off their cleverness by enumerating language rules and digging into the most obscure corners. That can do harm.
You’re not one of “those” people are you? I’m not. Luckily, I ain’t smart enough to be a hotdogger. But if I was brilliant…….
Note: I know that the code above is really C, but it was the first googled C++ example I stumbled across.
Related Articles
- Bjarne Stroustrup Reflects On 25 Years of C++ (developers.slashdot.org)
- Bjarne Stroustrup on C++ Inception (thebitsource.com)
C++ Dudes To Follow
If you’re a twit like me, and you also “do” C++, you might want to follow these people and resources on twitter:
They don’t tweet much, but when they do, they’re worth listening to. Do you know of any other C++ twitter resources that I should add to my list?
Quote Mangling
I love quotes because they pack a lot of energy into small packages without requiring a long winded and jargon filled explanation. I also like extending quotes to give another take on the wisdom imparted by the original text because I’ve learned to never believe anything 100 percent; including my own twisted and anguished thoughts. Here are some snarky Bulldozer00 quote enhancements:
- “When the going gets tough, the tough get going – right out the door with the cash.” (English proverb + Bulldozer00)
- “I don’t know the key to success, but the key to failure is trying to please everybody – another key to failure is trying to piss everybody off.” (Bill Cosby + Bulldozer00)
- “A lot of people mistake unnecessary complexity for sophistication – and those people are usually managers.” (Dan Ward + Bulldozer00)
- “If you are indispensable, you’re unpromotable – but at least you know how to directly create value.” (Unknown + Bulldozer00)
- “I love deadlines because I like the whooshing sound they make as they fly by – and the angst they instill in the managers who dictated them.” (Doug Adams + Bulldozer00)
- “Multitasking is not for serious work – it’s for managerial make-work.” (Bjarne Stroustrup + Bulldozer00)
- “I believe that there is such a thing as objective truth, but a lot of people have an objective truth that differs from mine – and those people are wrong.” (Cynthia Tucker+ Bulldozer00)
- “Debugging is like farting, it’s not so bad when it’s your own code – except when you crap your pants.” (Unknown + Bulldozer00)
- “What we need is more people to lose their temper in public – unless people in power are in the vicinity.” – (Watts Wacker + Bulldozer00)
- “The point of quotations is that one can use another’s words to be insulting – D’oh! and WTF?.” – (Amanda Cross+ Homer Simpson + Bulldozer00)
What quotes would you like to extend?
An Epic Heavyweight Battle
In this corner, we have Bjarne “No Yarn” Stroustrup, the father of C++. In the other corner, we have James “The Goose” Gosling, the father of Java. Ding, ding…… let’s get ready to ruuuumble!
“No Yarn” comes outs swinging and throws the first haymaker:
Well, the Java designers—and probably the Java marketers even more so—emphasized OO to the point where it became absurd. When Java first appeared, claiming purity and simplicity, I predicted that if it succeeded Java would grow significantly in size and complexity. It did. For example, using casts to convert from Object when getting a value out of a container (e.g., (Apple)c.get(i)) is an absurd consequence of not being able to state what type the objects in the container is supposed have. It’s verbose and inefficient. Now Java has generics, so it’s just a bit slow. Other examples of increased language complexity (helping the programmer) are enumerations, reflection, and inner classes. The simple fact is that complexity will emerge somewhere, if not in the language definition, then in thousands of applications and libraries. Similarly, Java’s obsession with putting every algorithm (operation) into a class leads to absurdities like classes with no data consisting exclusively of static functions. There are reasons why math uses f(x) and f(x,y) rather than x.f(), x.f(y), and (x,y).f()—the latter is an attempt to express the idea of a “truly object-oriented method” of two arguments and to avoid the inherent asymmetry of x.f(y).
In an agile counter move, “The Goose” launches a monstrous left hook:
These days we’re beating the really good C and C++ compilers pretty much always. When you go to the dynamic compiler, you get two advantages when the compiler’s running right at the last moment. One is you know exactly what chipset you’re running on. So many times when people are compiling a piece of C code, they have to compile it to run on kind of the generic x86 architecture. Almost none of the binaries you get are particularly well tuned for any of them. When HotSpot runs, it knows exactly what chipset you’re running on. It knows exactly how the cache works. It knows exactly how the memory hierarchy works. It knows exactly how all the pipeline interlocks work in the CPU. It knows what instruction set extensions this chip has got. It optimizes for precisely what machine you’re on. Then the other half of it is that it actually sees the application as it’s running. It’s able to have statistics that know which things are important. It’s able to inline things that a C compiler could never do. The kind of stuff that gets inlined in the Java world is pretty amazing. Then you tack onto that the way the storage management works with the modern garbage collectors. With a modern garbage collector, storage allocation is extremely fast.
On the age old debate about naked pointers, “The Goose” unleashes a crippling blow to the left kidney:
Pointers in C++ are a disaster. They are just an invitation to errors. It’s not so much the implementation of pointers directly, but it’s the fact that you have to manually take care of garbage, and most importantly that you can cast between pointers and integers—and the way many APIs are set up, you have to!
Enraged, “No Yarn” returns the favor with a rapid jab, jab, jab, uppercut combo:
Well, of course Java has pointers. In fact, just about everything in Java is implicitly a pointer. They just call them references. There are advantages to having pointers implicit as well as disadvantages. Separately, there are advantages to having true local objects (as in C++) as well as disadvantages. C++’s choice to support stack-allocated local variables and true member variables of every type gives nice uniform semantics, supports the notion of value semantics well, gives compact layout and minimal access costs, and is the basis for C++’s support for general resource management. That’s major, and Java’s pervasive and implicit use of pointers (aka references) closes the door to all that.
The “dark side” of having pointers (and C-style arrays) is of course the potential for misuse: buffer overruns, pointers into deleted memory, uninitialized pointers, etc. However, in well-written C++ that is not a major problem. You simply don’t get those problems with pointers and arrays used within abstractions (such as vector, string, map, etc.). Scoped resource management takes care of most needs; smart pointers and specialized handles can be used to deal with most of the rest. People whose experience is primarily C or old-style C++ find this hard to believe, but scope-based resource management is an immensely powerful tool and user-defined types with suitable operations can address classical problems with less code than the old insecure hacks.
Stunned silly, “The Goose” steps back, regroups, and charges back into the fray:
One of the most problematic (situations) over the years in C++ has been multithreading. Multithreading is very tightly designed into the code of Java and the consequence is that Java can deal with multicore machines very, very well.
“The Yarn” stands his ground and attempts to weather the ferocious onslaught:
The very first C++ library (really the very first C with classes) library, provided a lightweight form of concurrency and over the years, hundreds of libraries and frameworks for concurrent, parallel, and distributed computing have been built in C++. C++0x will provide a set of facilities and guarantees that saves programmers from the lowest-level details by providing a “contract” between machine architects and compiler writers—a “machine model.” It will also provide a threads library providing a basic mapping of code to processors. On this basis, other models can be provided by libraries. I would have liked to see some simpler-to-use, higher-level concurrency models supported in the C++0x standard library, but that now appears unlikely. Later—hopefully, soon after C++0x—we will get more libraries specified in a technical report: thread pools and futures, and a library for I/O streams over wide area networks (e.g., TCP/IP). These libraries exist, but not everyone considers them well enough specified for the standard.
And the winner is………?
So, do you think that I’ve served well as an impartial referee for this epic heavyweight battle? Hell, I hope not. I’m strongly biased toward C++ because it’s taken me years of study and diligent practice to become an intermediate-to-advanced C++ programmer (but still well below the skill level of the masters). I think that most Java programmer’s who religiously trash C++ do so out of fear of: its breadth+depth, its suitability for application at all layers of the stack, and the option to “get dangerously close to the machine“. On the other hand, C++ programmers who trash Java do so out of a sense of elitism and a disdain for object oriented purity.
Note: The snippets in this blarticle were copied and pasted from the delightful and engrossing “Masterminds Of Programming“. The book’s author, Federico Biancuzzi, not only picked the best possible people to interview, his questions were insightful and deeply thought provoking.
Transfer Of Mental Ownership
I don’t know how to write code in the Erlang programming language, but ever since reading Bjarne Stroustrup‘s “The Design And Evolution Of C++“, I’ve been interested in the topic of programming language creation, development, and adoption. Sinisterly, I look for how much support, or lack thereof, that management provided to the language creators.
In this entertaining InfoQ video, “A Discussion Of Basic vs. Applied Research In The Software Domain And The Creation Of Erlang“, kindly and soft-spoken Bjarne Dacker recounts the development of Erlang. Here are some of my distorted notes:
Many problems that need to be solved by software are not computationally intensive, they’re symbolic.
The sequential and synchronous Von Neumann programming model does not map cleanly into the realm of real-time control systems.
The Erlang team asked: “Why are software academics obsessed with all these subtle, disparate, awkward, and complicated communication schemes like buffers, semaphores, mailboxes, rendezvous, regions, pipes? Why not just simply send messages between asynchronously running processes?”
Erlang designers took the goodies from Modula, Ada, and Chill and discarded the baddies.
By being devious and cunning, Dacker was able to subvert the corpo bureaucratic mandate that “everybody shall use the centralized IBM mainframe” and he miraculously secured approval to purchase a dedicated VAX (close to state of the art at the time) computing platform for his team.
Ericsson management wanted Erlang to be proprietary; a secret weapon that would allow them to develop their telecommunication products faster than their competitors. On the other hand, Ericsson management disallowed the usage of Erlang internally because it wasn’t an open standard (LOL!).
You can’t just throw new technology over the wall to product teams. You must create mixed teams; embedding applied researchers within product teams. You must facilitate the transfer of “mental ownership”.
In 2009, “something” happened. The number of Erlang downloads at Erlang.org started to skyrocket.
In keeping with my goal of providing a dorky graphic with each blog post, I present Mr. Dacker’s process for the successful transition of applied research knowledge into the marketplace.
Notice that going “backward” and cycling multiple times through the mistake prone experiment/evaluate activities (which most sequential, linear, forward-only management CGHs abhor and forbid) is an integral part of Dacker’s process. The mixing of researchers with product developers occurs in the production/exploitation stage.














