[Tickit-dev] RenderBuffer and immutable Pen code style

Paul "LeoNerd" Evans leonerd at leonerd.org.uk
Fri Aug 21 13:35:33 BST 2015


I've recently been updating the embedded examples that come with the
libtickit C library source. I've noticed that a lot of them were still
using plan writes to terminal instances, instead of something
higher-level like RenderBuffer (or in fact, Windows, since that's what
I'm going through rewriting them to).

One consequence of this is that the code tends usually to operate on a
mutable pen; or rather, continues to change the actual terminal pen
using calls to tickit_term_chpen(2). This very imperative style isn't
something that would be too nice at a higher level. While it is
possible to largely take a low-level terminal-based example and rewrite
it to the equivalent renderbuffer calls, it seems nicer to use a
higher-level approach of immutable pen instances for each possible
style that is used, that are (possibly-lazily created and) cached by
the application. This way it still works if you make a more efficient
render handling function that actually uses the 'rect' argument to
reduce parts of the code that don't matter.

To further help this style I've started thinking that mutable pens are
a bad idea anyway, and we should be shifting the code to remove that
idea. Already the _ref/_unref pair are helping things, provided you
promise not to edit anything. The Perl layer of code has now started
deprecating the idea of pen change observers, so soon we can kill those
from the C library. The Perl module also keeps a distinction between
mutable and immutable pens, just by omitting any of the mutation
methods on the latter.

Should we continue doing that? Is anyone going to complain that they
really need mutable pens?

-- 
Paul "LeoNerd" Evans

leonerd at leonerd.org.uk
http://www.leonerd.org.uk/  |  https://metacpan.org/author/PEVANS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://mail.leonerd.org.uk/pipermail/tickit-dev/attachments/20150821/78d4543a/attachment.sig>


More information about the Tickit-dev mailing list