99
61
u/Cloakknight Apr 20 '19 edited Apr 20 '19
Image Transcription: Code
if(boolean.ToString()[0] == 'f')
{
'
'
'
}[the three ' are just visual studio placing marks for indentation, and not apostrophe characters]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
42
28
Apr 20 '19
please note that the three ' are just visual studio placing marks for indentation, and not apostrophe characters.
13
13
16
u/MalicousMonkey Apr 20 '19
Way faster since the program on only needs to check the first letter of the bool rather than the whole thing
Tapping head
7
9
u/Earhacker Apr 20 '19
Yeah so I've done exactly this before.
Postgres has a BOOLEAN data type. Unlike say MySQL which stores a true/false value as an INT 0 or 1, Postgres actually stores true and false values.
In Ruby, the PG gem (package) for accessing Postgres DBs returns these values as strings "true" and "false", and inexplicably not as instances of Ruby's TrueClass and FalseClass.
So I wrote a little wrapper function that abstracted out the conditional here, and wrapped every value in it that should have been boolean but was actually a string:
def string_to_bool str
str == "true"
endWhat's worse is, I was teaching at a coding school when I did this. It didn't matter much because we taught them about ORMs a few weeks later. But yeah, I taught newbies this awful code and I'm sorry.
12
u/SalvadorTheDog Apr 20 '19 edited Apr 20 '19
This doesn't compile. It's either Boolean with a capital B or bool; never boolean.
Edit: I'm dumb
58
u/brmifuse Apr 20 '19
That's a variable you dingus
28
10
u/c3534l Apr 20 '19
What a fucking moron he is! Who doesn't instantly recognize totally normal variable to have in your code like "boolean" that can't actually be a bool since they're capitalized in C#. What programmer isn't familiar with seeing classes named integer, and floating point numbers named string littered throughout their code. That's like stuff you learn on the first day.
4
u/Sharparam Apr 20 '19
they're capitalized in C#.
You're thinking of Java. In C# you use the keyword
bool.(Technically you can also use the
System.Booleanstruct but that's advised against and a waste of characters anyway.)2
u/brmifuse Apr 21 '19
I don't even know C#, I just assumed it was a variable from the ToString() function. Also, dingus was a sarcastic comment so please chill.
1
0
Apr 20 '19
[deleted]
0
Apr 20 '19
That sounded a lot more clever in your head, which apparently must be a common occurrence for you. Not that you'd notice it yourself, though
2
2
2
1
1
1
1
1
-3
u/gccpsben Apr 20 '19
Simply “if (!boolean) {....}”
22
u/runonandonandonanon Apr 20 '19
Not bad, but that only works if the value is false. The OP's algorithm will catch any value that starts with f.
3
201
u/EpikYummeh C# Apr 20 '19
This is especially bad because, in C#, converting a bool value to string will return either
TrueorFalseand thus not match a lower-case F. This is glorious.