Skip navigation.
 
mlRe: Trying to understand -- please help...
FROM : Andy Lee
DATE : Thu May 22 22:08:04 2008

On May 22, 2008, at 12:25 PM, glenn andreas wrote:
> On May 22, 2008, at 10:43 AM, Greg Titus wrote:

>> A lot of people have already mentioned that the memory management 
>> semantics for these methods are the same everywhere and are 
>> described in the conceptual documentation. I'd like to answer the 
>> obvious follow up question: even if it is described in the concept 
>> docs, how would it hurt to repeat it in the NSArray class method 
>> references? It is just one more line...

>
> But it's not just one more line - it's like a dozen or so (to handle 
> the whole semantics of the memory management, not to mention the 
> whole GC vs no GC), and it would be the same dozen lines in hundreds 
> of different methods.


I don't think you need to cover that much information.  I think a 
single sentence would suffice to remind people who are generally aware 
of the memory management issues, but haven't quite internalized all 
the rules yet.  And people who aren't aware of those issues would see 
there's *something* they need to figure out.

One sentence copied in a few hundred methods is trivial in the grand 
scheme of Cocoa documentation.  Look at all the lines telling us which 
version of OS X each method was available in.  Or the "See also" links 
(do we really need to be reminded of the -bounds method in the -
setBounds: docs?).  Or the fact that all method names are displayed 
twice -- once with arguments and once without.

> Even if you tried to shorten it up, say, to just make sure that it 
> "returns an autoreleased object" that would still require the reader 
> to understand what that means (so if you can shorten it up to just 
> that, why do you need it there at all?  Alternately, if you need to 
> explain that the object is autoreleased, why don't you have to 
> explain what that means?).


<sidenote-and-question>
I read a story once about a city that had a tunnel that ran under a 
mountain.  I wish I could remember the exact story and what book I 
read it in.  The gist of it was that the engineers needed to figure 
out how to word a sign at the end of the tunnel, reminding drivers to 
either turn their headlights on or off.  The solution was: "Are your 
headlights on?"  Does anyone know what book this was and what the 
story was?  The relevance here is that IMO the line in the 
documentation only needs to be a "headlights" reminder, not a full 
discourse on memory management.
</sidenote-and-question>

>  Worse, that isn't even accurate - you don't care if the object is 
> autoreleased or not (it may, for example, be a singleton that is 
> never actually released - for example [NSNumber numberWithInt: 0] 
> will return the same value every time you call it - the result isn't 
> autoreleased).


This just proves that "returns an autoreleased object" is the wrong 
line to add.  I'd suggest something like "You are responsible for 
retaining the returned object."

> My experience when I first learned it was that I tended to try to 
> over-think the situation.  Once I realized that it really was as 
> simple as it seemed, it all just clicked.


My experience was similar, I think.  Actually I don't remember; it 
seems so natural now.  Anyway, I'm not necessarily saying the docs 
need this additional line, only that it wouldn't be so bad if it were 
there, and a bit of judicious redundancy *might* help people learn the 
rules a little more quickly.

In a similar vein, I think it's worth mentioning that -setDelegate: 
doesn't retain the given object.  Same for other methods where you 
might expect the object to be retained.

--Andy

Related mailsAuthorDate
mlTrying to understand -- please help... john darnell May 21, 18:05
mlRe: Trying to understand -- please help... Torsten Curdt May 21, 18:13
mlRe: Trying to understand -- please help... Vijay Malhan May 21, 18:16
mlRe: Trying to understand -- please help... Paul Bailey May 21, 18:20
mlRe: Trying to understand -- please help... Hank Heijink (Mail… May 21, 18:28
mlRe: Trying to understand -- please help... João Pavão May 21, 18:29
mlRe: Trying to understand -- please help... Gérard Iglesias May 21, 18:34
mlRE: Trying to understand -- please help... john darnell May 21, 18:41
mlTrying to understand -- please help... Peter Hudson May 21, 18:47
mlRe: Trying to understand -- please help... Gérard Iglesias May 21, 18:49
mlRe: Trying to understand -- please help... Clark Cox May 21, 19:03
mlRe: Trying to understand -- please help... Gérard Iglesias May 21, 19:11
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 19:17
mlRe: Trying to understand -- please help... Bill Bumgarner May 21, 19:21
mlRe: Trying to understand -- please help... Hank Heijink (Mail… May 21, 19:25
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 19:32
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 19:36
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 19:38
mlRe: Trying to understand -- please help... Ilan Volow May 21, 19:40
mlRe: Trying to understand -- please help... I. Savant May 21, 20:05
mlRe: Trying to understand -- please help... I. Savant May 21, 20:07
mlTrying to understand -- please help... Johnny Lundy May 21, 20:35
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 20:45
mlRe: Trying to understand -- please help... Vijay Malhan May 21, 20:47
mlRe: Trying to understand -- please help... Bill Bumgarner May 21, 20:48
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 20:54
mlRe: Trying to understand -- please help... I. Savant May 21, 20:57
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 21:00
mlRe: Trying to understand -- please help... I. Savant May 21, 21:00
ml+initialize (was Re: Trying to understand -- please help...) Jason Stephenson May 21, 21:00
mlRe: Trying to understand -- please help... Michael Vannorsdel May 21, 21:07
mlRe: Trying to understand -- please help... Ilan Volow May 21, 21:08
mlRe: Trying to understand -- please help... Vijay Malhan May 21, 21:14
mlRe: Trying to understand -- please help... Shawn Erickson May 21, 21:24
mlTrying to understand -- please help... Johnny Lundy May 21, 21:37
mlRe: Trying to understand -- please help... Andy Lee May 21, 21:41
mlRe: Trying to understand -- please help... Jeff LaMarche May 21, 21:58
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 22:07
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 22:20
mlRe: Trying to understand -- please help... Uli Kusterer May 21, 22:33
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 22:37
mlRe: Trying to understand -- please help... Uli Kusterer May 21, 22:45
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 22:52
mlRe: Trying to understand -- please help... Christopher Nebel May 21, 23:06
mlRe: Trying to understand -- please help... Hamish Allan May 21, 23:09
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 23:15
mlRe: Trying to understand -- please help... Ken Thomases May 21, 23:28
mlRe: Trying to understand -- please help... Sherm Pendley May 21, 23:29
mlRe: Trying to understand -- please help... Andy Lee May 22, 01:18
mlRe: Trying to understand -- please help... Jens Alfke May 22, 04:23
mlRe: Trying to understand -- please help... Jens Alfke May 22, 04:30
mlRe: Trying to understand -- please help... Jens Alfke May 22, 04:37
mlRe: Trying to understand -- please help... Michael Vannorsdel May 22, 04:55
mlRE: Trying to understand -- please help... Caleb Strockbine May 22, 16:27
mlRe: Trying to understand -- please help... Greg Titus May 22, 17:43
mlRe: Trying to understand -- please help... glenn andreas May 22, 18:25
mlRe: Trying to understand -- please help... Andy Lee May 22, 22:08
mlRe: Trying to understand -- please help... Andy Lee May 22, 22:15
mlRe: Trying to understand -- please help... Joseph Kelly May 22, 22:16
mlRe: Trying to understand -- please help... Johnny Lundy May 22, 23:13
mlRe: Trying to understand -- please help... glenn andreas May 22, 23:42
mlRe: Trying to understand -- please help... Sherm Pendley May 22, 23:59
mlRe: Trying to understand -- please help... Andy Lee May 23, 00:02