Bug 186 – 'and' and 'or' as alternatives for && and ||

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P5
Component
dmd
Product
D
Version
D1 (retired)
Platform
PowerPC
OS
Mac OS X
Creation time
2006-06-08T12:55:00Z
Last change time
2014-02-15T13:20:42Z
Assigned to
bugzilla
Creator
barnaby

Comments

Comment #0 by barnaby — 2006-06-08T12:55:05Z
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.
Comment #1 by bugzilla — 2006-06-09T04:03:45Z
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.