[erlang-questions] wx_object and OTP design pattern

zxq9 zxq9@REDACTED
Wed Sep 10 04:22:59 CEST 2014


On Tuesday 09 September 2014 19:28:27 Frans Schneider wrote:
> 
> I want to incorporate wx in my application and was wondering how the
> wx_object behaviour fits into the OTP application structure. Any design
> patterns for this? All examples or applications using wxErlang I found
> do not follow the OTP prinicples.

I've been experimenting with wx quite a bit myself lately. I noticed the same 
thing looking for open source examples of wx use -- almost no utilization of 
wx_object. Then I started reading the code that appears when you run wx:demo/0 
more carefully. Scroll up to the header (which is not where the module code 
window starts at by default), and you'll notice the windows (note: be careful 
what "frame" and "window" mean in wx terminology) in demo all use wx_object.

Inspired by a combination of that and the Android-esque idea that one activity 
equals one frame, I have found wx_object to be a helpful thing. If I can 
provide an interface to a single user task in a single window, then wx_object 
is my wx-augmented gen_server that represents that activity.

There is a bit of a semantic stew up above ("frame", "task", "window", 
"activity", etc.) but the basic idea is that wherever you have a chunk of user 
functionality that is best represented as a process of its own (nearly always 
the case), it is easier to integrate that using a wx_object than to write a 
home-made wx process that talks to a GUI handling gen_server that then talks 
to whatever your logic bits are.

It is cumbersome, on the other hand, to start gen_serverizing every aspect of 
the GUI with wx_objects everywhere. As always, you just have to play around 
with this a bit on your own to decide what your "correct" level of granularity 
is there. I'm still toying with this and haven't decided, but Android folks 
define "activity" and "task" have provided me with reasonable starting points.

I am *intensely* interested in anyone else's opinion on this. Using Erlang in 
this way has vastly simplified my reasoning about GUIs, but it still seems that 
there are not many examples of wxErlang GUI applications in the wild so I feel 
like I'm blazing my own trail every day.

-Craig



More information about the erlang-questions mailing list