[Forwarded message from Russel Winder]

Subject: Re: PPIG discuss: Mixing decimal & hexadecimal
From: Prof Russel Winder <[EMAIL PROTECTED]>
To: Derek M Jones <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Date: 16 Apr 2001 23:29:57 +0100

Derek,

> Conceptually they are likely to represent different kinds of data.  One is a
> numeric value and the other is likely to be a pattern of bits (ok, the hex 
> value
> may be an address value being represented in hex for convenience).

Whilst it may be more normal to use octal or hex only for memory
addresses or values that directly represent bit patterns, or in the case
of hex, nibbles in a byte sequence, you are making an assumption that
there is a direct relationship between the syntax and the semantics.  I
do not think the assumptions you are making are entirely valid.

Certainly, people are more often than not taught that hex is for
addresses and bit-patterns and decimal is for proper numbers and it is
true that if you indoctinate people for long enough they begin to
believe the factoids they are told to be the truth.  Thus any amount of
experimentation or argumentation is going to have to deal with the issue
that this is a truth determined by forced usage rather than anything
deeper in the cognitive issues.

> Arrays are normally used to represent a sequence of the same kind of data.
> So mixing decimal and hex is suspect.

Why?
 
> The situation can be more complex for structures.  In this case individual
> members can have different uses:
> 
> struct {
>             int some_value;
>             int some_bits;
>             int another value;
>            } information[ 3 ]   = { { 23, 0x4f, 43},
>                                            {  0, 0xea,  8},
>                                            {  1, 0x00,  2}};
> 
> 
> The list of numeric values are not paired with each other, but the members
> of the struct.  So mixing decimal and hex in this context makes sense.

I wonder if you are trying to impose a deeper meaning to the
representation where there is in fact none other than learned usage.

> A simple coding guideline specifying the decimal and hex literals shall
> not be mixed, is too simple.  Context needs to be taken into account.
> 
> Once we start looking at context we need to consider gems like:
> 
>     x = y * 0x4e;
> 
> and
> 
>     a = b | 73;
> 
> Why would anybody use a hex literal in the context of a multiple, or a
> decimal literal in the context of a bit-wise OR operator?  Very suspect.

I really don't see an issue here.  I can imagine the above expressions
being natural and often used or, conversely, being obfuscation.  Without
the context of ther rest of the program and the programmer's design
notes, I do not think there is any conclusion that we can usefully draw.
 
> But how much practice?  I do now a handful of people who appear to mix
> decimal and hex effortlessly.  But then they have spent many years regularly
> working in hex as part of their job.  I would claim that very few programmers
> ever have that sort of exposure to hex.

The following may expose a political bias.  Some people may even see it
as not-PC.

It is certainly the case that the majority of the people who are briefly
educated in IT in a misguided effort to solve the putative IT skills
shortage have probably not heard of non-decimal bases such as
hexadecimal or base256.  The question is whether we are dealing with
properly educated professionals or the well intentioned amateurs.

Are we trying to support new learners or understand the depths of the
seasoned professional?  This is an important issue since the two are
very different domains. 

I would suggest that the handful of people who can are actually more
important that the many who can't.  Without understanding expertise
there is little that can be done for the learners. 

> A representation that has yet to be mentioned is floating-point.  This
> has the dubious advantage of looking like a decimal integer a lot
> of the time (when there is no exponent notation, the presence of a decimal
> point does not seem to cause any mental context switch {this is an
> unsubstantiated claim}), but not having some of the properties of an integer
> representation.

There is a serious issue buried in here.  When people use .14 or 14.
there can be problems due to poor rendering of the ..  However, the
biggest problem is actually with the +, -, * or / which are overloaded
in very bizarre ways in computing that lead to a large number of very
serious errors -- and a lot of very silly syntax in some programming
languages.


Russel.
====================================================================
Prof Russel Winder              Chief Technology Officer
OneEighty Software Ltd          Tel: +44 20 8263 2329
The Lansdowne Building          Fax: +44 20 8263 6314
2 Lansdowne Road                [EMAIL PROTECTED]
Croydon, Surrey CR9 2ER, UK     http://www.180sw.com           
====================================================================
Under the Regulation of Investigatory Powers (RIP) Act 2000 together
with any and all Regulations in force pursuant to the Act One Eighty
Software Ltd reserves the right to monitor any or all incoming or
outgoing communications as provided for under the Act

- Automatic footer for [EMAIL PROTECTED] ----------------------------------
To unsubscribe from this list, mail [EMAIL PROTECTED]  unsubscribe discuss
To join the announcements list, mail [EMAIL PROTECTED] subscribe announce
To receive a help file, mail [EMAIL PROTECTED]         help
This list is archived at http://www.mail-archive.com/discuss%40ppig.org/
If you have any problems or questions, please mail [EMAIL PROTECTED]

Reply via email to