Otte: staring into the abyss
Posted Aug 6, 2012 13:02 UTC (Mon) by jzbiciak
(✭ supporter ✭
In reply to: Otte: staring into the abyss
Parent article: Otte: staring into the abyss
My rule is simple: avoid the boring and evil (one is hard to write: the other is hard to read). What is boring to me is that repeated-over-and-over 'stic->' in your example: what is evil is a spaced-out initializer with a lot of space in which the eye gets lost.
In Pascal, I could have used a "with" block, but C lacks such things. In perl, I use the fat comma in a nicely indented initializer block:
my %hash =
foo => 0,
bar => 42,
baz => 1,
quux => 1234,
gronk => 0
The particular code I shared earlier (the STIC code) actually largely pre-dates wide availability of C's designated initializers. With a modern C compiler I would instead consider putting initializers like that block into const structures and use structure assignment to copy the block in in one go. That would both eliminate the boring repeated prefix, and would also likely reduce the overall code footprint since it would replace the discrete scalar assignments with a loop.
to post comments)