• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSObject Exercise comments?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSObject Exercise comments?


  • Subject: Re: NSObject Exercise comments?
  • From: Lee Cullens <email@hidden>
  • Date: Sat, 10 Dec 2005 11:34:58 -0500

Andreas,

Thank you for taking the time to wade through my little exercise. I guess it's obvious that starting my career in the 60's had a "cowboy" influence on my programming :-)

I'm using your comments to improve the exercise with as it will be a reference for me until I no longer need it and a couple clarifications would help.

Initializers should return an id.
- (id)initWithNumerator:(int)numerator denominator:(int)denominator;


I don't understand why one would use an indeterminate object reference type unless there was intended polymorphism afoot, or in the processing code a variable was being used for different objects (which doesn't help readability) .

> > // utility
> > -(NSMutableString *) formatFraction;

'description' is a method that most objects understand; it seems reasonable to use this method as a replacement.

- (NSString *)description;


I don't understand this point. Are you saying to use a generic method name for a specific manipulation of specific instance variables, or is the method name "description" a common convention for a method that "presents" a display version of instance variables?

And a comment on a comment.

> > -(Fraction *) reduceFraction
> > {
> > if (numerator)
> > {
[...]
> > {
> > [self release];
> >
> > return nil;
> > }

This seems wrong. You are supposed to return a *new* instance of Fraction here. Releasing the object will lead to memory management problems.


Intended to prevent returning a new ill-formed instance. I did nave a memory management issue (which this list helped me track down), but this was not the cause because I was releasing the object before returning it autoreleased. However, it is a good point because it leads to unnecessary confusion. I should have (and will) done the validity tests on the variables before ever allocating an instance, returning nil if there is a problem and avoiding the release altogether.

Thanks again,
Lee C

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: NSObject Exercise comments?
      • From: Andreas Mayer <email@hidden>
    • Re: NSObject Exercise comments?
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: Slightly OT: simulating a dock icon click via an AppleEvent (or otherwise)
  • Next by Date: Re: NSObject Exercise comments?
  • Previous by thread: Re: NSObject Exercise comments?
  • Next by thread: Re: NSObject Exercise comments?
  • Index(es):
    • Date
    • Thread