Re: [Ongui-dev] Thoughts on programming idioms
Status: Alpha
Brought to you by:
robinrowe
|
From: Robin R. <ro...@Mo...> - 2003-12-24 22:54:34
|
Mike,
Hi. Good to hear from you. I was wondering how it is going.
> Having a hell of a time getting Pango to work. Nearly there.
Please send documentation to the list of what problems you encounter and how
you overcome them.
> int main (int a_argc, char* a_argv[])
> OnGui::Label *m_label ;
Let's not do the m_ notation, or any other naming method Hungarianisms. If
we're writing OOP (we are, right?) then there should be no global variables.
That means *every* variable in a method would be a member variable unless it
was explicitly passed into the method as an automatic. Using m_ and a_
doesn't clarify anything and makes code unpleasant to read.
If you don't mind, data members in class definitions before methods. I want
to know what something is before I bother figuring out what it does. By the
way, if it becomes tedious to look past the data members to the methods
because of too many data members in the class that is an indication of
insufficient encapsulation (not enough classes). Classes shouldn't need to
have a long list of data members.
Regarding method names, can you make those upper and lower rather than lower
and upper? Your style is a bit too Java-ish for us old C++ dogs.
> int main (int a_argc, char* a_argv[])
> {
> class Button1 : public OnGui::Button
The definition of class Button1 had better be before main!
> OnGui::init (a_argc, a_argv);
> OnGui::run() ;
What's this? We already have an implicit initialization and run methods.
Don't need these C-ish GTK-like calls.
> 2) Reference counting.
Reference counting is evil. It never quite works right and always makes code
complicated to read and debug. If we need reference counting then we're on
the wrong track. The result will not be the sort of lightweight toolkit
envisioned. The point of the OnGui approach is that when the user hits the
callback he is already inside the relevant C++ object and can't get lost. I
don't know what it is you imagine counting.
Here's your example more like I have in mind:
class HelloDialog
: public OnDialog
// OnDialog is derived from OnWindow is derived from OnLayoutMgr.
{ OnButton hello_button;
public:
HelloDialog("hello_dialog")
: hello_button("hello_button",this)
// In its ctor the hello_button adds itself to the 'this' OnLayoutMgr
list.
{ hello_button.SetPosition(10,10);
// Or, position could also be set by resource file:
// "hello_dialog.hello_button.position 10 10"
// Each object needs a string name for this to work.
}
virtual void OnClick(Msg msg)
{ hello_button.Toggle("Not clicked","Clicked!");
}
virtual void OnClose(Msg msg)
{ QuitProgram();// posts a quit message
} };
int main()
{ HelloDialog hello_dialog;
hello_dialog.Show();
return MsgPump();
}
Comments?
Robin
---------------------------------------------------------------------------
Rob...@Mo... Hollywood, California
www.CinePaint.org Free motion picture and still image editing software
|