- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This is a pretty typical use case for
std::FootGunFactory
.Admin
Ah, the good old 100 case switch. Remember kids, if the list of conditions alone can't fit on your screen you should refactor.
Admin
Helicopter parents are a bad influence on their children.
Admin
In this case, even 3 cases would be 3 too many.
Admin
There are exceptions to the guideline on a switch(). The most common one is a complex state machine.
I think my personal record is somewhere around 38 states, in an automated test that parsed a COMPLICATED data file to set up a very complex device. (I don't feel comfortable saying any more than that about it.) There were a lot of things that had to be checked, the sequencing had to be correct, and there were several possible correct ways things could be sequenced.
Admin
You would expect that at some point they stop and ask themselves "There has to be an easier way...". Or maybe not. Do the little change and don't touch anything else as I bet there are no automated tests either.
Admin
The worst C++ I ever saw in a commercial application (did a short contract there) had very few classes, but each class was subclassed up to 9 levels deep, which each level either adding dozens of new methods/variables and overriding a large number of superclass items. Basically reading the code was painful as you never had any easy way to know what the code you were looking at actually did without lots of tracing up the class chain.
Admin
I have been programming in C++ on and off since the early 1990's. My first thought on seeing a template without a parameter was, "Will that even compile?" Apparently it can, but it really shouldn't. Of course, when I define a C++ template, (in the .h header file by the way) I make sure that the template parameter MUST appear in the parameters of the function somewhere. Otherwise what is the point, other than unnecessarily using compiler resources? My favourite example of a reasonable function template:
What we saw from the article, definitely not reasonable. So many opportunities for compiler optimization thrown away.
Admin
It's not actually a template without a parameter (which AFAIK it really not possible). It's a specialization. The syntax is a bit confusing at first, since specializations can be templates again, e.g. you could do:
A full specialization needs the "template <>" part to distinguish it from a non-template, but it's actually still a specialization of the original template with (here) 2 parameters.
This means, they got the syntax right, but not much else.
Admin
That is the source of the problem right there. The CEO is trying to keep costs down by hiring recent college graduates who couldn't get jobs somewhere else.
But I'm sure we all recognized that immediately.
Admin
Points for
default: assert(false);
I guess?This looks a lot like someone started out in C, then got all hot and bothered about switching to OOP but lost interest after the first chapter of "Teach Yourself C++".
Admin
I once saw a presentation by a rather famous language creator that used the "switch based on type" method in a common base class, and "test if the object can do something and if so call it otherwise do nothing" despite having a common base class for a backstop do-nothing method. In fact he suggested that since the latter happened so often, there should probably be a built-in in the language for it. I haven't checked the snake language recently to see if that ever made it in. It did thoroughly convince me that if the designer of the language was that far off, err, "base" in a 60-minute presentation, that I would have nothing else to do with that language. And haven't. Oh, and I pointed out a design flaw in one of the methods, which he confirmed.
Admin
I briefly worked for a medium-sized company who had a flagship app that should have been doable in maybe 30,000 lines of code, but actually was about 1.5 million lines. And those were super-convoluted templates and called through interface to a fare-thee-well lines. As an example, the app would generate "syntax error in config file" error messages, with an 18-level stack traceback. A useless traceback, as it stopped where the code had done a call through an anonymous interface. We spent three days trying to find the location of the error and eventually just gave up. Even tracing from the error message text proved fruitless. And, oh, the compiler would routinely crash as it was an eight year old compiler with no easy upgrade path. I was solo glad to get canned from that place!!
Admin
std::get() would be a function template where it makes sense you have to specify a template argument explicitly. std::make_shared() and std::make_unique() are more examples.
Admin
A lexer parser is another area where quite large switch statements are a valid option, the same with an interpreter, at least as long as you are not planing to dynamically add commands ;)
Admin
It's just a more poetic way of saying that if a switch has grown so large you are having trouble keeping track of how it works and what its supposed to do odds are it's too large.
Admin
The variety of footguns that C++ allows you to create is simply stunning. I do not think that there will ever be another language capable of this.
Admin
"An isosceles triangle"? Well it wasn't a right triangle, so maybe it was actually a wrong triangle.
Admin
Guns don't shoot feet. Idiots do.
Admin
" which means the parent has to know each of its children" This is problematic both in software development and among some of my friends.
Admin
Assuming Kari is from Finland i think i know what caused this: The only course you could take for learning c++ at universities used to be Generic Programming. A class where you learned the basic syntax in week 1 and then you were taught that, writing regular C with classes was for mouthbreathers. Write modern code that is type invariant instead! The more templaty your code the better your solution is. Obviously the company would mostly get people with this mind set drilled in as their employees
OOP was taught in a similiar manner in Java classes, where the more your classes inherited the better.