[GUI] Statically-typed read-only attributes

Sven Panne Sven.Panne at informatik.uni-muenchen.de
Sun Sep 14 19:07:42 EDT 2003


Nick Name wrote:
> [...] This raises the problem: what if I have also "instance Positioned 
> Window"? Well, this problem has many solutions, the simplest of wich is 
> *not* to have statically read-only attributes. I would rather try other 
> solutions, however they might complicate the class and type hierarchy.
> 
> What do you all think about this?

I think that the distinction (read-only, write-only, read-write) is very
important for a good API design: Runtime tests are evil when errors could
have been caught at compile time. The poor programmer would be forced to
consult the documentation for every widget to see if getting and/or setting
a particular attribute/property is allowed or not. :-P

My OpenGL/GLUT binding relies very heavily on "state variables", which are
very similar to the stuff in HToolkit and other proposals on this GUI list:

    http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/OpenGL/Graphics/Rendering/OpenGL/GL/StateVar.hs?rev=1.6&content-type=text/x-cvsweb-markup

The main difference is that there is no `w' (widget) argument, because
OpenGL/GLUT/OpenAL/... are based on an implicit context, which can be changed
separately outside the core API. In the case of OpenGL, the context is the
whole OpenGL state machine, which is typically a window-local entity managed
by a toolkit. Because of this, my get/set API is a bit simpler, but I'm quite
interested in a general (H98 conformant!) API for use in the GUI APIs and my
stuff.

Cheers,
    S.





More information about the GUI mailing list