W
why the lucky stiff
Martin said:I'd say conceptually abs belongs with floor, ceil, round and truncate.
And where do you stand in regard to .succ?
_why
Martin said:I'd say conceptually abs belongs with floor, ceil, round and truncate.
=20
Hmmm, prefix, postfix, or infix? Functional or object-oriented?
These are bottomless questions.
=20
One justification for sqrt(5) would be that "sqrt", works on more than
one class of objects (Fixnum, Bignum, Rational, etc). So does "abs" for
that matter, and I'm not crazy about 5.abs. As a method, sqrt would
have to be defined in every applicable class, either with new code or as
an included module. This spreads the definition out, which complicates
maintainence.
=20
Another reason is that the prefix style, sqrt(5), is somewhat closer to
the typical mathematical notation. I can't think of any unary
mathematical operations that are naturally postfix, unless you count
C++'s post-decrement and post-increment.
=20
This is all just criticism of library design, which is very much a
matter of style and taste. The "standard" library could stand some
attention to smooth out these style bumps, possibly by allowing either
prefix or postfix styles whenever possible. Then questions of style
would be forwarded to the programmer.
The definition of abs is not questionable; it returns self, negated
when self is negative, for all numeric value. On the other hand,
natural sqrt() may return float or integer, or something else. That's
the reason for sqrt() being a function in Math module.
Le 27/5/2005 said:|"It's 5.abs for absolute value, but Math.sqrt(5) for square root."
|
|Good point. That bugs me too. abs is a *function*, not logically a
|method.
I may be missing something, but why does it matter what the return
type is?
What is wrong with always returning a float just like Math.sqrt does?
-alternatively, although I prefer the first option-
Why couldn't the implementation of sqrt "cast" the result to an
instance
of the current self's type? So, if you ask an integer to sqrt, you get
an
integer back?
Like I said, maybe I am missing something, but it seems that
sqrt is a verb applied to numbers.
John.
On 5/26/05 said:Another reason is that the prefix style, sqrt(5), is somewhat closer to
the typical mathematical notation. I can't think of any unary
mathematical operations that are naturally postfix, unless you count
C++'s post-decrement and post-increment.
I can't think of any unary
mathematical operations that are naturally postfix,
One justification for sqrt(5) would be that "sqrt", works on more than
one class of objects (Fixnum, Bignum, Rational, etc). So does "abs" for
that matter, and I'm not crazy about 5.abs. As a method, sqrt would
have to be defined in every applicable class, either with new code or as
an included module. This spreads the definition out, which complicates
maintainence.
why the lucky stiff said:And where do you stand in regard to .succ?
Glenn said:+1
Hmmm, prefix, postfix, or infix? Functional or object-oriented?
These are bottomless questions.
One justification for sqrt(5) would be that "sqrt", works on more than
one class of objects (Fixnum, Bignum, Rational, etc). So does "abs"
for that matter, and I'm not crazy about 5.abs. As a method, sqrt
would have to be defined in every applicable class, either with new
code or as an included module. This spreads the definition out,
which complicates maintainence.
=> [Float, Precision, Numeric, Comparable, Object, Kernel]Fixnum.ancestors => [Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel]
Bignum.ancestors => [Bignum, Integer, Precision, Numeric, Comparable, Object, Kernel]
Float.ancestors
Another reason is that the prefix style, sqrt(5), is somewhat closer
to the typical mathematical notation. I can't think of any unary
mathematical operations that are naturally postfix, unless you count
C++'s post-decrement and post-increment.
This is all just criticism of library design, which is very much a
matter of style and taste. The "standard" library could stand some
attention to smooth out these style bumps, possibly by allowing either
prefix or postfix styles whenever possible. Then questions of style
would be forwarded to the programmer.
Logan said:Just to get offtopic, factorial is one.
Jim said:Factorial !
Actually, I think you have this backwards. It would be much more convenient
to have sqrt as a member function in order to implement it differently in
different classes. Numeric could hold the standard definition, but if a
subclass needed to redefine it, it could do so with little effort.
There is no backwards or forwards here.
Gene said:The rant-writer likes ruby. From his python rant:
===========8<
Though, I must admit, Python has the least inconsistencies of any
language I've ever used, excepting maybe Ruby.
oh no! its not at all!Jim said:Glenn Parker said:
As long as we are only talking asthetics, then I agree that either choice
is co-equal, neither is backwards or forwards. In fact, I would tend to
agree that sqrt(n) is more asthetically pleasing than n.sqrt.
However ...
But if we are talking maintenance (cf. "[sqrt as a method] spreads the
definition out, which complicates maintainence"), then I think it is clear
that the method implementation is (1) no more "spread out" that the
current implementation, (2) simpler to extend to for new types (e.g.
Complex). It is the stand-alone function (not method) implementation that
complicates maintainence. That is the part I thought was backwards.
Florian said:What about 5.-@ ?
Jonas said:what should that do?
5 substract at?
Le 27/5/2005 said:actually he seems to like both languages cause in the ruby rant he
refers to python and in the python rant he refers to ruby.
his choice of language is bad, some examples are stupid, and even me,
being quite a newbish, wonders why he rants about that, but some
examples are really good.
btw. isnt there a way to extend integer, fixnum and bignum with .sqrt ?
(just adding the method .sqrt arg, that again runs the sqrt method
which is possibly part of Kernel or Object, I am just guessing - is
that right?)
greetings
Jonas
Glenn said:Another reason is that the prefix style, sqrt(5), is somewhat closer
to the typical mathematical notation. I can't think of any unary
mathematical operations that are naturally postfix, unless you count
C++'s post-decrement and post-increment.
[...]
n is an Integer object and sqrt is a method on that object so it must
be n.sqrt - you could as well implement the third square root of 8 by
typing 8.sqrt 3 (I am not such a big math-guy... so maybe you could
just send over the whole exponent - 8^(1/2) =3D> 8.sqrt is equal to
8.sqrt .5 is equal to 8.sqrt(0.5) is equal to 8.sqrt(1/2) and so on...
well just my ideas on sqrt method - exuse me if its bs ;-(
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.