discuss-gnustep
[Top][All Lists]
Advanced

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

Re: PROPOSAL: Objective-C++


From: David Relson
Subject: Re: PROPOSAL: Objective-C++
Date: Mon, 19 Nov 2001 20:23:19 -0500

At 12:06 AM 11/19/01, you wrote:

> >    -- What is this 'blocks' feature in the POC compiler?
> >
>
> A block is a piece of code that can be passed as a parameter in a
> subroutine or a method.

With the risk of being flamed, I must say - frankly - that I don't think
it's a good idea to add this to the GNU Objective-C compiler ...

It would make the language more complex, while one of the virtues is its
simplicity.

It would not really add anything you can't do by using C pointers to
functions - or selectors - and similar tools ... even if blocks might be
cooler for smalltalk people, they are one thing more to learn ... one more
tricky syntax to get familiar with ... one more concept ... and their
practical usage is quite limited - if any.

I learned Objective-C after 3 years of (nearly) exclusive use of Smalltalk. I was pleased to get the added speed of C's primitive types (int, float, etc) and loops, but really missed blocks. A very simple use of a block is to apply a operation to all elements of a collection (array), for example:

- (void) arrayDo: (NSArray *) array
{
        [ array do: [ :item | item doSomething ]];
}

This example can currently be coded in Objective-C, but isn't nearly as elegant:

- (void) arrayDo: (NSArray *) array
{
        int i;
        for (i = 0; i < [ array length ]; i += 1 )
        {
                NSObject *item = [ array objectAtIndex: i ];
                [ item doSomething ];
        }
}

Also consider how to process a list, rather than an array. For the block form, the code would be the same (except the argument would be an NSList (or some such)). For the for loop variant, it'd be necessary to use an iterator and code with it.

I would LOVE to see blocks in Objective-C !


We don't want Objective-C to become crammed with new syntax like C++, so I
vote against it.

I'd vote for implementing real exception handling instead.

This would also be a valuable addition :-)

David





reply via email to

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