This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

programming style

 
jaspreet atwal
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My query is related to code shown below. Here I have declared a few variables, like JFrame, JTextArea as instance variables where as a few, like JPanel and JButton, as local variables inside method go(). I could also have made all the variables as instance variables or all of these as local variables... It would work fine. Now my question is what is a better coding practice? How and where will this make a difference.

I am sorry if this question sounds very stupid, I am still new to programming.
Thank you all!

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, I would move all variables into a method that you don't need to use outside of that method. They just clutter up the namespace (using another field called "frame" anywhere else in the program might become confusing), and the objects they're pointing to might not become eligible for garbage collection.
 
jaspreet atwal
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got yaa,
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic