[Grace-core] In praise of consistency

Kim Bruce kim at cs.pomona.edu
Thu May 17 12:51:33 PDT 2012


One of the pieces of the Grace language design that jumped up and bit my students has to do with consistency.

Grace allows parentheses to be dropped in many cases when applying a method to a single argument.  Thus we see examples like
	print "hello world"
These work when we have the parameter bounded by "" or {} and I believe if we have a constant (though not sure about that.  However, if we write
	print "Hello, world."++"other"
then we get a relatively obscure error message:
	No such method '++' on undefined, called at line 1.
	Methods are:
 	  ==
	  !=
	  /=
	  asString
	Runtime error around line 1 

I believe that this inconsistency will make life harder for novices.  The main reason that we need this is for user-defined control structures where we are passing blocks.  Thus I propose we only allow parens to be dropped if the parameter is surrounded by {}.

If we do this, most of the examples in James' paper will need to be fixed, but I believe the extra overhead is minimal.

Related to this, I am coming to have stronger and stronger feelings that automatically generating "setter" methods is a mistake.  Right now if x is an instance variable then we automatically generate methods x and x:=().  From a oo design point of view I don't particularly want to make it easy for students to directly access and update instance variables (even though it would implicitly go through method calls).  Secondly, if x:=() really is a method, and is used consistently with other methods then we would have to write:
	x:= (3+5) 
rather than 
	x:= 3+5
(as would be legal for a local variable).

Again, consistency is very important for novices and I would hate to have to get them to understand and consistently use them differently, especially since they are syntactically the same.

Interestingly, minigrace does allow the version without parens -- which is seemingly inconsistent with our rule for other methods.

Kim





More information about the Grace-core mailing list