Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #3142 > unrolled thread
| Started by | bob <bob@coolfone.comze.com> |
|---|---|
| First post | 2013-03-07 14:03 -0800 |
| Last post | 2013-03-09 09:32 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.programming
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
| From | bob <bob@coolfone.comze.com> |
|---|---|
| Date | 2013-03-07 14:03 -0800 |
| Subject | taxing syntax |
| Message-ID | <5d7a408b-e89e-41dc-b70f-b9951e449cba@googlegroups.com> |
Does anyone know the etiology of Objective-C method declarations? - (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. This is hard for me to remember, and it hurts my brain.
[toc] | [next] | [standalone]
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Date | 2013-03-09 09:27 +0000 |
| Message-ID | <HOGdnfrFNaPUnKbMnZ2dnUVZ8omdnZ2d@bt.com> |
| In reply to | #3142 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Date | 2013-03-09 09:32 +0000 |
| Message-ID | <XeedneogFePOn6bMnZ2dnUVZ7t-dnZ2d@bt.com> |
| In reply to | #3148 |
I wrote:
> The OO parts of Objective C are, I believe (though I can't cite a
> reference), directly taken from Smalltalk
Just to add: the Objective C article on Wikipedia appears well-balanced and
informative.
-- chris
[toc] | [prev] | [standalone]
Back to top | Article view | comp.programming
csiph-web