discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to enable "shorthand" access element in NSArray


From: Dr. H. Nikolaus Schaller
Subject: Re: How to enable "shorthand" access element in NSArray
Date: Sun, 28 Dec 2014 21:59:05 +0100

Am 28.12.2014 um 20:59 schrieb Rael Bauer <support@bauerapps.com>:
> 
> Can you please elaborate on why you say that?

He said this:

> 
>> as it (along with the property notation) destroy one of the key strengths of 
>> Objective-C: the orthogonality of syntax.  In particular, with the fragile 
>> ABI, you were allowed to allocate C arrays of objects, so myArray[1] means 
>> *(&myArray + 1).

Orthogonal syntax means: well designed and without hidden pitfalls.

In C language a.b is equivalent to (&a)->b and a->b to (*a).b.
And a[b] is equivalent to *(a+b) and even b[a].

In Objective C all method calls are:

[object method]

Now, with the property notation, what is a.b? It may be a method call. What is 
a[b]? It may be your shorthand array access (which is also a method call) but 
also something else.

So a method call may be hidden in syntax that did have a clear definition 
before Obj-C 2.0 was introduced.

And leads to strange (confusing and less readable) constructions like:

[[self.getter method].something other]

Some people find it great that you now can use some well known idioms from C++ 
and JAVA - but long-term users of Obj-C did not miss them at all, because it 
was already possible to program anything with Obj-C 1.0. Obj-C 2.0 adds 
complexity (more complex grammar and semantics: exceptions in the syntax rules 
and special cases) to the language that one has to learn and take care of. A 
more complex language increases the risk of flaws because it hides deeper what 
is really going on.

An interesting question is when [object method] will be recognised by JAVA 
compilers :)

— hns


reply via email to

[Prev in Thread] Current Thread [Next in Thread]