From: gabriele renzi Date: 2003-05-14T04:35:34+09:00 Subject: Re: Ruby OO? sin method? puts method? @@? il Tue, 13 May 2003 22:54:09 +0900, KONTRA Gergely ha scritto:: >On 0513, nobu.nokada@softhome.net wrote: >> > Than why not sin is a method? >> To fit to mathematical notation. >??? >I write sin(0.5) but also abs(0.5) >So I don't know why the difference, and why cannot a number tell it's >sin. This is analogous to "asdf".length and the others... # I_SUPPOSE=true I suppose that sin as the other Math methods, is function-like because, well, they are functions, end not properties of the Numeric objects. You have to chose where you'd like to put them, but think that if you start to put math methods in Numeric you'll have to chose when you want to stop, or you'll have an infinite number of function. For the sake of clearness it's better to have them in a separate module >> > And puts? >> puts is a method of IO class. >> STDERR.puts "asdf" >> Or you can use Kernel#display. >> "asdf".display(STDERR) >Again confusing for me... >Which approach uses ruby? >IO.puts(what) or what.puts(IO=stdout) and why it is not consistent. >The string displays itself, or the filehandle displays the string? >Or has ruby a habit in the core and not a concept? Why a string should know about how to display herself? You could end up putting in String every kind of IO object. I'm not so much in OO languages , I just used Java, Ruby and little C++ and python, su maybe having String.display (displaying_obj) is reasonable, but sounds inefficent to me. >Another ugliness in the syntax, which bothers me is the @ and @@ (and >will be @@@ ??) notation, which I think doesn't fit into the view. >Does anybody know the root of it? >In one side ruby tries to avoid the rude $ variables, but on the other >hand has @ and @@ variables (members)... > >Gergo You have to clearly separate the type of the variables, to avoid errors. You shoul mostly use local variables, so you save a type for them, but to avoid errors (for example overwriting a global variable or an instance variable in a loop) ruby makes difference beetween them as syntax. cheers