Simple Boolean question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Simple Boolean question

Post by pickle »

Hi All,

I was wondering if there's a simpler way to write this line:

Code: Select all

$row_bool = !$row_bool
I know it's pretty simple as it is, but I just can't stop thinking that there's a simpler way. Obfuscation is no object!!
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Post by Lord Sauron »

???,

This must be about the shortest and most unclear question ever :?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I want to use fewer characters to do the same thing as:

Code: Select all

$row_bool = !$row_bool
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't think there is a fewer characters way.. really.. other than shortening the variable name. :?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

LOL
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ok, I was just wondering. It was just nagging at me that it was more complicated than it needed to be. Ah well, thanks for putting my mind to rest :)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

i dont see how thats complicated at all..
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

how is it more complicated than it should be? what do you think it should be? Or how could it be easier? I think

Code: Select all

$bool != $bool
Is pretty easy if you know that ! means not
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

problem is.. that's always false. :D
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

just as

Code: Select all

$bool = !$bool
would also always be false...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

actually, no.. your's doesn't set.. only checks.. pickles sets to the negation.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

ahh yes, i forgot, I was thinking of something different! haha my bad! :P
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Well, you know how

Code: Select all

$var = $var + 1; /*can be written*/ $var++;
I was just thinking maybe there was a simple shortcut like

Code: Select all

$var=!
or something.

The question was meant more as a curious pipe dream than a problem I was dealing with. Thanks anyway folks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply