Comment On "True" and True

"We have an old codebase where strings are used as a swiss army knife," writes Jimmi Hested, "almost everything that goes in or out of a function is ends with a .ToString(), even it's already a string... and sometimes even if it already ends with .ToString()." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: "True" and True

2010-06-23 09:03 • by Severity One
insert into comments values ( "frist".toString() );

Re: "True" and True

2010-06-23 09:04 • by Chip (unregistered)
I strung together the frist.

Re: "True" and True

2010-06-23 09:06 • by bl@h (unregistered)
trwtf is that there is no empty finally block.

Re: "True" and True

2010-06-23 09:06 • by Any Named Moose (unregistered)
312675 in reply to 312672
Severity One:
insert into comments values ( "frist".toString() );

I think you meant

insert into comments values ( new String("frist").toString() );

captcha: bene ... no, not really

Re: "True" and True

2010-06-23 09:08 • by anon (unregistered)
label.Text = GetString("SettingsUpdated")

WTF, lol. I hope this actually updates it with 'The settings have been updated' instead of just a straight 'SettingsUpdated'.

Re: "True" and True

2010-06-23 09:13 • by n9ds
It's brilliant! No type mismatches, and just think how easy it would be to migrate the application to XML! It has the makings of Enterprisy.toString() written all over it!

Re: "True" and True

2010-06-23 09:17 • by evilspoons
(Commented edited because it was virtually identical to the one before, even though I am not the same person.)

When you have to do something like this to make your program work (and therefore disable half of the fundamental programming-flaw/error checking in, y'know, every modern programming language) you know something is very wrong.

Re: "True" and True

2010-06-23 09:18 • by RHuckster
I guess I'll get it out of the way...

...he's coding it so one day if there's a "File_Not_Found" state they can easily just add that in.

Re: "True" and True

2010-06-23 09:18 • by exel (unregistered)
Jimmi:
it's also worth noting the fact that the datatype to store the true/false values is nvarchar(5). What could possibly go wrong?


Well, for starters, FileNotFound will not fit in 5 characters.

Re: "True" and True

2010-06-23 09:20 • by Bryan The K (unregistered)
The real WTF is that he doesn't do anything with the catch block, am i right?

CAPTCHA: bene - A french food. bene

Re: "True" and True

2010-06-23 09:22 • by vydf (unregistered)
312683 in reply to 312680
exel:
Jimmi:
it's also worth noting the fact that the datatype to store the true/false values is nvarchar(5). What could possibly go wrong?


Well, for starters, FileNotFound will not fit in 5 characters.


Shorten it to fnotf. Clearly readable, and speaks for itself. And fits in 5 chars.

Re: "True" and True

2010-06-23 09:23 • by Alan (unregistered)
I hate to say I've done this too. Mainly because the company I work for refuses to give me a specification and the amount of time 'True','False' has changed to 'True','False','Some other weird state' is ridiculous.

My only saving grace is that they are stored in the database as enums?

Re: "True" and True

2010-06-23 09:23 • by LoztInSpace
"Old Code"?
I see way more of this now than before everything was (nay had to be) XML and web oriented.
Admittedly in some languages the types were cobbled together with strings & ints but at least we made the effort.
Now get off my lawn.

Re: "True" and True

2010-06-23 09:24 • by monkeyPushButton (unregistered)
312686 in reply to 312679
RHuckster:
I guess I'll get it out of the way...

...he's coding it so one day if there's a "File_Not_Found" state they can easily just add that in.
No, it stores as nvarchar(5) so it would be "File_".

Obviously TRWTF is that it is not stored as a nvarchar(14).

Re: "True" and True

2010-06-23 09:24 • by Knux2 (unregistered)

string temp1 = "false";
string temp2 = "false";
temp2 = "true";
string brainEXPLOSION = temp1 + temp2;


In other news, why didn't he have a constant string value for true and false? I mean, this would probably be bad, and may be hard to find deep in code:


string temp1 = "fale"

Re: "True" and True

2010-06-23 09:25 • by Skilldrick (unregistered)
This is all very sensible - string literals don't change, but what if the language changed and started using YES and NO for booleans instead? It's actually very sensible.

It's also very common in embedded systems where you only have ints and strings.

Re: "True" and True

2010-06-23 09:27 • by campkev
Am I the only one disappointed by the lack of .ToString() calls in an article that starts out by talking about how man .ToString() calls there are?

Re: "True" and True

2010-06-23 09:29 • by The_Assimilator
312691 in reply to 312687
Knux2:
In other news, why didn't he have a constant string value for true and false? I mean, this would probably be bad, and may be hard to find deep in code:


string temp1 = "fail"


FTFY

Re: "True" and True

2010-06-23 09:33 • by A F (unregistered)
This reminds me of the codebase that I work with where boolean values are stored in the database as CHAR(1) where '1' is considered true.

Thus, in the codebase, I find things like:
if (record.getFieldString(1).trim().compareTo("1") == 0)
{
...
}

Re: "True" and True

2010-06-23 09:36 • by Zylon
Jimmi needs an editor.

"almost everything that goes in or out of a function is^H^H ends with a .ToString(), even if it's already a string...

Re: "True" and True

2010-06-23 09:36 • by fjf (unregistered)
312694 in reply to 312675
Any Named Moose:
Severity One:
insert into comments values ( "frist".toString() );

I think you meant

insert into comments values ( new String("frist").toString() );

insert into comments values ( GetString (new String("frist").toString()).toString().toString() );

Re: "True" and True

2010-06-23 09:38 • by anon (unregistered)
312695 in reply to 312690
campkev:
Am I the only one disappointed by the lack of .ToString() calls in an article that starts out by talking about how man .ToString() calls there are?


Could that be TRWTF?

Re: "True" and True

2010-06-23 09:54 • by Drew (unregistered)
312697 in reply to 312684
Does your particular language not have an enum of its own?

CAPTCHA: enim. Like enum but for integers

Re: "True" and True

2010-06-23 10:01 • by Mike D. (unregistered)
312698 in reply to 312677
n9ds:
It's brilliant! No type mismatches, and just think how easy it would be to migrate the application to XML! It has the makings of Enterprisy.toString() written all over it!

So, did the developers miss the "everything is a string" simplicity of Tcl?

Re: "True" and True

2010-06-23 10:05 • by Kiss me I'm Polish
When all you have is a swiss army knife, everything looks like a string.

Re: "True" and True

2010-06-23 10:06 • by m a t t
312700 in reply to 312690
campkev:
Am I the only one disappointed by the lack of .ToString() calls in an article that starts out by talking about how man .ToString() calls there are?


"No, I am very disappointed too".ToString()

Re: "True" and True

2010-06-23 10:08 • by Rasmus Toftdahl Olesen (unregistered)
Why is tempStartTime and tempEndTime encoded as ints, where is the ToString() ?

Re: "True" and True

2010-06-23 10:13 • by Anonymous (unregistered)
I think there is an instinct for novice developers to overuse strings. They are simple to understand, easy to manipulate and have good native handling in most high-end languages. However, any developer that actually understands OO principles should have realised the folly of this approach by the time they left University. Anyone who takes string-based coding out of school and into their job clearly hasn't learnt enough to be writing production code. Today's submission looks like your typical "I just learnt VB6 and everything can be done with strings" type code (I know it's C# but you get my point and it never hurts to have a dig at VB developers).

Re: "True" and True

2010-06-23 10:16 • by Brian follower of Deornoth
312705 in reply to 312679
Won't fit "File Not Found" into 5 letters, though.

Re: "True" and True

2010-06-23 10:23 • by Rob (unregistered)
312706 in reply to 312698
Mike D.:
n9ds:
It's brilliant! No type mismatches, and just think how easy it would be to migrate the application to XML! It has the makings of Enterprisy.toString() written all over it!

So, did the developers miss the "everything is a string" simplicity of Tcl?

Oh wow, I've been working with TCL for a day now and nobody told me that. Suddenly a whole lot of weird behaviour makes perfect sense. I should really RTFM before diving into these things but thanks for the tip, benevolent stranger.

Re: "True" and True

2010-06-23 10:25 • by Some Wonk (unregistered)
312707 in reply to 312705
Brian follower of Deornoth:
Won't fit "File Not Found" into 5 letters, though.

You'll have to use the ISO approved FNF code, then.

Re: "True" and True

2010-06-23 10:33 • by Loren Pechtel (unregistered)
WriteComment("And what happens when it tries to store \"unknown\" into that field?".ToString().ToString());

Re: "True" and True

2010-06-23 10:34 • by A Mouse (unregistered)
312709 in reply to 312693
Yeah... That was really quite hard to read. The poor grammar kind of overshadowed the entire article. Though maybe the quotation was just done out of irony.

I accidentally the post.

Re: "True" and True

2010-06-23 10:35 • by frits
That's the most Visual Basicy C# I've ever seen.

Re: "True" and True

2010-06-23 10:35 • by Azd (unregistered)
I'm a bit concerned as we should have some code that does exactly this. It needs to get a start and end time and a selection of days of the week and send that info to a web service.

Hmm, think I better check this isn't our code.

Re: "True" and True

2010-06-23 10:37 • by John Preston (unregistered)
That's so stupid... what a bad coder. All those manual checks for literal "true" and "false"s.

You could do this way faster with a 2 constant global "true" and "false" strings to use in the compares, so you aren't dimming all those extra strings on the fly and even more so with a Boolean.TrueString and Boolean.FalseString assuming it's .Net like I get the impression it is.

Re: "True" and True

2010-06-23 10:42 • by John Preston (unregistered)
Also, I'm glad the DB uses nvarchar because those literal "true" and "false" strings he has could contain Unicode. So way to bloat the DB just that little bit more on top of storing strings instead of a Byte.

After all, since SQL Server won't let you Boolean, a string is way more logical than a Byte.

Re: "True" and True

2010-06-23 10:42 • by notme (unregistered)
This is known as "stringly typed" programming. See:

http://www.globalnerdy.com/2010/05/09/new-programming-jargon/

(Not making this url into a clickable one with bbcode, because the server will reject my message as spam...)

Re: "True" and True

2010-06-23 10:42 • by Mateus (unregistered)
at least they're using a webservice, that's good practice!

Re: "True" and True

2010-06-23 11:11 • by Anonymous (unregistered)
312719 in reply to 312712
John Preston:
That's so stupid... what a bad coder. All those manual checks for literal "true" and "false"s.

You could do this way faster with a 2 constant global "true" and "false" strings to use in the compares, so you aren't dimming all those extra strings on the fly and even more so with a Boolean.TrueString and Boolean.FalseString assuming it's .Net like I get the impression it is.

This is the sort of flamebait that might just get a bite, despite being the most obvious troll this side of Shrek. It's not the best troll I've seen round here but it's got a certain something to it so good luck to you sir, let's see if you net anything in...

Re: "True" and True

2010-06-23 11:13 • by Anon (unregistered)
312720 in reply to 312715
notme:
This is known as "stringly typed" programming. See:

http://www.globalnerdy.com/2010/05/09/new-programming-jargon/

[neologism]

Tagged accordingly!

Re: "True" and True

2010-06-23 11:21 • by Mark (unregistered)
312723 in reply to 312680
But, "null" will fit in there fine. And "maybe". So, it has that going for it.

Re: "True" and True

2010-06-23 11:41 • by Renan "C#" Sousa
312726 in reply to 312680
exel:
Jimmi:
it's also worth noting the fact that the datatype to store the true/false values is nvarchar(5). What could possibly go wrong?


Well, for starters, FileNotFound will not fit in 5 characters.


You just have to be synthetic. FNF.

Re: "True" and True

2010-06-23 11:41 • by Erasmus Darwin
A Proposed Replacement for Booleans

This code got me thinking, and I don't think it goes far enough. Booleans are obsolete technology, and they need to be updated. What's one of the first words little kids learn? "No." And "no" is really just false. So we shouldn't be using baby stuff for computers.

So this code takes the first step. It goes from booleans to strings. That's a big step, and it frees us up to redefine what a boolean means. Strings are flexible, so we could have a string that's "maybe" or "sort of" or "probably not". See because we aren't dealing with babies any more, so the black-and-white delineation of true/false is no longer enough.

But here's the problem. We're doing computer stuff. A computer doesn't know that "hell yes" is pretty damn true. We could define a whole bunch of values, but there's always something that'll fall through the cracks. Plus no one wants to go looking up the list of accepted values every time they code stuff. So we need something flexible.

Now we could invent some sort of super AI that can parse the strings and determine how truthy they are. But that's a lot of work, and we'd have to use the old, boring boolean system to do it since the super replacement booleans wouldn't be usable until the AI was done. So we need something we can use now.

Instead of an AI, we could use Google. You could do queries of "'hell yes' true" and "'hell yes' false" and go with the one with more hits. That's kind of like crowd-sourcing the web 3.0 paradigm through the wetware of website builders. But what if someone uses + for true and - for false? Google can't handle punctuation searches. What we really need to do is develop a new search engine that can, but again, we'd have to do all our development work using the old, boring booleans until it was done. No one in their right mind would want to do that. Again, we need something we can use now.

So here's where we get tricky. Instead of text strings, we switch to probabilities. That's all math and sciencey, and it can be evaluated by mathy computer machines, but it still gives us a lot of flexibility. Sure, we lose the ability to have a "hell yes" value -- it'll get encoded, say, as a less exciting 99.99% -- but we gain something that will work. However, since we're trying to be all math and sciencey, we'll encode 99.99% as .9999 because that's how the math people seem to do it, and they must know what they're doing because they study that stuff. So instead of strings, we can use floats for the booleans, but we still gain a vast number of possibilities. We can even represent things that're more true than true with values over 1, and that's amazing and powerful. For example, if I had a new boolean value for is_this_a_good_idea, I could assign a value of 2.6. That way, it's a good idea, and even if it wasn't, it's still a good idea, and even if it still wasn't, it still kinda is. And you know what's really cool? A lot of legacy code uses 1 for true and 0 for false, so it's easily ported to our system. Free backwards compatibility!

But there's a problem because floating point math is all weird. The IEEE has tried to contain the damage, but they're electricity people, and we don't want electricity, we want math and truth. So what we could do is turn those floating point numbers into integers and just do fixed point math. That really limits our precision though because what if a truth value is .0000000000000000000001? Rounding that to a lower precision would be tantamount to lying, and that's a bad way to start a new system for truth. So we need something better.

And that something better is strings. We store the neo-boolean values in strings, and we don't have to worry about all those crazy math limitations. Sticking ".0000000000000000000001" in a string is easy. We're done! There are at least a dozen programming languages that support strings, including Pascal, BASIC, and Algol 60. So I fully expect this standard to catch on.

Re: "True" and True

2010-06-23 11:44 • by EngleBart (unregistered)
312728 in reply to 312692
A F:
This reminds me of the codebase that I work with where boolean values are stored in the database as CHAR(1) where '1' is considered true.

Thus, in the codebase, I find things like:
if (record.getFieldString(1).trim().compareTo("1") == 0)
{
...
}
Which is very different than == 1 because like someone else pointed out, eventually, the DB column will be 0, 1, OR N.
N means Not applicable, not No -> false -> same as 0.

Then you get (..."1" != "1") means it could be 0 OR N, not just 0 vs. ("0" == "0") means it must only be 0.

Of course, the column name will still be named in such a way as to imply a boolean. Enabled, InStock, etc.

Re: "True" and True

2010-06-23 12:00 • by Satanicpuppy
312732 in reply to 312728
The truly delightful aspect is that "false" evaluates to TRUE if you're testing it, since its evaluated as a string, and yes, the string is valid and non-NULL.

Re: "True" and True

2010-06-23 12:05 • by VATIgers (unregistered)
Atleast he did not write

if (mondayCheckBox.Checked.ToString()=="true")
tempMonday = "true";

if (tuesdayCheckBox.Checked.ToString()=="true")
tempTuesday = "true";
......

Re: "True" and True

2010-06-23 12:11 • by un-anonymous prime (unregistered)
312734 in reply to 312684
Call me Sally if you like, but if the spec. says true, false, etc. I'd use an enum in in source code too, not just the DB.
Alan:
I hate to say I've done this too. Mainly because the company I work for refuses to give me a specification and the amount of time 'True','False' has changed to 'True','False','Some other weird state' is ridiculous.

My only saving grace is that they are stored in the database as enums?

Re: "True" and True

2010-06-23 12:21 • by ThingGuyMcGuyThing (unregistered)
312735 in reply to 312680
Jimmi:
it's also worth noting the fact that the datatype to store the true/false values is nvarchar(5). What could possibly go wrong?


Maybe I'm dumb, but does anyone know what could possibly go wrong? It seems to me that "true" and "false" should fit. NVARCHAR isn't null-character-terminated, is it?

Re: "True" and True

2010-06-23 12:22 • by Anon (unregistered)
312736 in reply to 312727
Erasmus Darwin:
A Proposed Replacement for Booleans

<snip>

I admire that you took the time to author such an expansive troll and I am especially impressed by the fact that your proposed solution doesn't actually fulfil the purpose of a boolean value in any way. Kudos, good sir, there is surely a job waiting for you in Redmond.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment