re: split up alloc and init?
re: split up alloc and init?
- Subject: re: split up alloc and init?
- From: Ben Trumbull <email@hidden>
- Date: Mon, 11 Feb 2008 14:06:12 -0800
Basically, is it safe to split up alloc and init?
It's a really bad idea.
It's a very error prone pattern. Having a partially initialized
object around is just begging for trouble. It's pretty rare for
classes to accept any message besides the initializer until after
it's completely initialized.
I've seen some very difficult to track bugs from this pattern. The
results of +alloc got assigned into some local, and someone else came
through the code later, didn't realize the original author never
initialized that variable properly N lines earlier, and great wrongs
befell.
In my experience, after about 6 months, "someone else" could just as
easily be future me for all intents and purposes.
It also just seems bizarre. Why not say what you really mean, and
pass the *Class* around. When you want a real instance, send the
class the +alloc message and Do The Right Thing. Classes are almost
first class objects. Objective-C is pretty handy that way.
--
-Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden