March 01, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a5nugt$4qh$1@digitaldaemon.com...
> "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a5nm1p$r0$1@digitaldaemon.com...
>
> > So what's so inconvenient about this?
> >
> > typedef int VKCode;   // in D I believe this makes a distinct type which
> > behaves identically to int except for type conversion can't
> >                                    // be implicitly done from int to
> VKCode
> > (though I think the opposite still happens implicitly)
> > static const VKCode
> >         LButton = 1,
> >         RButton = 2,
> >         Cancel = 3,
> >         MButton = 4,
> >         Back = 8, BackSpace = Back,
> >         Tab = 9,
> >         Clear = 12,
> >         Return = 13, Enter = Return,
> >         Shift = 16,
> >         Control = 17;  // this is assuming that implicit conversion from
> int
> > to VKCode can still be done in the initializer.
> >                                // if you think about it, that's really
an
> > explicit conversion anyway, don't you think?
>
> The difference is that enum defines its own namespace.
> So it'd be Key.Enter, Key.Tab, Key.A etc... I don't see
> any other way to do it apart from declaring a separate class
> specially for that - probably not the best idea...
>

How about placing them into it's own module
named Key.d?  Not the most beatiful solution
I agree though...



--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
__________________________________________
Remove _XYZ from my address when replying by mail



March 01, 2002
"OddesE" <OddesE_XYZ@hotmail.com> wrote in message news:a5oasr$hqb$1@digitaldaemon.com...

> How about placing them into it's own module
> named Key.d?  Not the most beatiful solution
> I agree though...

Two problems here. First is that there might be another module with
such (frequently used) name. Second is that if another module contains
a function Enter(), you'll have to resolve scope each time you use
it. With enum, you'd always use Key.Enter for key, and Enter() to
call function.


March 03, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message
news:a5omng$lmv$1@digitaldaemon.com...
<SNIP>
> Two problems here. First is that there might be another module with
> such (frequently used) name. Second is that if another module contains
> a function Enter(), you'll have to resolve scope each time you use
> it. With enum, you'd always use Key.Enter for key, and Enter() to
> call function.
>

Yes you are right, hadn't thought of that.


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
__________________________________________
Remove _XYZ from my address when replying by mail



March 23, 2003
"Pavel Minayev" <evilone@omen.ru> escribió en el mensaje
news:a5jben$16o8$1@digitaldaemon.com...
| "Walter" <walter@digitalmars.com> wrote in message
| news:a56tc4$1534$2@digitaldaemon.com...
|
| > Having lower bounds specifiable will work with D (and even with C), but
in
| > my decades (!) of programming I've never found a use for it. I came to C
| > from Basic, FORTRAN, and Pascal. I had some initial trouble getting used
| to
| > 0 based rather than 1 based, but never looked back. 0 based looked more
| > 'right' to me.
|
| Well, there are actually cases where you'd prefer some base other than 0.
| As you've seen, many people here consider 1 to be more suitable, and
| I understand them... also there are some other cases, for example, suppose
| you have an array of year income for 1990-2000, in Pascal you'd probably
| declare it as "array[1990 .. 2000] of integer", and then index it like
| income[1995], letting the compiler do his job and insert all the necessary
| decrements; the result is clean code, easy to read and maintain. In C,
| you have to do it all yourself, and probably define some const base =
1990,
| and clutter all your code with things like income[1995 - base].
|
| After all, it's as simple as subtracting the base from the index,
| a single SUB... ain't it worth the thing?
|
|

No one ever answered to this one. It seems very clever to me.

————————————————————————— Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17


March 26, 2003
"Carlos Santander B." <carlos8294@msn.com> wrote in news:b5k815$11ia$2@digitaldaemon.com:

> "Pavel Minayev" <evilone@omen.ru> escribió en el mensaje news:a5jben$16o8$1@digitaldaemon.com...
>| "Walter" <walter@digitalmars.com> wrote in message
>| news:a56tc4$1534$2@digitaldaemon.com...
>|
>| > Having lower bounds specifiable will work with D (and even with C),
>| > but
> in
>| > my decades (!) of programming I've never found a use for it. I came
>| > to C from Basic, FORTRAN, and Pascal. I had some initial trouble
>| > getting used
>| to
>| > 0 based rather than 1 based, but never looked back. 0 based looked
>| > more 'right' to me.
>|
>| Well, there are actually cases where you'd prefer some base other
>| than 0. As you've seen, many people here consider 1 to be more
>| suitable, and I understand them... also there are some other cases,
>| for example, suppose you have an array of year income for 1990-2000,
>| in Pascal you'd probably declare it as "array[1990 .. 2000] of
>| integer", and then index it like income[1995], letting the compiler
>| do his job and insert all the necessary decrements; the result is
>| clean code, easy to read and maintain. In C, you have to do it all
>| yourself, and probably define some const base =
> 1990,
>| and clutter all your code with things like income[1995 - base].

Having arrays with base 1 and zero-based index is likely to become a maintainer's nightmare: Whenever you see an array, you must look at it's declaration (or wait for a tooltip from you IDE) and check whether is zero- based or not. Array operations become much more bug prone. Once your brain adjusted to zero-based indices, you can easily write bug-free code for arrays or verify that a given code is bug-free. But switching between different bases is very difficult.

Zero-based indices are favoured over 1-based indices for implementations reasons. E.g. with a Byte you can address 256 array elements instead of only 255.

In D, there are many ways to express concepts, e.g. functions, classes, D- structs, templates. I believe that non-zero based arrays are not really required to express concepts in away that suitable for the problems, programmers have to solve.


Farmer.
March 27, 2003
"Farmer" <itsFarmer.@freenet.de> escribió en el mensaje
news:Xns934B78D5F5FDitsFarmer@63.105.9.61...
| "Carlos Santander B." <carlos8294@msn.com> wrote in
| news:b5k815$11ia$2@digitaldaemon.com:
|
| > "Pavel Minayev" <evilone@omen.ru> escribió en el mensaje
| > news:a5jben$16o8$1@digitaldaemon.com...
| >| "Walter" <walter@digitalmars.com> wrote in message
| >| news:a56tc4$1534$2@digitaldaemon.com...
| >|
| >| > Having lower bounds specifiable will work with D (and even with C),
| >| > but
| > in
| >| > my decades (!) of programming I've never found a use for it. I came
| >| > to C from Basic, FORTRAN, and Pascal. I had some initial trouble
| >| > getting used
| >| to
| >| > 0 based rather than 1 based, but never looked back. 0 based looked
| >| > more 'right' to me.
| >|
| >| Well, there are actually cases where you'd prefer some base other
| >| than 0. As you've seen, many people here consider 1 to be more
| >| suitable, and I understand them... also there are some other cases,
| >| for example, suppose you have an array of year income for 1990-2000,
| >| in Pascal you'd probably declare it as "array[1990 .. 2000] of
| >| integer", and then index it like income[1995], letting the compiler
| >| do his job and insert all the necessary decrements; the result is
| >| clean code, easy to read and maintain. In C, you have to do it all
| >| yourself, and probably define some const base =
| > 1990,
| >| and clutter all your code with things like income[1995 - base].
|
| Having arrays with base 1 and zero-based index is likely to become a
| maintainer's nightmare: Whenever you see an array, you must look at it's
| declaration (or wait for a tooltip from you IDE) and check whether is
zero-
| based or not. Array operations become much more bug prone. Once your brain
| adjusted to zero-based indices, you can easily write bug-free code for
| arrays or verify that a given code is bug-free. But switching between
| different bases is very difficult.
|
| Zero-based indices are favoured over 1-based indices for implementations
| reasons. E.g. with a Byte you can address 256 array elements instead of
| only 255.
|
| In D, there are many ways to express concepts, e.g. functions, classes, D-
| structs, templates. I believe that non-zero based arrays are not really
| required to express concepts in away that suitable for the problems,
| programmers have to solve.
|
|
| Farmer.

I wasn't referring to 1-based arrays only, but any-base arrays. By default, arrays would be 0-based, but what if we could have:

int [4..14] b; //starts in 4, ends in 13
int [-3..7] c; //starts in -3, ends in 6
int [10] a; //normal array, identical to int[0..10] a

Delphi supports that, and I think it could be an interesting addition.

————————————————————————— Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25


March 27, 2003
I disagree.  Nonzero-based arrays buy you convenience.  Now you don't have to remember to subtract the base, it'll do it automatically.

Not everybody thinks like a pro programmer.  That used to be one of the big selling points of BASIC that it had 1-based arrays.  I always liked the feature in Pascal.

If I want to index my array as 2,3,4 for some reason instead of 0,1,2,  why should the compiler force me to use 0,1,2?  I'll just go and use 2,3,4 anyway but now I have to write a stupid array wrapper class that does the subtraction for me, or remember to subtract 2 all the time.

I can't think of a good example off the top of my head, but say your indices are an enum type instead of int.  And let's just say that for instance your enum type only goes from 8 thru 12 because it also happens to be part of a hardware register matching some bits you don't have control over.  And you want to map those hardware states to some other data.  Well you have to remember to subtract 8 all the time or you'll waste memory or get an array bounds error.

It's such a simple thing...

D needs a range type.  Then using them for declaring arrays becomes easy; if it wasn't there you'd wonder why not.

Sean

"Farmer" <itsFarmer.@freenet.de> wrote in message news:Xns934B78D5F5FDitsFarmer@63.105.9.61...
> "Carlos Santander B." <carlos8294@msn.com> wrote in news:b5k815$11ia$2@digitaldaemon.com:
>
> > "Pavel Minayev" <evilone@omen.ru> escribió en el mensaje news:a5jben$16o8$1@digitaldaemon.com...
> >| "Walter" <walter@digitalmars.com> wrote in message
> >| news:a56tc4$1534$2@digitaldaemon.com...
> >|
> >| > Having lower bounds specifiable will work with D (and even with C),
> >| > but
> > in
> >| > my decades (!) of programming I've never found a use for it. I came
> >| > to C from Basic, FORTRAN, and Pascal. I had some initial trouble
> >| > getting used
> >| to
> >| > 0 based rather than 1 based, but never looked back. 0 based looked
> >| > more 'right' to me.
> >|
> >| Well, there are actually cases where you'd prefer some base other
> >| than 0. As you've seen, many people here consider 1 to be more
> >| suitable, and I understand them... also there are some other cases,
> >| for example, suppose you have an array of year income for 1990-2000,
> >| in Pascal you'd probably declare it as "array[1990 .. 2000] of
> >| integer", and then index it like income[1995], letting the compiler
> >| do his job and insert all the necessary decrements; the result is
> >| clean code, easy to read and maintain. In C, you have to do it all
> >| yourself, and probably define some const base =
> > 1990,
> >| and clutter all your code with things like income[1995 - base].
>
> Having arrays with base 1 and zero-based index is likely to become a maintainer's nightmare: Whenever you see an array, you must look at it's declaration (or wait for a tooltip from you IDE) and check whether is
zero-
> based or not. Array operations become much more bug prone. Once your brain adjusted to zero-based indices, you can easily write bug-free code for arrays or verify that a given code is bug-free. But switching between different bases is very difficult.
>
> Zero-based indices are favoured over 1-based indices for implementations reasons. E.g. with a Byte you can address 256 array elements instead of only 255.
>
> In D, there are many ways to express concepts, e.g. functions, classes, D- structs, templates. I believe that non-zero based arrays are not really required to express concepts in away that suitable for the problems, programmers have to solve.
>
>
> Farmer.


March 27, 2003

"Sean L. Palmer" wrote:
> 
> I disagree.  Nonzero-based arrays buy you convenience.  Now you don't have to remember to subtract the base, it'll do it automatically.

Yes, but it will cost any user of an array a little bit of performance for the potential base correction. If D is seeking to be a successor to C and C++ in system and game programming, one has to be very careful with this.

--
Helmut Leitner    leitner@hls.via.at Graz, Austria   www.hls-software.com
March 27, 2003
Base index is nothing next to fundamental array manipulation/creation functions. Experience stands behind that statement.  Mathematica arrays are 1-based, C arrays are 0-based, and I must often pass arrays between them.  The 0 vs. 1 issue has never hurt me.

The big deal is that C/C++ offers no help in array manipulation.  That is primarily why I use Mathematica so regularly.  Mathematica is a multiparadigm language offering functional-style array manipulations.  I would do these manipulations in C++ if that were possible.  The more of them in D, the better.

Just to give a flavor of what I mean - here is some Mathematica code pulled at random.  These lines showcase typical array manipulations and a bit of functional style.  They come from an autocorrelation spectral estimator that performs as fast as the equivalent C, but says, in mere lines, what would be pages of C.

'Table' is equivalent to Sean's 'range' (I think).  'Flatten' drops a multi-dimensional array down to 1 dimension.    This is the kind of stuff I wish I could do in D.  -Mark

X = InverseFourier[piece];
X2 = Map[(# Conjugate[#])&, X];
auto = Re[Chop[Fourier[X2]]] / Q;
s = Take[auto,M] Table[w[m],{m,1,M}];
s = Flatten[{s,Table[0,{N- (2 M - 1)}]}];
lastpart = Table[auto[[N-m+1 +1]] w[N-m+1],{m,N-M+1+1,N}];
s = Flatten[{s,lastpart}];
capS = Re[Chop[InverseFourier[s]]];



Sean L. Palmer says...
>
>I disagree.  Nonzero-based arrays buy you convenience.  Now you don't have to remember to subtract the base, it'll do it automatically.


March 27, 2003
As in C++, you don't pay for what you don't use.  It doesn't necessarily cost any performance anyway.

If your array is from 1..10, and starts at address 0x80000000, and each entry is 4 bytes long, the compiler just takes your index and does this to compute the address:

(index*4)+0x7ffffffc

If it were zero based, it'd do this:

(index*4)+0x80000000

There are situations where it would cost you performance, but not many.

Sean

"Helmut Leitner" <helmut.leitner@chello.at> wrote in message news:3E82FBF5.75FDADF4@chello.at...
>
>
> "Sean L. Palmer" wrote:
> >
> > I disagree.  Nonzero-based arrays buy you convenience.  Now you don't
have
> > to remember to subtract the base, it'll do it automatically.
>
> Yes, but it will cost any user of an array a little bit of performance for the potential base correction. If D is seeking to be a successor to C and C++ in system and game programming, one has to be very careful with this.