[phobos] Time to get ready for the next release

David Simcha dsimcha at gmail.com
Fri Apr 22 06:09:14 PDT 2011


On 4/22/2011 8:43 AM, Steve Schveighoffer wrote:
> There are a couple problems with this.
>
> First, there is the WTF factor when you want to set multiple colors with the same value:
>
> hist1.barColor = hist2.barColor = getColor(255, 0, 0);
>
> WTF? this is an error? But this works (enjoy the clarity of this):
>
> hist1.barColor = (hist2.barColor = getColor(255.0, 0)).barColor;

Yeah, it would be nice if the first one worked, but in a plotting 
library the second is more useful in practice.  When it comes to minor 
details like this, IMHO convenience is more important than consistency.  
Maybe if strict semantics are implemented, this could be solved by 
allowing property to be overloaded against non-property and defining a 
fluent mixin to define both in a single line of code.  Defining both 
manually is anti-DRY and not even worth considering.  IMHO they should 
have the same name because it's less crap to remember.

// CTFE function that returns both property and fluent getters and setters,
// using the convention that the target variable is named _varName.
// Unfortunately this also requires overloading templates and non-templates,
// which needs to be fixed.
string fluent(string varName, string docString) {
     return "/**" ~ docString ~ "*/\nauto " ~ varName ~ "() @property { 
return _" ~ varName ~ ";}\n" ~
                 "auto " ~ varName ~ "() { return _" ~ varName ~ ";}\n" ~
                 "typeof(this) " ~ varName ~ "(this This)(typeof(_" ~ 
varName ~ ") newVal) { \n " ~
                      " _" ~ varName ~ " = newVal;  return cast(This) 
this; }\n"
                 "auto " ~ varName ~ "(typeof(_" ~ varName ~ ") newVal) 
{ _" ~ varName ~ " = newVal;   return newVal; }"
}

> Second, it looks strange to have a function named barColor.  In an extreme interpretation, I could expect that with barColor, I am barring that color from the object ;)  Not that it would be a common interpretation, but the name looks more ambiguous than say, setBarColor.  There are certainly better cases that could demonstrate my point, as English is full of words that are both nouns or adjectives and also verbs.
>
In the context of a plotting library barColor makes perfect sense.  Lots 
of function names don't make sense when taken out of context, and 
requiring them to is a Draconian measure that would force all function 
names to be ridiculously long, like setHistogramBarColor().


More information about the phobos mailing list