You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a need for the boolean type at all, other than backwards compatibility?
Currently, Arduino's boolean type is defined as an alias to bool (thanks, Chris--A!). However I don't see the need to have a custom boolean type when C and C++ already provide one.
Advantages of the bool type are:
it is shorter
it is standard
it is consistent with other "abbreviated" C and C++ types such as int and char
I think it would be a good idea to stop using this custom boolean type and instead use the bool one; in my opinion, the fewer unneeded additions Arduino makes to the language, the better.
The steps for moving would be (in this order):
Replace all boolean from Arduino core and library functions with bool.
Update the documentation, removing all references to boolean and replacing them with bool (and maybe adding a note that the boolean type is deprecated).
State that the boolean type is deprecated. An __attribute__ ((deprecated ("use bool instead"))) on the boolean definition could be a good idea.
Eventually, a few versions after deprecating boolean, consider its removal. (Or leave it there forever, just in case.)
Reacted by Matt Baker, Avamander, Michał Kiełtyka, Tomáš Moravec, Rafael Campos Nunes, Pharap, Ladislas de Toldi, Rotzbua, Daniel A. A. Pelsmaeker, Frederic Pillon and 2 more
Is anyone against changing all usage of boolean in the Arduino cores, Arduino libraries, and example sketches to bool, accompanied by the same change in the reference pages? I'm willing to submit pull requests for the code changes but would like to get an idea if there are any objections first because it means multiple PRs to the various repos and I wouldn't want to make a lot of "noise" for something that is not actually wanted. I can't make the documentation changes but I can provide a list of all pages that need editing.
I'm against ever actually removing the boolean typedef. Maybe it never should have been done in the first place but now it's used in so much code that removing it would cause massive problems.
Reacted by NicoHood, Ladislas de Toldi, John Holman and Pharap
In case there's any confusion of how deprecating things works in either compiler, there's an example here of someone marking type aliases as deprecated with both GCC and MSVC (Visual Studio).
(Sadly had we been at the stage where most compilers were C++14 compliant it would have been as simple as [[deprecated("don't use boolean, use bool")]] instead.)
For now it's probably alright to just have the compiler detection boilerplate around where boolean is being declared (following a YAGNI approach), but if more things ever need deprecating in the future it might be better to define a DEPRECATED(name) macro with a different definition depending on which compiler is present (following a DRY approach).
(It would unfortunately mean introducing a new symbol that might leak out into user code, but having a large chunk of compiler-detecting code around everything that's ever deprecated is probably just asking for typos.)
@per1234 If people opt for the 'ease it in' option, I think the examples should still be changed along with the library code. Users should be given warning that the change is going to happen, but it should be made clear that it's going to happen and there's no backing out of it. Plus any new users who learn from those examples should be being taught the newly preferred approach, not the soon-to-be-deprecated approach (which will soon be giving them 'scary' warnings).
I would welcome a switch to the standard bool type, though in the end I think @cmaglie or @facchinm should comment whether they would want to merge such a change.
Reacted by Pharap, Kristoffer Engdahl, John Holman and Rotzbua
Activity
NicoHood commentedon Mar 10, 2016
I agree fully with your idea and down want to repeat them, cause they are exactly what I think too.
matthijskooijman commentedon Mar 10, 2016
Sounds like a good plan. Might be good to do this at a 1.7/1.8 release, not in a point release, though. I guess this also ties in with #4525 a bit.
matthijskooijman commentedon Mar 10, 2016
Sounds like a good plan. Might be good to do this at a 1.7/1.8 release, not in a point release, though. I guess this also ties in with #4525 a bit.
Also, using the deprecated attribute is a good plan (we should consider doing that more often) and apparently it actually works on typedefs too.
NicoHood commentedon Mar 12, 2016
Yo we should also use the depreciated thing for SerialEvent.
Use bool instead of boolean in examples
Use bool instead of boolean in examples
per1234 commentedon Jul 4, 2017
Is anyone against changing all usage of
booleanin the Arduino cores, Arduino libraries, and example sketches tobool, accompanied by the same change in the reference pages? I'm willing to submit pull requests for the code changes but would like to get an idea if there are any objections first because it means multiple PRs to the various repos and I wouldn't want to make a lot of "noise" for something that is not actually wanted. I can't make the documentation changes but I can provide a list of all pages that need editing.If that's considered too abrupt a change we could ease into it by first adding a note to https://www.arduino.cc/en/Reference/BooleanVariables and removing
booleanonly from library code but not from examples. Then making the rest of the change after some months delay. I'm not sure whether that would be terribly effective, probably better to just make the full change all at once.I'm against ever actually removing the
booleantypedef. Maybe it never should have been done in the first place but now it's used in so much code that removing it would cause massive problems.NicoHood commentedon Jul 4, 2017
Just do the full switch and add a depreciated pragma so users start switching their code. It really causes less errors and confusion.
https://msdn.microsoft.com/en-us/library/c8xdzzhh.aspx
Use bool instead of boolean in drivers (#888)
cousteaulecommandant commentedon Jul 6, 2017
@NicoHood that link is for VisualStudio though; not sure if that pragma works for GCC as well. GCC uses
__attribute__ ((__deprecated__)).Pharap commentedon Aug 4, 2017
In case there's any confusion of how deprecating things works in either compiler, there's an example here of someone marking type aliases as deprecated with both GCC and MSVC (Visual Studio).
(Sadly had we been at the stage where most compilers were C++14 compliant it would have been as simple as
[[deprecated("don't use boolean, use bool")]]instead.)For now it's probably alright to just have the compiler detection boilerplate around where
booleanis being declared (following a YAGNI approach), but if more things ever need deprecating in the future it might be better to define aDEPRECATED(name)macro with a different definition depending on which compiler is present (following a DRY approach).(It would unfortunately mean introducing a new symbol that might leak out into user code, but having a large chunk of compiler-detecting code around everything that's ever deprecated is probably just asking for typos.)
@per1234 If people opt for the 'ease it in' option, I think the examples should still be changed along with the library code. Users should be given warning that the change is going to happen, but it should be made clear that it's going to happen and there's no backing out of it. Plus any new users who learn from those examples should be being taught the newly preferred approach, not the soon-to-be-deprecated approach (which will soon be giving them 'scary' warnings).
matthijskooijman commentedon Aug 18, 2017
I would welcome a switch to the standard
booltype, though in the end I think @cmaglie or @facchinm should comment whether they would want to merge such a change.Replace boolean with standard bool.
Replace boolean with standard bool.
Replace boolean with standard bool.
ESPiLight.(h|cpp): Replace boolean with standard bool.
change boolean to bool
Use bool instead of boolean
Use bool instead of boolean
Use bool instead of boolean
Replace boolean with standard bool
Replace boolean with standard bool
Replace boolean with standard bool (#42)
Squashed commit of the following:
Use bool instead of boolean
Use bool instead of boolean
Use bool instead of boolean