in reply to Re^5: quickness is not so obvious
in thread quickness is not so obvious

The coding guidelines my colleageues and I are required to follow include:

There are also guidelines that specify that an assignment or assignment-like operator must be the left most operator in expressions and only one is allowed. These are also to avoid non-obvious side effects.

There are many other guidelines. When we violate a guideline we are required to document and justify the violation (unless there is an exception granted in the guidelines).

As a practical matter, my colleagues and I don't make as many violations of the guidelines as we should because of the time and effort to justify the violations. Getting more exceptions added is possible but is very difficult. The do { } while (--i); exception was among the easiest as we were able to show assembly language listings, generated by the compilers, which clearly showed the difference. Even then, it involved 5 or 6 presentations and reviews to get all the needed approvals.

Replies are listed 'Best First'.
Re^7: quickness is not so obvious
by LanX (Saint) on Jan 24, 2015 at 19:55 UTC
    > Use the postfix form when using ++ or --in an expression. To be consistant with i += 1

    but isn't this - as a sub expression - effectively a preincrement?

    Cheers Rolf

    PS: Je suis Charlie!

      Not only is it a preincrement, but the increment operator is on the left so when parsed by my eye i += 1 looks more like ++i than that other option.

      So the rationalising failed on both counts!

      Perl is the programming world's equivalent of English

      I didn't say it made technical sense.

      As a foot note to the quoted guideline: The guideline maintainers consider i++ to be shothand for i += 1 and consider the i++ form to better imply that relationship than the the ++i form.

      Again, I did not say it made technical sense.

      Also...

      Under "our" guidelines, i += x would not be a sub-expression.

      RonW said:
      There are also guidelines that specify that an assignment or assignment-like operator must be the left most operator in expressions and only one is allowed.

      I guess I should have included those in the <ul> list in my earlier post.

        So you are not allowed to use goatse?

        Does this rule also exclude call(i++) ?

        Cheers Rolf

        PS: Je suis Charlie!