<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Rambling Comments</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/" />
    <link rel="self" type="application/atom+xml" href="http://www.lenholgate.com/blog/atom.xml" />
    <id>tag:www.lenholgate.com,2010-12-10:/blog//12</id>
    <updated>2010-12-26T07:11:24Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 5.12</generator>

<entry>
    <title>Implicit Interfaces</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2006/01/implicit-interfaces.html" />
    <id>tag:www.socketframework.com,2006:/blog//12.663</id>

    <published>2006-01-07T09:57:58Z</published>
    <updated>2010-12-26T07:11:24Z</updated>

    <summary>ImplicitInterfaceImplementation - from Martin Fowler is an interesting piece where Martin suggests that it would be useful to be able to provide alternative implementations of a class&apos;s implicit interface. That is, given a class that does not inherit from an...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Dumbing down is dumb" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<a href="http://martinfowler.com/bliki/ImplicitInterfaceImplementation.html">ImplicitInterfaceImplementation</a> - from <a href="http://www.martinfowler.com/">Martin Fowler</a> is an interesting piece where Martin suggests that it would be useful to be able to provide alternative implementations of a class's implicit interface. That is, given a class that does not inherit from an interface, it's sometimes useful to be able to split the class into an implicit interface, the public operations that it provides, and treat that as if it were explicitly declared as an interface from which the class derives. This would be useful in testing as it would allow you to mock up things that are currently difficult to mock up. It's an interesting idea and it's generated a <a href="http://twasink.net/blog/archives/2006/01/implicit_interf_1.html">lot</a> of <a href="http://homepage.mac.com/keithray/blog/2006/01/06/#Interfaces">talk</a>. I'm not sure it's good though, it smacks of making things easy that are already easy if you approach the problem with enough discipline...]]>
        <![CDATA[<p>I think one of the biggest problems with this idea is, as Barry Kelly says over on <a href="http://barrkel.blogspot.com/2006/01/mf-bliki-implicitinterfaceimplementati.html">Entropy Overload</a>, classes like that often have multiple implicit interfaces and they're not always public. </p>

<p>I find that in C++ I tend to operate with explicit interfaces much of the time, it often works out easier in the long run to develop a class interface first, especially when developing in a TDD style. I write the test, I write the code under test, it needs to access another object to I work out the interface, implement a mock from that interface and, eventually, write tests for the object and develop the object. This is pretty much what <a href="http://www.interact-sw.co.uk/iangblog/2006/01/05/implicitinterfaces">Ian G suggests</a>, work only through interfaces. It does require a little more discipline and it is, sometimes, overkill but it works pretty well. </p>

Of course Martin's suggestion would make it easier to use third party code without wrapping it up in a shim of your own. Personally I think it's a good thing to get in the habit of segregating third party code and putting it behind a thin, object based firewall of your own devising. The shim/wrapper code allows you to blend the alien API into your standard ways of doing things and gives you a chance to refine the abstraction that the third party API provides. Chances are their abstractions are in terms of the problem that <i>they</i> solve whereas yours <a href="http://www.lenholgate.com/archives/000607.html">should be in terms of the problem that you are solving</a> and might only use a small part of the API... What's more, if you have slipped in an interface you can test without the third party code and you can, potentially, replace the third party code with other code if required...]]>
    </content>
</entry>

<entry>
    <title>If you enjoyed the Petzold thing earlier...</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2005/10/if-you-enjoyed-the-petzold-thing-earlier.html" />
    <id>tag:www.socketframework.com,2005:/blog//12.610</id>

    <published>2005-10-25T20:50:12Z</published>
    <updated>2010-12-26T06:29:17Z</updated>

    <summary>This may also be your kinda thing. Ellen Ullman&apos;s 1998 two part series &quot;The Dumbing-Down of Programming&quot; from Salon archives. Rebelling against Microsoft, &quot;My Computer&quot; and easy-to-use Wizards, an engineer rediscovers the joys of difficult computing. Returning to the Source....</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Dumbing down is dumb" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<p>This may also be your kinda thing. </p>

<p>Ellen Ullman's 1998 two part series "The Dumbing-Down of Programming" from Salon archives.<br />
</p><ul><li><a href="http://archive.salon.com/21st/feature/1998/05/cov_12feature.html">Rebelling against Microsoft</a>, "My Computer" and easy-to-use Wizards, an engineer rediscovers the joys of difficult computing.</li>
<li><a href="http://archive.salon.com/21st/feature/1998/05/13feature.html">Returning to the Source</a>. Once knowledge disappears into code, how do we retrieve it?</li></ul>

<p>Via <a href="http://farm.tucows.com/blog/_archives/2005/10/25/1322045.html">Joey deVilla</a> over at <a href="http://farm.tucows.com/blog">The Farm</a>.</p>

<p>I'd forgotten how readable Ellen Ullman was (especially for techies of "a certain age"). I read a novel of her's, Close To The Machine, this <a href="http://www.lenholgate.com/archives/000384.html">time last year</a>. Worth checking out, as is this <a href="http://archive.salon.com/21st/feature/1997/10/09interview.html">interview with her</a>, also in Salon.</p>

This week is becoming one of those weeks where I'm constantly reminded about my age (it started with me discovering that my Dad can now get cheaper car insurance if he includes <i>me</i> on it with <i>him</i>!) and just how long I've been in this business...]]>
        
    </content>
</entry>

<entry>
    <title>Sacrificing precision for ease of use?</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2005/09/sacrificing-precision-for-ease-of-use.html" />
    <id>tag:www.socketframework.com,2005:/blog//12.575</id>

    <published>2005-09-17T10:15:50Z</published>
    <updated>2010-12-24T06:35:15Z</updated>

    <summary>I&apos;m probably jumping the gun a little here as I can&apos;t find Herb Sutter&apos;s slides that Matt Pietrek is referring to, but... Once again I find myself asking why is it actually useful to repurpose the auto keyword in C++......</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Dumbing down is dumb" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<p>I'm probably jumping the gun a little here as I can't find <a href="http://www.pluralsight.com/blogs/hsutter/default.aspx">Herb Sutter's</a> slides that <a href="http://blogs.msdn.com/matt_pietrek/archive/2005/09/16/469213.aspx">Matt Pietrek</a> is referring to, but... Once again I find myself asking why is it actually useful to <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/tions_4.asp">repurpose</a> the <code>auto</code> keyword in C++...</p>

<p>The idea seems to be that rather than this:<br />
</p><pre class="brush: cpp gutter: false">foo::iterator<int> i = myList.begin();</int></pre><br />
You can do this:<br />
<pre class="brush: cpp gutter: false">// Type of 'i is inferred from the assignment
auto i = myList.begin();
</pre>]]>
        <![CDATA[<p>I really don't get what's with these "productivity" enhancements that allow people to think less whilst coding. Let's assume that I gain something whilst writing the code by using this new feature; and I'm not convinced that I would. Does someone whose job it is to maintain that code going to have the same gain? Let's consider the situation, you're looking at unfamiliar code and you come across this line:<br />
</p><pre class="brush: cpp gutter: false">auto i = myList.begin();</pre><br />
There's no indication of what myList is. There's no indication of what <code>begin()</code> returns. There's no indication of which version of <code>begin()</code> we're calling; is there a const version that returns something different to the non-const version? This code communicates less than the code that it replaces... <p></p>

<p>And, of course, this is actually quite a simplistic example. Let's say we have this function on a collection class:<br />
</p><pre class="brush: cpp gutter: false">const CMyObject *CMyCollection::GetObject(i) const;</pre><br />
So we might have a call site like this:<br />
<pre class="brush: cpp gutter: false">const CMyObject *pObj = myCollection.GetObject(i);</pre><br />
Which could, perhaps, become:<br />
<pre class="brush: cpp gutter: false">auto pObj = myCollection.GetObject(i);</pre><br />
But what we'd rather do is restrict what we use pObj for, so we decide to manipulate it via one of the interfaces that it implements instead...<br />
<pre class="brush: cpp gutter: false">const IObjBase *pObj = myCollection.GetObject(i);</pre><br />
How do we do that with this new fangled <code>auto</code>? I assume we don't? <p></p>

<p>C++ is a very expressive language; it allows you to be precise about what you want to do. What I'd like to know is what value this change has that makes up for the fact that the code is now potentially less precise and communicates considerably less? Perhaps the slides from talk will explain more... To me it just looks like the kind of thing that a lazy programmer writing a code generator would ask for...</p>]]>
    </content>
</entry>

<entry>
    <title>C# v3 Extension methods, syntactic sugar for the lack of free functions?</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2005/09/c-v3-extension-methods-syntactic-sugar-for-the-lack-of-free-functions.html" />
    <id>tag:www.socketframework.com,2005:/blog//12.573</id>

    <published>2005-09-16T14:12:36Z</published>
    <updated>2010-12-24T06:28:32Z</updated>

    <summary>There&apos;s a lot of noise coming out of the Microsoft PDC right now. Something that interested me was the future direction of C#; you can grab the spec from here. It seems they&apos;re adding &quot;extension methods&quot; which, to me, appear...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term=".Net" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Dumbing down is dumb" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<p>There's a lot of noise coming out of the <a href="http://pdcbloggers.net/">Microsoft PDC</a> right now. Something that interested me was the <a href="http://msdn.microsoft.com/vcsharp/future/">future direction of C#</a>; you can grab the spec from <a href="http://download.microsoft.com/download/9/5/0/9503e33e-fde6-4aed-b5d0-ffe749822f1b/csharp%203.0%20specification.doc">here</a>.</p>

It seems they're adding "extension methods" which, to me, appear to be just <a href="http://en.wikipedia.org/wiki/Syntactic_sugar">syntactic sugar</a> to make up for the lack of free functions...]]>
        <![CDATA[<p>In C++ you can have functions that aren't part of an object. In C no functions are part of an object. These are "free" functions. You can't have these kind of things in C# and Java because everything has to be part of an object even if the only purpose for the object's existence is to provide a home for a collection of <code>static</code> methods, go figure...</p>

<p>In C++ a recent idiom is to <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=267612">prefer free functions</a> over <a href="http://www.gotw.ca/gotw/084.htm">object methods</a> where possible. The argument is that creating non-member, non-friend, functions increases encapsulation because these functions don't need access to the object internals and therefore bundling them with the object simply reduces the encapsulation that the object provides by expanding the amount of code that has unnecessary access to the object's internals.</p>

<p>This means that, in modern C++, you may often see things like this:<br />
</p><pre class="brush: cpp gutter: false">int ToInt32(const std::string &amp;stringRep);</pre><br />
which can be used like this:<br />
<pre class="brush: cpp gutter: false">const int i = ToInt32(customerNumber);</pre><br />
Up until now the nearest that you could get to this in C# was something like this:<br />
<pre class="brush: cpp gutter: false">public class Stuff
{
  public static int ToInt32(string stringRep);
}</pre><br />
which can be used like this:<br />
<pre class="brush: cpp gutter: false">int i = Stuff::ToInt32(customerNumber);</pre><br />
The new "extension methods" proposal means that the call above can be rendered as this:<br />
<pre class="brush: cpp gutter: false">int i = customerNumber.ToInt32();</pre><br />
Which, in my mind, is madness. The method is <i>not</i> a member of the object so why should you call it using member syntax? What value does it add to be able to do this? If you're looking to remove the crufty <code>Stuff::</code> from the front of the call then why not simply allow functions to be defined at namespace scope? Then you could bring the names in with a normal using statement and use them in a way that's expected:<br />
<pre class="brush: cpp gutter: false">int i = ToInt32(customerNumber);</pre><br />
It's quite clear that <code>ToInt32</code> comes from a namespace somewhere and isn't a member of the object in question... <p></p>

<p>So, my question to <a href="http://blogs.msdn.com/ericgu/archive/2005/09/14/466510.aspx">all you .Net people</a> is why is this new syntax a good thing? I can only see scope for confusion and the eventual banning of this kind of thing in local coding standards...</p>]]>
    </content>
</entry>

<entry>
    <title>Some thoughts on complexity</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2004/02/some-thoughts-on-complexity.html" />
    <id>tag:www.socketframework.com,2004:/blog//12.362</id>

    <published>2004-02-29T13:57:12Z</published>
    <updated>2010-12-20T14:28:20Z</updated>

    <summary>I find that these days I prefer my complexity to be obvious. Things with hidden complexity aren&apos;t any less complex, they&apos;re just less obvious. If you make all of your complexity obvious then you know which pieces of code are complex and you can focus your attempts at simplification on the right places...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Dumbing down is dumb" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<p>I find that these days I prefer my complexity to be obvious. Things with hidden complexity aren't any less complex, they're just less obvious. If you make all of your complexity obvious then you know which pieces of code are complex and you can focus your attempts at simplification on the right places...</p>]]>
        <![CDATA[<p>Some of this comes from the testing that I've been doing; liberal use of parameterize from above means that an object that uses several services is explicitly given those services when you create it. This makes it easy to test as you can replace service providers with mocks. The complexity in the object is explicit because you can see it when you create it. It's obvious that it requires the services that it uses because you have to provide them at creation time. Some of it from a general distrust of 'dumbing down'; I've always thought that dumbing down is for the dumb...</p>

<p>The result of obvious complexity is that you need to make decisions before you can use it. You need to think. Taking <a href="http://www.serverframework.com/">The&nbsp;Server&nbsp;Framework</a> as an example; the server requires that you provide a object that implements the <code>IIOPool</code> interface, a socket allocator and a buffer allocator. At present the socket and buffer allocators are concrete objects, but they would have been interfaces if the code had been developed test first and they will probably become interfaces at some point in time. The server looks complex. Some might say it's harder to use because the complexity is obvious and that it would be better if the designer of the object made these decisions for the user. I'd prefer the user to learn a little more about the code they're using and make the decisions themselves. It makes my job, as a designer, easier, I don't have to know more than all my potential users, I can be stupid and it doesn't matter because the code is flexible and they can configure it how they want to. The user needs to take a little more time, perhaps, to understand what's going on; but once they do, they can make decisions that are appropriate for them.</p>

<p>I find that the complexity rises up the layers of code to the point where the decision can be made and at that point a new class is created that contains those decisions. Sometimes this decision point is at the top of the code, in <code>main</code>; sometimes, often, it's lower down. My point, I think, is that I like code where the decision point is under my control. For me this reduces risk. If I decide to use code where the decision point is inside the library or framework then I am tying my success to the fact that the library or framework designer knew better than me and made the right decisions. I don't mind the designer providing me with sensible defaults, I do mind when some things are made impossible.</p>

<p>I guess this is related to Joel's <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">Law of Leaky Abstractions</a>. I'm accepting that my abstractions can never be "perfect" for users that I don't know who have uses that I haven't thought of. In deference to them, I prefer to build in some flexibility. Providing flexibility means not making decisions that can't be changed and making the complexity obvious and so allowing your users to understand the complexity and make appropriate decisions.</p>]]>
    </content>
</entry>

</feed>



