Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- From: Douglas Alan <darkwater42@xxxxxxxxx>
- Date: Sat, 15 Aug 2009 13:01:43 -0700 (PDT)
On Aug 14, 10:25 pm, Dave Angel <da...@xxxxxxxx> wrote:
Benjamin Kaplan wrote:
On Fri, Aug 14, 2009 at 12:42 PM, Douglas Alan <darkwate...@xxxxxxxxx>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.
.
- Follow-Ups:
- Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- From: Steven D'Aprano
- Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- References:
- Unrecognized escape sequences in string literals
- From: Douglas Alan
- Re: Unrecognized escape sequences in string literals
- From: Aahz
- OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- From: Steven D'Aprano
- Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- From: Grant Edwards
- Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- From: Douglas Alan
- Unrecognized escape sequences in string literals
- Prev by Date: Re: getting the fractional part of a real?
- Next by Date: PyQt4.__file__ gives PyQt4/__init__.py as value
- Previous by thread: Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- Next by thread: Re: OT Signature quote [was Re: Unrecognized escape sequences in string literals]
- Index(es):
Relevant Pages
|