On Sun, 18 Jan 2015 23:16:11 +0000
Jens Bauer via Digitalmars-d <[email protected]> wrote:

> I'd like to give an example on a different use of the same 
> feature:
> 
> while(length--)
> {
>      *d++ = *s++;
> }
> if(length == -1)  /* the programmer will need to know the value 
> of length here. */
> {
>      /* handle case where length was exactly 0, it's now -1 */
> }
> 
> would become:
> 
> while(length--)
> {
>      *d++ = *s++;
> }
> otherwise
> {
>      /* handle case where length was exactly 0, it's now -1 */
> }
> 
first sample is just a bad code, but second sample is a kind of cypher.

there is no sense in doing such microoptimisations, as decent modern
compiler is able to do dataflow analysis and cse. and both samples are
bad, 'cause they violates the rule "check first, then process".

did you profile your code and found that such loops are real
bottlenecks? i bet they aren't. yet they less readable than clearly
spelled preconditions.

this is microoptimisation in the sake of microoptimisation, it wins
almost nothing and hurts code readability.

all in all it's one of that things that looks nice, but makes more
problems than they are able to solve. that's why language design is
hard: nicely looking features can have many unforseen consequences. ;-)

Attachment: signature.asc
Description: PGP signature

Reply via email to