<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Artima Developer Spotlight</title>
<link>http://www.artima.com/spotlight/</link>
<description>[full-text feed from fivefilters.org]: Highlights of the content flowing through Artima Developer.</description>
<image><title>Artima Developer Spotlight</title>
<link>http://www.artima.com/spotlight/</link>
<url>http://www.artima.com/images/artima88x33.gif</url>
</image>
<item>
<title>Rapid Hiring and Firing to Build the Best Teams</title>
<link>http://www.artima.com/forums/flat.jsp?forum=270&amp;thread=281763</link>
<guid isPermaLink="true" >http://www.artima.com/forums/flat.jsp?forum=270&amp;amp;thread=281763</guid>
<description>&lt;p&gt;&lt;em&gt;Message from fivefilters.org: If you can, please &lt;a href=&quot;http://fivefilters.org/content-only/#donate&quot;&gt;donate to the full-text RSS service&lt;/a&gt; so we can continue developing it.&lt;/em&gt;&lt;/p&gt;&lt;div&gt;&lt;td width=&quot;99%&quot; colspan=&quot;3&quot; valign=&quot;top&quot; readability=&quot;33&quot;&gt;
        


Summary&lt;br/&gt;
Apparently the founder of Kayak.com does this, in an attempt to not only prevent poisonous people from destroying teams, but to go in the other direction and create exceptional teams.


&lt;p&gt;Last night I went to the Extreme Programming San Diego meeting (it should probably be called &quot;Agile&quot; but I suspect the group is old enough that XP was what started it). A reader knew that I was in San Diego visiting my folks so he suggested it. I thought I'd dip my toe in the water and see if programming was any more interesting to me than the last time I checked. Especially since Agile practices tend to be more focused on people issues, which is where I seem to continue to drift.&lt;/p&gt;
&lt;p&gt;The first thing I noticed was the turnout. I'm guessing there are thousands of programmers in San Diego, but we got maybe 10 people to show up. That's probably a condemnation of the profession, where the majority don't read or learn new things. It could also be a number of other issues, the biggest of which is, I think, the fact that user groups cling to the same old approach that everyone else does: get a speaker to come in and give a lecture. The speaker was fine, and had even reduced bullet points in favor of more pictures. But there's something in my brain that says &quot;nap time&quot; whenever a projector gets turned on. The interaction is primarily one-way and scripted, but you can't fast-forward the lecture like you can on the web.&lt;/p&gt;
&lt;p&gt;When asked, I related my interest in people issues, where I've come to believe lie the biggest possibilities for improvement. As an example, I talked about building teams, and how difficult it is to do it well within the business structures we currently have. One of the people there mentioned Kayak.com, and how the founder had hired and fired hundreds of people in order to get the 30 or so that he currently employs.&lt;/p&gt;
&lt;p&gt;One way to look at the problem of company-building is that it should focus on creating great teams. I've heard numerous people say that the company could be in various kinds of bad shape but they could be happy in it as long as they were on a great team. If the team is indeed the fundamental component of the company, then it would be interesting to make an environment whose primary focus is to be a culture medium for great teams.&lt;/p&gt;
&lt;p&gt;One of the biggest problems in team building can be thought of as a version of the &quot;sunk cost&quot; issue. Although it's better to think of lost investment as just that -- lost -- when making decisions, our brains tend to think in terms of what we've already invested. So if you've invested a lot of time and money in hiring someone, you'll tend to hang on to that person until the pain of doing so exceeds your imagination of what it took to get them in that position. This means that a &lt;a class=&quot;reference&quot; href=&quot;http://video.google.com/videoplay?docid=-4216011961522818645#&quot;&gt;poisonous person&lt;/a&gt; can easily be in a team long enough to destroy it before finally being ejected, at which point it's too late. You've thrown a bass into your team of goldfish, and while the bass is eating up your team, you're thinking &quot;maybe he'll get full.&quot;&lt;/p&gt;
&lt;p&gt;The other big factor is legal. Some people sued companies for wrongful termination, so &lt;em&gt;every&lt;/em&gt; company adapted practices to prevent it. You can't just fire someone anymore, you have to give them a couple of 6-month evaluations to show due diligence.&lt;/p&gt;
&lt;p&gt;I suspect the Kayak.com founder has everyone sign a contract that allows them to be fired easily. Producing company loyalty in a situation like that might be tough ... but if you get the right people then maybe that goes away. People might become vicariously loyal to their company because they really want to be in their team.&lt;/p&gt;
&lt;p&gt;The real problem with hiring someone for a team is that you can't actually know how well they will work out until they're participating on a day-to-day basis. Nothing in an interview really tells you this. So apparently Kayak.com decided that most of the &quot;interview&quot; would go on by putting the person in the real situation and seeing how they worked out. Perhaps a little unsettling and brutal -- although looking for a job is never a great experience, and maybe having one, even if just for a short period, might be better than a long period out of work and looking -- but from the standpoint of the company it could produce some excellent results.&lt;/p&gt;
&lt;p&gt;Does anyone have links to stories about Kayak.com's approach? What other types of practices might help solve the problem of team-building?&lt;/p&gt;




        
		&lt;p&gt;
        &lt;/p&gt;&lt;/td&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://fivefilters.org&quot;&gt;Five Filters&lt;/a&gt; featured article: &lt;a href=&quot;http://medialens.org/alerts/09/091216_chilcot_inquiry_the.php&quot;&gt;Chilcot Inquiry&lt;/a&gt;. Available tools: &lt;a href=&quot;http://fivefilters.org/pdf-newspaper/&quot;&gt;PDF Newspaper&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/content-only/&quot;&gt;Full Text RSS&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/term-extraction/&quot;&gt;Term Extraction&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
</item>
<item>
<title>The Wonders of Cooperative Inheritance, or Using Super in Python 3</title>
<link>http://www.artima.com/forums/flat.jsp?forum=270&amp;thread=281435</link>
<guid isPermaLink="true" >http://www.artima.com/forums/flat.jsp?forum=270&amp;amp;thread=281435</guid>
<description>&lt;p&gt;&lt;em&gt;Message from fivefilters.org: If you can, please &lt;a href=&quot;http://fivefilters.org/content-only/#donate&quot;&gt;donate to the full-text RSS service&lt;/a&gt; so we can continue developing it.&lt;/em&gt;&lt;/p&gt;&lt;div&gt;&lt;div class=&quot;section&quot; readability=&quot;38&quot;&gt;

&lt;p&gt;Deep down, &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; in Python 3 is the same as in Python 2.X.
However, on the surface - at the syntactic level, not at the semantic level -
there is a big difference: Python 3 super is smart enough to figure out
&lt;em&gt;the class it is invoked from and the first argument of the containing
method&lt;/em&gt;. Actually it is so smart that it works also for inner classes
and even if the first argument is not called &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;self&lt;/span&gt;&lt;/tt&gt;.
In Python 2.X &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; is dumber and you must tell the class and the
argument explicitly: for instance our first example must be written&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class A(object):
    def __init__(self):
        print('A.__init__')
        super(A, self).__init__()
&lt;/pre&gt;
&lt;p&gt;By the way, this syntax works both in Python 3 &lt;em&gt;and&lt;/em&gt; in Python 2, this is
why I said that deep down &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; is the same. The new feature in
Python 3 is that there is a shortcut notation &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super()&lt;/span&gt;&lt;/tt&gt; for
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super(A,&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;self)&lt;/span&gt;&lt;/tt&gt;. In Python 3 the (bytecode) compiler is smart enough
to recognize that the supercall is performed inside the class &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;A&lt;/span&gt;&lt;/tt&gt; so
that it inserts the reference to &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;A&lt;/span&gt;&lt;/tt&gt; automagically; moreover it inserts
the reference to the first argument of the current method too. Typically
the first argument of the current method is &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;self&lt;/span&gt;&lt;/tt&gt;, but it may be
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;cls&lt;/span&gt;&lt;/tt&gt; or any identifier: &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; will work fine in any case.&lt;/p&gt;
&lt;p&gt;Since &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super()&lt;/span&gt;&lt;/tt&gt; knows the class it is invoked from and the class of
the original caller, it can walk the MRO correctly. Such information
is stored in the attributes &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__thisclass__&lt;/span&gt;&lt;/tt&gt; and &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__self_class__&lt;/span&gt;&lt;/tt&gt;
and you may understand how it works from the following example:&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class Mother(object):
    def __init__(self):
        sup = super()
        print(sup.__thisclass__)
        print(sup.__self_class__)
        sup.__init__()
&lt;/pre&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class Child(Mother):
    pass
&lt;/pre&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
&amp;gt;&amp;gt;&amp;gt; child = Child()
&amp;lt;class '__main__.Mother'&amp;gt;
&amp;lt;class '__main__.Child'&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Here &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__self__class__&lt;/span&gt;&lt;/tt&gt; is just the class of the first argument (&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;self&lt;/span&gt;&lt;/tt&gt;)
but this is not always the case. The exception is the case of classmethods and
staticmethods taking a class as first argument, such as &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;__new__&lt;/span&gt;&lt;/tt&gt;.
Specifically, &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super(cls,&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;x)&lt;/span&gt;&lt;/tt&gt; checks if &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;x&lt;/span&gt;&lt;/tt&gt; is an instance
of &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;cls&lt;/span&gt;&lt;/tt&gt; and then sets &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__self_class__&lt;/span&gt;&lt;/tt&gt; to &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;x.__class__&lt;/span&gt;&lt;/tt&gt;; otherwise
(and that happens for classmethods and for &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;__new__&lt;/span&gt;&lt;/tt&gt;) it checks if &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;x&lt;/span&gt;&lt;/tt&gt;
is a subclass of &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;cls&lt;/span&gt;&lt;/tt&gt; and then sets  &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__self_class__&lt;/span&gt;&lt;/tt&gt; to &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;x&lt;/span&gt;&lt;/tt&gt; directly.
For instance, in the following example&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class C0(object):
    @classmethod
    def c(cls):
        print('called classmethod C0.c')
&lt;/pre&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class C1(C0):
    @classmethod
    def c(cls):
        sup = super()
        print('__thisclass__', sup.__thisclass__)
        print('__selfclass__', sup.__self_class__)
        sup.c()
&lt;/pre&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
class C2(C1):
    pass
&lt;/pre&gt;
&lt;p&gt;the attribute &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.__self_class__&lt;/span&gt;&lt;/tt&gt; is &lt;em&gt;not&lt;/em&gt; the class of the first argument
(which would be &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;type&lt;/span&gt;&lt;/tt&gt; the metaclass of all classes) but simply the first
argument:&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
&amp;gt;&amp;gt;&amp;gt; C2.c()
__thisclass__ &amp;lt;class '__main__.C1'&amp;gt;
__selfclass__ &amp;lt;class '__main__.C2'&amp;gt;
called classmethod C0.c
&lt;/pre&gt;
&lt;p&gt;There is a lot of magic going on in Python 3 &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt;, and even more.
For instance, this is a syntax that cannot work:&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
def __init__(self):
    print('calling __init__')
    super().__init__()

class C(object):
    __init__ = __init__

if __name__ == '__main__':
    c = C()
&lt;/pre&gt;
&lt;p&gt;If you try to run this code you will get a
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;SystemError:&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;super():&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;__class__&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;cell&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;found&lt;/span&gt;&lt;/tt&gt; and the reason is
obvious: since the &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;__init__&lt;/span&gt;&lt;/tt&gt; method is external to the class the
compiler cannot infer to which class it will be attached at runtime.
On the other hand, if you are completely explicit and you use the full
syntax, by writing the external method as&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
def __init__(self):
    print('calling __init__')
    super(C, self).__init__()
&lt;/pre&gt;
&lt;p&gt;everything will work because you are explicitly telling than the method
will be attached to the class &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;C&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;I will close this section by noticing a wart of &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; in Python 3,
pointed out by &lt;a class=&quot;reference&quot; href=&quot;http://lucumr.pocoo.org/2008/4/30/how-super-in-python3-works-and-why-its-retarded&quot;&gt;Armin Ronacher&lt;/a&gt; and others: the fact that &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt;
should be a keyword but it is not. Therefore horrors like the
following are possible:&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
def super():
    print(&quot;I am evil, you are NOT calling the supermethod!&quot;)

class C(object):
    def __init__(self):
        super().__init__()

if __name__ == '__main__':
    c = C() # prints &quot;I am evil, you are NOT calling the supermethod!&quot;
&lt;/pre&gt;
&lt;p&gt;DON'T DO THAT! Here the called &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;__init__&lt;/span&gt;&lt;/tt&gt; is the &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;__init__&lt;/span&gt;&lt;/tt&gt; method
of the object &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;None&lt;/span&gt;&lt;/tt&gt;!!&lt;/p&gt;
&lt;p&gt;Of course, only an evil programmer would shadow &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; on purpose,
but that may happen accidentally. Consider for instance this use case:
you are refactoring an old code base written before the existence of
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; and using &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;mod&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;*&lt;/span&gt;&lt;/tt&gt; (this is ugly but we know
that there are code bases written this way), with &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;mod&lt;/span&gt;&lt;/tt&gt; defining a
function &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; which has nothing to do with the &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt;
builtin. If in this code you replace &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Base.method(self,&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;*args)&lt;/span&gt;&lt;/tt&gt; with
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super().method(*args)&lt;/span&gt;&lt;/tt&gt; you will introduce a bug. This is not common
(it never happened to me), but still it is bug that could not happen if
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; were a keyword.&lt;/p&gt;
&lt;p&gt;Moreover, &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt; is special and it will not work if
you change its name as in this example:&lt;/p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
# from http://lucumr.pocoo.org/2010/1/7/pros-and-cons-about-python-3
_super = super
class Foo(Bar):
    def foo(self):
        _super().foo()
&lt;/pre&gt;
&lt;p&gt;Here the bytecode compiler will not treat specially &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;_super&lt;/span&gt;&lt;/tt&gt;, only
&lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt;. It is unfortunate that we missed the opportunity to make &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;super&lt;/span&gt;&lt;/tt&gt;
a keyword in Python 3, without good reasons (Python 3 was expected
to break compatibility anyway).&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://fivefilters.org&quot;&gt;Five Filters&lt;/a&gt; featured article: &lt;a href=&quot;http://medialens.org/alerts/09/091216_chilcot_inquiry_the.php&quot;&gt;Chilcot Inquiry&lt;/a&gt;. Available tools: &lt;a href=&quot;http://fivefilters.org/pdf-newspaper/&quot;&gt;PDF Newspaper&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/content-only/&quot;&gt;Full Text RSS&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/term-extraction/&quot;&gt;Term Extraction&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
</item>
<item>
<title>Pattern Matching in Scala For Expressions</title>
<link>http://www.artima.com/forums/flat.jsp?forum=270&amp;thread=281161</link>
<guid isPermaLink="true" >http://www.artima.com/forums/flat.jsp?forum=270&amp;amp;thread=281161</guid>
<description>&lt;p&gt;&lt;em&gt;Message from fivefilters.org: If you can, please &lt;a href=&quot;http://fivefilters.org/content-only/#donate&quot;&gt;donate to the full-text RSS service&lt;/a&gt; so we can continue developing it.&lt;/em&gt;&lt;/p&gt;&lt;div&gt;&lt;td width=&quot;99%&quot; colspan=&quot;3&quot; valign=&quot;top&quot; readability=&quot;10&quot;&gt;
        


Summary&lt;br/&gt;
Scala pattern matchers with side effects can have unexpected results in for expressions.




    Scala has taken the traditional for-construct and put it on steroids.&amp;#13;
One of the interesting features is the ability to use pattern matching&amp;#13;
as part of a for expression.  For example, the following:&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code readability=&quot;8&quot;&gt;&amp;#13;
&lt;b&gt;case class&lt;/b&gt; Person(firstName:String, lastName: String);&lt;p&gt;&amp;#13;
&lt;b&gt;val&lt;/b&gt; people = List(&lt;br/&gt;&amp;#13;
  Person(&quot;Jane&quot;, &quot;Smith&quot;),&lt;br/&gt;&amp;#13;
  Person(&quot;John&quot;, &quot;Doe&quot;),&lt;br/&gt;&amp;#13;
  Person(&quot;Jane&quot;, &quot;Eyre&quot;));&lt;/p&gt;&lt;p&gt;&amp;#13;
&lt;b&gt;for&lt;/b&gt; (Person(&quot;Jane&quot;, last) &amp;lt;- people) &lt;b&gt;yield&lt;/b&gt; &quot;Ms. &quot; + last;&lt;br/&gt;&lt;/p&gt;&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
&amp;#13;
will (effectively) iterate over all people with a first name of Jane,&amp;#13;
bind &lt;code&gt;last&lt;/code&gt; to each person's last name in turn, and then&amp;#13;
generate a list of the results of the &lt;code&gt;&lt;b&gt;yield&lt;/b&gt;&lt;/code&gt; block,&amp;#13;
thus returning&amp;#13;
&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
List(&quot;Ms. Smith&quot;, &quot;Ms. Eyre&quot;)&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
&amp;#13;
In this example, we're using a case class to provide the pattern&amp;#13;
matching for us, but we can easily role our own.  For example,&amp;#13;
consider the following matcher which will return the first element of&amp;#13;
an iterator, if there is one:&amp;#13;
&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;b&gt;object&lt;/b&gt; First {&lt;br/&gt;&amp;#13;
  &lt;b&gt;def&lt;/b&gt; unapply[A](iter:Iterator[A]): Option[(A)] = {&lt;br/&gt;&amp;#13;
    &lt;b&gt;if&lt;/b&gt; (iter.hasNext) Some(iter.next) &lt;b&gt;else&lt;/b&gt; None;&lt;br/&gt;&amp;#13;
  }&lt;br/&gt;&amp;#13;
}&lt;br/&gt;&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
&amp;#13;
We can try to get the first element of some iterators:&amp;#13;
&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;b&gt;for&lt;/b&gt;(First(x) &amp;lt;- iters) &lt;b&gt;yield&lt;/b&gt; x;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;/code&gt;&lt;/code&gt;&lt;/blockquote&gt;&amp;#13;
&amp;#13;
However, this does not yield &lt;code&gt;List(1,3)&lt;/code&gt; as one might&amp;#13;
expect.  Instead, it yields &lt;code&gt;List(2, 4)&lt;/code&gt;!&amp;#13;
&amp;#13;
&lt;p&gt;&amp;#13;
So what is going on here?  According to &lt;em&gt;Programming in Scala&lt;/em&gt;,&amp;#13;
a pattern match in a for loop gets converted into a filter followed by&amp;#13;
a map.  Specifically,&amp;#13;
&lt;/p&gt;&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;b&gt;for&lt;/b&gt; (&lt;i&gt;pat&lt;/i&gt; &amp;lt;- &lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt;) &lt;b&gt;yield&lt;/b&gt; &lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
is translated by the compiler to&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; filter {&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; &lt;i&gt;pat&lt;/i&gt; =&amp;gt; &lt;b&gt;true&lt;/b&gt;;&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; _ =&amp;gt; &lt;b&gt;false&lt;/b&gt;;&lt;br/&gt;&amp;#13;
} map {&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; &lt;i&gt;pat&lt;/i&gt; =&amp;gt; &lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt;;&lt;br/&gt;&amp;#13;
}&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
&amp;#13;
In other words, first the input expression is filtered for those&amp;#13;
elements which match the pattern, and then in a separate pass, the&amp;#13;
pattern is applied for the purpose of&amp;#13;
evaluating &lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt;.  Unfortunately, there are a couple&amp;#13;
of issues with this.  First, if the pattern match is computationally&amp;#13;
expensive, that work will be doubled for every match.  Second, and&amp;#13;
more concerning, if the pattern match is not side effect free, then&amp;#13;
unexpected results like the one above can happen.  In the example&amp;#13;
above, the pattern match, by calling &lt;code&gt;next&lt;/code&gt; on an iterator,&amp;#13;
changes the state of the iterator, so that a different result comes&amp;#13;
out in the second pass.&amp;#13;
&lt;p&gt;&amp;#13;
Interestingly, &lt;em&gt;Programming Scala&lt;/em&gt; states that &quot;it's&amp;#13;
guarannteed that a pattern-matching generator will never throw&amp;#13;
a &lt;code&gt;MatchError&lt;/code&gt;&quot;.  In fact, this is not true.  For example,&amp;#13;
executing&amp;#13;
&lt;/p&gt;&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;b&gt;for&lt;/b&gt; (First(x) &amp;lt;- List(Iterator.single(1))) &lt;b&gt;yield&lt;/b&gt; x;&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
will try to access a single-element iterator twice, resulting in:&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
scala.MatchError: empty iterator&lt;br/&gt;&amp;#13;
    at $anonfun$2.apply(&amp;lt;console&amp;gt;:6)&lt;br/&gt;&amp;#13;
    at $anonfun$2.apply(&amp;lt;console&amp;gt;:6)&lt;br/&gt;&amp;#13;
    at scala.List.map(List.scala:812)&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
&amp;#13;
&lt;p&gt;&amp;#13;
One way to view this situation is that Scala's &lt;code&gt;&lt;b&gt;for&lt;/b&gt;&lt;/code&gt;&amp;#13;
construct is inherently functional, and should not be mixed with&amp;#13;
non-functional constructs such as iterators.  However, it turns out&amp;#13;
that there is a completely functional fix to this problem.  Simply&amp;#13;
change the compile-time pattern-match translation to something like:&amp;#13;
&amp;#13;
&lt;/p&gt;&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; map {&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; &lt;i&gt;pat&lt;/i&gt; =&amp;gt; Some(&lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;2&lt;/sub&gt;);&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; _ =&amp;gt; None;&lt;br/&gt;&amp;#13;
} filter {&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; Some(_) =&amp;gt; &lt;b&gt;true&lt;/b&gt;;&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; None =&amp;gt; &lt;b&gt;false&lt;/b&gt;;&lt;br/&gt;&amp;#13;
} map {&lt;br/&gt;&amp;#13;
  &lt;b&gt;case&lt;/b&gt; Some(x) =&amp;gt; x;&lt;br/&gt;&amp;#13;
}&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
or, more succinctly:&amp;#13;
&lt;blockquote&gt;&amp;#13;
&lt;code&gt;&amp;#13;
&lt;i&gt;expr&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; map {&lt;br/&gt;&amp;#13;
  &lt;i&gt;pat&lt;/i&gt;.unapply(_);&lt;br/&gt;&amp;#13;
} filter {&lt;br/&gt;&amp;#13;
  _.isDefined;&lt;br/&gt;&amp;#13;
} map {&lt;br/&gt;&amp;#13;
  _.get;&lt;br/&gt;&amp;#13;
}&amp;#13;
&lt;/code&gt;&amp;#13;
&lt;/blockquote&gt;&amp;#13;
Of course, there is a cost to this approach: by introducing a third&amp;#13;
pass, extra an extra list of &lt;code&gt;Option&lt;/code&gt; objects is created.&amp;#13;
Another fix would be to add new methods &lt;code&gt;filterMap&lt;/code&gt;&amp;#13;
and &lt;code&gt;filterForEach&lt;/code&gt; which cut down the work to a single&amp;#13;
pass.  While less elegant, it would clearly provide a performance&amp;#13;
boost, and it would be largely hidden from view.  In the mean time,&amp;#13;
one should use pattern matching in for expressions with care.



        
		&lt;p&gt;
        &lt;/p&gt;&lt;/td&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://fivefilters.org&quot;&gt;Five Filters&lt;/a&gt; featured article: &lt;a href=&quot;http://medialens.org/alerts/09/091216_chilcot_inquiry_the.php&quot;&gt;Chilcot Inquiry&lt;/a&gt;. Available tools: &lt;a href=&quot;http://fivefilters.org/pdf-newspaper/&quot;&gt;PDF Newspaper&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/content-only/&quot;&gt;Full Text RSS&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/term-extraction/&quot;&gt;Term Extraction&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
</item>
<item>
<title>Software Development Has Stalled</title>
<link>http://www.artima.com/forums/flat.jsp?forum=270&amp;thread=281006</link>
<guid isPermaLink="true" >http://www.artima.com/forums/flat.jsp?forum=270&amp;amp;thread=281006</guid>
<description>&lt;p&gt;&lt;em&gt;Message from fivefilters.org: If you can, please &lt;a href=&quot;http://fivefilters.org/content-only/#donate&quot;&gt;donate to the full-text RSS service&lt;/a&gt; so we can continue developing it.&lt;/em&gt;&lt;/p&gt;&lt;div&gt;&lt;td width=&quot;99%&quot; colspan=&quot;3&quot; valign=&quot;top&quot; readability=&quot;23&quot;&gt;
        


Summary&lt;br/&gt;
I think my subconscious mind has been figuring this out over the past number of years.


&lt;p&gt;For the longest time -- most of my time in the field -- we've always been able to look forward and have at least an inkling of the fantastic jumps ahead, and the productivity that software development tools would enable.&lt;/p&gt;
&lt;p&gt;But in recent years it has started to look like we're moving out of the revolutionary period of big innovation, and into a phase of relative stability. There are lots of reasons for this failure of imagination, but a large part of it might be that we've satisfied our initial needs. Software development has moved forward enough, and now we are just exploring what we can do with it. And we can do a lot with our current tools that we haven't yet fathomed.&lt;/p&gt;
&lt;p&gt;These things, however, do not drive forward the basic concepts of software development. They will certainly improve the world, but the pressure to rethink the &lt;em&gt;way&lt;/em&gt; that we program seems to be off.&lt;/p&gt;
&lt;p&gt;Do I have any research or facts to support this idea? None, whatsoever. It's all based on my intuition, and the fact that I've been getting less and less interested in programming languages over the past few years. But I've discovered that, however unreasonable my intuition might seem, it always tells me something useful.&lt;/p&gt;
&lt;p&gt;Even more important is my increasing awareness that, no matter how good and powerful our software tools get, we are only getting a fraction of the leverage out of them that we &lt;em&gt;could&lt;/em&gt; get.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Programming tools are no longer where the greatest potential lies.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We will get the biggest leverage, not just in programming but in all our endeavors, by discovering better ways to work together. Those are the sessions I will either be creating or attending at the upcoming &lt;a class=&quot;reference&quot; href=&quot;http://www.mindviewinc.com/Conferences/JavaPosseRoundup/&quot;&gt;Java Posse Roundup, March 15-19 2010&lt;/a&gt;. It's not going to be just about programming.&lt;/p&gt;




        
		&lt;p&gt;
        &lt;/p&gt;&lt;/td&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://fivefilters.org&quot;&gt;Five Filters&lt;/a&gt; featured article: &lt;a href=&quot;http://medialens.org/alerts/09/091216_chilcot_inquiry_the.php&quot;&gt;Chilcot Inquiry&lt;/a&gt;. Available tools: &lt;a href=&quot;http://fivefilters.org/pdf-newspaper/&quot;&gt;PDF Newspaper&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/content-only/&quot;&gt;Full Text RSS&lt;/a&gt;, &lt;a href=&quot;http://fivefilters.org/term-extraction/&quot;&gt;Term Extraction&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
</item>
</channel>
</rss>