Newsgroups: comp.lang.java,comp.object,comp.object.logic
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!in2.uu.net!ftpbox!mothost!schbbs!news
From: shang@corp.mot.com (David L. Shang)
Subject: Re: Java public instance variables harmful?
Reply-To: shang@corp.mot.com
Organization: MOTOROLA 
Date: Tue, 12 Mar 1996 14:39:24 GMT
Message-ID: <1996Mar12.143924.25396@schbbs.mot.com>
References: <RMARTIN.96Mar11083147@rcm.oma.com>
Sender: news@schbbs.mot.com (SCHBBS News Account)
Nntp-Posting-Host: 129.188.128.126
Lines: 46
Xref: glinda.oz.cs.cmu.edu comp.lang.java:30853 comp.object:45713 comp.object.logic:746

Even making variables private might not be safe if the method
on the variable is badly designed.

A programming language cannot ensure the correctness of a program,
just as a natual language cannot guarantee that every one speak the
right thing by using the language. If there were such a language, the
language might be useless in practice.

However, if the language encourages bad design, or the language
prohibit you from writing right things, it is a bad language.

By using Java or C++, do people really have to expose variables
in public interface? No. It is the application designers' choice!

In general, a released applcation developer's interface should not
contain any public variables. But within the application, it is
convenent to expose some public variables for implementations.

I do not see a sufficient reason for a language to prohibit
a developer from using public variables from a class developed
by him/herself.. And remember, 80% percent of usage of a general
purpose language is for developers.

Java's interface classes are a good feature for deliver application
interface to customers, which contains no variables. However,
the implementation of an interface is another world!

Don't try to set up the same criteria for your customers and for
your developers!

Many good things could be harmful if they are not properly used.

If a knife could be harmful, would you like to set up a law to
prohibit manufactory from producing kitchen knivies?

Functions are harmful because they have side-effects, would you
like to use a programming language without side-effects? I bet
you not unless you like a pure black box, to which you ask
something, but you can never get the answer. Yes, it answers,
but there is no visible place for it to put the answer. Writing
answers to display does need side effects, which might be harmful
in destroying something already displayed on the screen.  To find
the answer, should we have to check the value in memory?


David Shang
