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: Rael Bauer
Subject: Re: How to enable "shorthand" access element in NSArray
Date: Sun, 28 Dec 2014 23:36:40 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1

Thanks for the elaboration. It gives me a better understanding of the issue.

-Rael

On 2014/12/28 10:59 PM, Dr. H. Nikolaus Schaller wrote:
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]