Mailing List Archive


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

Re: [tlug] recomendations for a functional language



Since I'm a common lisp programmer I'd like to join your discussion.

On Wed, Nov 4, 2009 at 10:36 AM, Curt Sampson <cjs@example.com> wrote:
> Saved from bugs by the type system? Constantly. It's my primary tool to
> verify that what I'm writing makes sense.
>
> I write about 1/5 the number of unit tests that I used to write, and
> many of the ones now kicking around my biggest project I wrote for
> comfort early on. Yet I still feel that I have better reliability than
> in Ruby with five times the number of tests. I'll frequently do fairly
> major refactorings on large and wide-ranging parts of code that have no
> tests at all, relying entirely on the type system to make sure I make no
> errors doing this.
>
> And that's before we even get into the really sophisticated features of
> the type system. It's basically like learning yet another programming
> language.

I can say I largely agree with your opinion provide you have a sane
type system like Haskell's (if it is C++, good luck). Dynamically
typed language, which gives you the freedom also relies much on your
responsibility. The benefit is you can easily code up a partial
solution to guide you to the more general solutions. And once you have
the whole image, you can turn to a more carefully designed approach,
documenting all the interfaces, types, and adding some test cases. It
doesn't matter which language you use, it matters how you think of the
problem, if you can think mathematically, usually you are safe.

In practice, if it's a well defined problem, I'll document all the
function types, destructive semantics, exceptions and restarts. These
are essential information for anyone who needs to use my code.

Many people think since Common Lisp is a dynamically typed language,
anything compile-time type safety checks are hopeless, this is
actually very wrong. With type declaration (yes, common lisp supports
optional type declaration) and a good compiler like SBCL, you will get
warnings about type mismatches in compile-type. The problem is you
have to make sure all the library function you use are either correct
used (no missing cases) or fully type declared. Thus basically you are
only safe in your own code. BTW, I think high quality libraries are
much more important for dynamically typed languages.

However, the problem is usually you don't have enough time to think
systematically in every part of your software, and in that case, I
really hope I can use some statically typed language for me to avoid
making stupid mistakes. The result is lots of unnecessary type
checkings which makes the code neither easy to understand nor safe to
modify. Especially many common lisp programmers don't like to write
comments and documents.

Types are call conventions and documentations. So in a dynamically
typed language, do everybody a favor, write down the function types
(and exceptions)! (screaming...)

> Note that type checking isn't required for pattern matching; Erlang
> for example doesn't have compile-time type checking, yet has pattern
> matching. However, I find that compile-time type checking, and notices
> that you've missed a case in the pattern, to be exceedingly useful.
>

Agree!


Cheers,
Jianshi


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links