Re: [pygccxml-development] Additional attribute functionality
Brought to you by:
mbaas,
roman_yakovenko
From: Ben S. <bsc...@lu...> - 2007-12-04 21:33:02
|
Um, ok I finally saw this page. having a link to it inside the documentation would be useful.. I think that the use of exceptions in this context is overkill, considering that exceptions should only be used in "exceptional" cases. I think that java suffered from the same problem of overuse of exceptions. =20 However, I think I'll stick to mem_fun*s(..., allow_empty=3Dtrue) for = now. It makes more sense... =20 Cheers Ben =20 PS. I don't understand how we are avoiding a loop by writing =20 for decl in class_.decls(): =20 wouldn't this be the same if decls() returned a list? And then the benefit of a list would be it's standard operations... =20 ________________________________ From: Roman Yakovenko [mailto:rom...@gm...]=20 Sent: Tuesday, December 04, 2007 12:29 PM To: Ben Schleimer Cc: pyg...@li... Subject: Re: [pygccxml-development] Additional attribute functionality =09 =09 On Dec 4, 2007 9:58 PM, Ben Schleimer <bsc...@lu...> wrote: =09 Hi Roman, Another thing to keep in mind for after 1.0 is that the scopedef is very difficult to work with. When I write class_.member_function("foobar"), I expect either a value or None to be returned. I don't expect an exception to be thrown likewise, I'd like to see class_.member_functions("foobar") to return a list of declarations, zero if no declaration matches. Again, no exception should be through. Then I can take the list and manipulate it like a normal python list. =09 Did you read this http://language-binding.net/pygccxml/query_interface.html document? The behavior you are talking about was implemented intentionally.=20 =09 I prefer to think about "mem_fun" as "get" function, which should raise in error if there is 0 or 2+ member functions with the same name. The behavior you propose doesn't distinct between these cases. On the other side raised exception contains enough information to explain what went wrong.=20 =09 I think about "mem_fun*s*" as a query function, it can return zero or more items that match search criteria. You can customize the behavior of this function. By default it raises an exception if no match was found. Pass "allow_empty=3DTrue" as function argument to disable exception if no match was found. I understand that not everyone agrees with such behavior, so scopedef_t.ALLOW_EMPTY_MDECL_WRAPPER variable was introduced. You can set it to False, after this "mem_fun*s*" method will not raise exception on "no match".=20 =09 Now, the return value of the "mem_fun*s*" method is very carefully constructed class that allows the user to avoid writing of loops. Link to the class http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.mdecl _wrapper.mdecl_wrapper_t-class.html =09 The class implements "container" interface and in general you should not notice the difference between it and the list class.=20 =09 I am using pygccxml for code generation projects. May be you are right and the interface is really "less than intuitive", but it is very valuable for code generation projects maintenance. If the underlying code change, class was removed, renamed or moved, you get immediately very helpful error message.=20 =09 Does it make sense now? =09 P.S. Of course "mem_fun*s*" is just an example and every "query/select" function has same behavior. =09 --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/=20 |