On 12 Mar 2013, at 21:34, Graham Cox wrote:


On 13/03/2013, at 6:53 AM, Dave <d...@looktowindward.com> wrote:

If that is the case, then how do you signal to the compiler/ analyzer that you are returning a retained object?

In general you shouldn't return a retained object (unless it's temporarily retained and will be autoreleased of course)

Why? Where does it say this? And Autorelease is evil and should never be used if it can be avoided!

. If you are routinely doing this then your design is flawed. The reason it's hard to signal to the compiler that you're returning a retained object is that you shouldn't be doing it. When you have to do it, use the word 'new' in the method.

How many years experience do you have writing applications and OS level software? I've been doing it since that late 70's. And, in all that time, I have never (well rarely it's a long time!) heard a more silly statement then " If you are routinely doing this then your design is flawed." ("this" meaning returning a retained object). In that case Unix, MacOS X and most software on the market has a flawed design according to this logic! I've never seen anything about this written down in any Apple document. In fact see below - Apple seems to disagree with you!

The reason it's hard to signal to the compiler that you're returning a retained object is that you shouldn't be doing it. When you have to do it, use the word 'new' in the method.


So, the design is flawed because it's hard to signal to the compiler that you are retuning a retain object? Do you realize how silly that sounds? How can a compiler option/feature affect a design? Also, are you saying that ARC is a flawed design? With ARC you do nothing BUT return retained objects!

So lets say we have a number of fairly complex (non ARC) iPad Applications that work wonderfully with no memory leaks. The code is well written, commented and easy to understand and maintain, but these Apps contained methods that routinely return retained objects. Would you then say these apps have a "Flawed Design" simply for this reason?

The fact of the matter is that this *is* routinely done in many commercial applications that I have worked on and by many developers, both on the Mac and iOS. Originally, I don't think there was a "new" prefix, so older code has lots of methods beginning with "alloc". The "new" was added later to make it easier to signal to the compiler the the method is returning a retained object. Most developers I worked with think that using "new" as a prefix when returning a retained object.


Besides all this, it isn't hard to signal to the compiler you are returning a retained object, you just prefix the name with "new", "alloc", "retain" etc. As per:

http://clang.llvm.org/docs/LanguageExtensions.html#related-result-types

Unless there is another prefix to use, they I am going to continue ignore it too!

Again, no offence intended but when a person doesn't follow a rule because they think it doesn't apply to them, it's just a sign of inexperience and/or lack of understanding. Sorry, but there it is.

I don't think the rule doesn't apply to just "me", I think it's doesn't apply to *anyone* and that it either isn't a rule and you are mistaken or if it is a rule, it's a stupid one and I don't follow stupid rules.

The only reason you have given me is that this is bad is that "hard to signal to the compiler that you're returning a retained object" but it isn't hard, you just prefix with "new". If there are other reasons, then please do let me know and I will consider what you say, but so far you've not given one reference to an Apple doc that categorically states this and no real reason why its bad apart from it's hard to signal the compiler what you are doing, which is isn't! So, pardon me if I take no notice of what you say!

There are loads of "rules" in life that no one pays any attention to! There are load of rules that Apple have made that are routinely broken. A few that spring to mind are, using "_" in iVar names, have getters/setters with non-standard names,


For instance, there is a law in England that dates back hundreds of year that states that a Male may urinate on the public highway as long as he alerts people to this fact uses the offside of his cab to shield passers by from this unsightly spectacle! How many men do you hear announcing in Oxford street that that are going to Urinate and then doing it against the offside of their car! Not Many!!!!!

There is another that says perambulated baby carriages much be wheeled off the pavement and on the road! How many people do you see wheeling their offspring along the slow lane side of the A40? Not many.

However, according to you, these "rules" must be obeyed! So next time you need to relieve yourself while wheeling your baby buggy along a public highway, just announce the fact that you are about to urinate and off you go! Don't worry, the "rule" will protect you from arrest for indecent exposure and the other "rule" is just bound to stop the 20 Ton Truck dead in it's tracks before it wipes out your buggy!

I would say that anyone that blindly follows rules without question is an idiot.

All the Best
Dave


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to