Erik de Castro Lopo wrote:
<snipped>
> Sorry, many very reasonable people would disagree with this. CW, my C++ linear
> algebra example. Having '+' do sensible things with objects like matrices
> makes a huge amount of sense. On the other hand the C++ library using "<<"
> to access the output stream is simply crack.

Using '+' to sum matrices (or any identical mathematical types) is in no
way what I would consider an example of overloading.

<snipped>
> Function name overloading is a good thing. It means that you can a
> function named foobar which can carry out the foobar operation on
> more than one type of operand:
> 
>       void foobar (int i) ;
>       void foobar (float f) ;
> 
> makes far more sense than:
> 
>       void foobar_i (int i) ;
>       void foobar_f (float f) ;
> 
> especially as the number of different operand types increases. In
> this particular example, the compiler should figure out that
> 
>        foobar (my_int) ;
> 
> and
> 
>         foobar (my_float) ;
> 
> are two different functions.

Sure, the compiler can figure that out. What it can't figure out is when
you accidently pass the wrong operand type to foobar, because the
various foobars are quite happy to accept a range of different types.
Also anyone who has to debug or maintain the code now has to keep track
of the operand types, rather then have the compiler do it for them,
isn't that what you were trying to avoid?

As a side note, the difficulties/pitfalls of using an interpreter
instead of a compiler should start to become apparent.

A second side note, most (all?) dynamic typing languages have various
functions to explicitly cast data types, whilst not necessarily pretty
(or accurate), they can make code a little clearer to the interpreter,
compiler or maintainer. They can also make the code a little more future
proof in case the language's set of implicit casting rules is changed.

Cheers,
Malcolm V.
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to