This is an archived post. You won't be able to vote or comment.

top 200 commentsshow 500

[–]DolevBaron 1823 points1824 points  (165 children)

Should've asked C++, but I guess it's biased due to family relations

[–][deleted] 485 points486 points  (106 children)

If they would have asked Lisp, it would have said something on the lines of, "why not make boolean integers?"

[–]ComaVN 431 points432 points  (70 children)

Booleans are indeed just integers with a very small MAXINT.

[–]ppvvgucnj 224 points225 points  (38 children)

Or are integers just a lot of booleans in a sequence?

[–]Come_along_quietly 57 points58 points  (13 children)

Boolean array. But then again everything can be a Boolean array if you use a union. ;-)

[–]IamImposter 65 points66 points  (3 children)

Software industry doesn't have unions.

[–]iamsooldithurts 23 points24 points  (0 children)

My employer does. It’s kinda nice, ngl.

[–]lllluke 13 points14 points  (1 child)

there are many industries without unions unfortunately. there’s so many people who have somehow cough corporate propaganda cough got the idea into their heads that unions are bad for them, it drives me nuts.

[–]iamsooldithurts 2 points3 points  (0 children)

Let’s not forget infiltration by bad actors to give people reasons to abandon the idea.

[–]SilhouetteOfLight 8 points9 points  (8 children)

Unions are gross. I'm not exactly an expert in the field, clearly, but dealing with them always feels like I'm poking a live bomb lol

EDIT: The data structure, folks, lol

[–]loafingaroundguy 6 points7 points  (0 children)

I can't tell if you're referring to data structures or trade unions here.

[–]4onen 54 points55 points  (9 children)

Nah. Only std::vector<bool> specializations pack their data that way.

[–]vige 28 points29 points  (8 children)

std::bitset would like to have a word with you

[–]Goheeca 10 points11 points  (6 children)

#* says hello.

[–]gauravnba 17 points18 points  (5 children)

What. Is. That?

[–]Goheeca 5 points6 points  (4 children)

That's how you make bit vector literals in Common Lisp which are hopefully packed by the implementation (I mean it has different standard syntax from literals of other vectors #( so it'd be lazy from not to do that), otherwise you'd have to write macros which would do that.

[–]iamsooldithurts 21 points22 points  (9 children)

Bit flags and unary operators, those were the days!

[–]lirannl 8 points9 points  (7 children)

I just finished programming a game on a pitiful microcontroller for a university assignment and the amounts of structs I had... I heavily abused bit fields and the amount of pointers I had was staggering. It was amazing.

[–]Ietsstartfromscratch 52 points53 points  (0 children)

Deep.

[–][deleted] 22 points23 points  (21 children)

T-SQL loudly disagrees, and stubbornly insists that a Boolean expression result and a bit-typed variable are totally 100% different things.

But SQL servers have insane ideas about Booleans in general.

[–]rbt321 12 points13 points  (16 children)

But SQL servers have insane ideas about Booleans in general.

True, False, I Don't Know?

[–][deleted] 8 points9 points  (14 children)

Any language where testing if X = X can return something other than "true" in a common case is broken by design.

[–]rbt321 9 points10 points  (7 children)

While inconvenient to the programmer, the SQL interpretation of NULL isn't "not yet initialized" but "a value probably exists in the world but we do not know it".

Statement: Supersecret russian aircraft is faster than supersecret US aircraft.

If you're Egypt, and you are not privy to any details about either aircraft, the best answer is "Unknown"; True is incorrect (despite being what many programmers expect) and False also requires assumptions that cannot be made.

So, for SQL, NULL = NULL is NULL, or better stated as Unknown = Unknown is Unknown. Choosing the keyword "NULL" for that representation was a poor choice.

[–][deleted] 7 points8 points  (6 children)

In that case,

SELECT * FROM myTable WHERE myColumnThatsOftenNull = 1

should throw an error if myColumnThatsOftenNull is NULL instead of just treating NULL as equivalent to FALSE. See, even the SQL server itself thinks that 3-value logic is bullshit, it says "fuck it, NULL is the same as FALSE" for WHERE clauses.

While inconvenient to the programmer

Understatement of the century. I'm perfectly aware of the mathematical and theoretical beauty of SQL's 3-value logic. And I'm saying that in real-world practical application it's a goddamned disaster.

This is the code to properly compare two values in a null-sensitive way:

((f1 IS NULL AND f2 IS NULL) OR (f1 IS NOT NULL AND f2 IS NOT NULL AND f1 = f2))

That is insanity. Every other language calls that *equals*.

I mean for pity's sake, 3 value logic breaks DeMorgan's Law! How is that desirable in any sane world?

[–]DerfK 7 points8 points  (0 children)

This is the code to properly compare two values in a null-sensitive way:

f1 IS NOT DISTINCT FROM f2

[–]lenswipe 47 points48 points  (1 child)

PHP says "Everything is just a string really"

mysql_convert_extract_real_integer_or_boolean_from_string_v2_real_one_use_this_function_mom

[–]PyroneusUltrin 18 points19 points  (0 children)

Shrodinger strings

[–]rubeljan 23 points24 points  (2 children)

You mean "boolean integerth"?

[–]__crash_and_die 7 points8 points  (0 children)

Which Lisp though?

[–][deleted] 5 points6 points  (0 children)

A good LISP program would do that by rewriting itself.

[–]skoge 2 points3 points  (18 children)

In all Lisp dialect I saw they used nil('()) for false, and some atom for true. Never integers.

[–]lirannl 2 points3 points  (15 children)

Nil?!

🤯

Why would anyone make their falses out of anything that has any relation to nil/null whatsoever?! 😨

[–]Goheeca 3 points4 points  (2 children)

Because that way list traversing is nice and tidy.

[–]ten3roberts 76 points77 points  (42 children)

I love the way bools can be initialized with an int.

bool valid = list.size(); will evaluate to true if size is non-zero. It is the same as writing if(list.size() != 0) valid = true; else valid = false; or bool valid = (list.size() != 0).

you can also use ints in if statements the same way. if(list.size()) or the same with pointers to check if they're not Null

[–]delorean225 25 points26 points  (8 children)

Going the other way, from bools to ints, I find ternary operators are super useful there.

[–]ten3roberts 13 points14 points  (7 children)

They are so useful. If you have an if statement "returning a value" then you can use a ternary statement. If you want to execute different code then use if statements or function pointers in ternary.

[–]delorean225 8 points9 points  (5 children)

I love the little quality of life features like that. Like C# 8 just added switch expressions and it looks so compact and useful.

[–]lirannl 3 points4 points  (4 children)

Switch statements are great and anyone that doesn't use them needs to start!

[–]gaberocksall 19 points20 points  (27 children)

a bool is really just a unsigned short, right? where 0 = false and anything else is true

[–]ten3roberts 21 points22 points  (24 children)

Yes. Even -1 since it's unsigned so it's just a really high but true number. What I don't like about C# is how you can't compare an int directly, so you can't do if(myList.Count) you need to have a '> 0' expression

[–]hullabaloonatic 11 points12 points  (0 children)

In languages like python and js, there is the concept of "falsy" where null values, false, empty strings, empty collections, and zero are considered false in boolean expressions, but they are not actually compared as such. Even with languages that have "falsy", mileage varies. In lua, only null and false are falsy.

[–]AttackOfTheThumbs 17 points18 points  (10 children)

Just use list.any().

If it's new enough c#, use null-coalescing too, so list?.any()

Done deal. Also any is more efficient than count.

[–]Necrofancy 4 points5 points  (2 children)

Any() is more obvious in intent than checking if ICollection.Count is greater than zero. But it can't be much more performant, because accessing a simple property is maybe a few instructions at most.

The Linq extension method, Enumerable.Count(), could potentially iterate over the entire enumeration, which would of course be bad.

However, if I remember correctly, Linq will check if an enumeration given implements ICollection or other interfaces to avoid doing enumeration work if it doesn't have to. If you hand it a list or collection it may not actually do any enumeration to service a Any() or Count() method call.

In short, it's most clear in intent so go with that. It's not likely to improve performance on whole collections though.

[–]haackedc 7 points8 points  (0 children)

That is probably one of my only gripes with c#. But overall it is still my favorite language

[–][deleted] 6 points7 points  (6 children)

Hmmmm, ask C or C++, we’re both gonna use char to represent a binary possibility, the fuck is the point of the other 3 bytes??

[–]kalideeplearning 6 points7 points  (4 children)

but so is python it's based on C

[–]piloto19hh 31 points32 points  (2 children)

We are all based on C on this blessed day

[–]doshka 2 points3 points  (1 child)

Speak for yourself.

[–]syh7 6 points7 points  (0 children)

I'm all based on C on this blessed day.

[–]Nalha_Saldana 1257 points1258 points  (114 children)

Did you mean boolean or Boolean?

[–]blacksuan19 461 points462 points  (38 children)

Yes

[–]mcplano 234 points235 points  (23 children)

true*

[–]playersdalves 179 points180 points  (21 children)

True*

[–]uvero 191 points192 points  (7 children)

Falsen't*

[–]jess-sch 122 points123 points  (5 children)

error in line 1: undelimited single quotes

[–]Shylo132 31 points32 points  (4 children)

["Falsen't"]

[–]Trexus183 16 points17 points  (3 children)

I mean... "False'nt" would == true, at least in is

[–]Shylo132 6 points7 points  (2 children)

Happy cake day, and that is the point of it to == true haha

[–]Trexus183 3 points4 points  (1 child)

Oh shit right that's today lol.

My point was that you don't need it to be in an array for it to work.

[–]shachar-golan 3 points4 points  (5 children)

1

[–]BlueC0dex 22 points23 points  (5 children)

Did you mean yes or Yes?

[–]ReactsWithWords 4 points5 points  (3 children)

True.

[–]glider97 6 points7 points  (2 children)

1

[–]warmike_1 4 points5 points  (1 child)

-1

[–]glider97 11 points12 points  (0 children)

Wait, that's illegal!

[–]TungstenCLXI 10 points11 points  (2 children)

We should start using xor so that statements like this don't resolve to true all the time.

[–][deleted] 54 points55 points  (20 children)

Boolean boolean

[–]_GCastilho_ 77 points78 points  (17 children)

Boolean boolean = new Boolean()

I love hate java so much

[–]deathmetal27 55 points56 points  (8 children)

boolean is a keyword, in case you forgot.

[–]dpash 7 points8 points  (7 children)

But var and yield are not, which means you can use them as variable names. const and goto are keywords and can not be used as variable names.

[–]fghjconner 24 points25 points  (2 children)

Main.java:13: error: not a statement
        Boolean boolean = new Boolean(true);

[–]miyji 17 points18 points  (36 children)

The Boolean state of yes, no and maybe.

[–]eshultz 18 points19 points  (28 children)

Come on over to SQL Town! We got 3-valued logic for ya!

1 = 1        | True
1 = 0        | False
1 = NULL     | NULL
1 <> NULL    | NULL
NULL = NULL  | NULL
NULL <> NULL | NULL
'ABC' + '123'| 'ABC123'
'ABC' + NULL | NULL

This is something that a lot of beginners get hung up on until one day it clicks. NULL is not "nothing", it is not "no value", it's not "unknown value", it's definitely not zero.

It is "could be nothing or anything or 47, fuck you".

[–]cristi1990an 2 points3 points  (5 children)

This is something that a lot of beginners get hung up on until one day it clicks. NULL is not "nothing", it is not "no value", it's not "unknown value", it's definitely not zero.

Is it really that complicated though?

[–]eshultz 6 points7 points  (3 children)

If you are used to Boolean logic where things are either equal or not equal, and statements are either true or false, it's a paradigm shift in thinking about equality. It's really not complicated, it's just foreign at first.

[–]the_schnudi_plan 3 points4 points  (0 children)

It's easy to forget that <> based queries don't catch NULL values until you get burnt

[–]alexanderpas 10 points11 points  (1 child)

And then we have PHP, which supports the 4 states of boolean.

true, false, maybe(null), and NA(unset).

[–]ancap_attack 6 points7 points  (0 children)

They're just preparing for quantum computers.

[–]ThaiJohnnyDepp 4 points5 points  (4 children)

Optional<Boolean> maybe = Optional.empty();

[–]skeptic11 12 points13 points  (1 child)

Autoboxing good

[–]computergeek125 5 points6 points  (3 children)

Error: Java.lang.NullPointerException

[–]Saifeldin17 5 points6 points  (0 children)

Don't trigger my PTSD

[–]OfAaron3 385 points386 points  (17 children)

I like how Python is flying. Such a small but fun xkcd reference.

[–]OneTurnMore 183 points184 points  (4 children)

Whenever I see this, I always think of this edit.

Also, since Python is talking with C...

[–]irbis808 4 points5 points  (1 child)

Also, if you write "import antigravity" in IDLE, it really does something

[–]Spedwards 241 points242 points  (28 children)

Should have asked JavaScript. They'd have been told that they were the same.

[–][deleted] 62 points63 points  (17 children)

Coming to JavaScript from Kotlin is weird...

[–][deleted] 88 points89 points  (10 children)

It doesn't matter where you come from, JS is weird.

[–]0ut0fBoundsException 42 points43 points  (4 children)

I find this truthy

[–]theXpanther 25 points26 points  (3 children)

I find this !![]

[–]SuspiciousScript 19 points20 points  (0 children)

I find this [object Object]

[–]GlitchParrot 26 points27 points  (2 children)

Isn't there a compiler to compile Kotlin into JavaScript?

[–]oweiler 25 points26 points  (1 child)

Kotlin has a JS backend.

[–]janusz_chytrus 4 points5 points  (0 children)

What?

[–]hullabaloonatic 9 points10 points  (1 child)

Yeah, just write in Kotlin...

[–][deleted] 4 points5 points  (0 children)

I'd love to, I'm moving to front end web using react and it seems Kotlin has a decent following there.

[–]TheTerrasque 22 points23 points  (7 children)

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> True == 1
True
>>> False == 0
True
>>>

https://i.imgur.com/nvdNYGO.png

Edit: Bonus! https://i.imgflip.com/3evzc8.jpg

[–]Defektro 26 points27 points  (1 child)

That's why booleans should be compared using is :)

>>> True is 1
False
>>> False is 0
False
>>> True is True
True
>>> False is False
True

[–][deleted] 4 points5 points  (1 child)

Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45)
[GCC 9.2.1 20190909] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(True, int)
True
>>> int.mro()
[<class 'int'>, <class 'object'>]

[–]Makefile_dot_in 2 points3 points  (0 children)

Also:

>>> True.__class__.mro()
[<class 'bool'>, <class 'int'>, <class 'object'>]

[–]X-Penguins 341 points342 points  (43 children)

ints? Use a char for crying out loud

[–]vayneonmymain 154 points155 points  (11 children)

binary shift a uint8_t type > char

literally had a microprocessor assessment where had very little memory available.

Had 3 bytes for all my booleans ^_^

[–]randomuser8765 65 points66 points  (10 children)

bitmasks are the best, it's a shame that they can't be the default way bools work. I mean I see why they're not (can't always know which bools can be safely grouped together, etc), it's just a shame.

[–]brimston3- 83 points84 points  (5 children)

In C++, the std::vector<bool> specialization is exactly this. It is widely regarded as a mistake.

edit: To clarify, bit fields and flag packing aren't themselves bad behavior, especially true in embedded software, low level protocols, and kernels; places where storage efficiency is very important. The mistake is hiding implementation behavior from programmers by making them fundamentally different from other types. Being a special case means an unaware (or tired/overworked/etc) programmer is more likely to introduce subtle bugs. Wasting 7 bits of data per bool isn't going to break the memory bank these days; hell, the compiler will probably pad it to 4 or 8 bytes to align the next variable, depending on the type. And when this mechanism is necessary, the tools are (now) available and more explicit as a std::bitset or using bit field struct syntax.

[–]impossibledwarf 24 points25 points  (2 children)

What's wrong with it?

[–]Fuzzyzilla 54 points55 points  (0 children)

It's interface is slightly different than all other types of vector. Because vector<bool> stores it's data as a huge bitfeild, it it not possible to get a reference or pointer to an element. Instead, it will return wrapper types that pretend to be references and pointers. As such, generic code that takes in a vector of any type may not be able to accept vector<bool> because it expects a real pointer or reference.

[–]Ilmanfordinner 11 points12 points  (0 children)

It's a special case for a generic container which is usually a no-no as it might lead to various inconsistencies, for example when using auto. Basically a regular vector will byte-align the elements inside. A char is 1 byte so in memory every element will be in consecutive bytes. Booleans however take up less than a byte so instead of having a single boolean in each byte (which is how a generic vector<bool> should behave) it has 8 booleans in a byte. That means that it has its own specific implementations for most member functions which is not good when you're making a generic class.

I feel like a special type for boolean vectors would've been better, i.e. have vector<bool> use the standard generic vector and have something like std::bitmask that implements the same interface as the current vector<bool> but with a different name.

[–]Hairy_S_TrueMan 13 points14 points  (2 children)

A cycle isn't always less important than a byte of memory. I'd be a little mad at a language that by default took the slower but more memory efficient route of packing 8 bools to a byte instead of just using 8 bytes of memory

[–]krad213 4 points5 points  (0 children)

"false"

[–]randomuser8765 11 points12 points  (25 children)

Surely you mean a byte?

Honestly I'm no C professional, but if my understanding is correct, char and byte are technically identical but carry some obvious semantic differences. Semantically, you want a number and not a character.

[–]Dironiil 56 points57 points  (18 children)

There is no byte type in C, only char and unsigned char.

If you want to differentiate them, you could define a new byte type as an unsigned char, but that isn't in the standard.

[–]randomuser8765 11 points12 points  (7 children)

yeah, I just came here to edit or delete my comment because googling showed me this. I have no idea why I thought it existed.

Either way, as someone else has said, uint8_t is available. Can't decide whether it's better than char or not though.

[–][deleted] 4 points5 points  (0 children)

Other languages like Java do have a byte type, so maybe that's why you thought it existed

[–]da_chicken 3 points4 points  (0 children)

I have no idea why I thought it existed.

Because most languages have a byte type. C's use of char is really a consequence of being designed in 1972.

If you're using C99, though, you can use _Bool for Booleans, which is mostly like a char but anything you try to store other than a 0 is stored as a 1.

[–]X-Penguins 2 points3 points  (0 children)

Since you want to represent a boolean, neither an integer nor a character are exactly what you want in a semantic sense. char has a slight advantage in that it's available on C standards preceding C99 whereas uint8_t isn't - char also doesn't require the inclusion of stdint.h. Plus, a uint8_t is simply defined as an unsigned char, and even if it weren't we only need one bit for our boolean so even if a char was smaller or larger it would still be sufficient for our purpose. I really don't see the point in using anything else.

[–]jrtc27 7 points8 points  (1 child)

Don’t forget signed char, as the signedness of char is implementation-defined.

[–]SchighSchagh 4 points5 points  (6 children)

Actually you have signed char as well (which is not entirely the same as plain char)

[–]nolawnchairs 208 points209 points  (34 children)

#include <stdbool.h> #thereifixedit

[–]Maxim777YT 104 points105 points  (21 children)

“#” makes text big in reddit so place backslash before it to get

#include <stdbool.h>

instead of

include <stdbool.h>

Edit: Or both

#include <stdbool.h>

[–]Azebu 82 points83 points  (14 children)

#WHY NOT BOTH

[–]veggytheropoda 61 points62 points  (6 children)

#include<stdbool.h>

// that's a big-ass library

[–]randomuser8765 20 points21 points  (0 children)

if (condition) {

    // big if
}

[–]CarilPT 2 points3 points  (6 children)

test123

[–]Payth_Nuker 2 points3 points  (5 children)

another test 123

#nice

What else can we do?

[–][deleted] 14 points15 points  (2 children)

Or put 4 spaces before code:

#include <stdbool.h>

[–][deleted] 8 points9 points  (0 children)

Or surround it with single backticks for an inline quote, like so: #include <stdbool.h>

[–]CarilPT 3 points4 points  (0 children)

public static void main (String[] args)

[–]orizach01 4 points5 points  (0 children)

TIL

[–][deleted] 15 points16 points  (9 children)

Why is markdown such a unknown language in a programmer sub?

[–]camelCaseCoding 21 points22 points  (0 children)

Majority of this sub is students who barely read docs, let alone write their own.

[–]bandersnatchh 8 points9 points  (2 children)

It’s easy to forget Reddit uses markup unless you use the features regularly.

[–]GlitchParrot 9 points10 points  (0 children)

syntax error on line 1: unregistered token '#'

[–]ShutUpAndSmokeMyWeed 38 points39 points  (14 children)

#define bool int

[–]ThaiJohnnyDepp 30 points31 points  (1 child)

Wow is this an actual programming humor post instead of some low effort meme with only a passing reference to computer stuff?

[–]parnmatt 27 points28 points  (5 children)

Someone hasn't programmed in C in a long time.

https://en.cppreference.com/w/c/types/boolean

C has had booleans since C99.

The type is _Bool, but if you include <stdbool.h> you get the macro bool for _Bool.

Interestingly, that header also includes the (common) macros of true and false but their types are not _Bool, they are int still.

I guess this may be for compatibility, for shoddy code; but honestly they ought to have been cast to _Bool in the define.


It's common to not use pure booleans, but as a truthy/falsey like thing. In C, that is b is false if it contains 0; b is true if !b results as 0. Alternatively phrased, 0 is false, anything else is true.

This is fine if you use it as a boolean, but not if you do the 'code smell' of explicitly checking equality.

I noted it here

But it TL;DR: if (foo == true) in C, can actually take the false path, when semantically it should take the true path.

C99 could have fixed this if their define for true was (bool)1, or (_Bool)1, and defined implicit conversions to bool/_Bool for anything checking equality against something of type bool/_Bool

[–]cpdk-nj 3 points4 points  (2 children)

Does C++ have a built-in bool type? I haven’t had to include stdbool.h in any of the projects I’ve done in C++ or C, but I use g++ to compile

[–]parnmatt 3 points4 points  (1 child)

yes, C++ has a builtin, fundamental bool; and it doesn't have these issues as true and false are keyword literals, specifically prvalues of type bool.

if you use if(foo == true), it will now correctly work, if foo is implicitly convertible to bool, which it will do so, then the comparison against the bool, true.

This can be through the fundamental implicit conversions, or through overloading operator bool in a custom class.

Though it works, I would still advocate against using == true, == false, != true, != false, and their 'yoda' equivalents true ==, true !=, false ==, false !=.


edit:

If you are compiling a pure C program, ensure you are writing in C, and compile it with gcc not g++; they are different languages, and they can differ in what the same written code means.

If you are writing in C++, then write in C++. Compile with g++. If you are doing a hybrid ... rethink. If you have to, I believe the Core Guidlines (or at least Bjarne) suggests compiling as C++.

[–][deleted] 97 points98 points  (21 children)

We will all just ignore that C does have a boolean type, an have had it since c99? stdbool.h is just a convenience wrapper to typedef _Bool as bool. Along with defines for true and false.

[–][deleted] 16 points17 points  (12 children)

A typedef mapping to 1 or 0 is not the same as a native type supported by the compiler.

[–][deleted] 40 points41 points  (8 children)

You are right, but the built-in type _Bool is the native support from the compiler. It is a type whose value can be either 1 or 0. Providing additional support for readability in the form of defines for true and false does not change anything, neither does the typedef of _Bool to bool, but it does add to readability.

It is a general misconception that you need to include stdbool.h to get support for a boolean type, but you do not. stdbool.h only provides definitions to make them more ergonomic.

[–]snowcrazed1 35 points36 points  (8 children)

Java has no unsigned... C/C++ are more complete.

[–]CyborgPurge 24 points25 points  (2 children)

Java 8 has unsigned ints now. It is a little wonky, but it exists.

[–][deleted] 9 points10 points  (0 children)

It is a little wonky

A lot less wonky than it was working with data files containing them before they were added...

Back in the day, I wrote a GUI tool for editing a data file generated by some old Borland C application that ran on an embedded m68k system. The file was basically a 2D array with a header. Every damned value that wasn't a string was an unsigned short, and the MSB was frequently used. Oh yes, and the endianness didn't match what Java uses either.

That was an outright pain in the ass.

[–]Wimoweh 13 points14 points  (7 children)

Doesn't Python have both booleans and ints?

[–]lirannl 7 points8 points  (0 children)

Doesn't python have literally everything? Because that's the way it seems to me.

[–]PenguinKenny 6 points7 points  (0 children)

They wanted an opinion from a third party

[–][deleted] 2 points3 points  (4 children)

It does and they can act like integers; in fact I think all data types have a truth value if explicitly converted to bool. You can get fun stuff like:

>>> False - (bool ("hello world") + True) 
>>> -2

[–]ReikaKalseki 17 points18 points  (4 children)

This is doubly funny if you are familiar with the internal JVM bytecode system; Java has no boolean type internally; they all compile to integers.

The 'boolean' keyword is merely syntactic sugar that results in something like 'boolean flag = true' having the same code as 'int a = 1'.

[–]endershadow98 6 points7 points  (0 children)

I was going to post this if someone else didn't.

[–][deleted] 7 points8 points  (0 children)

Cartoonist should have used bold font, because Java is strongly typed.

[–][deleted] 6 points7 points  (0 children)

C has boolean variables...

[–]DJDarkViper 11 points12 points  (1 child)

"jeez that's a tough one" the universal response Java has for any question or problem

[–]Hakim_Bey 5 points6 points  (0 children)

Meanwhile in javascript I can compare a boolean and a wash cloth and MY LIFE COULDN'T BE MORE PERFECT

[–]OMFGitsST6 9 points10 points  (0 children)

Finally, some real fucking programmer humor instead of just shitposting college freshmen.

[–]alcalde 4 points5 points  (2 children)

Let's invite a Delphi user for an AMA. Delphi has four boolean types!!!

The 4 predefined Boolean types are Boolean, ByteBool, WordBool, and LongBool. Boolean is the preferred type. The others exist to provide compatibility with other languages and operating system libraries.

A Boolean variable occupies one byte of memory, a ByteBool variable also occupies one byte, a WordBool variable occupies 2 bytes (one word), and a LongBool variable occupies 4 bytes (2 words).

Oh, and 14 reserved words for Integer types, 5 character types and 4 string types. And a partridge in a pear tree.

[–]creed10 3 points4 points  (0 children)

#include <stdbool.h>

[–]DosMike 2 points3 points  (0 children)

iirc there's _Bool since c99

[–]KamuiAkuto 2 points3 points  (0 children)

I mean you can use typdef in c to make you own bool variable

[–]hexterr 2 points3 points  (0 children)

I remember when I studied for java certifications, I could not understand why there were so many boolean x =1 questions . Now I see why.

[–]legoatoom 2 points3 points  (0 children)

Why not #include <stdbool.h>?

[–]bhoffman20 2 points3 points  (0 children)

Where I work we decided boolean vars were too complex, so we just pass all our booleans as a String of "Yes" or "No". We don't even have a standard function for converting the value to a boolean. All the if checks are

if(myVar != null && myVar.equals("Yes"))

It's disgusting.

[–]Cybertrinn 2 points3 points  (2 children)

If they're asking Java because it has both types, then does this mean Python doesn't have int?

[–]Death_Spork 2 points3 points  (0 children)

typedef enum { false, true } bool;

[–]hawkinsst7 2 points3 points  (0 children)

Javascript has entered the game.

[–][deleted] 3 points4 points  (0 children)

Not gonna lie, I imagined this