Other languages' features in Ruby

B

Ben Giddings

Hrm, well I'm a Ruby/Java/C/C++/Python/Perl/Lisp/Javascript/PHP...
um... and others programmer.

We've had Java/C++/Whatever programmers ask for type checking,
operator overloading, polymorphism and a whole host of compile time
checking.

Is there a good way to get what type checking does for you? Maybe some
kind of ruby-lint program that looks through your source code and tries
to see if you're making odd assumptions about the type of your
variables? Or (much more useful in my opinion) something that will try
to catch the use of uninitialized variables? This would be helpful in
catching typos, like calling the class variable @my_var, but ending up
using it as @myvar.
Lisp programmers have enquired about macros (occasionally).

Are there good ways of doing what Lisp macros do for you?

Maybe the fact people keep asking for this points to the need for a set
of FAQs that pick features from other languages and explain if they
exist in Ruby, how to use them, and if they're not there, why not.
Maybe such a FAQ already exists, I don't know.

Ben
 
P

Phil Tomson

Hrm, well I'm a Ruby/Java/C/C++/Python/Perl/Lisp/Javascript/PHP...
um... and others programmer.



Is there a good way to get what type checking does for you?

Unit testing.
Maybe some
kind of ruby-lint program that looks through your source code and tries
to see if you're making odd assumptions about the type of your
variables? Or (much more useful in my opinion) something that will try
to catch the use of uninitialized variables?

Well, that already happens:

def foo(bar)
puts a
end

foo(1)
NameError: undefined local variable or method `a' for #<Object:0x401d1ce0>
from (irb):5:in `foo'
from (irb):8

....OK, admitedly, that's at runtime, but that's why you want unit tests.
This would be helpful in
catching typos, like calling the class variable @my_var, but ending up
using it as @myvar.


Are there good ways of doing what Lisp macros do for you?

Perl has input filters (see the perlfilter docs) that sort of act like a pre-processor
for yout source. This was originally intended for encrypting source-code, but now is
used for lots of other purposes. Perl even has a command line argument (-p, I believe)
that will pass the source through the c pre-processor before Perl interprets it.

I wonder how difficult it would be to do input filters for Ruby?

On the otherhand, it's probably not a feature needed in Ruby as much as it is in Perl.
Maybe the fact people keep asking for this points to the need for a set
of FAQs that pick features from other languages and explain if they
exist in Ruby, how to use them, and if they're not there, why not.
Maybe such a FAQ already exists, I don't know.

Ben

Phil
 
J

Joel VanderWerf

Phil said:
Perl has input filters (see the perlfilter docs) that sort of act like a pre-processor
for yout source. This was originally intended for encrypting source-code, but now is
used for lots of other purposes. Perl even has a command line argument (-p, I believe)
that will pass the source through the c pre-processor before Perl interprets it.

I wonder how difficult it would be to do input filters for Ruby?

On the otherhand, it's probably not a feature needed in Ruby as much as it is in Perl.

Would the filter operate on strings or parse trees?

Strings wouldn't satisfy the Lisp folks, because they're used to
s-expressions.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top