From: Christian Szegedy Date: 2001-05-15T18:33:35+09:00 Subject: [ruby-talk:15150] Discussion on new Ruby features I know it is not very polite to start a discussion about new Ruby features after 3 days learning of Ruby. I can't refrain, since Ruby is so impressive and it really should be the best of the best: a universal approach to even (moderately) runtime critical tasks. Let me start: I think that a good way of programming is to start with a prototype in a language that is fast to program (such as Ruby), and, then replace the run-timing critical parts with some more optimized code. Normally it means that you have to reprogram some parts of the code in C,C++,Assembler,... But, what makes it inherently complicated to write some Ruby to C compiler which speeds up the code significantly? The lack of the instance typing mechanism of Ruby. Whithout this, no compiler would produce essentially faster code than a good interpreter. Of course, you say, this is one of main features of ruby, and one of the reasons of its flexibility. This is obviously true. On the other hand I insist that some C/Java-like typing mechnism would be nice in Ruby. The best way IMVHO is to do it optionally: You could allow to restrict an object to a specified type, if you want, but you are not required to do so. This would have more advantages: 1) Better optimization for compilation to C/C++ 2) Better debugging in some situations. 3) The possibility of optimize some part of the code without rewriting it in some other language. E.g. if you recognize that some part of the code is slow, and uses a lot of Fixnums or Floats then you could restrict the variables to that type and the ->C compiler speed it up extremely. On the other hand, if you think that your code is unsafe, since some variable x should always be of class X, then, given some simple syntax, it would be easier (shorter code, and probably more effective, since it could be built in into the interpreter) than redifining the writer function of x, and programm the check in Ruby. I think that three type of restrictions could be interesting: 1) Very Strict: variable x is exactly of class X (no inheritance allowed) 2) Strict: variable x of some class derived from class X 3) Dynamic (like the signature mechanism in gcc): variable x allows all functions of a module. (this would allow the compiler to create some signature table and pass it instead of the variable.) For the case something similar would ever be implemented, I would stress that it should have some appealing syntax (like all other Ruby features) make one remember to the C/Java/Pascal like typing. I think that a Pascal like syntex would fit quite well, since it does not seem creating ambiguity, but I am not quite sure. I eagerly await your flaming :) Christian