discuss-gnustep
[Top][All Lists]
Advanced

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

Re: ANN: One Step to GNUstep - pre-release version 0.9


From: David Chisnall
Subject: Re: ANN: One Step to GNUstep - pre-release version 0.9
Date: Mon, 13 Jun 2011 16:43:06 +0100

On 13 Jun 2011, at 16:15, Richard Frith-Macdonald wrote:

> ObjC 2 certainly doesn't avoid  needing the concept of getter and setter 
> methods ... if you want to give people a gentle introductions to ObjC you can 
> leave out setter and getter methods anyway (not that they really add 
> complexity). A good introduction to object oriented programming would 
> discourage the idea of properties/instance-variables and encourage thinking 
> about what objects *do* anyway.

Setter and getter methods in Objective-C are one of the points that frequently 
confuse new developers, because there are a lot of gotchas in the assignment.  
This is so widespread that Google's Objective-C style guide even explicitly 
states how accessors should be written, and gets it wrong!

The biggest advantage of using synthesized property accessors happens when you 
thrown in GC.  The synthesized accessors with switch between the GC and retain 
/ release semantics depending on whether GC is being used.  This is most 
important with atomic properties, because these are much faster in GC mode than 
retain / release mode.

> It also has nothing to do with reference counting ... thats a completely 
> different issue (do you use reference counting or garbage collection), and if 
> you want to use GC then it's been around for traditional ObjC a lot longer 
> than ObjC2 (where it's currently in the process of being added in svn trunk 
> by David).

Correct assignment in a reference counting environment is nontrivial.  If you 
look at recent Apple tutorials, they let you avoid thinking about this by 
telling you to use synthesised properties and then use those set and get 
methods, rather than assigning directly to ivars!  This is significantly 
slower, but in most code no one actually cares about the performance 
difference, and it means that you automatically get correct code in GC or 
retain/release code.

> ObjC2 adds a few good features, but it adds a lot of fairly useless 
> complexity to a simple language and makes it much harder to learn.  In 
> particular the blocks syntax is rather ugly and doesn't fit well belonging 
> more to a functional programming paradigm than an object oriented programming 
> paradigm, so that adds considerable complexity,

Blocks were in Smalltalk right from the start.  They are one of the fundamental 
features of most object oriented languages.  The syntax is, I agree, quite 
ugly, but they're one of the fundamental building blocks of object oriented 
languages.  JavaScript and Self manage a rich object system with just 
dictionaries and blocks.

After using Pragmatic Smalltalk for a bit, the main thing I missed when 
returning to Objective-C was the BlockClosure class.  With Objective-C 2, I can 
use blocks in Objective-C code, and it makes life a lot easier for a whole lot 
of things (sorting, filtering, visitor pattern...).  

> and the dot syntax for property access encourages writing of inefficient code 
> (which is probably the last thing you want to encourage in a novice). 

Well, it encourages writing code where it's difficult to see the underlying 
semantics, which you don't want to encourage.  I'd much rather see novices 
writing inefficient but correct code than writing highly optimised wrong code 
though...

> So your initial impression that ObjC 2 is not needed for novices is not just 
> correct, it's IMO the case that ObjC 2 is best avoided for a novice.

Unless the novice wants to read any Apple tutorials written in the last few 
years.  Or if they wanted to play with any frameworks originally developed for 
OS X or iOS...

David

-- Send from my Jacquard Loom




reply via email to

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