What I personally would generally include would be a comment
along the lines of "this struct represents the KillAllHumans
message body as per " where the struct is
defined, and then a comment along the lines of "overlay our
message structure over the buffer to extract our data". This way
even if someone wasn't familiar with the bitset notation, they
could probably infer it.
I agree, comments are for the information you add, although well
thought out variable names go a long way to making code
understandable:
/* as per some specification */
struct KillAllHumans_Body {
...
}
I'll grant you that perl is very organic, probably the best "code
as you think" language that I know of, but the vast collection of
syntax and the functional density one can achieve (and some seem
compelled to do so) makes it a pain to read if you didn't write
it.
I am not disputing that it is easy to write obfuscated Perl but
Perl style guidelines have come a very long way with
Perl Best Practices by Damian Conway and the Perl::Critic
module and the perlcritic
program. There is a lot of Perl code written by other people
that I find very easy to read. The key is to write clear code
and use good variable and function names. The sigils provide
context (and higher information density) which is what makes
good Perl code easier to read than good Java or C code. YMMV.
Gregory Chaitin, one of the founders of algorithmic information
theory once said in jest:
The LISP interpreter is about three-hundred
lines of Mathematica code. Then I redid it in C, and it's a
thousand lines of C, and the program is incomprehensible,
which means that I'm a good C programmer!
Perl does tempt you to show off by writing incomprehensible
(and perhaps incompressible) code. The style guidelines and
experience can help you avoid this temptation.
IMO, the Camel Book is informationally dense. One reading was
not nearly enough for me. I probably have read it all at least a
half dozen times. I haven't used it in years because it is
almost all on-line now and also part of the perldoc system.
[...] how do you iterate through an array of hashmap references [...]
for my $hash_ref in (@Array_of_hash_refs) {
... $hash_ref->{$key} ...
}
IMO, with descriptive variable names this construct is both
easy and clear. I think it is beautiful. If you want to
access just one element then use:
$Array_of_hash_refs[$index]->{$key}
For nested data structures like this I prefer to make the top
level structure a reference so this becomes:
$Array_of_hash_refs->[$index]->{$key}
Which I think is a little more consistent.
I've taught Perl in college and I admit there are some
(perhaps many) people who will never master it. OTOH,
I once wrote a CSM system in Perl in the time the Java
folks said they would need to come up with an estimate
for how long it would take them to do it.