Re: Cocoa and Computational Expense
Re: Cocoa and Computational Expense
- Subject: Re: Cocoa and Computational Expense
- From: Justin Carlson <email@hidden>
- Date: Sun, 21 Jun 2009 01:50:00 -0400
How can I tell how computationally expensive a class or method is?
I've never been this far from the metal. Is there a corpus
somewhere listing this, or do programmers just know these things
from their experience?
Hi Kevin,
I recommend running Shark for tasks really want to inspect. It is a
lifesaver.
In the old days, we would cut corners and break rules to get better
performance or memory usage. The idea of "more" meant thousands of
dollars more. Now, resources for your average little application
seem to be limitless. So, do I just walk the straight and narrow
and let the Frameworks worry about these things for me?
The typical response is: Yes, if it is already implemented for a
general and usable case, then use it. If it then does not work for
your program, or well enough, then program it to suit your needs.
Since Apple has already invested a lot of time into text editing
facilities, re-implementing it may not be worth your time investment,
though I agree that 30% is high, and good programmers can often write
application specific programs which are better suited for the given
task.
Finally, on a side note and because this is my first OOP, just how
big should a class get? Just as a rule of thumb. I have 700 lines
and 50 methods in my MyDocument class and it seems positively
bloated to me.
It probably is too large, but I really couldn't answer this
considering the amount of information provided. I tend to use
relatively small objects, many of my objc classes are quite small 2 or
3 ivars and around 100 lines of implementation. I also use a fair
amount of C++. My C++ classes are even smaller, though I am more
interested in reuse than a lot of programmers out there.
Is this normal?
That's unusual for my code, but it has been the best choice for some
objects that I've written. The chances that it is highly reusable may
be significantly lower, though that may not be a concern for you.
Or might I possibly have a bad design? I only see a couple of lines
that could be factored into their own method and nothing that could
really me moved into its own class.
It's hard to say without seeing the code. If it is a document, and you
have a bunch of UI or user event specific code, then you could begin
by moving those to a new class. In a NSDocument subclass there a few
methods to override, so you should expect it to be slightly larger. If
you don't need visible methods, it can help to move methods into
functions (esp. if they are small and should likely be inlined.
I know these are rather vague questions with amorphous answers, but
I am hoping somebody can shine some light or at least show me which
door I need to go through.
Thanks in advance to any and all who are able to reply.
Kevin
I hope that helps somewhat.
J
_______________________________________________
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