• 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: [NOOB] Finding Information (was: real noob question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NOOB] Finding Information (was: real noob question)


  • Subject: Re: [NOOB] Finding Information (was: real noob question)
  • From: julius <email@hidden>
  • Date: Mon, 19 Jan 2009 20:33:25 +0000


On 19 Jan 2009, at 16:17, mmalc Crawford wrote:


On Jan 19, 2009, at 6:10 AM, julius wrote:

I too followed up on the example link which took me to the top of the NSDecimalNumber Class reference document. Scrolling down the first thing I came accross under Tasks was "Creating a Decimal Number" and just beneath that a link to
+ decimalNumberWithDecimal:
which looked exactly like what the OP was asking for, viz:
<>
Creates and returns an NSDecimalNumber object equivalent to a given NSDecimal structure.
+ (NSDecimalNumber *)decimalNumberWithDecimal:(NSDecimal)decimal>
</>
Ah, and look perhaps I don't need to use an alloc....
Now with all respect to the writers of this documentation, my first question is "what is a decimal structure?".


Typically here I would either click the link to NSDecimal in the method declaration, or go to the Companion Guide listed at the top of the API reference.
Or ... (see below)


I followed up on  NSDecimal and obtained:
[...]
Scareeeeeee!!!! and nothing like what I thought it might be.


So either back to NSDecimalNumber,

or to the Companion Guide.
True, I don't go there as often as perhaps I should.
Following up on your suggestion I just did and went directly to the “Using Decimal Numbers” part of the document
http://developer.apple.com/documentation/Cocoa/Conceptual/NumbersandValues/Articles/DecimalNumbers.html#/ /apple_ref/doc/uid/20000176-CJBCAGDI


where it says
<>
Using Decimal Numbers

NSDecimalNumber is an immutable subclass of NSNumber that provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa x 10 exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer between -128 and 127.
</>
and goes on to talk of calculation errors and the NSDecimalNumberBehaviors protocol. It does not however illuminate what I perceived as the OP's need for a way of doing something essentially like [myDecimalNumberObj setValue: 23.3].


I have had reason to think about this quite frequently and have come to the conclusion that there is nothing simple or straightforward about writing easy to use technical manuals.


Indeed.


One of the main problems it seems to me occurs when I'm trying to get quickly to an answer and rather than read and digest every word of the manual


I have had reason to think about this quite frequently and have come to the conclusion that, when documentation is written, it should be padded with extraneous words and phrases that readers can safely ignore.
I appreciate the irony but it misses the point that on many occasions we really do just need a straight answer to a simple question. Sometimes such an answer exists and sometimes it does not. Sometimes to ask a particular question demonstrates sufficient ignorance to suppose that it is a text book and not a manual one should be reading. In the case of a text book a bit of redundancy is very useful especially if it addresses the fact that each person has their own way of learning. One would not expect much redundancy in a technical manual but an excellently designed manual would consider the different users and the different ways in which the information it contains might be needed. For instance, one may contrast the need to understand how something works from the need to find the correct switch to turn the thing on.

I suppose there must be a good reason for there not being a simple way of assigning a value to one of these NSDecimalNumber objects but I could find no such reason in the documentation and its absence just appears so intuitively unreasonable that one is loth to stop searching (see below for why in this case a search would ultimately have been successful). NSDecimalNumber appears to be used for arithmetic and as a wrapper. I've had sufficient similar difficulties in the past with wanting to wrap numbers to have ended up writing my own wrappers. So I have a notion of the frustration one might feel in such cases.




O.K. lets leave that and go back to see if we can find something that looks a bit more like the OP's number : 23.30.
The next heading beneath "Creating a Decimal Number" is "Initializing a Decimal Number" and head of the list is
<>
– initWithDecimal:
</>
That looks promising.. but
<>
initWithDecimal:
Returns an NSDecimalNumber object initialized to represent a given decimal.
- (id)initWithDecimal:(NSDecimal)decimal>
</>


No good: there's that NSDecimal again, but note that this time it is not described as a structure but as a "decimal" !!!!
Back to the top of the list:
<>
Initializing a Decimal Number
* – initWithDecimal:
* – initWithMantissa:exponent:isNegative:
* – initWithString:
* – initWithString:locale:
</>


But there is nothing here that looks anything like it would allow me to intialise with a numeric value like 23.30.

It's not clear why, throughout, you have ignored:
(a) initWithMantissa:exponent:isNegative:
(b) "Inherits from NSNumber : NSValue : NSObject"

In this case, (b) might have actually lead you astray(*), but it should have been in your search path.
Well, i always look for the simplest answer first, e.g. initWithDouble:. Not finding that, I look for the next simplest, in this case I went for the string option.

Why would I not have considered initWithMantissa:exponent:isNegative:? Well my first thought is that now instead of having to deal with one value I have to handle three. That tells me I'm getting into complexities I would rather avoid. In the case of a literal such as 23.3 is easy enough to express is as mantissa exponent though one still needs to be careful and there are consequences for code readability. In the more general case of myCGFloatValue say, that feels less inviting.

As to "inherits from NSNumber" wow! No. That was not the first place I would have gone to look for an answer but now that I have, wow indeed! Thank you very much. I'm still not used to going up and down the inheritance hierarchy. That's what comes of not having been brought up long term on OO.


int main(int argc, char *argv[])
{
NSDecimalNumber *myDecimalObj = [[NSDecimalNumber alloc]initWithString:@"23.30"];
NSLog(@"myDecimalObj doubleValue=%6.3f",[myDecimalObj doubleValue]);

CGFloat myCGFloatValue = 43.4;
NSDecimalNumber *myOtherDecimalObj = [[NSDecimalNumber alloc]initWithFloat:myCGFloatValue];
NSLog(@"myOtherDecimalObj doubleValue=%6.3f",[myOtherDecimalObj doubleValue]);
}
Result:
2009-01-19 20:00:36.655 test[3242:10b] myDecimalObj doubleValue=23.300
2009-01-19 20:00:36.656 test[3242:10b] myOtherDecimalObj doubleValue=43.400
Most excellent.
Thanks again.




(*) <http://www.cocoabuilder.com/archive/message/cocoa/2009/1/10/227253 >
(You did search the archives as well, didn't you?)
Well, I am not the OP here and I was just taking a quick look at the problem and reporting on the possibility that actually finding the answer was not of the easiest as indeed it was increasingly appearing to be.

I have just taken a look at the link and it indicates there is no easy answer. (except of course that there is and it is NSNumber! I had written most of this before taking the advised look at the hierarchy)



I'll stop here.

Why?
because it was not actually I who needed the answer but the OP and I had other things to do. I merely was making the point that with the best will in the world, the documentation is not always straightforward. And how many times is it that it is the smallest of things that impede our progress.

At this stage, although you should actually have found an answer, you should have at least looked at the Companion Guide and if that didn't address the issue you should have sent in feedback using either the form at the bottom of each documentation page or using Radar.
As far as I can see in this case the companion guide does not take one far towards answering the OP's question.



My point is that learning a system via the manual is not the easiest thing in the world and just pointing people at specific pages in the manual though helpful is not always necessarily the best way of doing things.

Looking at just the API reference pages is typically as useful a way to learn about Cocoa as using a dictionary to learn a foreign language. If you want to learn about how methods etc. are used in context, then turn to the Companion Guides.
Yes but as I just said they don't always answer or help answer the questions one needs answering.



One of those imponderable mysteries I guess. But someone must have thought it worthwhile.... so why not say so in the documentation?

All the references to Companion Guide above notwithstanding, as it happens, this isn't well addressed in the Guide. Please either send feedback or file a Radar (<http://bugreport.apple.com/>) to have this addressed.
On this issue of feedback and bug reports. I would not feel it right to submit a bug report since i don't think of this as a bug. I have frequently returned feedback along the lines of "an example would be nice" or "how then does one do x!!!" but now do it rarely. There is just so much of it.

Why then should I have spent so much time on this issue? I much appreciate this list and the advice volunteered and sympathise with the feelings of irritation that must be occasioned by people who could perhaps have looked closer at the documentation or have not looked at it at all. Nevertheless I sometimes feel the need to restate the obvious: learning the system is not easy and sometimes the manual does not give up its secrets readily. And as in the present instance it can sometimes be the tiniest of things that stops one getting to the answer.

And thanks for the BIG HINT.
I'll definitely put that lesson into
http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/animatedPaint.pl

Wow!
All the best
Julius


http://juliuspaintings.co.uk



_______________________________________________

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


References: 
 >Re: [NOOB] Finding Information (was: real noob question) (From: julius <email@hidden>)
 >Re: [NOOB] Finding Information (was: real noob question) (From: mmalc Crawford <email@hidden>)

  • Prev by Date: Re: [NOOB] Finding Information (was: real noob question)
  • Next by Date: Re: NSPredicateEditorRowTemplate for NSDate
  • Previous by thread: Re: [NOOB] Finding Information (was: real noob question)
  • Next by thread: Check URL Status
  • Index(es):
    • Date
    • Thread