In my exploration of Polymer Dart 1.0.0, I've found for events, and observer methods, I am forced to use this pattern
@reflectable
void someEvent([_, __]) {
...
}
or on an observer method
@Observe('someField')
void someFieldChanged([_, __]) {
...
}
I understand what the square brackets are for, optional parameters, I also understand that if you don't care about the passed parameters, you can represent this parameter with the underscore. What surprised me was the examples I looked at used double underscore, __, as the second symbol between the square brackets. When I tried to use just a single underscore again, I get a duplicate formal parameter error. Is there some reason why the second parameter you don't care about has to be different from the first? By this logic, if I include a third one, does it mean it'll have to be a triple underscore ___?
Thanks.
Double underscores are used for fully private variables. If your class is intended to be subclassed, and you have attributes that you do not want subclasses to use, consider naming them with double leading underscores and no trailing underscores.
The use of double underscore ( __ ) in front of a name (specifically a method name) is not a convention; it has a specific meaning to the interpreter. Python mangles these names and it is used to avoid name clashes with names defined by subclasses.
Single Trailing Underscore( var_ ): Used by convention to avoid naming conflicts with Python keywords. Double Leading Underscore( __var ): Triggers name mangling when used in a class context. Enforced by the Python interpreter.
The Python interpreter modifies the variable name with ___. So Multiple times It uses as a Private member because another class can not access that variable directly. The main purpose for __ is to use variable /method in class only If you want to use it outside of the class you can make it public.
Nothing special. _
as __
as a
are just variable identifiers. _
is often used to name an unused variable.
Here there are 2 variables unused, the first one is named _
and the second one __
.
With multiple unused variables it's common to name them _
, __
, ___
... or _1
,_2
,_3
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With