This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programming Techniques

 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends
I am new to Java
My java class file size is 15 k now.
Is there anyway to reduce the size of class file.
I heard that the efficient way of doing programming is doing program which generates less size of class name.
is there anybody knows how to do the programming which will creates the less size class name ?
please give me some programming techniques.
Thanks in advance
Yours
Rajesh
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you really have a need, don't spend time worrying about the sizes of your classes. Worry about writing code that makes sense.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well tinkering with the size of a classfile is really just optimization, much the same as trying to improve performance. So I thought that I would share with you some thoughts on the topic.
From "Effective Java" by Joshua Bloch (quotes that he took from elsewhere) Item 37 (page 162)

More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.
-William A. Wulf


We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil.
-Donald E. Knuth


We follow two rules in the matter of optimization:
Rule 1. Don't do it.
Rule 2 (for experts only) Don't do it yet-that is, not until you have a perfectly clear and unoptimized solution.
-M.A.Jackson


Strive to write good programs rather than fast ones.
Strive to avoid design decisions that limit performance.
-Joshua Bloch

So the advice is to forget about the footprint of your class and the speed of the code until the code is bug-free. Then get a refactoring book and start worrying about such things.

[This message has been edited by Cindy Glass (edited December 19, 2001).]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to disagree with Cindy on this. Sorry Cindy. Of course, you are a better source for knowledge on JAVA than I am. But I look at this situation from a different point of view.
Forget about the language. Optimization is something that programmers have ignored since memory and CPU speeds began to grow. "Oh, we are only utilizing 16 of the 64 bits of a CPU running at 1.3 GigHz. Who cares if it is optimized. It will still run fast." Bah I say!!
Can you imagine going back to a full blown app and try to optimize it then?? How much code would you realize that you had to re-write?
I think that optimization and speed should be at least in the top 5 programming stages. (Yes, even in the JAVA world)
Just think how much better Windows could be if Microsoft worried about such things.
Just my opinion.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And a valid opinion it is too.
Note that I was just quoting Joshua.
While he has a very valid point, I must admit that we have code reviews that look at performance and efficiencies - even on an original write.
However admitting that makes for much fewer fireworks .
That said, I am not sure that just decreasing the size of a classfile is going to make an application more efficient. A typical method of doing this is to split that large class into smaller classes. While that is probably a good idea from an OO point of view, it could be LESS efficient, it sort of depends on the code.
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing with performance tuning is that focus is often misplaced. Use a profiler to identify the bottlenecks in your application. That takes a lot of the guesswork and "gut feel" out of the process. Then decide which bottleneck, if any, is worth optimizing.
Is it really worth having 4 reviewers spend 15 minutes (for a total of 1 hour of costly development time) arguing over whether a for loop is more efficient that a while loop? This example may be extreme but the point is, optimize only when it is worth the effort.
Good programs are those that are: clear, simple, well-structured. Get the form right and speed will follow. For the majority of the work we do, this is as optimal as we should strive for.
My $0.02
Junilu
 
Reuben Cleetus
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose what can be best said for Optimization, is that it is something that ought not to take precedence over the primary goals in Software Engineering -- create an app that satisfies user requirements, AND which is easy to maintain.
Readability and maintainability are therefore a very high priority. I think programmers in general should err on the side of readability, unless speed is absolutely mission-critical. I cannot think of any such application that I have been involved in, and frankly, I don't think there are many cases when speed absolutely is THE most important issue.
Surely device drivers and other low-level system programming can justifiably promote speed very high up on the list of priorities, but elsewhere, it should be balanced with maintainability.
Regards,
Reuben Cleetus.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just an addition to what said above. In my opinion, readability is the most important aspect of coding, besides meeting the specs. To anyone who is new reading this--there is almost nothing easier to maintain than well commented code. Self-commenting code along with well placed block and inline comments can save much and many headaches.

------------------
Jason R. Kretzer
Software Engineer
http://alia.iwarp.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic