Whoever wrote that line of code and didn't comment it should be shot.
Ahem.
The code (tries to?[1]) compose a 32-bit pattern from the
(supposedly?[1]) 8-bit patterns for 4,3,'K','P' in that order (MSB),
it's the standard way to do it.
what would you like the comment to say? please not:
int four = 2 + 2 // set four equal to the sum of 2 plus 2
Comments that points out comment common idioms or language features:
- doesn't really add any information not already available in code
- needs maintenance when refactoring
- water out the value of comments, so you don't spot the ones that
matter, like:
// must keep list sorted to maintain far-away-class Foo invariant
The code-reader will need to understand the language and idioms to
understand the code anyway, and you don't want a page of explanation on
every expression or statement.
Besides, there is an easy way to find out what the code does, check the
language reference or a book on C#, or even just a newsgroup
The fact that I have to reference [1] shows that I lack understanding of
the language/complier to adequately evaluate what's happening. No
*simple* comment could be given here to explain why the coder chose this
implementation.
What would be nice would probably be a reference to WHERE it is defined
that LOCSIG should be this value, for example "see ProtocolFoo rev1.4,
p523, table 15". And that site should probably explain why the coder has
chosen to use the compiler-charater-set for two of the values, and int's
for two other.
BTW: LOGSIC should *probably* be an unsigned int, since it seems to
really be a bit-pattern. and you could get a nasty surpise when doing
LOGSIC >> 24 on an int (not a problem here, since (LOGSIC & 80000000) ==
0) (Another thing I wouldn't like to write in a comment
[1]. I'm not entirely up to scratch on C# compilers, character-sets and
the "'" operator. Isn't the C# compiler using some default char-set of
the environment (like C-compilers)? and 'P' might have some
non-ascii-'P'-encoding in, for example, a EBCDIC environment?