944,155 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4661
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 21st, 2005
0

What means "best practice"?

Expand Post »
Hello everyone,


I have always seen some methods are described as "best practice". I am wondering what means "best practice", an algorithm?


Thanks in advance,
George
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Feb 22nd, 2005
0

Re: What means "best practice"?

Can you post an exaple of where "best practice" is used?
Reputation Points: 16
Solved Threads: 9
Master Poster
OurNation is offline Offline
780 posts
since Aug 2004
Feb 22nd, 2005
0

Re: What means "best practice"?

Thanks OurNation,


Quote originally posted by OurNation ...
Can you post an exaple of where "best practice" is used?
There are many examples. For example, you can search "best practice" in http://java.sun.com, and you can find many of them.


regards,
George
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Feb 22nd, 2005
0

Re: What means "best practice"?

Probably whatever is the most efficent...Like if you have a small program that could be accomplished with an iterative loop, it would NOT be good practice to use recursion.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Nov 4th, 2005
0

Re: What means "best practice"?

Anyone know of some simple best practice lists somewhere? Searching the sun link above is a bit blinding.

Here is a simple issue which new Java programmers meet quite quickly...

If I write a class that will be instantiated ONLY once is it best practice to put most of the initialisation code in the initialiser block or in the constructor?

In many cases there is loads of code that would work in either position because it is pre-configuring instance variables before they are used or displayed.

For trivial classes this doesn't make much difference but as classes grow it gets more important to have a clear structure or sequence for the initialisation code.
Reputation Points: 10
Solved Threads: 1
Light Poster
Gargol is offline Offline
46 posts
since Oct 2005
Nov 4th, 2005
0

Re: What means "best practice"?

This ref covers some useful basic stuff on layout.

http://java.sun.com/docs/codeconv/CodeConventions.pdf

Umfortunately it doesn't extend to my initialisation code issue et al.

Anyone have a link to something that takes it a bit further?
Reputation Points: 10
Solved Threads: 1
Light Poster
Gargol is offline Offline
46 posts
since Oct 2005
Nov 5th, 2005
0

Re: What means "best practice"?

If the class only needs to be instantiated once, does it need to be instantiated at all? Why not use static methods? My personal preference is to avoid adding object-orientation that doesn't have to be there - it makes everything seem cleaner, somehow. This also takes care of the constructor vs init method issue - if there's no instantiation, there's no constructor.

Just a thought.
Reputation Points: 41
Solved Threads: 31
Junior Poster
G-Do is offline Offline
146 posts
since Jun 2005
Nov 5th, 2005
0

Re: What means "best practice"?

Static methods are not OO, and therefore not recommended by good OO approaches (which are best practice).

That's not to say they don't have their uses, but in strict OO design you will not find them.
At most some singletons and methods which have no instance specific functionality may be turned into static methods at some point if such yields superior performance.

Of course in reality that's often factored into the design as people get experienced enough to make such decisions at an early stage, but it's only the absolute beginners who make everything static, effectively abandoning OO altogether.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 5th, 2005
0

Re: What means "best practice"?

Thanks. Looks like it's the constructor. I understand that design patterns also indicate this although I'm unsure how to check that one out.
Reputation Points: 10
Solved Threads: 1
Light Poster
Gargol is offline Offline
46 posts
since Oct 2005
Nov 6th, 2005
0

Re: What means "best practice"?

Buy yourself "Head First Design Patterns" by Eric and Elisabeth Freeman (0596007124).

It's an excellent book that explains not just the patterns but why and how to use them.
I knew the basic idea before reading that book and could recognise them, but couldn't for the life of me figure out how to apply that knowledge consistently.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Rezisable Panels?
Next Thread in Java Forum Timeline: run the number to the word equivalent





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC