[Grace-core] In praise of consistency

Andrew P. Black black at cs.pdx.edu
Fri May 18 15:37:27 PDT 2012


On 18 May 2012, at 11:41 , Kim Bruce wrote:

> I think that's right.  The first is definitely what I would want to write, while I assume the second involves the method request of "on" to self with parameter output.mainStream and then taking the results of that request and using it as a parameter to method "reversed".
> 
> Kim

So now we have agreed on what you like, I'm going to write in praise of consistency, and point out that what you like is inconsistent.  It's inconsistent because it uses parenthesis for two different, and contradictory, purposes.

The first use of parenthesis is for grouping.  The outer set of parentheses around  (on (output.mainStream)) is for grouping.   These parentheses say that everything inside the parens is a single expression and should be evaluated first (here by requesting on from self.)

The second use of parentheses is to say that a method take an argument.    This follows the mathematical usage f(x). Note carefully that the meaning of these parens is different from the grouping parens.  f(x) means that f operates on x, i.e., (f x).  Indeed, some mathematicians prefer to write exactly that, in order to be consistent.

(Oxford, and Richards) BCPL resolved this inconsistency by using [ ] to provide arguments and ( ) for grouping.  Fortress uses juxtaposition for application, and ( and ) only for grouping.  Using BCPL brackets,  our example would be

	print ["hello".reversed (on [output.mainStream] ) ]

which distinguishes the applications from the grouping.   The two nested sets of [ ] tell us immediately that there are two method requests.  Are the parens necessary at all?

I would argue that 

	print ("hello".reversed) on (output.mainStream)

is no better than

	print "hello".reversed on output.mainStream

since the grouping implied by the parens is already implied by the dots, which "visually" bind more tightly than the spaces.  In contrast,

	print ["hello".reversed] on [output.mainStream]

is an improvement, since now we are using [ and ] consistently to mean "here is an argument".

I don't expect to win you over to this point of view.  But please don't argue that what you want to do is "consistent".  It is conventional, but it is not consistent.   Maybe being conventional is more important than being consistent, but that's a different argument.

If we just want to be consistent, and don't want to usurp bracts for application (which will look really ugly when the arguments are blocks), then I think that we could use these two forms:


	print "hello".reversed on output.mainStream

and

	print ("hello".reversed on output.mainStream)



> 
> 
> 
> On May 18, 2012, at 10:21 AM, Andrew P. Black wrote:
> 
>> So, I think that Kim and Michael are both saying that the two forms should be
>> 
>> 
>> 	print ("hello".reversed) on (output.mainStream)
>> 
>> and
>> 
>> 	print ("hello".reversed (on (output.mainStream)))
>> 
>> 
>> Is that right?
>> 
>> 	Andrew



More information about the Grace-core mailing list