What means "best practice"?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 189
Reputation: George2 is an unknown quantity at this point 
Solved Threads: 0
George2 George2 is offline Offline
Junior Poster

What means "best practice"?

 
0
  #1
Feb 21st, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 780
Reputation: OurNation is an unknown quantity at this point 
Solved Threads: 9
OurNation's Avatar
OurNation OurNation is offline Offline
Master Poster

Re: What means "best practice"?

 
0
  #2
Feb 22nd, 2005
Can you post an exaple of where "best practice" is used?
PETA People for the Eating of Tasty Animals.


FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 189
Reputation: George2 is an unknown quantity at this point 
Solved Threads: 0
George2 George2 is offline Offline
Junior Poster

Re: What means "best practice"?

 
0
  #3
Feb 22nd, 2005
Thanks OurNation,


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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: What means "best practice"?

 
0
  #4
Feb 22nd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 46
Reputation: Gargol is an unknown quantity at this point 
Solved Threads: 1
Gargol's Avatar
Gargol Gargol is offline Offline
Light Poster

Re: What means "best practice"?

 
0
  #5
Nov 4th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 46
Reputation: Gargol is an unknown quantity at this point 
Solved Threads: 1
Gargol's Avatar
Gargol Gargol is offline Offline
Light Poster

Re: What means "best practice"?

 
0
  #6
Nov 4th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 146
Reputation: G-Do is an unknown quantity at this point 
Solved Threads: 28
G-Do's Avatar
G-Do G-Do is offline Offline
Junior Poster

Re: What means "best practice"?

 
0
  #7
Nov 5th, 2005
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.
Vi veri veniversum vivus vici
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: What means "best practice"?

 
0
  #8
Nov 5th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 46
Reputation: Gargol is an unknown quantity at this point 
Solved Threads: 1
Gargol's Avatar
Gargol Gargol is offline Offline
Light Poster

Re: What means "best practice"?

 
0
  #9
Nov 5th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: What means "best practice"?

 
0
  #10
Nov 6th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC