On Dec 20, 2008, at 9:56 PM, Roger Lovelock wrote:
> I see a lot of underscores and double underscores used in python/dabo
> variable names and also when looking at some menu code a
> construction with
> brackets an underscore and then further brackets eg
>
> vm.append(_("Display Methods", ... etc ))
>
> and, of course, __main__ etc etc
OK, there are 3 separate things here. First let's take the leading
double underscores.
This is the only way to make something "private" in Python. I quote
that because it isn't really private; Python internally mangles the
name so that if you make an identically-named method/attibute in a
subclass, it won't override the superclass version, as it will
internally use a completely different name.
There is also the double-double underscores. This is to indicate that
this is a "magic" method or attribute in Python. What I mean by
"magic" is that if you don't know exactly what it's doing, you
shouldn't mess with it or risk seriously screwing things up.
Next are atts/methods that are preceeded by a single underscore.
Technically this has no effect on the code; it's just another
character. But by convention it is used to denote an implementation
detail of the class that is not meant to be referenced outside of the
class. As an example, many of our controls have a _caption attribute
to store the content of the Caption property. The reason we named it
with a leading underscore is that as a developer, you shouldn't read
or set that value directly. 'Caption' is the public interface, and
that's what you should use.
Finally, there is a method whose name is simply an underscore. This
may look odd, but it is the convention in C for indicating a string
that is localized. The _() method takes the value and replaces it with
the version of that string for the currently-set locale, if there is a
translation available for it. All strings that are displayed to the
user in Dabo are localized by wrapping them with the _() method. And
hey, if you speak a foreign language and would like to provide
translation services, you can contribute to Dabo by going to this page:
https://translations.launchpad.net/dabo/trunk/+pots/dabo
We've only got a tiny bit of the framework localized, with the
biggest chunk done so far in German.
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/[email protected]