- 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
You are a prime fuckwit.
I quoted from a comment on the number of branches in the switch statements that are actually there. This was clearly documented to be 26 in each one of two. Someone then said that meant a total of 62 branches, whereas there are 52 branches (26*2).
You assumed (decided without any evidence) I was talking about the number of possible branches if we are talking about the widest possible interpretation of alphanumeric, that all characters in all positions of all the strings might be upper case letters, lower case letters, or digits. And even then you got it wrong, because there is, if it is really that way, a total of (26+26+10) times 2 branches in the pair of switches. But there are not 26+26+10 in each one, just 26. The comments say so.
Now fuck off and die.
Admin
And you only arrived at 62?
EDIT: my apologies, we were talking about alphanumerics
Admin
Damned englishists, assuming we all have 26 letters in our alphabets...
Admin
Those people are stupid. Goto is evil because it is an arbitrary jump that results in spaghetti code. Break and return are part of a high-level structure (loop or function) and don't result in spaghetti code.
Admin
Fair point. Sorry. The widest possible interpretation of unaccented Latin Alphabet/Arabic numeral alphanumeric. Good catch.
Admin
You should use
if ("AA01".equals(wk_code))
etc. instead to minimize the number of possible NPEs. (In general, it is less likely that a literal constant is non-null than a variable.)If we'd check for wk_code being non-null before, we could optimize the code a bit:
Well, I think the lines consisting of single curly braces should be kept for they perform better in a PPL environment.
Admin
In fact, in this case using std::map<> is always slower than using the original array lookup.
The map is created using static constructor on application initialization, so it will use O(n) time during every program start. Whereas the O(n) array lookup is only done on error exit, which hopefully does not happen every time.
Original code is fine, though it would be cleaner if everything was just in a single const array.
Admin
If something is happening to initialize the map at runtime, your compiler sucks.
Admin
Please tell me, does there then exist a C++ compiler that does not suck? Both clang and gcc generate runtime initialization for your code, even if the variable is const and even if -O3 is enabled.
Admin
I don't know. But I do know that it's entirely within reason that a compiler could do it. Have you tried Intel? I've heard it does some weird optimizations like loop interchange.
Admin
I didn't read any of that and fuck you.
Admin
How do you suggest it would work? Would the data reside in heap or in .text? Would there have to be a constexpr-based based implementation of std::map and std::string, or would the compiler go executing random pieces of code during compilation?
Admin
And Visual Studio 2015, in both debug and release configurations.
Admin
Indeed. With proper use of break/return/continue/insert-another-coin you will end up with schupfnudel[1] code, or at worst penne[2] code because you have strict rules on how the program flow can be altered, leaving you with well defined dumplings[3] which can be dipped in sauce[4] as you eat them. Once you start adding unrestricted gotos[5] into the mix then you run the risk of turning your code into a block of instant ramen[6].
[1] It's like a cross between a dumpling and penne. [2] It's like schupfnudel, but not like a dumpling. [3] It's like the interference pattern when you send schupfnudels and penne through two tiny slits and then allow them to land on a plate on the other side. This experiment proves that pasta acts as both a particle and a wave at the same time, and that it would very much like you to take your classical interpretation of how food behaves and stuff it in an uncomfortable place.[7] [4] The sauce isn't a metaphor for anything at all. It's just in the story because if you're going to eat dumplings, you really should have a nice sauce to dip them in. [5] With no restrictions on the programmer, that is. An actual unrestricted GOTO would be the GOAWAY command, which always results in undefined behaviour. By definition. [6] The kind that comes in a square package, costs $0.49 and comes with a coupon for $0.50 off of your next package of instant ramen. If you have ever eaten this then it may be hard to believe that there exists another kind of ramen which is made with actual food and is served in fancy restaurants.[8] [7] Like in the back of a Volkswagen. [8] The kind which don't serve soup in styrofoam cups or coffee mugs. If you're a student then you'll just have to trust me when I say that such things exist.
Admin
I ain't reading that tiny shit.
Admin
It's too early for dinner.
Admin
Thank you for you contribution ! :stuck_out_tongue_winking_eye:
I'm TRYING to get a badge consarndit!
that would be the article, no? I would, but,Admin
Crypto-GOTO? Anathema! I am sure, you are always coding without drawing your Nassi–Shneiderman diagram first, right? ;-)
Admin
Admin
Mind you, it's still preferable over cup-a-soup.
EDIT: Though I may be used to a higher quality of instant noodles than you.
Admin
Why?
Filed under: Also, my favourite brand is Maruchan
Admin
Considering that the standards keep relaxing constexpr constraints, I foresee a future where you could have a constexpr map of strings. I'm thinking too far ahead though - basically, at this point in time, you're right and I'm wrong.
Admin
Who could be more trustworthy than that?
Admin
http://ramenhakata.com/
Yes, but the relation between ramen in packets and fancy restaurant ramen is analogous to the relation between mac-n-cheese in the blue box versus macaroni and cheese made from scratch by a good cook.
Admin
I would like to point out that calling this "instant" ramen is inaccurate. Those blocks of allegedly food-like ... stuff ... require three minutes of cooking (plus the time to bring the water to a boil prior to cooking). Three minutes != instant.
Admin
:doing_it_wrong:
They were 14 for 99 cents last time I went to a 99 Cents Store
Admin
I've never seen them come with a coupon, but they cost about $2 for a box of 12 packages.
Admin
A mere three minutes? I usually keep them on for 20!
@codinghorrorbot
Admin
@Tsaukpaetra Is Doing It Wrong™
<!-- SockBot/2.10.2 (Bewitching Burlap; owner:loopback0; user:CodingHorrorBot) 2015-10-23T20:28:19.621Z -->Admin
The stuff I have is 'pour boiling water over it, wait for 3 minutes. No cooking. Unox, which is an unilever brand.
Admin
IME, the cup-of-soup sort of stuff wants that; the brick-of-noodles wants the water to continue boiling for three minutes. Nissin definitely does; I just checked. However, I don't have any other brands available to check, so I'll take your word that at least some brands are satisfactory (for some definition of satisfactory) without actual cooking.
It could be argued that "no cooking" puts those into the realm of "instant," sort of, but I'd still say 3 minutes != instant.
Admin
Well, I think they recommend 3 minute wait for cup-a-soup as well. I don't tend to time it, but instead go by 'cooled down far enough to eat', combined with the brick of noodles having gone soft.
Thinking on it further, I wouldn't be surprised if cup-a-soup is an unilever brand as well.
EDIT: yup, cup-a-soup is unilever.
Admin
I think you reversed something there..
Admin
instant adj. anything that takes less time than mixing and cooking biscuits from scratch.
I though everyone knew that, but maybe you had to be there when "instant" was invented. Like I was.
Admin
Where do you start? Milling flour? Reaping wheat? Sowing wheat? Cross-breeding grasses to create wheat? Creating plant life?
Admin
With this recipe as a typical example. Note the prep time of 15 minutes, which you will spend on prep, and the cook time of 10 minutes.
But I really shouldn't have chosen that as my example; I should have used traditional noodles, which require 10-15 minutes cooking in boiling water, and frequent stirring. As opposed to Ramen noodles, which are throw noodles and water in microwave and cook three minutes, during which time you can browse the web.
The "instant" concept as envisioned by the food industry and began to appear circa '65 to '75, involved any elimination of the time-consuming and complex traditional "scratch" recipes, in favor of 1-2-3 step recipes with premixed ingredients that generally reduced the time to 25% or less of scratch preparation.
You know how marketing is; the word "instant" was market-speak for very fast and very easy, so you didn't have to waste time cooking.
That was not insignificant either. When I was a kid, my mother would spend anywhere from 30 to 60 minutes to prepare each meal, three meals a day; two hours of her day shot any way you looked at it. Because meal preparation was a continuous task, during which you did little else, because everything had to be timed to be ready at the same time.
We also lived far from town (50 miles) and so one can't just run to the store: When we bought food it was for the next two weeks (i.e., she had to plan every meal for the next two weeks in advance) with additional on hand in case we couldn't get to town in that period. And self-canning, picking fruit for jams, butchering our own livestock, etc.
Earlier in our history, it was worse. She told me one time that, when she was a little girl, ('40's) if you wanted beans for dinner, preparation started the day before with placing the dried beans on to soak.
Generally hard for us to imagine spending an hour each meal, and all that preparatory planning, just to eat, when there's a pizza at our door 20 minutes after the phone call. (Heck, when I was a little kid, we didn't have a phone.)
Admin
Yeah this sucks, especially during feast meals like Thanksgiving "dinner"...
Wait, is there another way? We still sort our Pinto beans for rocks and runts before cooking the next day. Don't tell me they've "instant-ized" those too?Admin
I think I've only ever seen beans potted or canned.
Admin
I see dried beans in the store, so people must still do the long soak, though you can get it down to an hour if you do it right. But I think most hurried people get their beans pre-soaked in a can, as suggested by @PleegWat.
Admin
Partial evaluation is a thing, though it doesn't yet appear to have escaped the CS labs, in which the compiler does indeed go executing random pieces of code during compilation. All right: not random, but anything deterministic is fair game.
Admin
It's used in compilers for many languages, but most function(al units) have so many hidden side-effects that only a very limited subset actually gets evaluated ahead of time. Languages that do more extensive pre-compilation effectively have to be designed with doing that in mind; for the rest it isn't worth going to the bother required. (The time and limited effort available are better spent making optimizations that users will actually see…)
Admin
Well you can buy them in cans. Saves like 4 hours on your chili recipe and frankly I can't tell the difference.
Admin
That's interesting, because my hobby language has specific syntax for differentiating expressions that should be evaluated at compile time, mainly because C++'s template syntax is horrible and I wanted to fix it in my language. Of course now I have problems like infinite loops and deep recursion to deal with...
Admin
I'm coming into this a bit late, and will probably get flamed. But:
What is wrong with using an associative array?
The Function can be a "wrapper" to any persistent store of the error descriptions.
errorCode, by definition has to be made up of characters that should be legal for the array, or index to a table. Also, by definition, there are going to be unique and need not be ordered
Admin
Do we need a donkey-head :badger: ?
Admin
You need to construct it runtime, so a linear scan is faster, since you're only searching once.
Admin
Also: :giggity:.
Admin
I read your reply and, as I often do (to some posts in general), heard this:
https://www.youtube.com/watch?v=ss2hULhXf04
Which seemed to make more sense. I am sure what you said makes some sense to somebody, but my view is: That is like saying something along the lines of "...having a 100,000 line product inventory database table is a complete waste if somebody only looks at one Product..."
Admin
It's a compiled language thing. Read the thread.
Admin
I fail to see the relevance. Pre-compiled, runtime compiled, or just plucked out of the air. The list of descriptions exist as an (in this case) associative array and when "something" spits out an error code (which may not be fatal, so there may be more of them), then the associated text is available