[E-Lang] get, set, and dot

Karp, Alan alan_karp@hp.com
Mon, 26 Feb 2001 09:53:21 -0800

I don't like the dot notation because it hides a semantically useful
concept.  There is a real difference between foo.blah=1 for a public
variable and foo.setblah(1) with a public method.  Using the latter assures
me that any necessary checking is being done.  Similarly, bar = foo.blah on
a public variable is guaranteed to be free of side effects and that it
really assigns the value of the public variable; bar = foo.getblah() does

Actually, I'm opposed to the use of public variables.  All variables should
be private and accessed with getters and setters.  The only justification
seems to be efficiency and saving a few lines of typing.  I don't find the
extra typing to be a burden, and modern compilers are real good at inlining.
Besides, if you always use getters and setters, you won't break anyone's
code when you need to do more with the variable.  Of course, you can get
this behavior by always interpreting foo.blah as foo.getblah() or
foo.setblah(), but it has problems.  Maybe because my mother tongue is
Fortran I often type = when I mean ==.  If I type 

	if ( foo.blah = 1 ) 

by mistake, something bad happens.  If I type 

	if ( foo.getblah() = 1 )

by mistake, the compiler tells me I've got an error. 

Alan Karp
Principal Scientist
Decision Technology Department
Hewlett-Packard Laboratories MS 1U-2
1501 Page Mill Road
Palo Alto, CA 94304
(650) 857-3967, fax (650) 857-6278

> -----Original Message-----
> From: Marc Stiegler [mailto:marcs@skyhunter.com]
> Sent: Saturday, February 24, 2001 10:10 AM
> To: E Language Discussions
> Subject: [E-Lang] get, set, and dot
> Another thing the ertpMintMaker reminded me of is that I 
> seriously dislike
> the dot notation
> foo.blah := 1
> and
> bar := foo.blah
> in the special case when foo has methods getBlah and setBlah. It feels
> convenient the first time you use it, but I found it 
> disorienting reading
> the ertpMint, I kept on losing track of which language I was 
> looking at. I
> had to keep thinking, "No, foo does not have a blah method or 
> a blah public
> variable."
> My real heartburn with it comes from the perspective of 
> writing the book of
> E. E in a Walnut does not describe this notation now. If the 
> notation is
> left in the language, I cannot exclude it from the basic 
> book, I cannot even
> put it in an "Advanced" section, because people will see it in other
> people's code all the time. So it has to go in the "Basic 
> Programming" part
> of the book, which is already huge with E's syntactic 
> variations.  Yet it is
> just a special case: "dear reader, on those occasions where 
> someone uses the
> JavaBeans getBlah and setBlah conventions, there is yet 
> another syntactic
> alternative you need to remember. Learn this too before I 
> introduce you to
> the really cool stuff in E."
> If everyone loves this notation, I guess it is here to stay, and I'll
> document it without making it sound quite so grumpy in the 
> book as it sounds
> above. But if there are other people who dislike it, now is 
> the time to
> speak up, we are running out of time to kill this thing 
> before the whole E
> chicken finally gets hatched.
> --marcs
> _______________________________________________
> e-lang mailing list
> e-lang@mail.eros-os.org
> http://www.eros-os.org/mailman/listinfo/e-lang