|
Eventually I thought of it in the same way as what I call "switch Considered Harmful". You sometimes see switch when the code is crying out for a virtual function and polymorphism. Other times, the switch is a just a simple if , but it's still gross. I'll do it when adding the virtual function would be really messy, but even then it makes me hold my nose.
|
|
|
|
|
Greg Utas wrote: You sometimes see switch when the code is crying out for a virtual function and polymorphism.
WindowProc s. Top-level WindowProc s! Old school cool!
|
|
|
|
|
I didn't know what a WindowProc was, so I had to investigate. It looks like common practice might have been to switch on a message type.
For many years I worked in a procedural language where the better frameworks centered around creating a struct of function pointers that was subsequently registered against a type. This supported hand-rolled polymorphism:
TypeStructs[type].function(args); Not bad for things designed circa 1980.
|
|
|
|
|
Greg Utas wrote: I didn't know what a WindowProc was, so I had to investigate. It looks like common practice might have been to switch on a message type. Very much so. Like many other people I created a Windows wrapper, and one of the challenges was handling the callback messages. Here's an old (now almost outdated) article if you are interested. Search for winProc , case sensitive. (This article is much better, but doesn't go into as much technical depth.)
Greg Utas wrote: Not bad for things designed circa 1980. Cool!
|
|
|
|
|
Interesting work, putting C++ wrappers around a dog's breakfast.
And anyone who has a similar opinion of Hungarian notation must be doing something right!
The last time I wrote GUI software was for the Amiga. But if I ever need to do it for Windows, I'll have to look at your articles in more detail.
|
|
|
|
|
|
I'm all for it, but in practice if-less coding is very hard, if at all possible.
It's probably possible, but often not more readable.
The reason should be obvious.
If a function has one if-statement, your amount of tests double.
Two if-statements and they quadruple!
That also means that every time you change the code you need to check two or four (or eight!) code paths.
The problem is, those if-statements will not be in a single function, but across your entire application, and you need to take it into consideration every time.
My favorite, if (entity.type == 'x') { ... } else { ... }, and every time you need to work with entity you need to check for the type (and know you have to)!
I think that's what makes programming as hard as it is and is the source of many bugs as well.
|
|
|
|
|
Yes, I mentioned the
if(entity.type == ...) problem in my second post above. More than once, I had to hunt down all the logic based on a type (usually represented by an enum ) when a new type was added to the system.
But what's this testing thing of which you speak?! I didn't follow that at all.
|
|
|
|
|
Greg Utas wrote: usually represented by an enum That's luxury!
I'm currently hunting down some type which starts out as a single letter in the product entity, but later, in an order and some results, is translated to two or four letters.
It's always a string, so I'm looking for "S" or "SA" or "SAWR", which can all mean "S", the only reason why they're different is because the original programmer is inconsistent as heck.
I have to be careful though, because sometimes "S" means "South"
And "S" is just one of the six types and not all types show up in the same place
Greg Utas wrote: But what's this testing thing of which you speak?! I didn't follow that at all. It's when you release your software and users are going to use it.
If your software has lots of bugs simply call it alpha or beta or rebrand the patched version as v2.
|
|
|
|
|
Quote: Common sense is so rare these days, it should be classified as a super power
I want that shirt!
Thinking about it, I've just found a new sig ... @Chris-Maunder ... any chance of showing sigs in QA? :InnocentWhistleSmiley:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yeah, nah.
Sorry mate.
cheers
Chris Maunder
|
|
|
|
|
Dang!
Pretty please with sugar on?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Great. Another supper power I don’t possess.
There is only one Vera Farmiga and Salma Hayek is her prophet!
Advertise here – minimum three posts per day are guaranteed.
|
|
|
|
|
Why is it called common sense when it's so rare???
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Because the more "celebrity" you become (or think you become) the less you have of it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Unless you think someone has the copyright on that statement (and you want to respect copyrights), why don't you have one made, e.g. at spreadshirt.com? You'll find pre-made tees at a much lower price - spreadshirt.com is typically at USD 24 - but if you really want it, you may be willing to pay the price.
I have about a dozen tees made by spreadshirt, essentially plain white text on black. At the moment I am wearing one decaring, "I, for one, like Roman numerals". (I have had to explain the double meaning to a few that are not native English speakers.) Another one has the text "The Space Station: They call it rocket science, but haven't even got 1 G" and a drawing of a mobile phone. One that was bordering on copyright infringement use the YouTube logo in its invitation "Me train, YouTube?" - but a lagre fraction of those who get it, feel offended, so I am not using that one everywhere. Another one that I have had to explain to several people is the one declaring "I say sibboleth". ... People take note of my tees, and when I haven't come to work in a new one for months, people start asking. My problem is that I don't like throwing away stuff that are still in good condidion. At the moment, I have perfectly fine tees in my closet for a few years.
|
|
|
|
|
Nowadays nonsense is becoming commonsense.
|
|
|
|
|
I've always said - There is nothing more uncommon than common sense.
Kelly Herald
Software Developer
|
|
|
|
|
If you need me I'll be around. and around. and around.
When I'm done I'll get my coat.
Real programmers use butterflies
|
|
|
|
|
You'll get better mileage without the spare tire.
|
|
|
|
|
Where are you where you need a coat?
Because it's Haaat everywhere!
|
|
|
|
|
Had a coworker comment about a long night, and I mentioned something about long days and long nights. Sounded like a song.
Which there are many, but I stumbled across an album of that name[^].
|
|
|
|
|
There's always the Beatles' classic A Hard Day's Night
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
For some reason that made me think of Wasted Days and Wasted Nights[^].
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|