- 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
Here, it's quite common to see 'Y' and 'N' being used in a CHAR(1) field. I've had the database veterans (I'm a software veteran who dives into the database world on occasion) say that using a BIT instead of a CHAR(1) IS false economy... and hem and haw when I point out that it enforces the use of one of two possible values for a Boolean field.
Admin
I'm presently working on a code base where the original authors apparently never heard of booleans and enums, so all sorts of flags and status are passed as strings. Like, I just found one where at one point they pass in a string "called from stock screen", and in the function there are a couple of places where it says 'if (passed.equals("called from stock screen")) ...'.
Of course, inevitably somebody doesn't get the string quite right. They tend to put "equalsIgnoreCase" just to handle the problem of someone messing up the capitalization. I found one case where a bug made it to production where someone made a typo and switched to letters in the string, and so the condition was never true.
But sometimes the battle is hopeless. I wrote a new module recently where I created enums for a code value. And when I looked back at it later, I found that someone who had to subclass it began his override of a function with:
Admin
If any of you kids had ever been within 5 abstraction layers of an actual computer, you'd know that all they really do is pass around strings of ones and zeros. All other data types are syntactic candy for the lazy and ignorant.
Now get off my lawn. And take your IDEs with you.
Admin
Can someone help me on why that posted code is so bad other than no catch logic. I don't know what that last line does but if its really a webservice call, don't the parameters have to be strings so isn't that why he did not use bools?
Admin
SO why aren't you using Enum's in your code?
They are available in many languages.
Admin
<quote>Can someone help me on why that posted code is so bad other than no catch logic. I don't know what that last line does but if its really a webservice call, don't the parameters have to be strings so isn't that why he did not use bools?</quote>
His webservice.updateSettings should accept booleans and do the conversion internally, that will reduce his stringification to a single point of fail.
Admin
Are you studing fuzzy logic by any means?
Admin
He already has the data as booleans:
His webservice should have accepted the booleans directly:
Admin
(That sound effect could be the door slamming behind them after I boot them out. Or it could be me shooting them in the head so I can post their bodies on stakes as a warning to others. Depends on the exact interview methodology I'm using at that time.)
Admin
Admin
Admin
I was spoiled for many years because I used to work in a language where it was legal to do something like this:
I currently work in a language where WTFery is the norm:
Not naming names!
Admin
That's what I meant. Sorry, I was delusional from biking to work today.
Admin
"Frist" would.
Admin
I think this is pure genius. Now you can not only use "true" and "false" but also "maybe" in cases where more research is required and "later" for deferred decisions. This man is simply ahead of his time. That or he's making a magic 8-ball program.
Admin
Wow.. it's called humor Jr. Learn the word, love it. Embrace it.. cuddle it.
Admin
The fun bit is that, to my understanding, if this is C#/.net strings are invariant.
so all those little "true"s get turned into one pointer in the generated IL, and all the "false"s get turned into another.
so the code basically ends up just comparing pointers instead of strings.
Admin
To string everything.. That would be great for PHP! I could almost smell a PHP 5.4!
Admin
He should have defined constant Strings TRUE and FALSE to minimise any error in physically writing "true" and/or "false". In fact, doing so would probably allow him to make comparisons using == instead of .Equals(), and would allow easy insert into XML (as suggested by others). Of course, we might have to define new "and", "or", "xor", "not" etc.....
Admin
You could speed things up a bit with little loss of expressiveness by using 64-bit integers as fractions of one.
Admin
Yup. Until he accidently starts using "False" or "True" of "FALSE" or "TRUE" or etc.....
Admin
Thanks Sally.
Admin
Maybe I misunderstad, but in much of the current computer world it is less efficient to use Bits, because everything is created around the premise that the world is a happier place when there are bytes rather than bits (even Nybbles seem obsolete). It would not surprise me if using a bit field rather than a character therefore has computational overhead in a DB (or even in many common programming languages). Then again, I'm no veteran of programming or databases....
Admin
Admin
That's what I call a SOA ( String Oriented Architecture)
Admin
Meh, this is just about normal in some contexts, such as when parsing/writing data in text files. Or as appears to be the case for this example, passing them into a web service.
Admin
It may not be something he has a choice about, if the webservice object is from a 3rd-party library, or from some code-gen tool that treats everything as strings. In which case the tool may be crap, but not something the writer of this code had anything to do with.
Admin
Admin
The computational overhead would be absolutely minimal and probably not even measureable. Bitwise operations are extremely fast, assuming such operations need to be performed.
Other than that, you are partially right. An individual bit won't be retrieved, since the minimum that can usually be retrieved is double-word (4 bytes). This means that 31 bits are "wasted" in the read but the significance of this is absolutely tiny.
What IS important, though, is that many / most / all? database engines optimise the storage of bits. For example, SQL Server will pack up to 32 bit fields in a single table into a single integer field behind the scenes. Storage and retrieval are therefore very quick for multiple bit fields.
That's a pretty good reason to use them.
Admin
Fairies Nuts
Admin
404 will do
Admin
CYA
Admin
Maybe the developer was forced to use strings by the webservice he calls.
Admin
Hat's off to you kind sir for brightening my morning by making me laugh!
Admin
Strings the universal data type
Admin
Sir, I recommend that you Get Help Now. Although brilliant, your suggestion indicates that your mind is about to implode and form a neutron brain. This could have negative consequences for your ability to consume beer.
Admin
Admin
He had full control of this and the webservice, so there's really no excuse.
Admin
Well, for a starters, you can fit Not a Number into 3 chars, so i see no problem with FnF :-)
Admin
You ain't got no pancake mix! There ain't no pancake mix in there!
Admin
Jesus... how thick can one get...
Ah well...the joys of programming.
Admin
Yup you misunderstood. A bit in this context is a database column data-type, and not a unit of size. This column type takes 1 byte of storage, or 8 bits, or 2 nibbles.
Gimme a few secs while I reintegrate this mainframe...
Okay, so the code is very noob, the power of ToString() shines like so:
Admin
FTFY
Admin
?
If you've gone that far wrong, why not be completely wrong?
Admin
Something like this eventually happened, where 'Y' and 'N' were "accidentally" placed in a column and since anything that was not '1' was interpreted as false, everything ended up being false.
Of course, there were additional WTFs in the code sample such as trimming strings that do not need to be trimmed and using the comparesTo method for equality tests.
Admin
My biggest issue with our codebase is not so much the idea of using CHAR(1) for booleans in the database itself but with the fact that in our code they are not using a method which we constructed for this very purpose called getFieldBoolean which returns, well, a boolean value.
Admin
Ha! Only 1. In our codebase where boolean values are stored in the database as CHAR(1), any of '1', 'T', 't', 'Y', or 'y' may be considered as true, and anything else (including null) is false.
On the plus-side, we did push back when a German client wanted to define parameters with 'J' for Ja.
Admin
I am ;) Just missed that out of my reply.
Admin
Okay...I don't know Skilldrick so I'm hoping this is all tongue-in-cheek humor, including the way-off dig of the embedded world. This all so wrong, so very wrong...
Admin
This is something for the "Blog" of "Unnecessary" Quotation Marks: http://www.unnecessaryquotes.com/