Home arrow static arrow Java Programming [Archive] - is "interface" neccessary in java?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - is "interface" neccessary in java?
This topic has 103 replies on 7 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next »

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jun 30, 2004 1:27 AM (reply 75 of 103)



 
To reiterate what a lot of people are saying:

   Optimization is not bad.
   Optimization when you don't have any proof that it needs optimization is probably a waste of time.

That second statement seems to be the one lichduang has trouble with. Step by step:

   Most methods are not bottlenecks.
therefore
   Most methods do not require optimization
therefore
   Most early optimization is wasted

Combine with
   Most bugs are not optimization issues

From which reasoning (and from experience) I deduce that time is better spent on clarity of code than it is on optimizing methods that are not known to be performance problems.

Where this bears on lichduang's original preference to arrays over collections is purely that collections are less error prone. Lichduang, I draw your attention to several earlier posts which demonstrate a variety of different ways to iterate over an array. Some of them contain common bugs. Can you produce a similar set of problematic iterations over a collection ? I don't think so, and that, essentially, is why I prefer them.

The code that I then posted (to calculate primes) was illustrating that first-cut code is often good enough for solving the problem at hand (in this case generating primes) and may even out perform carefully optimised solutions. Disregarding the List v. Array issue here, it still demonstrates that optimisation is often a waste of time, and can even slow down your code !

If you still disagree, then prove it. I haven't seen any code from you that supports your stance so far, other than your for loop which (I think) has been rather conclusively demolished by the buggy demonstration examples that follow it.

D.
 

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jun 30, 2004 1:35 AM (reply 76 of 103)



 

But saying optimization consideration is going to be wasted before bottleneck showing up is making an extreme statement.

We're not saying it is going to be wasted. We're saying it is probably going to be wasted. The only point at which you will know which methods are bottlenecks is when you run your code with the real-world data. If you try to predict it, you will get it right some of the time, but you will also:

   Waste time optimising methods that aren't slow enough to be worth it
   Miss methods that desperately need to be optimised

There is never enough time on a development project to address all of the issues. The more non-issues you waste time on, the fewer problems will get fixed.

The exception to this rule is if you are writing the software for fun and just like optimisation. At which point, go for it - but remember that even (especially ?) spare time is a scarce resource.

Going back to that primes software, even though I was trying to prove a point, personally I thought that the code was going to be slower than a sieve of eratosthenes for a parameter of 10,000. So out of interest, after I'd cobbled together the quick and dirty solution, I also spent some time writing a simple sieve. It was significantly slower. I may not have proven the point to you, but I've certainly reinforced it in my own mind.

Dave.
 

Posts:648
Registered: 6/26/00
Re: is "interface" neccessary in java?  
Jun 30, 2004 3:33 PM (reply 77 of 103)



 
Optimization is not bad.
Optimization when you don't have any proof that it needs optimization is probably a waste of time.

Good, we are getting to somewhere now. I agree that the further the optimization to do, the less and less benefit you will get. Everything has a tradeoff, and until the bad side turns up so much after you going too far in that direction.

My understanding of the word probably in the statement is that you do keep performance consideration in mind while development. Even before knowing your bottleneck, you do choose class over the others, or choose an efficient way to solve a problem. But you just think that using array is too much of thinking performance. Or even more so, you think that using object array over object List under any circumstance is not justified.

We are shifting the arguing topic to how much early optimization is too much, and when early optimization is beginning to waste your time. Not about you should do early optimization or you should not do any early optimization at all. Correct?

Some great examples posted by dcminter earlier showed how error prone indexing can be. While saying that the natural index looping in program is the source of bugs or errors, that behavior does not really tie to array. We do index looping all the time regardless we do array or not. Let's say the problem requires you to loop through the elements in the List in reverse order. You are going to use the same indexing loop as array. Let's say the problem requires you to skip the first 20 elements before iterating. You are going to use the same indexing loop again. If List is providing indexing API, why is the examples only apply to array.

Sorry, too busy, coming back with clear examples of those...

--
 

Posts:6,750
Registered: 1/25/04
Re: is "interface" neccessary in java?  
Jun 30, 2004 3:53 PM (reply 78 of 103)



 
Again I'm just speaking for myself here.

Good, we are getting to somewhere now. I agree that
the further the optimization to do, the less and less
benefit you will get. Everything has a tradeoff, and
until the bad side turns up so much after you going
too far in that direction.

That's all very true, but it goes even further. When you start to do any optimization at all without knowing that you are solving a performance problem, chances are you will get no benefit from it.

My understanding of the word probably in the
statement is that you do keep performance
consideration in mind while development. Even before
knowing your bottleneck, you do choose class over the
others, or choose an efficient way to solve a problem.

I agree with all that.

But you just think that using array is too much of
thinking performance. Or even more so, you think
that using object array over object List under any
circumstance is not justified.

I think it isn't justified in the name of performance unless you know using a List causes a bottleneck.

We are shifting the arguing topic to how much early
optimization is too much, and when early optimization
is beginning to waste your time. Not about you should
do early optimization or you should not do any early
optimization at all. Correct?

I'd say early optimization is too much. :-)

Some great examples posted by dcminter earlier showed
how error prone indexing can be. While saying that
the natural index looping in program is the source of
bugs or errors, that behavior does not really tie to
array. We do index looping all the time regardless we
do array or not. Let's say the problem requires you
to loop through the elements in the List in reverse
order. You are going to use the same indexing loop as
array.

Or you could sort the array in reverse order. If the list is not a RandomAccess (which for some twisted reason doesn't extend List), then iterating in reverse would potentially be extremely slow. Now that's the sort of thing I wouldn't consider premature optimization. It can be done in a way that doesn't decrease readability and chooses what is probably a middle-of-the-road performance level.

Let's say the problem requires you to skip the
first 20 elements before iterating.

I don't recall ever needing to do that. Maybe others do it all the time, though, I have no idea. I would be surprised.

If List is
providing indexing API, why is the examples only apply
to array.

Huh?
 

Posts:2,830
Registered: 9/1/03
Re: is "interface" neccessary in java?  
Jun 30, 2004 4:00 PM (reply 79 of 103)



 
If List is
providing indexing API, why is the examples only
apply
to array.

Huh?

list provides 'get(k)', similar to 'array[k]', i think this is what is meant.

really the benefit isn't a 'list' perse, but the Iterator or Enumerator or whatever
it is called.

an interesting thing to note about 1.5 is that you can use the new little
'for each' statement with arrays as well as collections ...
 

Posts:4,500
Registered: 17.04.98
Re: is "interface" neccessary in java?  
Jul 1, 2004 1:38 AM (reply 80 of 103)



 
To reiterate what a lot of people are saying:

���Optimization is not bad.
���Optimization when you don't have any
proof that it needs optimization is probably a
waste of time.

That second statement seems to be the one lichduang
has trouble with. Step by step:

���Most methods are not bottlenecks.
therefore
���Most methods do not require
optimization
therefore
���Most early optimization is wasted

and those statements combined are THE major reason why software these days is so incredibly bloated and sluggish compared to the software created in the 1980s and early 1990s.

Noone seems concerned that today's applications run slower on 3GHz machines with 1GB of 400MHz RAM than did similar applications that ran in 1994 on a 50MHz machine with 16MB RAM.
Noone seems concerned that that modern application takes up 2GB of harddiskspace where the old one fit in under 5MB.
 

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jul 1, 2004 1:44 AM (reply 81 of 103)



 
Even before knowing your bottleneck, you do choose class over the others, or choose an efficient way to solve a problem

No, no, no, no, no. Note my use of the word proof. You optimise only when you have proven that you need to optimise. Not on a whim, or because you "think" it will need it.

Always choose a class because it is easier to use.
Always choose a way to solve a problem because it is the easy way to solve the problem.

Like the primes example - the easy way to solve the problem is to blindly test each number in turn to see if it's divisible by its predecessors. The optimised ways to solve the problem are complicated and turn out not to be faster for quite large searches. If I follow your advice I get to (1) waste time writing an optimised routine and (2) write one that's slower. What a bargain. If I follow my own advice, I get to write a routine that takes very little time to write, understand, and run. See ? No, I didn't think so.

We do index looping all the time regardless we do array or not.

Most indexing is used to iterate over all items in the collection (list or array). That's why iterators are so useful.

Let's say the problem requires you to loop through the elements in the List in reverse order.

Then I would either reverse the list, or use a reverse iterator.

You are going to use the same indexing loop as array. Let's say the problem requires you to skip the first 20 elements before iterating.

In that special case, there's less advantage to using a list, but that's an unusual case. The usual case (which is what you gave as an example with your for loop) is iterating over everything.

If List is providing indexing API, why is the examples only apply to array.

Because lists are usually accessed through iterators.

Lists give you iterators, and resizeability.

Arrays give you performance (but it's very rarely worth it), type safety (which sometimes is) and the ability to hold primitives (which usually isn't).

Sorry, too busy, coming back with clear examples of those...

Riiight. Spending your time optimising something ?
 

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jul 1, 2004 2:07 AM (reply 82 of 103)



 
Yes, we all hear that load of old cobblers from time to time.

and those statements combined are THE major reason why
software these days is so incredibly bloated and
sluggish compared to the software created in the 1980s
and early 1990s.

Bloated is a non issue. RAM is cheap.

I don't find it sluggish. Mostly software these days is absolutely snappy compared to the early nineties. I was doing tech support in '95 and it was a nightmare largely because Windows 3.xx couldn't really take proper advantage of extra ram.

Noone seems concerned that today's applications run
slower on 3GHz machines with 1GB of 400MHz RAM than
did similar applications that ran in 1994 on a 50MHz
machine with 16MB RAM.

That's just wrong from my experience. I don't know what you're doing that slows it all down, but I love our new whizzy fast machines (and I have a 0.8GHz machine with 512Mb of RAM, so I'm poor in comparison).

Linux was so-so-ok in '94 on a machine of that spec, but guess what, there was very little software for it, and it still wanted 100Mb of disk to be a pleasant experience.

Noone seems concerned that that modern application
takes up 2GB of harddiskspace where the old one fit in
under 5MB.

Because a 100Gb drive is so cheap. My first hard disk drive was 32Mb, second hand, shed sectors, and no, my machine didn't feel fast unless I was doing pure number crunching.

The following is off the top of my head, but I'm sure you can find accurate figures on the ILog website:

On the subject of number crunching, ILog sell some rather nice software for solving linear programming problems. As a result of improvements in their algorithms (guess what things aren't getting worse) they gain about 1000 fold improvement in their alg. As a result of improvements in hardware they get another 1000 fold improvement.

So, a 1,000,000 improvement in processing time. The problem we were using their software to resolve would still be running if we had started it back then (10 to 20 years ago). Now it takes five minutes.

And guess what, they're smart people who probably do not spend all their time optimising the data load routines, the command line tool, and the IDE. They concentrate on the optimiser which is where they need pure performance.

Most people write software for a living, not as some exquisite yet obsolete craft like wood turning. Our customers want software that solves their problems, not which satisfies some curious aesthetic sense.

If you feel like that, why don't you run circa 1985 software ? AT&T Unix ? VMS ? Dos ? We'll stick with Win2K, OS X, and the latest flashy version of Linux thanks.

Dave.
 

Posts:21,719
Registered: 98-02-20
Re: is "interface" neccessary in java?  
Jul 1, 2004 4:43 AM (reply 83 of 103)



 
and those statements combined are THE major reason why
software these days is so incredibly bloated and
sluggish compared to the software created in the 1980s
and early 1990s.

IMO, s'ware has gotten bigger since the 80s and 90s for two reasons:

(1) RAM and hard disks are cheap and plentiful. S'ware developers are using more because more is available,
(2) We're solving bigger problems than we were back then. Better h'ware has made it possible to attempt problems that were impossible back then.

Noone seems concerned that today's applications run
slower on 3GHz machines with 1GB of 400MHz RAM than
did similar applications that ran in 1994 on a 50MHz
machine with 16MB RAM.

I'd like to see some statistics and benchmarks on this. I think it's an incorrect statement.

Noone seems concerned that that modern application
takes up 2GB of harddiskspace where the old one fit in
under 5MB.

That 5MB code was a vi text editor, not a graphical IDE. It was written in assembler or a low-level language that made maintainence much harder.

I think, too, that we need to parse "modern application". I'm certain that we can find applications that run far faster today than they ever did. Scientific computing on distributed architectures is making it possible to solve problems that were literally impossible on older systems. That's a smart combination of hardware and software, because the algorithms used are fundamentally different. All the speedup can't be attributed to faster CPUs.

I'm not saying that people shouldn't think about optimization or performance. Those are still important. To me, that means knowing enough not to go for bubble sort and full table scans and knowing what Big-Oh notation is.

But to say that s'ware hasn't progressed at all seems to neglect a lot of progress.

%
 

Posts:11,186
Registered: 06.04.04
Re: is "interface" neccessary in java?  
Jul 1, 2004 5:14 AM (reply 84 of 103)



 
Noone seems concerned that that modern application takes up 2GB of harddiskspace where the old
one fit in under 5MB.

That 5MB code was a vi text editor, not a graphical IDE. It was written in assembler or a low-level
language that made maintainence much harder.

cough vi ran fine on a PDP 11/60 with a meager 64 K words ... even 'vim' nowadays, with its graphics
extensions is just a bit over 1 megabyte ...

Of course, if machines become faster, identical applications run faster, but, all IMHO of course,
all those RAM and gigantic disk space does invite, and permits, sloppier coding than when one
has to squeeze everything in, say, 64KB RAM and 80MB hard disks ... a lot of enginuity was born
in those days; because people had to be clever; nowadays the sky is the limit and permits for a
lot of sloppy coding to get away with it ... All that enginuity on the other hand, makes nowadays
applications run faster, so e.g. bigger and bigger problems can be solved (think of those NP hard
thingies where a 1000x faster/larger processor/RAM just allows for a log(log(1000)) larger problem).

kind regards,

Jos
 

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jul 1, 2004 5:22 AM (reply 85 of 103)



 

It all strikes me as being a bit like complaining about screen sizes getting bigger.

Sure, in the old days, you only needed a couple of K to hold the entire screen, or indeed, none with a TTY output. And you could get all your work done.

So what ? I like my 1280x1024 24 bit colour monitor. It makes my life a nicer place. By the "in the old days we only had noughts" reasoning that's a waste of resources, but hey, that's your problem, not mine.

I don't think that deep ingenuity should be required to solve mundane problems. Better to concentrate the ingenuity on the really hard stuff, so that we don't have to spend a few years writing a typesetting application just so our tech books can look nice (Knuth).

Sure it's a brilliant system, but I'd rather have the full series of books before he keels over.

D.
 

Posts:5,904
Registered: 04/03/99
Re: is "interface" neccessary in java?  
Jul 1, 2004 5:30 AM (reply 86 of 103)



 
...and another thing ;-)

My favourite IDE is Eclipse. Currently I'm running 3.0M9 (I must install the release when I have a few minutes). That takes up about 100Mb on my system. Big enough for you ?

And that's a lot of disk space by 1995 standards. But so is 5Mb by 1995 standards. For me personally, on my (well, actually ICL's at the time) Linux system that would have been 5% of the total. My current (2004) system has just short of 40Gb. So 100Mb is 0.25% of the total.

Yes folks, surprise surprise, for me the opportunity cost of installing a fully featured IDE has fallen dramatically.

And if you compare Eclipse to any circa '95 editor and think they're equivalent, you're insane.

Dave.
 

Posts:37,103
Registered: 3/30/99
Re: is "interface" neccessary in java?  
Jul 1, 2004 8:16 AM (reply 87 of 103)



 
And that's a lot of disk space by 1995 standards. But
so is 5Mb by 1995 standards. For me personally, on my
(well, actually ICL's at the time) Linux system that
would have been 5% of the total. My current (2004)
system has just short of 40Gb. So 100Mb is 0.25% of
the total.

Along with those thoughts, the two computers I currently own:

2GHz, 1GB, 40GB, 1024x762 or something, 14" laptop -- <$800, purchased fall 2003

Dual 450MHz, 512MB, 1280xwhatever, 15" -- $2000, purchased fall 2000

Previous computers I have owned:

33 MHz, 16-64MB RAM, ????MB HD 14" ... -- $1800, I think, purchased 1994

25 MHz, 4MB, 80MB, 9" B&W -- >$3000, purchased 1990

So my CPU is about 80 times faster, I've got 256 times as much ram, 512 times as much HD, a bigger color monitor, for less than 1/3 of the price. You'd almost have to go out of your way to try to make a program inefficient if you want it to use a larger fraction of my computing resources, or my computing dollar, on my "now" machine than my "then".

 

Posts:6,750
Registered: 1/25/04
Re: is "interface" neccessary in java?  
Jul 1, 2004 8:18 AM (reply 88 of 103)



 
and those statements combined are THE major reason why
software these days is so incredibly bloated and
sluggish compared to the software created in the 1980s
and early 1990s.

Noone seems concerned that today's applications run
slower on 3GHz machines with 1GB of 400MHz RAM than
did similar applications that ran in 1994 on a 50MHz
machine with 16MB RAM.
Noone seems concerned that that modern application
takes up 2GB of harddiskspace where the old one fit in
under 5MB.

I know this has been rebutted, but I just have to comment... 72% of all facts and statistics are made up on the spot. Right? :-)
 

Posts:11,186
Registered: 06.04.04
Re: is "interface" neccessary in java?  
Jul 1, 2004 8:45 AM (reply 89 of 103)



 
72% of all facts and statistics are made up on the spot. Right? :-)

Wrong; after substantial statistical research that figure turned out to be 98.366733567%

kind regards,

Jos
 
This topic has 103 replies on 7 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next »