Re: WOWS or Cocoa bug?
Re: WOWS or Cocoa bug?
- Subject: Re: WOWS or Cocoa bug?
- From: Paul Lynch <email@hidden>
- Date: Mon, 6 Nov 2006 07:01:51 +0000
On 6 Nov 2006, at 01:33, Ricardo Strausz wrote:
yap, I did it like this and it is working quite good...
(details in http://strausz.blogspot.com/2006/11/calculatorjava-
revisted.html )
p.d., BTW, does someone knows?: if XML is the transport "encoding",
are numbers always "written" as strings while moving from the
client the server (and vice-versa)?
Yes, XML is supposed to be a human readable format, and will always
encode numbers as strings. Of course, being a committee design, it
will very often encode real strings as CDATA, but you can see why
(eventually).
Is there any good reason to use numbers instead of strings?
Reasons, yes, some of them good; but I don't think any of them are
really compelling.
One reason to use a string is because you know that, as a web
service, you will be passing through XML, which means that your data
will end up as a string whatever you do - but the encapsulation
should mean that you don't care about that.
Any good interface should be self-documenting, which I feel is
probably the strongest reason to define the interface to use a
decimal number object; details such as conversion between
NSDecimalNumber and java.math.BigDecimal should be taken care of for
you by the interface. Sticking with objects rather than primitives
means that you can consider error passing, and also the validity of
nulls in the interface.
Paul
On Nov 5, 2006, at 7:17 PM, Kieran Kelleher wrote:
I have not looked at this in detail, but fit seems obvious to use
strings to pass accurate decimals and convert to BigDecimal for
the calculation.
new BigDecimal( String numberAsString )
NSDecimalNumber initWithString
On Nov 5, 2006, at 2:48 PM, Ricardo Strausz wrote:
On Nov 5, 2006, at 10:27 AM, Paul Lynch wrote:
On 5 Nov 2006, at 13:46, Ricardo Strausz wrote:
I am using doubles in both sides: the server and the client...
Shall I blame them?
You should. float and double are both floating point primitives
in java; double offers more precision (the number of significant
digits) than float. But, as pointed out, any type of float is
inherently precise.
If you want to create a calculator object, it is a good idea to
use BigDecimal. Java was originally designed as a PDA/set top
box language, and its roots often show. Treat this as an
opportunity to demonstrate the benefits of encapsulation in an
object oriented design :-).
This is easy to say... not so easy to implement.
The Java side is waiting for two double values which, in
particular, can be directly operated (they understand the + sign)
so, in order to operate with BigDecimals, the implementation on
that side most be re-implemented — and it is not enough to
instantiate the BigDecimals inside that method because the
"approximation-error" remains there. On the other side, the stubs
are also implemented using doubles, so a re-implementations is
needed also there; even worst, there is no equivalent to
BigDecimal in Objective-C (the closest is NSDecimalNumber).
Therefore, I am thinking in use strings to pass the values from
the client to the server...
is this the efficient way to do this?
On Nov 5, 2006, at 3:47 AM, Paul Lynch wrote:
On 5 Nov 2006, at 01:35, Ricardo Strausz wrote:
Playing with WOWS and Cocoa I found that even a simple sum,
is buggy...
I'd published the Calculator.java example from WO and consume
it with WebServicesCore.framework in a very straight-forward
way (the details are in http://strausz.blogspot.com/2006/11/
consuming-calculatorjava-ws.html ); while adding 3.4 to 6.6,
instead of 10.0 I did get 9.999998099999999 ... close, but
not correct =:+(
To whom I shall blame?
At a guess - blame floats.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden