RE: Euphoria being OO Survey.
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> May 16, 2003
- 639 views
> From: fred at jordah.freeserve.co.uk [mailto:fred at jordah.freeserve.co.uk] > > Matt wrote: > Matt, think of it this way. You are attempting to write a > cross-platform GUI library. To make this library readily > cross-platform you'll have to code your own widgets...eg lists,menus > > With time you go to look at all your widgets and see a lot of > repeated code, then u have to clean it up. Clean up ends up > introducing bugs, with time, u go to notice that it gets > annoying trying to modularise your code as it grows > bigger...etc. With OO, i would create simply a class with eg default > properties,virtual functions,methods. Say, CWnd Class like in > MFC, then to all other controls eg when coding the button class. i would > simply create a class that inherits from the CWnd class, then overide certain > methods and have a button control. Well, frankly, this is an example of a poor engineering process (which I am often guilty of following). There's no reason why you had to repeat a lot of code. Some planning up front could have saved that effort. I've found that over time I've gotten better at the up front planning (a big part of which is making a conscious decision to do so), and it's a tremendous help. I've heard many say that OO ("properly" done) often requires *more* up front design work. > I dunno how to explain it since i'm not an experienced OO > user but i think u get what i'm getting at...(i think polymophism). > Anyway, have u used MFC? See how easy it is? what is better, > is that, coding ur custom controls is simply involves extending certain > classes eg CWnd Have not, and probably will never use MFC. In any case, this is really not unlike the process of extending, say, win32lib (of which I've done quite a bit). When I added ListViews and TreeViews, I didn't have to write a whole new slew of functions that duplicated other things. I simply extended what was already there and appropriate to the task, and added new functionality that didn't exist (dealing with ImageLists, for instance). > Another issue is when you have function names/proc names that > are similar but different in function...eg Incase you look at win32lib, > If you look at his setText() proc, u'll notice he uses the if switch > lots to adjust for it to work for different controls eg > If class=Menu then > --code here > elsif class = window then > --code here > end if > > wouldn't it be easier to do > eg in java > JFrame mw = new JFrame(); > JMenu me = new JMenu(); > mw.setText("blah"); > me.setText("xxg"); > mw.setVisible(1); How is the java example easier than the following? constant mw = create( JFrame ), me = create( JMenu ) setText( mw, "blah" ) setText( me, "xxg" ) setVisible( mw, 1 ) >From the library standpoint, why is the if switch so wrong? It simply brings the code to one place, which is probably a plus for maintenance. Also, many of the functions in win32lib end up sending a very similar message to some control, but having all of it in one place simplifies things a bit (e.g., only need to allocate a string in one place). If you don't like the if switch, you can use routine_id() to add arbitrarily large numbers of routines (which can, of course, be located anywhere) using an associative list: ix = find( control_type, valid_control_types ) call_proc( control_routines[ix], {}) Matt Lewis