Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #3148

Re: taxing syntax

From "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org>
Newsgroups comp.programming
References <5d7a408b-e89e-41dc-b70f-b9951e449cba@googlegroups.com>
Subject Re: taxing syntax
Date 2013-03-09 09:27 +0000
Message-ID <HOGdnfrFNaPUnKbMnZ2dnUVZ8omdnZ2d@bt.com> (permalink)

Show all headers | View raw


bob wrote:

> - (return_type)instanceMethod2WithParameter:(param1_type)param1_varName
> param2_callName:(param2_type)param2_varName;
>
> Am I the only one who finds this extremely unnatural?  In particular, the
> type appearing in parentheses is strange to me.

You'll get used to it ;-)

Anyway, I don't know Objective C, but the syntax appears to be an effort to 
combine the syntax of Smalltalk methods (which works very well) with a 
statically typed language.  Smalltalk is dynamically typed, so the above 
example would be expressed as:

    instanceMethod2WithParameter: param1_varName param2_callName: 
param2_varName
        ... function body...

or, with some noise removed:


    instanceMethod: var1 param2: var2
        ... function body...

The OO parts of Objective C are, I believe (though I can't cite a reference), 
directly taken from Smalltalk, so that seems the likely history.

It may be that the use of brackets around the type name is influenced by the C 
"cast" syntax, and is intended to suggest that you are "casting" the underlying 
object reference (i.e. a Smalltalk-style untyped reference) to the declared 
type, but that's mere speculation.

The syntax certainly looks clumsy to me.  Perhaps they'd have been better off 
with something parallel to the original C syntax where the parameters were 
named in the function header, but type declarations were made separately.
    return_type
    instance_method(var1, var2)
        type1 var1;
        type2 var2;
    {
        ... function body...
    }

(That's from 20+ year old memory, so I may have the details wrong).

So -- in the hypothetical case -- the Objective-C method would have read:

    return_type
    instanceMethod: var1 param2: var2
        type1 var1;
        type2 var2;
    {
        ... function body...
    }

    -- chris 

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

taxing syntax bob <bob@coolfone.comze.com> - 2013-03-07 14:03 -0800
  Re: taxing syntax "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-03-09 09:27 +0000
    Re: taxing syntax "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-03-09 09:32 +0000

csiph-web