Article View: comp.lang.eiffel
Article #1140Re: Hungarian notation
From: Todd Knarr
Date: Tue, 09 Jan 1996 02:17
Date: Tue, 09 Jan 1996 02:17
43 lines
3027 bytes
3027 bytes
In <hawkfish-0801960904580001@blv-pm3-ip24.halcyon.com>, hawkfish@punchdeck.com (Richard Wesley) writes:
>I've found it useful to use typedefs for all sorts of things like this.
>Looping through a FooArray with a FooIndex is much more robust than using
>a long or something.
I try to avoid syntactic-saccharine typedefs when possible. There's no
language-level gain from typedef'ing an int or long to something else
just for that, and it virtually requires an explosion of variables to
deal with multiple arrays of different types. The result of using several
different variables to step through several different arrays at different
times, just because those arrays have elements of different types, tends
to be confusion. When the index is really significant then it makes sense
to use seperate variables ( eg. when nCurrentMerchItem holds the index of
the current item as other processing is done ), but as was pointed out
there are a lot of constructions where the index is only significant for
a line or two of code ( where your code is saying, basically, "Do >this<
to every item in the array." ).
One of my rules is that, when I do something like that, I use integer
variables like i and j. That maps nicely to the uses of such letters in
math classes and the like. I can then tell instantly whether the indexes
are significant or just grind work.
>This is reasonable for C, but these days I find myself using auto_ptr and
>my own auto_array templates to deal with this problem. On the other hand,
>it could still be useful inside a class that used an array to represent
>something (e.g. a string).
Even in a lot of higher-level things like your auto_array it makes sense
to index things by an integral value. There's a significant gain in safety
at times, but at others you simply introduce redundant checks. If, for
instance, an index is validated once and never altered after that, there
is no need to revalidate it on every access. ( NB: being certain the index
will never become invalid is, of course, the trick. )
--
Todd Knarr : tknarr@xmission.com | finger for PGP public key
| Member, USENET Cabal
Seriously, I don't want to die just yet. I don't care how
good-looking they are, I! don't! want! to! die!"
-- Megazone ( UF1 )
Technical Details
Message-ID:
<4csj8i$gsa@news.xmission.com>Path:
arc1-ca.pugleaf.net!newsfeed.internetmci.com!xmission!newsReferences:
<30C40F77.53B5@swsbbs.com> <30EF0415.6FE1@tus.ssi1.com> <1996Jan7.045815.8676@ohstpy> <4cpb00$nqk@news.xmission.com> <hawkfish-0801960904580001@blv-pm3-ip24.halcyon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsfeed.internetmci.com!xmission!news From: tknarr@xmission.com ( Todd Knarr ) Newsgroups: comp.lang.eiffel,comp.lang.ada,comp.edu,comp.lang.c,comp.lang.c++,comp.lang.modula2,comp.lang.modula3 Subject: Re: Hungarian notation Date: 9 Jan 1996 02:17:54 GMT Organization: Chaos Central Message-ID: <4csj8i$gsa@news.xmission.com> References: <30C40F77.53B5@swsbbs.com> <30EF0415.6FE1@tus.ssi1.com> <1996Jan7.045815.8676@ohstpy> <4cpb00$nqk@news.xmission.com> <hawkfish-0801960904580001@blv-pm3-ip24.halcyon.com> Reply-To: tknarr@xmission.com ( Todd Knarr ) NNTP-Posting-Host: slc31.xmission.com X-Newsreader: IBM NewsReader/2 v1.2