Shodhan Sheth
22.m@Pune
single n lookin
shodhan[dot]sheth[at]gmail[dot]com
It's worth noting here a major difference between Ruby and most other languages. In (say) Java, you'd find the absolute value of some number by calling a separate function and passing in that number. You might writethis is intresting. the point here is that one cannot exklusively define all operations possible on the class number. what if tomm theres a new formatting option out. i think that the java filosofy was to have Math.xxx methods for funktionalities on the number klass that number should not be aware of. this is a design issue. it is always safer to have objekts handle operations on self on their own. on the other hand, having a kommon klass for simple operations as deskribed above might lead to a smaller memory map.
number = Math.abs(number) // Java code
In Ruby, the ability to determine an absolute value is built into numbers---they take care of the details internally. You simply send the message abs to a number object and let it do the work.
number = number.abs
0 Comments:
Post a Comment
<< Home