Post increment and decrement

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 12 09:14:22 PDT 2015


On 12/03/2015 10:14, monarch_dodra wrote:
> On Wednesday, 11 March 2015 at 17:23:15 UTC, welkam wrote:
>> Observation Nr. 1
>> People prefer to write var++ instead of ++var.
>
> The root of your reasoning stems from this "observation", which I
> argue is wrong.
>
> The recommendation has always been to chose ++var, unless you
> have a reason to chose var++.

Where the result is not needed, var++ is probably more common. I'd 
rather read post-increments.

Grep -c phobos for simple for loops:

; word++):
etc/c/zlib/crc32.c:9
etc/c/zlib/deflate.c:1
etc/c/zlib/gzwrite.c:2
etc/c/zlib/inftrees.c:6
etc/c/zlib/trees.c:25
etc/c/zlib/zutil.c:2
std/algorithm.d:2
std/bitmanip.d:5
std/concurrency.d:1
std/container/rbtree.d:2
std/digest/md.d:1
std/digest/ripemd.d:1
std/digest/sha.d:2
std/math.d:3
std/parallelism.d:1
std/path.d:2
std/random.d:1
std/regex/internal/backtracking.d:3
std/regex/internal/ir.d:1
std/regex/internal/kickstart.d:5
std/regex/internal/parser.d:2
std/regex/internal/tests.d:1
std/regex/package.d:1
std/socket.d:8
std/stream.d:1
std/string.d:2
std/uni.d:18
std/uri.d:11
std/utf.d:3
std/uuid.d:2
std/windows/charset.d:1
std/zip.d:2
std/zlib.d:3
unittest.d:1

; ++word):
std/algorithm.d:8
std/bitmanip.d:1
std/encoding.d:7
std/format.d:4
std/internal/math/biguintcore.d:9
std/internal/math/biguintnoasm.d:17
std/internal/math/biguintx86.d:14
std/internal/math/gammafunction.d:2
std/math.d:1
std/numeric.d:2
std/process.d:3
std/random.d:3
std/stream.d:2
std/utf.d:1
std/windows/registry.d:4
std/xml.d:1



More information about the Digitalmars-d mailing list