[Prev][Next][Index][Thread]

Re: Dylan runtime checking vs C++



Well Dylan doesn't really have C++ style raw pointers. So referencing
nil pointers in the C-sense of looking into location 0, is simply an
impossibility. Thanks to garbage collection, you also cannot reference
an object after it's freed, nor double delete an object, nor corrupt the
memory manager state by calling delete instead of delete[]. (Except of
course when you start interfacing directly to C code. Then you can do
all sorts of evil C things if you're not careful. But if you ARE
careful, you can wrap the C in such a way that you take advantage of
Dylan features and avoid the problems, and this is much easier than it
would be directly in C.)

More generally Dylan does a very good job of trapping runtime errors.
Referencing a slot (member) that has not yet been given a value is
guaranteed to produce a runtime error, unlike C/C++. Any C runtime error
that I can think of off the top of my head will be trapped cleanly by
Dylan.

Dylan has a more general and capable exception handling mechanism than
C++, and one typical way of using it is very much like C++: try blocks,
catch handlers, and throwing of object-based exceptions, with a
top-level default exception handler, as with C++ that provides an error
message. The 2 differences are: that this C++ like exception-handling
mechanism is built on an accessible and well-documented lower layer that
can be used in other ways; and Dylan catches a whole lot more errors for
you.

The biggest problem with C++ exceptions is the massive quantities of
library code that were written before C++ exceptions were standardized.
If you work much with C++, then exceptions are just one of several
completely different styles of error handling that you will have mixed
up in your code. It gets to be a really horrible mess. Exceptions were
in Dylan from the beginning.

As an aside, manual memory management in C++ would be painstaking and
error-prone no matter what. But there are several different conventions
for allocating/tracking/freeing memory and again if you work much with
C++ you wind up with mixed techniques throughout your code because of
differences in libraries. This makes memory management MUCH more
painful.


Full Name wrote:
> 
> I have just started learning Dylan at as part of a course study. And i
> am trying to compare this PL with C++.
> 
> I would like to know the difference between Dylan and C++ in terms of
> how well does Dylan catch runtime errors, like array out-of-bounds
> errors and dereferencing of nil pointers. Does programs terminate
> nicely, with error messages that shows the source of the problem? Does
> it allow programs to catch such errors (e.g., via exceptions)?
> 
> Please if you have an answer to the above questions let me know.
> 
> Abdi



References: