Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: jrobinss Newsgroups: comp.lang.java.programmer Subject: Re: alias for Integer Date: Fri, 18 Nov 2011 08:26:26 -0800 (PST) Organization: http://groups.google.com Lines: 65 Message-ID: <19404286.1644.1321633587044.JavaMail.geo-discussion-forums@yqhd1> References: <21374513.220.1321627842805.JavaMail.geo-discussion-forums@yqmj32> <12712433.869.1321630449979.JavaMail.geo-discussion-forums@prmf13> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 62.23.212.45 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1321633587 2030 127.0.0.1 (18 Nov 2011 16:26:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 18 Nov 2011 16:26:27 +0000 (UTC) In-Reply-To: <12712433.869.1321630449979.JavaMail.geo-discussion-forums@prmf13> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=62.23.212.45; posting-account=raMt9AoAAACPbWkv8OI-qo2nMs4SyD7X User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10046 Aaah, it had been some time, but I'm not disapointed. :-) I'm sorry Lew, but I feel that I haven't been quite clear. This is a large piece of code, not extraordinary but still a reasonable siz= e, and I didn't write it. I end up manipulating indexes all over the place,= so that I have for example a table (or map or whatever) that associates da= tabase indexes to matrix indexes, or identifiers to indexes, etc. These are= all ints or Integers, and take part in ringamaroles of loops, indexes of i= ndexes of arrays of arrays and such joyous constructs. In short, it's a lot= of ints and hard to understand. That these indexes and identifiers are all integers is in fact nearly a coi= ncidence (it *is* very handy to reuse matrix libraries), conceptually they = are not the same thing; the ID of an object could be a string, it just happ= ens to be an int. I am certainly not obfuscating my code by replacing a typ= e such as Integer with DbIndex or MyObjId, on the contrary I am stating to = everyone, including the compiler, that this should be congruent with indexe= s, not to matrix sizes or number of chars in string of what-have-we-nots. T= he error I am trying to avoid is to use a DB index in place of a matrix ind= ex in the middle of a large set of loops. (of course a nice side effect is that I could replace some IDs with strings= or objects or anything, benefiting from encapsulation, but here it's not t= he objective) See this as the same as when you call a method that takes ten ints as entry= params: the main risk of error is to get confused in the order of paramete= rs, and nothing will warn you except some strange bug a year later. A way t= o avoid it is to type strongly parameters, so that the caller may call new Rect(new Rect.Length(x), new Rect.Width(y)) instead of new Rect(x, y) which is kind of verbose overkill in this particular example of course, but= it's just an illustration. Ok, so that's the reason why the typing. As for the optimisation, I am perfectly aware that one of the most-cited mo= ttos here is "premature optimization is the root of all evil" (with which I= wholeheartedly agree, BTW). I am not prematurely optimizing: I am about to= optimize some code that I didn't write, and it's certainly not premature b= ecause the code *is* slow. For me, this always starts with a bit of local r= ewriting in order to better understand the code and to guarantee that my ch= anges won't break anything, in particular by letting the compiler help me o= ut. The o-word, which acts as a kind of magnet for your reactions, was not = the core subject of my post, which is probably why you feel you don't have = any elements about it: I didn't provide any, because that was not my questi= on. I merely stated that performances were potentially an issue, because th= at is generally one of the parameters to take into account when choosing a = particular implementation. I hope this clarifies. Many thanks to you, Lew, and also to Roedy and Mark for answering. I'll kee= p your answers in mind while I progress. For those who wonder about structures and matrixes etc, I'm starting by rep= lacing types, but I may do another code writing iteration where I replace s= tructures. So that it may go like this... original code: Blob better: Blob even better: MyBlob extends Blob, or extends Blob gettin' better: MyBlob with methods using ints, bye bye boxing :-) JRobinss