www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Wouldn't it be better if ...

reply Peter <Peter_member pathlink.com> writes:
I was looking at some of the modules such as ctype and math, and see that the
"is" functions (i.e. isalpha, isnan) return a value of type int.  Given that
this is a modern language having boolean types available, would it not be better
to return a value of type boolean?  I'm thinking that code would be clearner.
May 02 2004
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Sure would, but we can't agree on what boolean would be!

I think it should be an integral type, whose size is the same as that of the
architecture (for performance; the various supporting reasons for this are in my
<self-serving promotion>forthcoming book "Imperfect C++"</self-serving
promotion>), and which should *not* be implicitly convertible to/from any other
integral type.

But Walter, and a handful of other people, seem content to have it be aliased to
bit.

In the libraries I write, I typedef (remember D's typedefs are strong ones)
boolean from int, and use the casts as appropriate to return them. Walter
doesn't
like this, but I'm immutable on this point.

"Peter" <Peter_member pathlink.com> wrote in message
news:c74i4i$l54$1 digitaldaemon.com...
 I was looking at some of the modules such as ctype and math, and see that the
 "is" functions (i.e. isalpha, isnan) return a value of type int.  Given that
 this is a modern language having boolean types available, would it not be
better
 to return a value of type boolean?  I'm thinking that code would be clearner.
May 02 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

Sure would, but we can't agree on what boolean would be!

I think it should be an integral type, whose size is the same as that of the
architecture (for performance)
  

But Walter, and a handful of other people, seem content to have it be aliased to
bit.
  
Won't bit be an integral type be a size that is optimal for the architecture. I mean for the systems we use now byte is the most optimal choice for Boolean (due to caching and other factors). If your using a single bit then it will be the size of a byte. -- -Anderson: http://badmama.com.au/~anderson/
May 02 2004
prev sibling parent reply School <itsnotvalid-news yahoo.com.hk> writes:
Matthew 提到:
 Sure would, but we can't agree on what boolean would be!
 
 I think it should be an integral type, whose size is the same as that of the
 architecture (for performance; the various supporting reasons for this are in
my
 <self-serving promotion>forthcoming book "Imperfect C++"</self-serving
 promotion>), and which should *not* be implicitly convertible to/from any other
 integral type.
 
 But Walter, and a handful of other people, seem content to have it be aliased
to
 bit.
 
 In the libraries I write, I typedef (remember D's typedefs are strong ones)
 boolean from int, and use the casts as appropriate to return them. Walter
doesn't
 like this, but I'm immutable on this point.
 
 "Peter" <Peter_member pathlink.com> wrote in message
 news:c74i4i$l54$1 digitaldaemon.com...
 
I was looking at some of the modules such as ctype and math, and see that the
"is" functions (i.e. isalpha, isnan) return a value of type int.  Given that
this is a modern language having boolean types available, would it not be
better
to return a value of type boolean?  I'm thinking that code would be clearner.
It would be even better if you write a book called "Learning D" or "The D Programming Language" or "Thinking in D" or "Prefect D".
May 03 2004
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
"School" <itsnotvalid-news yahoo.com.hk> wrote in message
news:c75hcv$23rj$1 digitaldaemon.com...
 Matthew 提到:
 Sure would, but we can't agree on what boolean would be!

 I think it should be an integral type, whose size is the same as that of the
 architecture (for performance; the various supporting reasons for this are in
my
 <self-serving promotion>forthcoming book "Imperfect C++"</self-serving
 promotion>), and which should *not* be implicitly convertible to/from any
other
 integral type.

 But Walter, and a handful of other people, seem content to have it be aliased
to
 bit.

 In the libraries I write, I typedef (remember D's typedefs are strong ones)
 boolean from int, and use the casts as appropriate to return them. Walter
doesn't
 like this, but I'm immutable on this point.

 "Peter" <Peter_member pathlink.com> wrote in message
 news:c74i4i$l54$1 digitaldaemon.com...

I was looking at some of the modules such as ctype and math, and see that the
"is" functions (i.e. isalpha, isnan) return a value of type int.  Given that
this is a modern language having boolean types available, would it not be
better
to return a value of type boolean?  I'm thinking that code would be clearner.
It would be even better if you write a book called "Learning D" or "The D Programming Language" or "Thinking in D" or "Prefect D".
Well, you may be onto something there. ;)
May 03 2004
parent reply Brad Anderson <brad dsource.dot.org> writes:
http://www.thedprogramminglanguage.com/

Wonder who owns that domain name...

Matthew wrote:
 "School" <itsnotvalid-news yahoo.com.hk> wrote in message
 news:c75hcv$23rj$1 digitaldaemon.com...
 
Matthew 提到:

Sure would, but we can't agree on what boolean would be!

I think it should be an integral type, whose size is the same as that of the
architecture (for performance; the various supporting reasons for this are in
my
<self-serving promotion>forthcoming book "Imperfect C++"</self-serving
promotion>), and which should *not* be implicitly convertible to/from any
other
integral type.

But Walter, and a handful of other people, seem content to have it be aliased
to
bit.

In the libraries I write, I typedef (remember D's typedefs are strong ones)
boolean from int, and use the casts as appropriate to return them. Walter
doesn't
like this, but I'm immutable on this point.

"Peter" <Peter_member pathlink.com> wrote in message
news:c74i4i$l54$1 digitaldaemon.com...


I was looking at some of the modules such as ctype and math, and see that the
"is" functions (i.e. isalpha, isnan) return a value of type int.  Given that
this is a modern language having boolean types available, would it not be
better
to return a value of type boolean?  I'm thinking that code would be clearner.
It would be even better if you write a book called "Learning D" or "The D Programming Language" or "Thinking in D" or "Prefect D".
Well, you may be onto something there. ;)
May 04 2004
parent reply Stephan Wienczny <wienczny web.de> writes:
If you look at the whois entry, you will see that the owner is Synesis 
Software and the administrative contact is
Dr Matthew D. Wilson

Brad Anderson wrote:
 http://www.thedprogramminglanguage.com/
 
 Wonder who owns that domain name...
 
May 04 2004
parent Brad Anderson <brad dsource.dot.org> writes:
I'm shocked beyond all reason.  ;)

Stephan Wienczny wrote:
 If you look at the whois entry, you will see that the owner is Synesis 
 Software and the administrative contact is
 Dr Matthew D. Wilson
 
 Brad Anderson wrote:
 
 http://www.thedprogramminglanguage.com/

 Wonder who owns that domain name...
May 04 2004
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Peter" <Peter_member pathlink.com> wrote in message
news:c74i4i$l54$1 digitaldaemon.com...
 I was looking at some of the modules such as ctype and math, and see that
the
 "is" functions (i.e. isalpha, isnan) return a value of type int.  Given
that
 this is a modern language having boolean types available, would it not be
better
 to return a value of type boolean?  I'm thinking that code would be
clearner. Generally, a computation of 0 or !0 involves one or two less instructions than converting it to 0 or 1.
May 02 2004
parent reply Hauke Duden <H.NS.Duden gmx.net> writes:
Walter wrote:
 "Peter" <Peter_member pathlink.com> wrote in message
 news:c74i4i$l54$1 digitaldaemon.com...
 
I was looking at some of the modules such as ctype and math, and see that
the
"is" functions (i.e. isalpha, isnan) return a value of type int.  Given
that
this is a modern language having boolean types available, would it not be
better
to return a value of type boolean?  I'm thinking that code would be
clearner. Generally, a computation of 0 or !0 involves one or two less instructions than converting it to 0 or 1.
Well, then maybe a boolean shouldn't be a bit (hint,hint), but its own type where true simply means !=0. IMHO, your using int instead of bool for a situation where you really MEAN a boolean is a tell-tale sign that something is wrong with the current bool implementation. Not that it hasn't been mentioned before ;). Hauke
May 03 2004
parent "Walter" <newshound digitalmars.com> writes:
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message
news:c752e6$1e7a$1 digitaldaemon.com...
 Walter wrote:
 Generally, a computation of 0 or !0 involves one or two less
instructions
 than converting it to 0 or 1.
Well, then maybe a boolean shouldn't be a bit (hint,hint), but its own type where true simply means !=0.
I'm just one of those people, probably very few in number, who think that C got it right by using 'int' for it and testing for 0 or !0. It's very efficient, and I am loathe to give that up for anything less than a thoroughly compelling reason. It's served me well for 20+ years of C coding. There are 3 scenarios for a boolean: 1) need it to be fast 2) need a single value to be small 3) need a packed array of boolean values 'int' serves (1) well. D's 'bit[]' serves (3), and 'bit' does double duty by also being a byte wide value when used outside of an array, serving (2).
 IMHO, your using int instead of bool for a situation where you really
 MEAN a boolean is a tell-tale sign that something is wrong with the
 current bool implementation.
While I see your point, I don't view it that way. I view it as getting comfortable using an idiom that maps well onto efficient execution on the hardware. Perhaps one reason I am so comfortable with it is all the assembler programming I've done.
 Not that it hasn't been mentioned before ;).
Indeed. I recall the usenet flame wars on this back in the 1980's. The various camps have all long since dug in and well fortified their positions, so I don't think anyone is going to change their mind <g>.
May 03 2004