www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 186] New: 'and' and 'or' as alternatives for && and ||

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=186

           Summary: 'and' and 'or' as alternatives for && and ||
           Product: D
           Version: 0.157
          Platform: Macintosh
        OS/Version: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: barnaby daltonsgate.com


example:

if("aardvark" < "zebra" and "C" < "D")
    writefln("all is right in the world");

I've found this is a small change that really helps. Especially when it has
lower precedence than &&, ||.
For example:

while(obj = getobj() && good(obj)) { ... }

actually means:

while(obj = (getobj() && good(obj)) { ... }

with the C precedence. This doesn't compile (unless obj is a boolean).
With lower precedence, the extra brackets would not be needed for this
to give the natural interpretation. I find this pattern comes up commonly,
and I miss it from higher level languages like Ruby.


-- 
Jun 08 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=186


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX





In C++, 'and' and 'or' are already alternatives for && and ||, and they have
the same precedence as && and ||. Adding them to D, but with different
precedence, is likely to cause confusion and hard to spot bugs, especially for
someone who is a long time C or C++ programmer.

The reason they were added to C++ was not because they were more readable, but
because some keyboards don't have & and | keys. This has turned out to be a
waste of time - most programmers find the "alternative tokens" to be awful and
find it easier to spend $10 on a new keyboard.

Many people believe that C and C++ (and by implication D) already have far too
many operators and too many precedence levels. Adding more will not be welcomed
- unless those new operators really solved a desperate problem. That's a pretty
high bar to overcome.

And lastly, this is a bug list. Feature enhancement requests shouldn't go here.
Discussion about feature requests should go in the newsgroups, and there are
wiki pages with lists of the more popular ones.


-- 
Jun 09 2006