dolibarr-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dolibarr-dev] Start using booleans instead of integers acting like


From: Laurent Destailleur (eldy)
Subject: Re: [Dolibarr-dev] Start using booleans instead of integers acting like booleans
Date: Mon, 06 Aug 2012 12:42:17 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0

Le 06/08/2012 08:29, Régis Houssin a écrit :
as Marcos says, for some cases it may be useful in differentiating 0 and false, false as a state and a 0 value, it could avoid mistakes.

This should never happen.
If we need a third status, we must add status -1 or 2 (to 0 and 1) but we should not mix types.




Le 06/08/12 01:44, Laurent Destailleur (eldy) a écrit :
Le 06/08/2012 01:17, Marcos García a écrit :
Hello,

I've checked Dolibarr's code and I've seen that many functions are using integers 1 and 0 as booleans, which actually shouldn't be used because:
1. When checking for True or False, it could be a conflict between 0 and False

This should not happen because when a variable int is used as a boolean, we want 0 to be false and 1 to be true. And this is the defautl behaviour of PHP:
0=false
1=true

We simply should never use boolean but we prefer using integer with rule (0=false, 1 or other = true). When we need a third value (2), we can replace test if ($var) with if ($var==1) or if ($var ==2) according to what we want to do.

That's why we must only use integer.
Boolean is a type very useless and we often need to modify to support a third value, so let's start from scratch with directly int. Even if at the beginning, we need only 2 values.
2. It's not a good practice.

I think this should not be changed immediately but start migrating into it.

Regards,
 
Marcos García
address@hidden



_______________________________________________
Dolibarr-dev mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev


-- 
Eldy (Laurent Destailleur).
---------------------------------------------------------------
EMail: address@hidden
Web: http://www.destailleur.fr

Dolibarr (Project leader): http://www.dolibarr.org
To make a donation for Dolibarr project via Paypal: address@hidden
AWStats (Author) : http://awstats.sourceforge.net
To make a donation for AWStats project via Paypal: address@hidden
AWBot (Author) : http://awbot.sourceforge.net
CVSChangeLogBuilder (Author) : http://cvschangelogb.sourceforge.net


_______________________________________________
Dolibarr-dev mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

Cordialement,
-- 
Régis Houssin
---------------------------------------------------------
Cap-Networks
Cidex 1130
34, route de Gigny
71240 MARNAY
FRANCE
VoIP: +33 1 83 62 40 03
GSM: +33 6 33 02 07 97
Web: http://www.cap-networks.com/
Email: address@hidden

Dolibarr developer: address@hidden
Web Portal: http://www.dolibarr.fr/
SaaS offers: http://www.dolibox.fr/
Shop: http://www.dolistore.com/
Development platform: https://doliforge.org/
---------------------------------------------------------


-- 
Eldy (Laurent Destailleur).
---------------------------------------------------------------
EMail: address@hidden
Web: http://www.destailleur.fr

Dolibarr (Project leader): http://www.dolibarr.org
To make a donation for Dolibarr project via Paypal: address@hidden
AWStats (Author) : http://awstats.sourceforge.net
To make a donation for AWStats project via Paypal: address@hidden
AWBot (Author) : http://awbot.sourceforge.net
CVSChangeLogBuilder (Author) : http://cvschangelogb.sourceforge.net

reply via email to

[Prev in Thread] Current Thread [Next in Thread]