[Issue 10862] Assignment inside if condition still sometimes accepted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 21 06:33:14 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10862



--- Comment #13 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-08-21 06:33:11 PDT ---
(In reply to comment #12)
> That said, I'm a real bitch for vertical alignment

Sure I like that too.

(In reply to comment #12)
> as well as clear repeatable instructions per line. 

That sounds like code duplication to me. The constraint could have been:

if(op.canFind("<", "<=", "==", "!=", ">=", ">")) { }

But then there are other code duplications which are just lazy, such as:

if(msg.empty)
{
    throw new AssertError(format(`_assertPred!"%s" failed: Return value of [%s]
%s [%s] was [%s] instead of [%s].`,
                                 op,
                                 origLHSStr,
                                 op,
                                 rhs,
                                 result,
                                 expected),
                           file,
                           line);
}
else
{
    throw new AssertError(format(`_assertPred!"%s" failed: Return value of [%s]
%s [%s] was [%s] instead of [%s]: %s`,
                                 op,
                                 origLHSStr,
                                 op,
                                 rhs,
                                 result,
                                 expected,
                                 msg),
                           file,
                           line);
}

Why not reduce this to:

string tail = msg.empty ? "." : format(": %s", msg);
throw new AssertError(format(`_assertPred!"%s" failed: Return value of [%s] %s
[%s] was [%s] instead of [%s]%s`,
                             op,
                             origLHSStr,
                             op,
                             rhs,
                             result,
                             expected,
                             tail),
                       file,
                       line);

Boom I saved you 8 lines. Don't tell me this is somehow slowing down
performance, the cost of throwing an exception is much higher than allocating a
small string. Plus AssertError is typically unrecoverable.

All of this duplication adds up, and you end up with the massive std.datetime.
Meanwhile someone believes they have to save that one whitespace character in
the "if" statement. It's completely absurd.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list