× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



This isn't necessarily directly related to what's being said here, but:

I would note that, in the balance between maintainability/readability and
cost of CPU cycles, maintainability always wins in my book.  No part of your
system costs as much as the time of human beings to do analysis/programming
over the lifetime of a software product.  Performance doesn't have to be
optimal in easily 80% of all applications that are written.  That doesn't
mean to be stupid, just not to get your knickers in a twist over small
things.

If instantiating a throw-away object somehow makes the code more readable,
I'd say go for it (unless your object is an out of control huge thing with
all sorts of ridiculous start up costs - you get the balance).  Also, your
shop should have coding standards that address this sort of thing.  If you
don't, you should be working towards them.

I would also mention that I am really a C++ programmer masquerading as a
JAVA programmer, and have no concept of the JRE's capabilities for
optimization at any release level. :)

My 2¢  

Joe


-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx]On Behalf Of Joe Pluta
Sent: Thursday, June 16, 2005 10:40 AM
To: 'Java Programming on and around the iSeries / AS400'
Subject: RE: Cost of instantiating


> From: albartell
> 
> 
> Integer total1 = new Integer(0);
> Integer total2 = new Integer(0);
> Integer total3 = new Integer(0);
> Integer total4 = new Integer(0);
> Integer total5 = new Integer(0);
> Iterator iter = myList.iterator();
> while (iter.hasNext()) {
>     total1 = new Integer(0);
>     total2 = new Integer(0);
>     total3 = new Integer(0);
>     total4 = new Integer(0);
>     total5 = new Integer(0);
> 
>     total1 = methodTotal1();
>     total1 = methodTotal1();
>     total1 = methodTotal1();
>     total1 = methodTotal1();
>     total1 = methodTotal1();
>     // write totals to PDF
> }

I don't understand.  What is this supposed to emulate?  The only thing
being done here is:

total1 = methodTotal1();
// write to PDF

What is all the other stuff supposed to represent?  If you meant to be
doing this:

total2 = methodTotal2();
total3 = methodTotal3();
total4 = methodTotal4();
total5 = methodTotal5();

Then the code should be thus:

Integer total1 = methodTotal1();
(...)
Integer total5 = methodTotal5();
// write to PDF

You shouldn't be creating the original Integer(0) objects, since they're
all thrown away.  Personally, though, I might write a method writeTotals
which accepts the five Integer objects, and do this:

writeTotals(
  methodTotal1(), methodTotal2(), methodTotal3(),
  methodTotal4(), methodTotal5());


Joe


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.