Re: [GD-General] Eiffel
Brought to you by:
vexxed72
From: Jesse J. <jes...@mi...> - 2001-12-23 00:03:21
|
At 10:08 AM -0500 12/21/01, Thatcher Ulrich wrote: >On Dec 21, 2001 at 01:56 -0500, Kent Quirk wrote: >> >> fact, one of the things that I love about Java and wish that C++ had was >> anonymous classes. They provide the only way to deal with the concept of >> functors in generic algorithms where the functor is defined at the same >> point as the algorithm is used. In C++ you can put it nearby. In Java >> you can stick an anonymous class right inline. It's a powerful, useful, >> and very general mechanism, similar to a lambda notation. > >Someone showed me this trick recently: > > ... > struct Function { > static void Call(int arg) { > // some code. > } > } Instance; > SomeFunctionTakingAFunctionPointer(Function::Call); > ... People have been writing templatized callback classes in C++ for years. Boost has recently adopted one that is pretty darn cool (see the function and bind links at <http://www.boost.org/libs/libraries.htm#Function-objects>). It allows you to write code like this: Editor* editor = ...; boldButton->SetCallback(boost::bind(&Editor::SetStyle, editor, kBold)); italicButton->SetCallback(boost::bind(&Editor::SetStyle, editor, kItalic)); When the button is clicked it calls the callback with the argument provided. The prototypes look like this: void Button:: SetCallback(boost::function& f); void Editor::SetStyle(uint32 style); boost::bind takes a pointer to a free function, member function or functor object with N arguments and returns a boost::function argument that takes fewer arguments. You can even do things like leave the middle argument of a 3-argument function unbound. It's not as nice as a real closure system, but it's enormously useful and it's also efficient and typesafe. >I'm still sick of C++ though. The useful modern stuff I want to use >is all a huge PITA. Templates stink, (lack of) introspection stinks, >header files stink, manual memory management stinks, and pardon me, >but IMHO the STL stinks as far as usability goes. I don't think templates stink. The syntax is awkward and there's not enough support for template meta-programming, but having what amounts to a separate language at compile time is a very powerful feature that lets C++ do stuff that Java, C#, and Eiffel can't touch. The weak support for introspection doesn't bother me as much as the lack of any dynamism in the language. Pascal and Modula-2 were the first real languages I used so I like the concept of compile-time type checking, but a dynamic language really can make some important things simpler. Right now I think a language like Dylan where you can have both types and untyped variables is the way to go, but perhaps I'll change my mind after I get more experience with Ruby. I don't think STL stinks at all from a usability standpoint. Once you wrap your head around the concept of containers, iterators, and algorithms it's really easy to use and very powerful. The only problem are the icky error messages and the truly awful way that Plauger wrote his version of the library. But the biggest problem with C++ might be that it simply requires too much time and study to become proficient in the language and aware of all the pitfalls. Even the stuff published in magazines like C/C++ Users Journal is full of problems. -- Jesse |