kaarna
Joined: 03 Apr 2006 Posts: 92 Location: Finland
|
Posted: Sat May 26, 2007 5:54 am Post subject: import Gtk = gtk.Window; Thoughts about namespaces? |
|
|
Just a quick idea I got from Tango concerning namespaces. Tango uses this kind of importing for some of the modules, to give them namespaces that are easier to handle.
How about suggesting that gtkD be used like this (this might not compile or be good, I'm just throwing an idea here):
Code: |
import Gtk = gtk.Main; //this is changed from gtk.GtkD;
import Gtk = gtk.Window;
import Gtk = gtk.Button;
//notice, NO gtkc.gtktypes;
class MyApp : public Gtk.Window
{
public:
this()
{
super( Gtk.WindowType.TOPLEVEL ); //This is changed from GtkWindowType.TOPLEVEL
setTitle("My window");
m_button = new Gtk.Button("My button");
add( m_button );
showAll();
}
protected:
Gtk.Button m_button;
}
void main(char[][] args)
{
Gtk.Main.init(args); //This is changed from GtkD.init(args);
MyApp myApp = new MyApp(); //or just: new MyApp();
Gtk.Main.run(); //this is changed from GtkD.main();
}
|
Looks good to me.
The capitalization of
Code: | import Gtk = gtk.Window; |
might be better to be
Code: | import Gtk = Gtk.Window; |
but I'm not sure about that. Because D says that module names should be lowercase...
So gtk.GtkD should in my opinion be changed to gtk.Main. And I like Gtk.Main.run() better that GtkD.main();
And the enums should be defined for example in a module called gtk.gtkenums, or gtk.Enums, or gtk.gtktypes; or something like that. And that module should be public imported to all internal gtk.modules. The gtkc.gtktypes should only contain the C structs. Like this should be put to all gtkD source files:
Code: | public import Gtk = gtk.Enums; |
//or gtk.Types; or something similar.
Maybe that way it would automatically be imported always?? And that would look alot cleaner.
The way it works is that you could still do the normal
import gtk.Window
and use Window directly, if you want to. But we would just suggest in the examples and in the documentation that you're supposed to bind everything to a namespace Gtk.
And ofcourse other namespaces like:
import Gdk = gdk.Something;
import Cairo = cairo.Context; //Yes, and the Cairo class should be renamed to Context as it's that way everywhere else...
So what do you think? There might also be some other improvements that could be made. |
|