<div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/21 Frank Shearar <span dir="ltr">&lt;<a href="mailto:frank.shearar@gmail.com" target="_blank">frank.shearar@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 20 December 2013 21:16, Chris Muller &lt;<a href="mailto:asqueaker@gmail.com">asqueaker@gmail.com</a>&gt; wrote:<br>
&gt; On Fri, Dec 20, 2013 at 3:01 PM, Frank Shearar &lt;<a href="mailto:frank.shearar@gmail.com">frank.shearar@gmail.com</a>&gt; wrote:<br>
&gt;&gt; On 20 December 2013 20:42,  &lt;<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>&gt; wrote:<br>
&gt;&gt;&gt; Chris Muller uploaded a new version of Environments to project The Trunk:<br>
&gt;&gt;&gt; <a href="http://source.squeak.org/trunk/Environments-cmm.37.mcz" target="_blank">http://source.squeak.org/trunk/Environments-cmm.37.mcz</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; ==================== Summary ====================<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Name: Environments-cmm.37<br>
&gt;&gt;&gt; Author: cmm<br>
&gt;&gt;&gt; Time: 20 December 2013, 2:42:33.974 pm<br>
&gt;&gt;&gt; UUID: c2e36521-ef29-4aa3-9425-84793a2d007c<br>
&gt;&gt;&gt; Ancestors: Environments-nice.36<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Minor cleanups while trying to learn Environments.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =============== Diff against Environments-nice.36 ===============<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Item was changed:<br>
&gt;&gt;&gt;   ----- Method: AddPrefixNamePolicy class&gt;&gt;prefix: (in category &#39;as yet unclassified&#39;) -----<br>
&gt;&gt;&gt; + prefix: aString<br>
&gt;&gt;&gt; +       ^ self new<br>
&gt;&gt;&gt; +                setPrefix: aString ;<br>
&gt;&gt;&gt; +                yourself!<br>
&gt;&gt;&gt; - prefix: aString<br>
&gt;&gt;&gt; -       ^ self basicNew initializeWithPrefix: aString!<br>
&gt;&gt;<br>
&gt;&gt; Why make the AddPrefixNamePolicy mutable? That seems like a bad idea.<br>
&gt;&gt; Unless there&#39;s some seriously major gain to be had, we should _not_<br>
&gt;&gt; add setters. The &quot;basicNew initializeWithFoo:&quot; idiom makes it clear<br>
&gt;&gt; that &quot;AddPrefixNamePolicy new&quot; will not result in a properly<br>
&gt;&gt; initialised object. It avoids giving people the impression that it&#39;s<br>
&gt;&gt; OK to monkey with the object&#39;s state. It&#39;s also the closest we can get<br>
&gt;&gt; to immutability, given that the only way we can initialise an object&#39;s<br>
&gt;&gt; state correctly is by sending it messages. (I realise the idiom&#39;s not<br>
&gt;&gt; in SBPP, but sometimes we can improve on the classics.)<br>
&gt;&gt;<br>
&gt;&gt; I like how you renamed lots of parameters to indicate the kind of<br>
&gt;&gt; things they ought to contain (&quot;aNamespace&quot; -&gt; &quot;aDictionary&quot;), but<br>
&gt;&gt; please, no setters.<br>
&gt;<br>
&gt; Yeah, both things are simply documented best-practice conventions.<br>
&gt; It&#39;s best not to call basicNew except for serialization frameworks or<br>
&gt; otherwise with a good reason to, otherwise #initialize won&#39;t get<br>
&gt; called from the one place it should be called from.<br>
<br>
</div></div>My point is that I don&#39;t think you should send #new at all, because<br>
that suggests that you could have an AddPrefixNamePolicy with no<br>
prefix.<br>
<div class="im"><br>
&gt; So that requires changing the method name from #initializeWith...: to<br>
&gt; simply #set...:, which is Kent Becks &quot;Constructor Parameter Method&quot; on<br>
&gt; page 25 of his book.<br>
<br>
</div>I have a copy of SBPP (sadly not in the same country as me anymore),<br>
which is why I specifically suggested that sometimes we can improve on<br>
the classics :)<br>
<div class="im"><br>
&gt; Now, I&#39;ve heard the suggestion to name these methods as &quot;myPrefix:<br>
&gt; prefixString myNamespace: aDictionary&quot;, so that, should a developer<br>
&gt; ever think he wants to use them, it will look and read awkwardly in<br>
&gt; the calling code.<br>
&gt;<br>
&gt; But that relies on a convention for &quot;privatizing&quot; that no other<br>
&gt; private methods can afford.<br>
<br>
</div>As does that #new prefix: cascade.<br>
<div class="im"><br>
&gt; Therefore, nothing besides the categories/protocols are either needed,<br>
&gt; nor should be used, to indicate whether a method is ok to use from the<br>
&gt; outside.<br>
&gt;<br>
&gt; And, I confess, Beck says Constructor Parameter Methods should be<br>
&gt; categorized as &#39;private&#39; but I trumped him because<br>
&gt; &quot;initialize/release&quot; is just as private (e.g., no one calls those from<br>
&gt; the outside) plus.. that&#39;s what it is for!  And, it co-locates it with<br>
&gt; #initialize where it belongs and easy to see all initialization under<br>
&gt; one protocol.<br>
&gt;<br>
&gt; Whew!<br>
<br>
</div>I almost entirely agree with you. Except that I think that calling<br>
#basicNew and initialising within the #initializeWithFoo: methods is<br>
superior because<br>
* you don&#39;t need a setter (as in, you don&#39;t need a method that looks<br>
and smells and tastes exactly like a classic<br>
expose-my-state-for-mutation setter.<br>
* #initializeWithFoo: tells you the ways you can construct a valid<br>
instance, and if you want to construct an _invalid_ one you have to<br>
work at it - actively subvert the API.<br>
* #initializeWithFoo: tells you much louder exactly what it will do,<br>
where #setFoo: (a) looks like a Java-style mutator and (b) suggests<br>
that you can (partly!) _reinitialise_ an object. Worse, #setFoo: only<br>
partially initialises the object, where #initializeWithFoo: completely<br>
initialises an object.<br>
<br>
So in the end we&#39;re arguing about two conventions that do more or less<br>
the same thing. I don&#39;t see any _improvement_ in using #new, and in<br>
fact see several (admittedly minor) downsides. So what&#39;s the point<br>
then of &quot;fixing&quot; this?<br>
<br>
(As I already said, I think the parameter renaming&#39;s a great idea.<br>
It&#39;s just the #new setFoo: stuff that I dislike.)<br>
<span class="HOEnZb"><font color="#888888"><br>
frank<br>
<br>
</font></span></blockquote></div><br></div><div class="gmail_extra">Yep, I&#39;m completely in line with Frank on this particular point.<br></div></div>