The Comma Operator's Deprecation Can't Come Soon Enough
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 15 12:46:04 PDT 2014
On Tue, Jul 15, 2014 at 07:16:17PM +0000, Martin Krejcirik via Digitalmars-d wrote:
> On Tuesday, 15 July 2014 at 18:50:08 UTC, John Colvin wrote:
> >and not just because I don't like the comma. I'd say it's generally
> >bad practice to hide that write to `flag` inside the
>
> You are right for the 'final' code, but the point of my example is,
> that I can move the flag to another if and don't have to change
> anything else.
>
> Also an assignment is not allowed in a condition and without the comma
> operator, it wouldn't be possible at all. That's way too restrictive.
Not true:
T* ptr;
if ((ptr = getPtr()) !is null) {
...
}
Nevertheless, it's a bad idea to have side effects in if-conditions. It
makes code hard to follow, and is a cosy place for subtle bugs to hide.
T
--
Never trust an operating system you don't have source for! -- Martin Schulze
More information about the Digitalmars-d
mailing list