[mercury-users] Error detection rate in Mercury vs Other Languages (esp C++ and Python)

Mark Brown mark at csse.unimelb.edu.au
Mon Dec 5 16:46:33 AEDT 2011


Hi Charles,

On 30-Nov-2011, Charles Shuller <charles.shuller at gmail.com> wrote:
> All,
> 
> I'm curious if anyone can share their impressions, or references to
> peer-reviewed papers, on the rate of error detection by the Mercury
> compiler versus other compilers or run-times/interpreters.
> 
> I'm under the impression that the Mercury compiler is able to detect
> significantly more errors that a C++ compiler, or Python run-time
> (assuming some reasonable test suite); however, I've realized that I
> have no basis for that impression, and am wondering if there is any
> justification for my belief.

You can try a bit of a thought experiment with any language you know.
Imagine having a correct program, then mutating it in some "random"
ways to simulate the sorts of bugs that you judge to be typical in
your project (e.g., deleting or transposing lines, misspelling procedure
or variable names, missing or extra procedure arguments, etc.).  How
often are these mutations likely to be noticed by the compiler?

In Prolog, for example, I find that any change that's not a syntax error
tends to get through, although warning about singleton variables helps
a lot.  In Python, misspelling an attribute name in an assignment
will tend to never be detected, even if the name is singleton.

In Haskell or ML, I find it quite difficult to introduce a bug like this
without the compiler noticing.  Likewise in Mercury, although as others have
pointed out it's harder to do this in code that is declared det than semidet
or nondet code.

In C a lot depends on the data structure design.  Structures that are used
in conjunction with lots of explicit type casts tend to force the compiler
to accept the programmer at their word, whereas careful use of C types
can allow the compiler to detect a lot of problems.  Interestingly, I learnt
this lesson in C after using Mercury -- getting useful error detection from
the Mercury compiler motivated me to write C code for which the C compiler
could likewise perform useful error detection (and I haven't looked back).

I draw two conclusions from this.  First, the rate of error detection is
not just a function of the language, but of the coding style as well.
If there are any papers on this topic, then to me they would be useless
unless they took account of this.  Second, learning Mercury (or Haskell)
can make you a better programmer in other languages such as C, because you
can develop a better appreciation for what the compiler can do for you.

Cheers,
Mark.

P.S.  Can't resist an old joke:

Q.  How many Prolog programmers does it take to change a light bulb?
A.  no

:-)

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list