Compile time type checking

I think the main reason that languages such as Ruby, Python, Perl and TCL
tend to be used for “scripting” as opposed to “real applications” is that
they lack compile time type checking. Since there is no compile step in
Ruby, maybe this should be called pre-release type checking.

I’m curious how some of you that have written real applications in Ruby have
dealt with this. Don’t you have problems where an application crashes on a
user because the wrong type of object gets passed to a method and it tries
to invoke a method of the object that it doesn’t have?

It seems to me that it’s nearly impossible to write enough unit tests to
catch all of these issues before code is released for production use.

I love Ruby syntax, but this issue may be one that keeps many people using
Java instead.

···

WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.


It seems to me that it’s nearly impossible to write enough unit tests to
catch all of these issues before code is released for production use.

I’d say the majority of my code does not involve a large variety of types
within a certain bit of functionality – so unit testing this is pretty
easy. Even in a case where a piece of code could be working with an object
of one of many different types, I’d think many cases could still unit test
each combination. And in cases where I need to verify the type I’m working
with, I can still code this in Ruby.

To me the flexibility and freedom from not having to type everything (plus
type in all the overhead typing code :slight_smile: is well worth the trade off for
type-safety - especially with unit tests continually exercising the code.

Chris
http://clabs.org

“Volkmann, Mark” Mark.Volkmann@AGEDWARDS.com writes:

I’m curious how some of you that have written real applications in Ruby have
dealt with this. Don’t you have problems where an application crashes on a
user because the wrong type of object gets passed to a method and it tries
to invoke a method of the object that it doesn’t have?

I love Ruby syntax, but this issue may be one that keeps many people using
Java instead.

But Java has run-time type checking as well. Consider an average
running Java program. How many objects are extant? 1,000? 2,000? How
many variables do you have? 20? 30? So, where are all the other
objects? In collections. And how do you get to them? By casting at
every access. The type gets discovered at run time.

How many class cast exceptions do you see in Java? In reality, not
many.

In the same way, I don’t often see the wrong kind of object being used
in Ruby. However, to ensure that, I have to exercise the various paths
through the code, so I rely on unit tests to give me the confidence
that my code is reasonable.

Cheers

Dave

Hi,

In my opinion, compile time type checking helps, but it is by itself not
sufficient. I think guarding against arbitrary user input goes beyond
type checking; for example, although user inputs a numeric when we expect
numeric, we also need to check the range of the value. However, I don’t
think it is impossible to write an input checking routine in a
scripting language that is as robust as that used in a compiled language.

During development time, yes, the lack of compile time type checking
sometimes gives me trouble when I run a script. However, the
corresponding error message is usually obvious enough for me to quickly
fix the error and rerun the program. So I think it is a trade-off; we
may get error more easily, but we can also fix it faster. The only
tricky part is, if there is some type mismatch but the code is not
invoked, the error will not appear. I also do not know how to make sure
that every part has been tested with all possible values (maybe it is
impossible?)

Regarding the crashing, I think it has more to do with the exception
mechanism in the language than the compile type checking. For example,
although C provides compile time type checking, I see a lot of commercial
codes which crashed severely. When an exception hierarchy is well
defined, on the other hand, the crash can be more graceful. Finally, I
think preventing crash on a user really depends on how much testing we can
do before releasing the code, independent of the type of language.

For me, the more serious problem with scripting languages is the extra
overhead in terms of memory and execution performance. We simply cannot
gain something for nothing.

Regards,

Bill

···

==============================================================================
Volkmann, Mark Mark.Volkmann@agedwards.com wrote:

I think the main reason that languages such as Ruby, Python, Perl and
TCL
tend to be used for “scripting” as opposed to “real applications” is that
they lack compile time type checking. Since there is no compile step in
Ruby, maybe this should be called pre-release type checking.

I’m curious how some of you that have written real applications in Ruby have
dealt with this. Don’t you have problems where an application crashes on a
user because the wrong type of object gets passed to a method and it tries
to invoke a method of the object that it doesn’t have?

It seems to me that it’s nearly impossible to write enough unit tests to
catch all of these issues before code is released for production use.

I love Ruby syntax, but this issue may be one that keeps many people using
Java instead.


WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.


I haven’t done that much in Ruby, yet, but I’ve don lots in ObjC. I
always type strongly and I can count on one hand the number of times
that it’s saved me any trouble.

I suppose that you could argue that the habit of strong typing itself
keeps me out of trouble. Could be, but it doesn’t feel that way.

···

On Tuesday, August 27, 2002, at 11:47 AM, Volkmann, Mark wrote:

I think the main reason that languages such as Ruby, Python, Perl and
TCL tend to be used for “scripting” as opposed to “real
applications” is that they lack compile time type checking. Since
there is no compile step in Ruby, maybe this should be called
pre-release type checking.

I’m curious how some of you that have written real applications in
Ruby have dealt with this. Don’t you have problems where an
application crashes on a user because the wrong type of object gets
passed to a method and it tries to invoke a method of the object that
it doesn’t have?


The higher we soar the smaller we appear to those who cannot fly.
-Friedrich Wilhelm Nietzsche, philosopher (1844-1900)

Volkmann, Mark wrote:

I think the main reason that languages such as Ruby, Python, Perl and
TCL tend to be used for “scripting” as opposed to “real
applications” is that they lack compile time type checking. Since
there is no compile step in Ruby, maybe this should be called
pre-release type checking.

Lets see, web sites, databases, ecommerce, accounting, simulation, stock
control, epos, payroll … any more non ‘real applications’. Oh yes
wordprocessors and spreadsheets. Of that list I have worked on 6 (web
sites, databases, ecommerce, stock control, epos, payroll) that were
written in Perl and have used the rest which were written in Perl,
Python or TCL (for those of you who remember Point the TCL/TK
wordprocessor).

Ok I have not heard of a Flight Simulator written in Perl but what are
these ‘real applications’ you talk of?

···

So, where are all the other
objects? In collections. And how do you get to them? By casting at
every access. The type gets discovered at run time.

Oh, yeah - that, too :slight_smile: I always forget this argument, but it’s the best
one.

I don’t think that was the assertion, was it?

If I read the original poster correctly, he was saying compile time
checking helps a lot; it obviates the need for some unit tests.

···

— William Djaja Tjokroaminata billtj@z.glue.umd.edu wrote:

Hi,

In my opinion, compile time type checking helps, but it is by
itself not
sufficient.

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com