Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating to Arc with poor naming standards

I'm dealing with a codebase where naming standards have been routinely ignored. So, there are methods in some classes which return objects with reference counts of 1 even though the method name does not conform to NARC. Fantastic stuff.

I'd like to convert the project to use automatic reference counting, but I'm a little nervous due to the fact that NARC naming standards have been ignored altogether. Does anyone know whether ARC relies on NARC naming standards to work properly?

Thanks,

Sean

like image 799
seanoshea Avatar asked Sep 24 '12 19:09

seanoshea


2 Answers

ARC does rely on the naming conventions to work correctly. However...

If you only used ObjC objects, then it will typically "work out" as long as you only have ARC code. For example, if you had a method like:

- (id)something {
  return [[Something alloc] init];
}

This is wrong (in non-ARC code), but ARC will balance it out by effectively adding an extra autorelease. In fact, the above is correct ARC code, so it's fine.

My suggestion, if this is almost all ObjC code, is to auto-convert to ARC and then run the static analyzer. The problem may actually be much smaller than you fear if it's fairly simple code that just happens to have bad naming.

If this is heavily Core Foundation toll-free bridged code, things are a little more complicated. Then I'd recommend running the static analyzer first and getting your naming right before converting. Luckily, naming conventions is something that the static analyzer is very good at.

like image 136
Rob Napier Avatar answered Nov 04 '22 02:11

Rob Napier


I had to convert several projects to ARC and so far never encountered any problems directly due to naming conventions whatsoever.

Actually the conversion is really straight forward - so while I fully understand your state of mind about the code you have to deal with - I wouldn't really worry too much.

So far I have never encountered any seriously difficult situation during conversion as long as the code to be converted was correct in the first place and somehow clear to understand.

In fact using ARC I find is as trouble free as any other language with built in GC - concerning memory issues of course!

In worst case you may always run the static analyzer - but even that is rarely required nowadays with ARC.

Probably the most critical situation is discussed here: What kind of leaks does automatic reference counting in Objective-C not prevent or minimize?

like image 3
user387184 Avatar answered Nov 04 '22 01:11

user387184