473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

final/package-private underused

Step on my soapbox... :-)

I believe that the "final" keyword is underused in Java. I have
gotten into the habit of using it on EVERY method parameter, instance
variable, and local variable unless I have reason not to do so. I
also use it on class definitions although one could argue that that
defeats the idea behind code reuse (I have the source code and can
change it to not be final if necessary).

I also believe that package-private is WAY underused. All of my
methods are declared without "public" unless they must be visible
outside of the package.

What do others think?
Jul 17 '05 #1
2 5288
G. Ralph Kuntz, MD wrote:
Step on my soapbox... :-)

I believe that the "final" keyword is underused in Java. I have
gotten into the habit of using it on EVERY method parameter, instance
variable, and local variable unless I have reason not to do so. I
also use it on class definitions although one could argue that that
defeats the idea behind code reuse (I have the source code and can
change it to not be final if necessary).
I mostly agree with you, although I stop short of declaring method
parameters final. Also, I do not think it is a good idea for class
declarations. One should not need to change the class you wish to
extend in order to extend it, that defeats the purpose of re-use via
inheritance. (Although re-use via inheritance is overrated.)

I also believe that package-private is WAY underused. All of my
methods are declared without "public" unless they must be visible
outside of the package.


I disagree with you here. I try to avoid package level access
completely. (I assume here that you mean non-private methods when you
say "all of my methods...") I like to keep classes self-contained. If
another class needs access to something in my class it should be public.
Otherwise I feel you've broken encapsulation.

Rebuttals?

Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2
Raymond DeCampo <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in message news:<nX*******************@twister.nyroc.rr.com>. ..
G. Ralph Kuntz, MD wrote: .... I mostly agree with you, although I stop short of declaring method
parameters final. Also, I do not think it is a good idea for class
declarations. One should not need to change the class you wish to
extend in order to extend it, that defeats the purpose of re-use via
inheritance. (Although re-use via inheritance is overrated.)
.... I disagree with you here. I try to avoid package level access
completely. (I assume here that you mean non-private methods when you
say "all of my methods...") I like to keep classes self-contained. If
another class needs access to something in my class it should be public.
Otherwise I feel you've broken encapsulation.

Rebuttals?

Ray


I agree on the issue with private classes and many times have had to
go back and change them to public, but why do you not use final on
method parameters? It has save my butt on more than one occasion
where I entered

void myMethod(final int someVariable) {
someVariable = ...
}

where I meant to enter

this.someVariable = ...

(One could argument against naming locals/parameters with the same
names as instance variables).

Of course, you are correct about the "non-private" -- I always use the
most restrictive "protection" that I can --
private->protected->"package private"->public.

I have an easier time finding bugs when I know that the only calls to
a method are inside the current class, package, etc.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Barry Warsaw | last post by:
Python 2.4 final will probably be released in a few hours so this seems like a good time to release the standalone email package, version 3.0 final. Unless there's some last second snafu, this...
16
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.4. Python 2.4 is a final, stable release, and we can recommend that Python users...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
0
by: Stéphane Mottelet | last post by:
XMLlab-1.4 final release is out ! XMLlab is an XML-based simulation authoring environment. The proposed description language allows to describe mathematical objects such as systems of ordinary...
3
by: shorti | last post by:
running on AIX with DB2 v8.2.2 I ran across a problem with naming source files with similar names. For instance, if I have these three files: upd_startaccessingdb.sqc upd_startusingdb.sqc...
0
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.6 (FINAL). Python 2.3.6 is a security bug-fix release. While Python 2.5 is the...
13
by: ravi | last post by:
I am a final year computer engineering student i am looking for some good as well as tough project ideas in C/C++ Can anybody help me by giving their ideas Thanks in advance.
0
debasisdas
by: debasisdas | last post by:
The following thread contains some useful tips/sample codes regarding PACKAGES in oracle, that the forum members may find useful. A package is a collection of procedures,functions,cursors,global...
0
by: Edward K Ream | last post by:
Leo 4.5 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See:...
0
by: Edward K Ream | last post by:
Leo 4.5.1 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.5.1 final fixes several important bugs in Leo 4.5 final: - Eliminated...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.