On 03 Nov 2014, at 18:08, Dirk Hohndel <[email protected]> wrote: >> Just as a general rule: “1” is never a good name for anything except the >> smalls non-negative integer. > > Oh I love that... I may have to quote you at some point.
Besides the fact that I misspelled „smallest“and the fact that 1 is the
smallest positive integer, this is actually one of the very few things I
learned about programming. I have never received any formal education in
computer science or anything like that and have done my share of spaghetti
coding as a kid. But I had pretty much lost interest in programming when I
entered university.
That was only revived when I learned about perl from a fellow graduate student
which was in many ways much more what I liked compared to languages like C
(with declared variables and so many ways to shoot yourself in the food with
pointers etc). One of the many things I liked so much about perl is that
„array“ as a data type (or rather structure), the thing that is indexed by
integers, has much fewer uses than the C programmer thinks. Many things that
look like arrays are actually lists, where reasonable operations are first,
next or last elements, shifting, concatenating and of course iteration are
typical operations but „give me element number 17“ rarely is. And with foreach
it is so much harder to produce an obi wan error than with for (i=0; i <= 17;
i++) {} („Should it be <17?!?“).
And if you need a structure of indexed objects, indices are rarely again
integers, they can be anything in which case what looks like an array is
actually a hash. With that you can say „give me the dillutant cylinder“ rather
than „give me cylinder 1“ („or was it 0?!?“) and again you can interate etc etc.
In any case, this realisation really struck me and I think it is really
important to use the correct type for index sets (or none at all) but using
integers suggests so many wrong things (like the possibility to do arithmetic
on them) while in the cases above all one really uses that every finite set can
be bijectively mapped to exactly one set of the form {0, 1, 2, …, n} but that
map is not canonical (if you like the language of category theory).
TL;DR
I try hard to avoid integer indices unless they are really asked for.
Best
Robert
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
