[Bluej-discuss] bluej-discuss Digest, Vol 53, Issue 30

pwarren at uaeu.ac.ae pwarren at uaeu.ac.ae
Mon Dec 3 08:54:37 GMT 2007


Overloading ==

Java has no syntactic difference between a reference and a value. The user of the language is thus encouraged to believe that they are the same; it is just an implementation detail. So if s is a string and we print it and get "It is me", and t is a string and we print it and get "It is me", we are likely to to conclude that s == t is true. It would be in most programming languages, and would be so in Java most of the time, but not all the time. To understand why requires a knowledge of how Java is implemented. But it is not apparent why from the syntax or behave in a uniform way with value types.

So == behaves differently, but subtly differently, under different circumstances. No wonder the students are confused. There is clear theoretical reasons for understanding why they are.

Regards Peter

"Programming without proper math skills is like writing proper English gibberish, where all the words are correct, even the syntax, but nothing makes any sense." 


Dr Peter Warren
Faculty Chair
Room 3100
College of Information Technology
PO Box 17555
Al Ain
United Arab Emirates
Tel    + TBA office
Mobile +971 50 673 9146
Fax    +971 3  762 6309
Home   +971 3  767 0586
Email pwarren at uaeu.ac.ae
     PeterRWarren at gmail.com
      PeterWarren at acm.org
      PRWarren at telkomsa.net


----- Original Message -----
From: bluej-discuss-request at bluej.org
Date: Saturday, December 1, 2007 0:52 am
Subject: bluej-discuss Digest, Vol 53, Issue 30

> Send bluej-discuss mailing list submissions to
> 	bluej-discuss at bluej.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.bluej.org/mailman/listinfo/bluej-discuss
> or, via email, send a message with subject or body 'help' to
> 	bluej-discuss-request at bluej.org
> 
> You can reach the person managing the list at
> 	bluej-discuss-owner at bluej.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of bluej-discuss digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: confusion over = (Lon Levy)
>   2. Re: confusion over = (Lon Levy)
>   3. Re: confusion over = (and == ?) (Ian Barland)
>   4. Re: confusion over = (and == ?) (Paul McCard)
>   5. Re: confusion over = (and == ?) (Louise Laforest)
> 
> 
> -------------------------------------------------------------------
> ---
> 
> Message: 1
> Date: Fri, 30 Nov 2007 09:50:20 -0600
> From: "Lon Levy" <LXL at oregon.k12.wi.us>
> Subject: Re: [Bluej-discuss] confusion over =
> To: "General discussion for users of BlueJ" <bluej-discuss at bluej.org>
> Message-ID: <474FDCDC.293A.008B.0 at oregon.k12.wi.us>
> Content-Type: text/plain; charset=UTF-8
> 
> Good morning Michael,
> 
> I have said numerous times how grateful I am to you and the BlueJ team
> for a wonderful pedagogical IDE.  I continue to believe that it is the
> best tool for teaching Java.  Now I wish I was teaching Blue 
> instead. 
> 8-(
> 
> A tip of the hat to you, sir,
> 
> Lon.
> 
> Lon Levy, MS-CSEd
> Computer Science Teacher
> Volunteer Computer Club Advisor
> Oregon High School
> 608-835-1316
> 
> Lon.Levy at oregonsd.org
> LXL at oregon.k12.wi.us
> cs at levytree.net
> 
> non somnos requiem
> 
> 
> >>> Michael K?lling <M.Kolling at kent.ac.uk> 11/30/2007 5:44 AM >>>
> On 30 Nov 2007, at 11:22, Michael E. Caspersen wrote:
> 
> > ... teaching language Blue...
> 
> Yes, in Blue everything was an object. And operations had a 
> uniform  
> syntax, for example
> 
>    2.add(4)
> 
> But then there were "aliases". I have just looked at the language 
> spec 
> 
> again (after a long time!). Here is what it says:
> 
> "All types in Blue are classes and all data are objects.  This 
> general 
> 
> rule
> simplifies the language design.  There are, however, a number of 
> data 
> 
> types
> for which it is convenient to use syntax other than the Blue 
> object  
> call to
> perform one of their operations.  The reason for this can be:
> 
> 	? Another syntax is commonly used and is therefore more
> intuitive (e.g.
>          3 + 5 for integer addition, rather than 3.add (5)  ).
> 	? Another syntax simplifies use of elementary constructs which
> should  
> be
>          used by beginners before the underlying language 
> concepts need
> to be
>          understood, e.g.
>        	print (?result=?, 42)
>           instead of
>        	output.write (?result=?.concat (42.toString))
> 	? Another syntax is more convenient (usually because it is
> shorter, see
>          above).
> 
> For these reasons, several operations on the predefined classes 
> are  
> supported
> by special syntax.  This special syntax is allowed in addition to 
> the 
> 
> standard
> object-call syntax generally available for all classes, and is  
> referred to as
> aliases.
> ...
> Note that aliases are a pure syntactic addition which does not add any
> functionality to the language.  They do not affect the semantics or
> the
> theoretical language description of Blue (although they are part of
> the
> language), and are purely intended to increase readability and  
> intuitivity of
> statements. "
> 
> Oh yes, and Blue uses, of course, = for equality check and := for  
> assignment...  :)
> 
> If anyone is really interested in dead old languages, the spec is
> here:
> 
> 	http://www.cs.kent.ac.uk/people/staff/mik/blue/doc/spec-102.pdf
> 
> 
> Michael
> 
> _______________________________________________
> mailing list bluej-discuss at bluej.org 
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Fri, 30 Nov 2007 12:29:10 -0600
> From: "Lon Levy" <LXL at oregon.k12.wi.us>
> Subject: Re: [Bluej-discuss] confusion over =
> To: <bluej-discuss at bluej.org>
> Message-ID: <47500216.293A.008B.0 at oregon.k12.wi.us>
> Content-Type: text/plain; charset=US-ASCII
> 
> Hi Kyle,
> 
> You say that "==" is not overloaded.  Perhaps overloaded is the 
> wrong term, but the concept is there.  Java in a Nutshell, Table 2-
> 4 lists it twice:
> 
>  ==    primitive, primitive      equal (have identical values)
>  ==    reference, reference    equal (refer to the same object)
> 
> When there are two methods of the same name, one of which has two 
> primitives as parameters and the other has two references as 
> parameters, the methods are said to be overloaded.  Thus, my use 
> of the term.  "==" is not a method, it is a comparison operator, 
> so it is not quite the same thing.
> 
> I think we are all saying the same thing (including a couple of 
> people who wrote me off-list), just using different terminology.  
> Students getting confused over this should not be surprising.
> 
> Regards,
> 
> Lon.
> 
> Lon Levy, MS-CSEd
> Computer Science Teacher
> Volunteer Computer Club Advisor
> Oregon High School
> 608-835-1316
> 
> Lon.Levy at oregonsd.org
> LXL at oregon.k12.wi.us
> cs at levytree.net
> 
> non somnos requiem
> 
> 
> >>> Kyle Gillette <scheme2java at yahoo.com> 11/29/2007 11:46 PM >>>
> Lon Levy wrote:
> I would be careful with using "is equal" for "==".  Instead, I use 
> "is the same as".  This is important because in Java the "==" is 
> overloaded to mean 'the same value' for primitives and 'the same 
> instance' for objects. 
> 
> I don't think that == is overloaded at all.  For both primitives 
> AND references it is comparing the values stored within the 
> variables.  If two references refer to the same object, then they 
> are equal, because their references have the same contents - 
> perhaps an address, :-o.  The real problem for students is 
> thinking that == compares the two objects when it does not.  I 
> believe that this confusion comes from the way we can treat 
> primitives.  I try to create references for each object that is 
> instantiated. I know that there are instructors who do not believe 
> in teaching it this way.
> 
> Point a;    // a [_]   lame attempt at drawing a box
> a = new Point(3,5);   // a[_]--->[3,5]  
> 
> Kyle
> 
> 
>      
> ____________________________________________________________________________________Be a better pen pal. 
> Text or chat with friends inside Yahoo! Mail. See how.  
> http://overview.mail.yahoo.com/ 
> _______________________________________________
> mailing list bluej-discuss at bluej.org 
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Fri, 30 Nov 2007 14:28:14 -0500
> From: Ian Barland <ibarland at radford.edu>
> Subject: Re: [Bluej-discuss] confusion over = (and == ?)
> To: <bluej-discuss at bluej.org>
> Message-ID: <C375CE7E.6EB1%ibarland at radford.edu>
> Content-Type: text/plain;	charset="US-ASCII"
> 
> Carl Alphonce writes:
> >
> > "==" is not overloaded.  "==" does the same thing in both cases.
> >
> I'd argue that == is overloaded, and even mention in CS1:
>  == : int, int --> boolean
>  == : double, double --> boolean
>  == : Object, Object --> boolean    (once we have talked about 
> references)
>   / : double, double --> double
>   / : int, int --> int              // named "quotient" in some 
> languages
> Yes, like any good overloaded method, each version of == does a 
> similar task
> (unlike "/").
> 
> [True, these different overloaded methods for == might each 
> compile to the
> same op code, but at the high-level of Java syntax == must be 
> overloaded so
> that the auto-casting rules for 0==0.0, etc, can be invoked.  Also 
> note that
> Double.NaN == Double.NaN, so the == for doubles requires an extra 
> checkwhich the other overloaded versions don't.]
> 
> 
> Is it worth *teaching* that even operators have signatures?  I've 
> found so;
> it helps reinforce that "==" returns a result which is usable, it 
> also helps
> explain why "/" seems to give different answers, and overall it 
> just helps
> unify the whole idea of calling functions.  (And while you might 
> sigh that
> it's a whole second syntax for calling a function, at least it's 
> not as
> (b)ad hoc as the syntax for casting primitives.)
> 
> --Ian B.
> 
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Fri, 30 Nov 2007 19:53:24 +0000
> From: Paul McCard <p.mccard at btinternet.com>
> Subject: Re: [Bluej-discuss] confusion over = (and == ?)
> To: General discussion for users of BlueJ <bluej-discuss at bluej.org>
> Message-ID: <47506A34.7040106 at btinternet.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> An HTML attachment was scrubbed...
> URL: http://lists.bluej.org/pipermail/bluej-
> discuss/attachments/20071130/6e449bcd/attachment-0001.html 
> 
> ------------------------------
> 
> Message: 5
> Date: Fri, 30 Nov 2007 15:44:57 -0500
> From: Louise Laforest <laforest.louise at uqam.ca>
> Subject: Re: [Bluej-discuss] confusion over = (and == ?)
> To: General discussion for users of BlueJ <bluej-discuss at bluej.org>
> Message-ID: <70B6FB42-7C41-41A1-8E88-497D824FE164 at uqam.ca>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> And also in C++, he can write p -> next to get the field "next" in 
> a  
> struct pointed to by p wich would be confusing if we had the 
> operator  
> "->" for the assignment statement as it was suggested earlier (ok, 
> 
> just for C++ programmers !).  Why they get rid of the ":=" for the 
> 
> assignment statement ?  I think it would be more uniform with the  
> other assigments operators +=, -=, *=, and so on.
> 
> I've taught lots of languages and students had no problems with ":="
> 
> Louise
> 
> 
> Le 07-11-30 ? 14:53, Paul McCard a ?crit :
> 
> > Of course, in C++ the programmer can define additional 
> overloadings  
> > of operators to make everything even clearer!  ;-)
> >
> > Paul.
> >
> > Ian Barland wrote:
> >>
> >> Carl Alphonce writes:
> >>>
> >>> "==" is not overloaded. "==" does the same thing in both cases.
> >> I'd argue that == is overloaded, and even mention in CS1: == :  
> >> int, int --> boolean == : double, double --> boolean == : 
> Object,  
> >> Object --> boolean (once we have talked about references) / :  
> >> double, double --> double / : int, int --> int // named 
> "quotient"  
> >> in some languages Yes, like any good overloaded method, each  
> >> version of == does a similar task (unlike "/"). [True, these  
> >> different overloaded methods for == might each compile to the 
> same  
> >> op code, but at the high-level of Java syntax == must be  
> >> overloaded so that the auto-casting rules for 0==0.0, etc, can 
> be  
> >> invoked. Also note that Double.NaN == Double.NaN, so the == for 
> 
> >> doubles requires an extra check which the other overloaded  
> >> versions don't.] Is it worth *teaching* that even operators 
> have  
> >> signatures? I've found so; it helps reinforce that "==" returns 
> a  
> >> result which is usable, it also helps explain why "/" seems to  
> >> give different answers, and overall it just helps unify the 
> whole  
> >> idea of calling functions. (And while you might sigh that it's 
> a  
> >> whole second syntax for calling a function, at least it's not 
> as  
> >> (b)ad hoc as the syntax for casting primitives.) --Ian B.  
> >> _______________________________________________ mailing list 
> bluej- 
> >> discuss at bluej.org To unsubscribe or change your preferences, go 
> to  
> >> http://lists.bluej.org/mailman/listinfo/bluej-discuss
> > _______________________________________________
> > mailing list bluej-discuss at bluej.org
> > To unsubscribe or change your preferences, go to
> > http://lists.bluej.org/mailman/listinfo/bluej-discuss
> 
> 
> -----------------------------------------
> Louise Laforest, Ph.D.
> Professeure
> Universit? du Qu?bec ? Montr?al
> D?partement d'informatique
> t?l?phone (514) 987-3000 poste 7790
> fax (514) 987-8477
> laforest.louise at uqam.ca
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: pastedGraphic.tiff
> Type: image/tiff
> Size: 25512 bytes
> Desc: not available
> Url : http://lists.bluej.org/pipermail/bluej-
> discuss/attachments/20071130/592a357c/attachment.tiff 
> -------------- next part --------------
> 
> 
> 
> 
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> bluej-discuss mailing list
> bluej-discuss at bluej.org
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
> 
> 
> End of bluej-discuss Digest, Vol 53, Issue 30
> *********************************************
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pwarren.vcf
Type: text/x-vcard
Size: 335 bytes
Desc: Card for <pwarren at uaeu.ac.ae>
Url : http://lists.bluej.org/pipermail/bluej-discuss/attachments/20071203/9e09c333/attachment.vcf 


More information about the bluej-discuss mailing list