<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Antti Holvikari</title>
 <link href="http://anttih.com/atom.xml" rel="self"/>
 <link href="http://anttih.com/"/>
 <updated>2017-01-21T10:18:54+00:00</updated>
 <id>http://anttih.com/</id>
 <author>
   <name>Antti Holvikari</name>
   <email>anttih@gmail.com</email>
 </author>

 
 <entry>
   <title>Beyond Test Driven Development</title>
   <link href="http://anttih.com/blog/2012/06/27/beyond-tdd.html"/>
   <updated>2012-06-27T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2012/06/27/beyond-tdd</id>
   <content type="html">&lt;p&gt;Sometimes spiking is much more productive than TDD.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Refactor away your comments</title>
   <link href="http://anttih.com/blog/2011/01/07/refactor-comments.html"/>
   <updated>2011-01-07T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2011/01/07/refactor-comments</id>
   <content type="html">&lt;p&gt;I used to think commenting code extensively was vital to code readability. I
no longer think that is true. There are far better solutions for making code more
readable.&lt;/p&gt;

&lt;p&gt;When you start practicing Test Driven Design, you start to pay more attention
to refactoring. Refactoring is a key activity in TDD because the goal is to pass
the test as fast as possible without thinking too much of the elegance of
the solution. When the tests pass you refactor. The purpose of the refactoring
is to avoid taking huge technical debt so that at any given moment the code is
as extensible and readable as possible.&lt;/p&gt;

&lt;p&gt;Code commenting does the opposite. It makes the code harder to modify. Comments
won’t survive the refactoring because you have to remove or edit them to match
the new implementation. Then the worst happens and you make a mistake in a
comment. This mistake is never caught by the compiler or the runtime. &lt;strong&gt;Comments are bound to
be incorrect.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While reading about Donald Knuth’s literal programming in &lt;a href=&quot;http://codersatwork.com/&quot;&gt;Coders at
work&lt;/a&gt; I came to realize how different literal programming and
TDD are. In some ways, &lt;strong&gt;Literal programming is the opposite of TDD&lt;/strong&gt;. Knuth
describes how he doesn’t extract subroutines into real subroutines,
but merely comments some parts of bigger subroutines. In TDD we add comments
after we’ve tried to make the code as readable as possible by refactoring.
A comment is the last resort to make the code more readable. In literal
programming, commenting is the main tool for achieving readability. In TDD we
write the test, code and then add a possible comment. In literal programming
you explain yourself first with comments, then write the production code.
(Knuth didn’t even write the code on a computer, instead he wrote the whole
program [TeX] on paper first.) &lt;strong&gt;Literal programming can increase readability,
but it’s the arch enemy of refactoring&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Code readability is very important. In fact, it’s one of the
&lt;a href=&quot;http://c2.com/cgi/wiki?XpSimplicityRules&quot;&gt;Rules of Simple Design&lt;/a&gt;. How do we increase the readability
of our code then, if not by commenting? We use the programming language
itself. Modern programming languages like Ruby and Python allow you to write
very expressive code. Create small methods, no longer than a few lines and use
descriptive names. Use Extract Method on a commented block of code and you’re
much better off. Additional method calls hardly have any performance impact.
I guarantee your bottlenecks are somewhere else.&lt;/p&gt;

&lt;p&gt;Certainly there is a place for comments. When should you add a comment?
Code that justifies a comment is one that is not tied to the
implementation, one that survives trivial refactoring. Such place could be a
particularly nasty Regular Expression or a data structure that is an important
part of the architecture (such as Domain objects). &lt;strong&gt;In general: if you just
cannot express your intent with code, consider adding a comment.&lt;/strong&gt;&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Michael D. Hill On Too Much</title>
   <link href="http://anttih.com/blog/2010/11/07/on-too-much.html"/>
   <updated>2010-11-07T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2010/11/07/on-too-much</id>
   <content type="html">&lt;p&gt;Old post by Michael D. Hill on the XP mailing list. These are also some of the
reasons I like XP. It keeps things real, while at the same time embracing
good engineering practices. &lt;a href=&quot;http://tech.groups.yahoo.com/group/extremeprogramming/message/3497&quot;&gt;Read the whole thing&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;Unbelievably complicated unit testing frameworks: You don’t need
them. You need the ability to write a test function, add it to a
list of test functions, and call them. How long will it take you
to write that code? Four hours? Six? Write it. Over time you
may see other things that will be handy, but you don’t need them
now.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Corner cases you’ve invented where the XP method seems to
have contradicted itself: You don’t need them. If you really
encounter them in the field, which for the most part I seriously
doubt you ever will, here’s how you solve them. 1) Pick one
interpretation or the other. 2) Implement it. 3) Try it.
4) If you don’t like it, change it until you do. 5) If you can’t
change it enough, pick the other interpretation.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Unbelievably-difficult-to-unit-test classes you’ve created:
You don’t need them. If it can’t be unit-tested, it can’t be a
stable central part of your code, so throw it away. Divide one
staggeringly complex object into thirty dead simple ones. Unit
test them.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Umpty-nine-levels of inheritance and abstraction with private
inner reverse-schreck semiotic slipsoid sub-class interactivity
devices that make your design impossible to even describe, let
alone debug: You don’t need them. I am truly staggered to hear
how many folks are using the arcana of their programming
environments rather than the mainstream.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;The generic solution to all problems having to do with a
generalized and abstract class representing XXXXX’s: You don’t
need it. You need a class representing XXXXX’s AS SEEN BY YOUR
CUSTOMER’S USER STORIES. Code one. Forget about dividing the
world up into philosophically correct hierarchies. Divide the
&lt;em&gt;problem&lt;/em&gt; into &lt;em&gt;pragmatically&lt;/em&gt; correct ones.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Unit tests that are designed to prove that your object will
survive a thermonuclear blast: You don’t need them. Unit tests
should be renamed object tests, an argument I’ll take up later.
Write a unit test to test ONE object, not all that objects that
one talks to. If you cannot find a way to do it, your object is
almost certainly too complicated. Simplify it, and try again.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Unit tests that are really functional tests: You don’t need
them. The functional tests prove that everything works together
to satisfy the customer’s stories. The unit tests do not exist
to prove that your program is correct. They exist to make your
work faster and easier. Pretend your object is floating in a
petri dish, not in a live cell. Test it &lt;em&gt;without&lt;/em&gt; testing its
neighbors. If you can’t, re-write until you can.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Paint-scraper programs that capture and test screen output
for form-based apps: You don’t need them. De-couple all
program functionality from UI functionality. Unit-test it.
Write generic client-controls that use generic data-servers.
Unit-test them. Derive concrete data-servers connected to your
model. Unit-test them. Build forms by connecting clients to
servers. Unit-test them for tab-order and screen-layout.
Get your functionals to 100%. Ship. Wait for stock options to
mature.&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>PHP and assertions</title>
   <link href="http://anttih.com/blog/2010/11/04/php-assertions.html"/>
   <updated>2010-11-04T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2010/11/04/php-assertions</id>
   <content type="html">&lt;p&gt;I want to make &lt;a href=&quot;http://sham.anttih.com&quot;&gt;Sham&lt;/a&gt; itself to throw Exceptions. Currently you need to use
whatever testing framework you are using for asserting. This means that for
example with PHPUnit your assertions will look something like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$this-&amp;gt;assertTrue($stub-&amp;gt;calls('method', 'param 1')-&amp;gt;once());
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This is too verbose.&lt;/p&gt;

&lt;p&gt;To integrate with PHPUnit correctly I would need to throw
&lt;code class=&quot;highlighter-rouge&quot;&gt;PHPUnit_Framework_AssertionFailedError&lt;/code&gt; exceptions. This would make Sham
assertions report correctly as failures, and not as errors. However, I don’t
want to integrate only with PHPUnit, I want Sham to be as simple and generic as
possible.&lt;/p&gt;

&lt;p&gt;What we need is an &lt;code class=&quot;highlighter-rouge&quot;&gt;AssertionException&lt;/code&gt; class in PHP’s itself. This small
addition would make testing tools play nicely together. PHPUnit would extend
AssertionException and so would Sham. We would all have the same meaning for a
failing test.&lt;/p&gt;

&lt;p&gt;This kind of thing would be easy to implement in PHP, but as far as I know
there is no way of implementing anything in PHP that would be included in PHP.
That is, all the &lt;a href=&quot;http://php.net/manual/en/book.spl.php&quot;&gt;SPL classes&lt;/a&gt; are implemented in C.&lt;/p&gt;

&lt;h2 id=&quot;assert&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Assert&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Taking this a bit further, there should also be something in PHP that would throw
these AssertionErrors. For this I propose the &lt;code class=&quot;highlighter-rouge&quot;&gt;assert&lt;/code&gt; keyword. The assert
statement would look like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;assert &amp;lt;expression&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If the expression evaluates to false, an &lt;code class=&quot;highlighter-rouge&quot;&gt;AssertionException&lt;/code&gt; would be thrown.&lt;/p&gt;

&lt;p&gt;Yes, there’s &lt;a href=&quot;http://fi2.php.net/assert&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;assert()&lt;/code&gt;&lt;/a&gt;, the function, but it’s hideous.&lt;/p&gt;

&lt;p&gt;Maybe I’ll pick up my dusty Extending and Embedding PHP someday and whip up a
patch. Until then, any takers?&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>JSON interpreter in Io</title>
   <link href="http://anttih.com/blog/2010/10/29/json-in-io.html"/>
   <updated>2010-10-29T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2010/10/29/json-in-io</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://iolanguage.com/&quot;&gt;Io&lt;/a&gt; is amazing. Here’s a (naive) JSON interpreter in
Io.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;JSON := Object clone do(
    curlyBrackets := method(
        call message arguments foreach(msg,
            self setSlot(
                call sender doString(msg name),
                JSON clone doMessage(msg next ?next)
            )
        )
        self
    )

    squareBrackets := method(
        call message arguments map(a, JSON clone doMessage(a))
    )
)

JSON clone do(

    {&quot;key&quot; : &quot;value&quot;,
     &quot;list&quot; : [1, {&quot;nested&quot; : 42}],
     &quot;nest&quot; : {&quot;key2&quot; : &quot;value2&quot;}}

) slotSummary println
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, the JSON within the do() block is not a string, it’s literal
JSON which is valid Io syntax.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ io json.io
 JSON_0x383220:
  key              = &quot;value&quot;
  list             = list(1,  JSON_0x2b1020:
  nested     ...
  nest             = JSON_0x2d12e0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

</content>
 </entry>
 
 <entry>
   <title>Debugging console for Solar</title>
   <link href="http://anttih.com/blog/2008/12/01/debugging-console-for-solar.html"/>
   <updated>2008-12-01T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2008/12/01/debugging-console-for-solar</id>
   <content type="html">&lt;p&gt;Here’s a little project I’ve been working on. It’s a debugging/profiling
console for &lt;a href=&quot;http://solarphp.com&quot;&gt;Solar&lt;/a&gt; applications. I call it
&lt;a href=&quot;http://github.com/anttih/starburst_debug_console&quot;&gt;Starburst_Debug_Console&lt;/a&gt;. It displays a console on top of your website which
shows you your SQL queries, logs and &lt;code class=&quot;highlighter-rouge&quot;&gt;$_SERVER&lt;/code&gt; vars.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3222/3073940977_67b73e8c70.jpg&quot; alt=&quot;SQL Profiler for
Solar&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You can download it by clicking
&lt;a href=&quot;http://github.com/anttih/starburst_debug_console/zipball/0.1.0-alpha&quot;&gt;here&lt;/a&gt;.
There’s install instructions over at the &lt;a href=&quot;http://github.com/anttih/starburst_debug_console/tree/master&quot;&gt;project
page&lt;/a&gt;. Yep,
that’s git, go ahead and fork it!&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>On PHP Namespace Separator</title>
   <link href="http://anttih.com/blog/2008/11/05/on-php-namespace-separator.html"/>
   <updated>2008-11-05T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2008/11/05/on-php-namespace-separator</id>
   <content type="html">&lt;p&gt;There’s been a lot of negative commenting around the choice of the new namespace separator for PHP. The choice was backslash &lt;code class=&quot;highlighter-rouge&quot;&gt;'\'&lt;/code&gt;. The usual answer to these comments is: “Pick a better one, and let’s see how that works out” or “please stop commenting, &lt;code class=&quot;highlighter-rouge&quot;&gt;'\'&lt;/code&gt; is the only one that works”.&lt;/p&gt;

&lt;p&gt;And I understand this. &lt;code class=&quot;highlighter-rouge&quot;&gt;'\'&lt;/code&gt; is the only viable choice.&lt;/p&gt;

&lt;p&gt;But the thing is, backslash sucks as a namespace separator. You can’t create namespace names with string interpolation because &lt;code class=&quot;highlighter-rouge&quot;&gt;'\n'&lt;/code&gt; would then get transformed to a newline. But above all, it’s ugly.&lt;/p&gt;

&lt;p&gt;I’d much rather live without namespaces than have a bad (ugly) implementation. I mean, do you really want namespaces this badly?&lt;/p&gt;

&lt;p&gt;Also, the old excuse of “you don’t have to use namespaces” completely misses the point that I have to maintain some poor guy’s code someday that has namespaces in it.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Solar Blog - Using registry_set to auto-register objects</title>
   <link href="http://anttih.com/blog/2008/09/22/solar-blog-using-registry-set-to-autoregister-objects.html"/>
   <updated>2008-09-22T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2008/09/22/solar-blog-using-registry-set-to-autoregister-objects</id>
   <content type="html">&lt;p&gt;I have just published my first entry on the new Solar project blog. Go read
about &lt;a href=&quot;http://solarphp.com/blog/read/8-using-registry-set-to-auto-register-objects&quot;&gt;Using registry_set to auto-register objects&lt;/a&gt;. It’s one of
the cool new features of Solar version 1.0.0alpha2.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Solar 1.0.0alpha2 Released And A New Blog</title>
   <link href="http://anttih.com/blog/2008/09/21/solar-100alpha2-released-and-a-new-blog.html"/>
   <updated>2008-09-21T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2008/09/21/solar-100alpha2-released-and-a-new-blog</id>
   <content type="html">&lt;p&gt;A new version of Solar has been released. You can see the full &lt;a href=&quot;http://solarphp.com/blog/read/3-solar-100alpha2-released&quot;&gt;list of changes&lt;/a&gt; on our &lt;a href=&quot;http://solarphp.com/blog&quot;&gt;new blog&lt;/a&gt;. Yep, that’s right, the Solar project now has a blog. Keep your eye on it for some cool Solar knowlegde. I will be blogging there about Solar and maybe cross-posting some of the stuff here too.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>My first OpenCoffee meetup</title>
   <link href="http://anttih.com/blog/2008/08/10/my-first-opencoffee-meetup.html"/>
   <updated>2008-08-10T00:00:00+00:00</updated>
   <id>http://anttih.com/blog/2008/08/10/my-first-opencoffee-meetup</id>
   <content type="html">&lt;p&gt;Last thursday I went to the &lt;a href=&quot;http://entrepreneur.meetup.com/1320/&quot;&gt;OpenCoffee&lt;/a&gt; meetup for the first time. For you who don’t know what it is: it’s a meetup for people interested in startups and other webby stuff, at least that’s the impression I got.&lt;/p&gt;

&lt;p&gt;The meeting was at &lt;a href=&quot;http://www.ravintolanolla.fi/&quot;&gt;Nolla&lt;/a&gt;, my favourite lunch place. I had a blast and met so many nice people. Conversations ranged from programming to movies and politics. I think I even had a conversation about &lt;a href=&quot;http://www.erlang.org/&quot;&gt;Erlang&lt;/a&gt;, very cool. It’s a very international group and half of the conversations are in english which I think is really nice. I met programmers, consultants, designers and managers. I never thought I could run out of business cards, but I did :-). I think I also doubled my jaiku contacts.&lt;/p&gt;

&lt;p&gt;It happened that &lt;a href=&quot;http://tripsay.com&quot;&gt;tripsay.com&lt;/a&gt; had their launch on the same day and they had a launch party at the same time. We continued to &lt;a href=&quot;http://www.kaarle.com/&quot;&gt;Kaarle XII&lt;/a&gt; where we were supposed to meet with the Tripsay guys. I had to leave around midnight and never met them. I don’t know if they ever came there.&lt;/p&gt;

&lt;p&gt;I strongly recommend others to join the meetup. I will definitely attend in the future. A big thank goes to Ville Vesterinen from &lt;a href=&quot;http://www.arcticstartup.com/&quot;&gt;ArcticStartup&lt;/a&gt; fame for organizing this awesome meetup. And thanks a lot everyone who I met – I look forward to meeting you again.&lt;/p&gt;

</content>
 </entry>
 
</feed>

