On Aug 14, 10:25 pm, Dave Angel <da...@ieee.org> wrote: > Benjamin Kaplan wrote:
> > On Fri, Aug 14, 2009 at 12:42 PM, Douglas Alan <darkwate...@gmail.com>wrote: > >> P.S. Overloading "left shift" to mean "output" does indeed seem a bit > >> sketchy, but in 15 years of C++ programming, I've never seen it cause > >> any confusion or bugs. > > The only reason it hasn't is because people use it in "Hello World". I bet > > some newbie C++ programmers get confused the first time they see << used to > > shift. People typically get confused by a *lot* of things when they learn a new language. I think the better metric is how people fare with a language feature once they've grown accustomed to the language, and how long it takes them to acquire this familiarity. > Actually, I've seen it cause confusion, because of operator precedence. > The logical shift operators have a fairly high level priority, so > sometimes you need parentheses that aren't obvious. Fortunately, most > of those cases make compile errors. I've been programming in C++ so long that for me, if there's any confusion, it's the other way around. I see "<<" or ">>" and I think I/ O. I don't immediately think shifting. Fortunately, shifting is a pretty rare operation to actually use, which is perhaps why C++ reclaimed it for I/O. On the other hand, you are right that the precedence of "<<" is messed up for I/O. I've never seen a real-world case where this causes a bug in C++ code, because the static type-checker always seems to catch the error. In a dynamically typed language, this would be a much more serious problem. |>ouglas P.S. I find it strange, however, that anyone who is not okay with "abusing" operator overloading in this manner, wouldn't also take umbrage at Python's overloading of "+" to work with strings and lists, etc. Numerical addition and sequence concatenation have entirely different semantics. -- http://mail.python.org/mailman/listinfo/python-list