caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: John Whitington <john@coherentgraphics.co.uk>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Do you use a debugger with OCaml? If not, why not?
Date: Wed, 25 Nov 2015 08:23:14 -0500	[thread overview]
Message-ID: <CALdWJ+zPC94SQjf8jdCOkUTgmhjGyQ9n8rXCPawcmVOQofP1WA@mail.gmail.com> (raw)
In-Reply-To: <5655AE66.6000307@coherentgraphics.co.uk>

[-- Attachment #1: Type: text/plain, Size: 3758 bytes --]

The use of a debugger usually indicates that a programmer lost a control of
its own program and has no idea whats going on.
If a programmer doesn't own a program, and tries to understand existing
program, written by someone else, then it means to me,
that the program is written so poorly, that it is too hard to recover its
semantics by reading its source code representation.

OCaml, as well as any other functional programming language, encourages to
compose big programs from small and understandable
pieces. Due to unique properties of functional programming paradigm this
composition is usually linear (lack of mutable state and side-effects).
Also,
OCaml has a reach type system, that allows a programmer to specify his
assumptions and program invariants, so that any violation
will be caught on compile time.

So, if properly applied, OCaml allows one to write big programs without
need for debugging at all. Of course, it is possible to write Fortran 77 in
OCaml, in that case you will soon find yourself in the debugger prompt.

Sometimes, though, especially when you heavily interact with outside world,
like user interface, networking, etc, you find yourself on a loose ground,
since your assumptions cannot be defined in terms of OCaml typesystem (no
dependent typing, no linear typing). In that case you need to study
the dynamics of a program. Usually, in this cases the debugger is not
useful, since the program interacts in real-time with some external agent,
that is
not going to wait for you.

My personal approach to debugging is to start from static analysis of the
code and try to limit the search space. I also try to extract all possible
assumptions
that was made by a programmer. Once I have a list of possible suspects, I
instrument the code and insert some tests. Sometimes the instrumentation is
just
a printf, sometime it is just an assert. Quite often, this is just `assert
false`. I continue this operation, until only one suspect is left. In most
use cases, the
initial stage of reading code, will already leave me with only one or two
suspects, as if the code is written properly it is usually easy to find a
proof (an alibi) for
most cases. Of course this require some programming discipline:

1. limit the use of mutual state
2. limit the use of exceptions in favor of returning variant types (option,
result, or_error)

This two rules ensures linearity, due to the lack of side effects. And
usually, this is side effects, that we're trying to debug with a debugger
or printfing.


On Wed, Nov 25, 2015 at 7:49 AM, John Whitington <
john@coherentgraphics.co.uk> wrote:

> Hi,
>
> Like, I suspect, many people, my method has always been to insert Printfs,
> and stare at code until I find the problem. In fact, the ocaml.org page
> on ocamldebug says:
>
> "In fact, for complex programs, it is likely the case that the programmer
> will use explicit printing to find the bugs, since this methodology allows
> the reduction of the trace material: only useful data are printed and
> special purpose formats are more suited to get the relevant information,
> than what can be output automatically by the generic pretty-printer used by
> the trace mechanism."
>
> So, I ask: What do you use for debugging small and large OCaml programs?
> If not a debugger, why not? What problems prevent it? How does your
> debugging process differ when writing OCaml compared with other languages
> you use?
>
> John
>
> --
> John Whitington
> Director, Coherent Graphics Ltd
> http://www.coherentpdf.com/
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 4922 bytes --]

  parent reply	other threads:[~2015-11-25 13:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 12:49 John Whitington
2015-11-25 13:12 ` Francois Berenger
2015-11-25 13:23 ` Ivan Gotovchits [this message]
2015-11-25 15:27   ` Gerd Stolpmann
2015-11-25 16:04     ` Chan Ngo
2015-11-25 13:26 ` Matthieu Dubuget
2015-12-01 12:06   ` Matthieu Dubuget
2015-11-25 14:02 ` Markus Weißmann
2015-11-25 14:05 ` Nils Becker
2015-11-25 15:55 ` Daniel Bünzli
2015-11-26  9:14   ` Leonardo Laguna Ruiz
2015-11-26 10:59     ` Tom Ridge
2015-11-30 17:56       ` Xavier Van de Woestyne
2015-11-25 16:06 ` Maverick Woo
2015-11-25 16:16 ` Anton Bachin
2015-11-25 16:52   ` Michael Grünewald
2015-11-25 18:23     ` Török Edwin
2015-11-25 20:23 ` David MENTRÉ
2015-11-26 10:11 ` Malcolm Matalka
2015-11-26 10:57 ` Romain Bardou
2015-12-11 18:58 ` Richard W.M. Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALdWJ+zPC94SQjf8jdCOkUTgmhjGyQ9n8rXCPawcmVOQofP1WA@mail.gmail.com \
    --to=ivg@ieee.org \
    --cc=caml-list@inria.fr \
    --cc=john@coherentgraphics.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).