A proposal for NATURAL syntax

2 messages Options
Embed this post
Permalink
Paolo Redaelli

A proposal for NATURAL syntax

Reply Threaded More More options
Print post
Permalink
I have a little proposal for NATURALs.

People coming from other languages will find code like

n8 := 1.to_natural_8
n16 := 1.to_natural_16
n32 := 1.to_natural_32
n64 := 1.to_natural_64

a little "verbose" or cumbersome to use.

Someone could also wonder if such a syntax will be "optimized away" by
the compiler either Eiffel or C. Chances are high that an unoptimized
implementation will allocate an unnecessary temporary integer on the
stack.

I would like to propose a tentative syntax for Gnu-Eiffel that could
look like:

n8 := {NATURAL_8 1}
n16 := {NATURAL_16 1}
n32 := 1U
n64 := {NATURAL_64 1}

People reading code find "perfectly natural" to infer the type of an
integer constant "from the context"; we have already lengtly discussed
why inferring the type of an object from its context is not good for
program clarity or even

The proposal for 8,16 and 64 bit naturals is modelled after the usual
in-place creation of objects. Syntax for 32bit is inspired from both C
and SmartEiffel unicode string syntax. In fact <stdint.h> declares
things like:

# define UINT32_MAX             (4294967295U)

As such a number does not fit an int.
This C header also uses a low-level syntax like ours, in a form like
this:

# define INT64_MAX              (__INT64_C(9223372036854775807))

C is also declaring the type of a constant together with its value,
taking the same path of SmartEiffel but hiding it from the casual C
programmer.

As 64-bit processor is becoming really widespread I suggest to conceive
a shorter notation also for 64 bit values. A generic solution could be
valueUlength hence having

n8 := 1U8
n16 := 1U16
n32 := 1U -- or 1U32
n64 := 1U64

Knowing that in a not-too-far future we could change the default when
the length is not specified from 32 to 64 bit values. I find this
particularly tricky.
Perhaps it would be wiser to avoid a default length at all. At least it
will make programmer conscious of the precision and resolution of the
values they are using.

Paolo who started programming on a Commodore 64 where "int" is 8bit....


Hendrik Boom-2

Re: A proposal for NATURAL syntax

Reply Threaded More More options
Print post
Permalink
On Tue, Nov 18, 2008 at 09:15:52AM +0100, Paolo Redaelli wrote:
> I have a little proposal for NATURALs.
>
> People coming from other languages will find code like
>
> n8 := 1.to_natural_8
> n16 := 1.to_natural_16
> n32 := 1.to_natural_32
> n64 := 1.to_natural_64

Speaking as a reader, I find the above much more readable and no
more verbose or cumbersome than
>
> n8 := {NATURAL_8 1}
> n16 := {NATURAL_16 1}
> n32 := 1U
> n64 := {NATURAL_64 1}
>

-- hendrik