From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,30e368bdb3310fe5 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,30e368bdb3310fe5 X-Google-Attributes: gid1014db,public X-Google-Thread: fac41,af40e09e753872c X-Google-Attributes: gidfac41,public X-Google-Thread: f8c65,30e368bdb3310fe5 X-Google-Attributes: gidf8c65,public X-Google-Thread: 103376,30e368bdb3310fe5 X-Google-Attributes: gid103376,public X-Google-Thread: 1008e3,30e368bdb3310fe5 X-Google-Attributes: gid1008e3,public X-Google-Thread: 10db24,30e368bdb3310fe5 X-Google-Attributes: gid10db24,public From: tknarr@xmission.com ( Todd Knarr ) Subject: Re: Hungarian notation Date: 1996/01/09 Message-ID: <4csj8i$gsa@news.xmission.com>#1/1 X-Deja-AN: 134548090 references: <30C40F77.53B5@swsbbs.com> <30EF0415.6FE1@tus.ssi1.com> <1996Jan7.045815.8676@ohstpy> <4cpb00$nqk@news.xmission.com> organization: Chaos Central reply-to: 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 Date: 1996-01-09T00:00:00+00:00 List-Id: In , 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 )