Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Ville-Pertti Keinonen <will@exomi.com>
Cc: Matt Gushee <mgushee@havenrock.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Re: Feeding the OCaml GUI troll
Date: Fri, 02 Sep 2005 22:39:41 +1000	[thread overview]
Message-ID: <1125664781.7262.51.camel@localhost.localdomain> (raw)
In-Reply-To: <1125646841.735.57.camel@acerf.exomi.com>

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

On Fri, 2005-09-02 at 10:40 +0300, Ville-Pertti Keinonen wrote:
> On Thu, 2005-09-01 at 23:15 +1000, skaller wrote:
> 
> > I am. My idea is this: GET RID OF CALLBACKS.
> > The idea is to use (user space) threads instead.
> > 
> > The big problem with GUI's is that they're passive.
> > You write 'event handlers' and have to store the current
> > state manually. By control inverting the code, you can
> > just use a thread for each widget.
> 
> Have you actually done this in a GUI context, or do you just find it
> conceptually attractive?

I have done some brief experiments to check it can be
made to work .. but the real answer is no, it is only
a planned application (of Felix). But see below ..

> I've experimented with GUI concepts and event mechanisms in OCaml, and
> created an event mechanism that could relatively easily be used in a
> sort-of control inverted form by manually wrapping things into
> continuations.  I never ended up making use of that form of events for
> the actual low-level GUI functionality, because it always seemed easier
> to just use methods or attach callbacks to events and use explicit
> state. 

Yes, that seems likely for simpler low level things:
for example for a button (my example) clearly you just
need a boolean flag, which is pretty easy to maintain
manually.

However I *have* used the mechanism in a sophisticated embedded
environment, namely a telephony system.

We found, as above, that for some event handling,
callbacks were indeed better: some events like 
'phone call disconnected' are global, pervasive,
and in this case quite final.

Other events didn't fit so easily into this category.
Excuse brief explanation: the system used an asynchronous
real time data base. One task was to terminate a prepaid
phone call when the client's money ran out. In a place
like USA, where phone companies offer various deals,
and there are multiple time zones, the costing algorithm
can be quite complex -- especially if the client is
mobile (basically a recursive tree search with
pruning is required to find the minimum cost 'route')

To do this with hand written callback driven code is 
well nigh impossible. The algorithm is hard enough
written in a functional form with referential transparency
to help reason you have it right.

The fact the control inverted (event driven) form
is object oriented/procedural, yet equivalent to
a purely functional algorithm, makes mechanical
control inversion attractive -- but the utility
is only apparent in more complex examples.

>  Now that could simply be because I was sort-of porting a GUI
> library that I had written earlier (in C++ and Scheme) and I'm rather
> used to GUI mechanisms layered around inheritance (one of the few places
> where it actually seems natural to me).

I guess you start with simplistic procedural code, but
then find it is too hard to tailor and start using 
inheritance to help with that.

Unfortunately, a bit further down the track,
you again find it isn't good enough, and you need
much more dynamics -- and you have to switch
to delegation.

Further still, even that isn't dynamic enough,
and you start needing real message passing, that is,
posting events into the event queue as a means of
communicating between widgets.

The real question is, at this stage of sophistication,
whether you wouldn't be better off due to strong
static type checking, implementing stuff with functional
style instead: functional code can represent state too,
using closures.

I don't know the answer .. but I do know existing GUI's
are pretty bad. It is FAR too hard to get even simple
things to work, and hardly any GUI applications around
have any really high level functionality: the programmers
are struggling so hard to get really basic things to work.

> > For example for a button something like:
> > 
> > 	let rec wait_down () =
>   ...
> 
> > 	and wait_up () =
>   ...
> 
> > is purely functional: it uses the program counter
> > to maintain state, instead of a mutable state variable.
> 
> But consider that the state of a button isn't quite that simple.

The code was just an example of the style: for a more sophisticated
widget -- I mean lets go all the way and look at a tree widget,
an edit widget, or a canvas ... it isn't clear functional code
will be easier.

> Tracking the state explicitly isn't difficult 

No, not for a button. But for complex widgets it is.

Lets face it -- most programmers can't even get the mouse cursor
right. GQView, magnify/shrink with the mouse changes the mouse
from (+) to (-) when you next move the mouse .. which is plain
wrong (it should change as soon as you click to magnify or
shrink).

Many games .. mouse droppings (they got the double buffering
wrong).

So the fact is, programmers simply cannot manage trivial
state in a modern GUI correctly -- particularly they cannot
keep the user view of the state properly synchronised with
the internal state.

Interestingly I think Tk handles this quite well (it knows
when state is changed and re-renders the right things at
the right time automatically).

Windows is particularly BAD at some things, for example,
the tool used to edit the environment is utter rubbish:
PATH etc have very long string values and the dialog
box is small and fixed size .. this is just rubbish.

Another example: the ocamlbrowser is quite nice,
except it spawns top level windows left right and
centre, gets the size wrong, so every window has
to be adjusted. Any decent tool would allow you to spawn
those windows inside a pane or container of your choice:
modern 'Window managers' are just rubbish.

Sophisticated applications (eg Visual Studio) will give
you the choice .. but it is all hand programmed
for that particular application. I have designed a 
system called HWM (Hierarchical Window Manager) which
does away with that completely -- instead of a toolbar
you get a tree widget, which allows you to move windows
around in groups, and mutate their containers to any kind
you like (top level, panes, notebooks, etc). 

I have actually implemented this three separate times.
It relieves the programmer of the burned of hand coding
'mega-widgets' and leaves the organisation of widgets
up to the end user in a consistent way.

Of course .. this is a fairly radical concept .. the 
Open Source community would rather just copy Windows
and add minor improvements than bother to do any real
design work.

The real problem, IMHO, is C. You just cannot consider
new high level concepts for a GUI and implement them in C:
it is way too hard. 

Ocaml offers opportunities to do much better .. but there
is no point just copying existing GUIs: we already have
LablTk and LablGtk, which provide standard functionality
rewrapped more nicely. If we're going to do a real GUI
designed to take advantage of an advanced functional
programming language, we need to do a whole lot better
than what we already have .. and I do not see how to do this
without a lot of design work.

We do NOT want something with the same look and feel as
existing GUIs. They suck. But we have to have something
much better to be convincing .. do you remember the days
before Drag-and-Drop existed?

IMHO the *key* problem with GUI's -- and why real (TM) developers
hate using them -- is the lack of automation: unix script 
sucks, but it does provide automation. If we're going to make
a new GUI it has to have full automation capability.

The only way I can think of to do that is to base the 
core components of the GUI on Category Theory -- for example
have 'product' widgets and 'sum' widgets which represent
a collection and a set of alternatives, respectively,
and a standard way to combine them graphically.

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2005-09-02 12:40 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-28 15:38 Does LablTk have a future? Matt Gushee
     [not found] ` <aefe758210f7fa0b9846b0ea4278cf3a@rouaix.org>
2005-08-28 23:21   ` [Caml-list] " Matt Gushee
2005-08-29 22:33 ` Jon Harrop
2005-08-30  4:39   ` Matt Gushee
2005-08-30 11:39     ` Yaron Minsky
2005-08-30 11:48     ` Jon Harrop
2005-08-30 12:22       ` David MENTRE
2005-08-30 13:45         ` Jon Harrop
2005-08-30 15:47           ` David MENTRE
2005-08-30 16:08             ` Jon Harrop
2005-09-01  4:25               ` Matt Gushee
2005-09-01 11:20                 ` Matt Gushee
2005-09-01 11:26                   ` Matt Gushee
2005-09-01 14:09                 ` Chris Campbell
2005-08-30 16:21           ` Bardur Arantsson
2005-08-30 17:47           ` [Caml-list] " David Thomas
2005-08-30 18:06             ` Tyler Eaves
2005-08-30 19:01             ` Jon Harrop
2005-08-30 22:55               ` Chris Campbell
     [not found]               ` <c22844d10508301553b54841b@mail.gmail.com>
2005-08-30 22:56                 ` Fwd: " Chris Campbell
2005-08-30 23:04                   ` Doug Kirk
2005-08-31  0:08                   ` Fwd: " Jon Harrop
2005-08-31  0:31                     ` Olivier Andrieu
2005-08-31  8:48               ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) David MENTRE
2005-08-31  9:06                 ` Proposal a GUI from Ocamlsdl Christophe Raffalli
2005-08-31 14:39                   ` [Caml-list] " Jon Harrop
2005-09-01 19:27                     ` Nathaniel Gray
2005-08-31 14:27                 ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) Jon Harrop
2005-09-01  4:49                 ` Feeding the OCaml GUI troll Matt Gushee
2005-09-01 13:15                   ` [Caml-list] " skaller
2005-09-01 13:28                     ` David MENTRE
2005-09-01 13:50                       ` skaller
2005-09-01 14:43                     ` Chris Campbell
2005-09-02  7:40                     ` Ville-Pertti Keinonen
2005-09-02 12:39                       ` skaller [this message]
2005-09-03 10:34                         ` Damien Bobillot
2005-09-03 12:30                           ` skaller
2005-09-04 14:08                           ` Richard Jones
2005-09-03 11:10                         ` yoann padioleau
2005-09-03 11:30                           ` Jonathan Roewen
2005-09-03 17:23                           ` Doug Kirk
2005-09-04 14:01                         ` Richard Jones
2005-09-01 19:23                 ` Feeding the OCaml GUI troll (was: Re: [Caml-list] Does LablTk have a future?) Nathaniel Gray
2005-09-01  4:31             ` [Caml-list] Does LablTk have a future? Matt Gushee
2005-09-01  4:17       ` Matt Gushee
2005-09-01 13:25         ` Jon Harrop
2005-08-30  7:16   ` GUI for OCaml (was: Re: [Caml-list] Does LablTk have a future?) David MENTRE
2005-08-30  9:53     ` GUI for OCaml Christophe Raffalli
2005-08-30 10:28       ` [Caml-list] " David MENTRE
2005-08-30 13:04         ` Bünzli Daniel
2005-08-30 17:13         ` David Thomas
2005-08-30 11:18       ` Mark Shinwell
2005-08-30 14:22       ` Jacques Carette
2005-08-30 23:12         ` Pietro Abate
2005-08-30 14:14     ` GUI for OCaml (was: Re: [Caml-list] Does LablTk have a future?) Richard Jones
2005-08-30 15:33       ` mmzeeman
2005-08-30 15:44         ` Jon Harrop
2005-08-30 22:34         ` yoann padioleau
2005-09-01  4:58           ` Matt Gushee
2005-08-30 16:01       ` Jon Harrop
2005-08-30 16:25         ` Chris Campbell
2005-08-30 22:49           ` yoann padioleau
2005-08-30 16:03       ` Chris Campbell
2005-08-30 22:31     ` yoann padioleau
2005-08-31  8:19       ` About Lablgtk2 (was: e: GUI for OCaml) David MENTRE
2005-09-03 11:41         ` yoann padioleau
2005-08-30 17:35   ` [Caml-list] Does LablTk have a future? Olivier Andrieu

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=1125664781.7262.51.camel@localhost.localdomain \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=mgushee@havenrock.com \
    --cc=will@exomi.com \
    /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