<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hadi Hariri&#039;s Blog</title>
	<atom:link href="http://hadihariri.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hadihariri.com</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 12:06:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='hadihariri.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Hadi Hariri&#039;s Blog</title>
		<link>http://hadihariri.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hadihariri.com/osd.xml" title="Hadi Hariri&#039;s Blog" />
	<atom:link rel='hub' href='http://hadihariri.com/?pushpress=hub'/>
		<item>
		<title>Android applications with Kotlin</title>
		<link>http://hadihariri.com/2013/05/21/android-applications-with-kotlin/</link>
		<comments>http://hadihariri.com/2013/05/21/android-applications-with-kotlin/#comments</comments>
		<pubDate>Tue, 21 May 2013 06:07:45 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Kotlin]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2953</guid>
		<description><![CDATA[Did you know you can write applications for Android using Kotlin instead of Java? Here&#8217;s how, in one minute! Converting to Kotlin IntelliJ offers a series of features targeted at Android development, among these is the ability to quickly create Android Components: For instance, selecting to create a new Activity will generate the corresponding XML [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2953&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Did you know you can write applications for Android using <a href="http://kotlin.jetbrains.org">Kotlin</a> instead of Java? Here&#8217;s how, in one minute!</p>
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='560' height='315' src='http://www.youtube.com/embed/SznPkYHGxLY?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span>
<h2>Converting to Kotlin</h2>
<p>IntelliJ offers a series of features targeted at Android development, among these is the ability to quickly create Android Components:</p>
<p><img title="NewMenu.png" alt="NewMenu" src="http://hhariri.files.wordpress.com/2013/05/newmenu.png?w=211&#038;h=300" width="211" height="300" border="0" /></p>
<p>For instance, selecting to create a new Activity will generate the corresponding XML layout, source file and update and the application manifest. Quite useful. The problem is though that the source generated is in Java, which isn&#8217;t an issue of course unless you&#8217;re working with Kotlin. However, you can easily work around this. Simply use IntelliJ&#8217;s helper to create the necessary components, then select the generated Java file in the Project window and from the <em>Code</em> menu click on <em>Convert Java File to Kotlin File</em> (there&#8217;s a different shortcut depending on your keyboard layout).</p>
<p><img style="border:0;" title="CodeMenu.png" alt="CodeMenu" src="http://hhariri.files.wordpress.com/2013/05/codemenu.png?w=320&#038;h=235" width="320" height="235" border="0" /></p>
<p>All this functionality is available in both <a href="http://www.jetbrains.com/idea/">IntelliJ Ultimate as well as the free OSS IntelliJ Community Edition</a>, the same one <a href="http://android-developers.blogspot.com.es/2013/05/android-studio-ide-built-for-android.html">Android Studio</a> is built on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2953/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2953&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2013/05/21/android-applications-with-kotlin/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/05/newmenu.png" medium="image">
			<media:title type="html">NewMenu.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/05/codemenu.png" medium="image">
			<media:title type="html">CodeMenu.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Freedom to work</title>
		<link>http://hadihariri.com/2013/03/16/freedom-to-work/</link>
		<comments>http://hadihariri.com/2013/03/16/freedom-to-work/#comments</comments>
		<pubDate>Sat, 16 Mar 2013 08:38:47 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2902</guid>
		<description><![CDATA[Yahoo has called in all their remote workers. Come June, they&#8217;re either sitting at desk in Silicon Valley or they&#8217;re looking for another job. I&#8217;d be looking for another job. Not because of having to go the office everyday, but because they&#8217;re trying to solve the wrong problem. It seems like they feel if people [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2902&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Yahoo has <a href="http://www.businessinsider.com/marissa-mayer-tells-hundreds-of-remote-yahoo-employees-work-in-an-officeor-quit-2013-2">called in all their remote workers</a>. Come June, they&#8217;re either sitting at desk in Silicon Valley or they&#8217;re looking for another job.</p>
<p>I&#8217;d be looking for another job. Not because of having to go the office everyday, but because they&#8217;re trying to solve the wrong problem. It seems like they feel if people are bound to a schedule, working in an environment where they can be controlled, everything will sort itself out.</p>
<p>Were I work, people set their own schedules. Whether they&#8217;re working from home or in an office. There are no <em>office hours</em>, no controls, no micromanagement. And yet it works. It works because of two main cultural values: <strong>respect</strong> and <strong>care</strong>.</p>
<h3>Respecting the individual. Caring for the individual</h3>
<p>Respect is not limited to treating people politely. It is respecting them as individuals, it is understanding that each person is different, works in different ways, has different challenges or circumstances that need to be dealt with. However, it is more than just acknowledging it, it is doing something about it. It is caring enough to want help.</p>
<p>Applying these values in a work environment between employer/employee, between team members is what makes the difference. And it makes a very important difference.</p>
<p>An employee needing flexible hours can either be faced by an employer who makes excuses about why it won&#8217;t work out or someone that is willing to help accomodate the employee. Helping this person out shows them that their employer cares enough about them as an individual. And if there is respect, this behaviour then becomes reciprocal.</p>
<p>These values needs to be applied to all aspects: between colleagues, teams, an individual&#8217;s work, the collective work, the project and on a more global scale, the goals of the company.</p>
<h3>The culture of mistrust.</h3>
<p>It is the feeling of respect and caring for each other, and the things we do that builds up and creates a relationship of trust.</p>
<p>Mistrust on the other hand emerges  as soon as you ask someone to clock in/out. When you ask them for detailed daily reports, you&#8217;re saying that you&#8217;re not sure if they&#8217;ve actually been working all day.  When you micromanage, you&#8217;re telling them, that not only do you not trust them, but you don&#8217;t respect them enough to be more than an insignificant cog in the machinery.</p>
<p>This creates tension. It leads to parties disrespecting each other. And as this happens, people stop caring. Why care about something you don&#8217;t respect? As a result, efficiency drops. Employers lose. Teams lose. The company loses. The individual loses.</p>
<p>It becomes another 9 to 5 job for a pay check.</p>
<h3><span style="font-size:1.142857143rem;line-height:1.846153846;">Perks don&#8217;t buy respect </span></h3>
<p>A spokesperson for <a href="http://www.businessinsider.com/why-marissa-mayer-told-remote-employees-to-work-in-an-office--or-quit-2013-2">Yahoo writes</a>:</p>
<blockquote><p>[Marissa] Mayer is happy to give Yahoo employees standard Silicon Valley benefits like free food and free smartphones…&#8221;</p></blockquote>
<p>Free donuts, constant flow of coffee and sodas are great. But if there is no respect, it means very little. Perks alone don&#8217;t buy respect or fulfil individuals. They are the icing on the cake. But there needs to be a cake.</p>
<p>Taking freedom away from people by forcing them into a 9 to 5 schedule on-site and then saying you&#8217;ll give them a mobile phone is not going to solve anything.</p>
<p>Care for people. Respect them. Give them the freedom to work. They&#8217;ll give you their best.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2902/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2902&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2013/03/16/freedom-to-work/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatically Building Pull Requests from GitHub with TeamCity</title>
		<link>http://hadihariri.com/2013/02/06/automatically-building-pull-requests-from-github-with-teamcity/</link>
		<comments>http://hadihariri.com/2013/02/06/automatically-building-pull-requests-from-github-with-teamcity/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 11:24:47 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[TeamCity]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2882</guid>
		<description><![CDATA[Scenario You&#8217;re running an OSS project* and someone makes a pull request. You&#8217;ve got two choices: Merge and Pray Pull to local branch, build, run tests and merge if all OK What do you do? Well, what is it going to be? I know what I&#8217;d like to do, and GitHub makes it so so [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2882&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h3>Scenario</h3>
<p>You&#8217;re running an OSS project* and someone makes a pull request. You&#8217;ve got two choices:</p>
<ul>
<li>Merge and Pray
<li>Pull to local branch, build, run tests and merge if all OK </li>
</ul>
<p>What do you do? Well, what is it going to be?</p>
<p><img style="display:inline;" title="dealwithithmerge.png" border="0" alt="Dealing with Pull Request" src="http://hhariri.files.wordpress.com/2013/02/dealwithithmerge.png?w=510&#038;h=600" width="510" height="600"></p>
<p>I know what <em>I&#8217;d like</em> to do, and GitHub makes it so so tempting:</p>
<p><img title="mergerequestgithub.png" border="0" alt="Merge Pull Request" src="http://hhariri.files.wordpress.com/2013/02/mergerequestgithub.png?w=600&#038;h=43" width="600" height="43"></p>
<p>But unfortunately I go with the second option.</p>
<p>That&#8217;s a pain, specially if you do a quick code-review and things look decent. Yet you still need to make sure that it builds and all tests pass.</p>
<p>Well, luckily for me, and <a href="https://twitter.com/hhariri/status/298436432765259777">my ability to continuously interfere in conversations</a>, I found out that there is a better way. And what&#8217;s even nicer, is that it&#8217;s also possible with TeamCity.</p>
<p>*This applies to non-OSS too</p>
<h3>Automatically Building All Pull Requests</h3>
<p>What I want to do is have TeamCity automatically build all Pull Requests for me of my main repository, and notify me if it is successful. And I want this to happen without me having to configure every single fork as a repository in TeamCity, because like that, it wouldn&#8217;t be manageable. Here&#8217;s a diagram explaining it:</p>
<p><img style="display:inline;" title="TCFlowDiagram.png" border="0" alt="TC Flow Diagram" src="http://hhariri.files.wordpress.com/2013/02/tcflowdiagram.png?w=600&#038;h=446" width="600" height="446"></p>
<p>This will drastically improve the workflow since we no longer have to manually create a local branch of the pull request, check it, build it and only then merge it.</p>
<h3>Configuring TeamCity</h3>
<p>Setting up TeamCity to do this is really simple. It actually only requires one thing: configuring the <strong>Branch Specification</strong> under the VCS root:</p>
<p><img style="display:inline;" title="TCGitConfig.png" border="0" alt="TC Git Config" src="http://hhariri.files.wordpress.com/2013/02/tcgitconfig.png?w=600&#038;h=423" width="600" height="423"></p>
<p>Let&#8217;s see what this means and why it works. When a pull request is made, GitHub automatically creates a reference that holds the pull request as well as one that is a merge with the master branch. What we&#8217;re saying to TeamCity is to monitor this branch, in addition to the main branch. In this syntax, <em>pull</em> refers to the pull request. The * refers to ANY pull request, and the <em>merge</em> indicates that we&#8217;re interested in the pull request merged with the master branch. This means that when TeamCity builds, it will build the branch that was merged. If we want to build the branch, without merging, we could use the following:</p>
<p><strong>+:refs/pull/*/head</strong></p>
<p>So to recap, adding <em>merge</em> builds the result of the merge, and adding <em>head</em>, just the pull request without the merge.</p>
<p>The result of these builds show up in TeamCity like so:</p>
<p><img style="display:inline;" title="TCResult1.png" border="0" alt="TC Result 1" src="http://hhariri.files.wordpress.com/2013/02/tcresult1.png?w=600&#038;h=139" width="600" height="139"></p>
<p>where the number denotes the pull request. Now, we can actually make this a bit nicer by allowing us to see whether the particular request was the result of a merge or just the branch itself. For that, we can specify the following in the Branch Specification</p>
<p><img style="display:inline;" title="TCAltConfig.png" border="0" alt="TC Alt Config" src="http://hhariri.files.wordpress.com/2013/02/tcaltconfig.png?w=600&#038;h=151" width="600" height="151"></p>
<p>with TeamCity now indicating whether this was a merge or head:</p>
<p><img style="display:inline;" title="TCResult2.png" border="0" alt="TC Result 2" src="http://hhariri.files.wordpress.com/2013/02/tcresult2.png?w=456&#038;h=216" width="456" height="216"></p>
<p>In addition, TeamCity also provides us with a Dropdown, where we can filter all the different pull requests:</p>
<p><img title="Filter.png" border="0" alt="Filter" src="http://hhariri.files.wordpress.com/2013/02/filter.png?w=284&#038;h=293" width="284" height="293"></p>
<h3>Seeing notifications on the Pull Request</h3>
<p>As this is a normal build, like any other build, we can configure TeamCity to receive notifications via email, tray icon, etc, both on successful builds as well as failed builds. However, there is one other thing that we can do: see the result of the build on the Pull Request page on GitHub. In order for this to happen, we do need to install a plugin for TeamCity which currently doesn&#8217;t ship out of the box. This plugin, written by <a href="https://twitter.com/jonnyzzz">Eugene Petrenko</a> uses some hooks GitHub provides to add notification information on the Pull Request page.</p>
<p>To install it, <a href="https://github.com/jonnyzzz/TeamCity.GitHub">download the plugin as a zip file</a> and place it in the plugins folder of the server and restart the server.</p>
<p>Once that&#8217;s installed, we can now display build status information on the GitHub pull request by adding a Build Feature to our Build Steps:</p>
<p><img style="display:inline;" title="BuildFeature.png" border="0" alt="Build Feature" src="http://hhariri.files.wordpress.com/2013/02/buildfeature.png?w=600&#038;h=300" width="600" height="300"></p>
<p>and filling in some simple configuration parameters:</p>
<p><a href="http://hhariri.files.wordpress.com/2013/02/image1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://hhariri.files.wordpress.com/2013/02/image_thumb1.png?w=507&#038;h=473" width="507" height="473"></a></p>
<p>And with that, we can see the status on the Pull Request page on GitHub.</p>
<p><a href="http://hhariri.files.wordpress.com/2013/02/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://hhariri.files.wordpress.com/2013/02/image_thumb.png?w=1512&#038;h=415" width="1512" height="415"></a></p>
<p>* If you&#8217;re running your OSS project on <a href="http://teamcity.codebetter.com">TeamCity at CodeBetter</a>, you now have this plugin available.</p>
<h3>Summary</h3>
<p>Although my example was based on <a href="http://blogs.jetbrains.com/teamcity/2013/01/25/teamcity-8-0-code-name-gaya-eap-is-open/">TeamCity 8.0 which is currently in EAP</a>, this feature also works with TeamCity 7.1.3+ (and even <a href="http://www.lshift.net/blog/2013/01/13/continuous-integration-for-github-pull-requests-with-teamcity">previously covered by others</a>). The examples are also based on OSS projects, but you can apply the same workflow to private repositories also, hopefully making things a little bit easier.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2882/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2882/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2882&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2013/02/06/automatically-building-pull-requests-from-github-with-teamcity/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/dealwithithmerge.png" medium="image">
			<media:title type="html">dealwithithmerge.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/mergerequestgithub.png" medium="image">
			<media:title type="html">mergerequestgithub.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/tcflowdiagram.png" medium="image">
			<media:title type="html">TCFlowDiagram.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/tcgitconfig.png" medium="image">
			<media:title type="html">TCGitConfig.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/tcresult1.png" medium="image">
			<media:title type="html">TCResult1.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/tcaltconfig.png" medium="image">
			<media:title type="html">TCAltConfig.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/tcresult2.png" medium="image">
			<media:title type="html">TCResult2.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/filter.png" medium="image">
			<media:title type="html">Filter.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/buildfeature.png" medium="image">
			<media:title type="html">BuildFeature.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2013/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Extension Function Literals in Kotlin or How to enforce restrictions in your DSL</title>
		<link>http://hadihariri.com/2013/01/21/extension-function-literals-in-kotlin-or-how-to-enforce-restrictions-on-your-dsl/</link>
		<comments>http://hadihariri.com/2013/01/21/extension-function-literals-in-kotlin-or-how-to-enforce-restrictions-on-your-dsl/#comments</comments>
		<pubDate>Mon, 21 Jan 2013 18:35:17 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Kotlin]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2850</guid>
		<description><![CDATA[Take a look at the following code, an example of a specification written using spek In this code, given, on and it are all functions. Kotlin allows top-level functions to be defined (without the need for them to belong to a class). As such, we could merely declare these functions in a single file as [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2850&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Take a look at the following code, an example of a specification written using <a href="http://github.com/hhariri/spek">spek</a></p>
<p><script src="https://gist.github.com/4586574.js"></script></p>
<p>In this code, <em>given</em>, <em>on</em> and <em>it</em> are all functions.</p>
<p>Kotlin allows top-level functions to be defined (without the need for them to belong to a class). As such, we could merely declare these functions in a single file as below:</p>
<p><script src="https://gist.github.com/4586610.js"></script></p>
<p>At first sight it might not seem like a bad approach, but it is. The problem is that you cannot prevent someone from calling the code like so:</p>
<p><script src="https://gist.github.com/4586615.js"></script></p>
<p>or even:</p>
<p><script src="https://gist.github.com/4586618.js"></script></p>
<p>or any other weird combination for that matter.</p>
<p>This means that we would now have to put in additional runtime checks to verify that things are called in the correct manner; context has been set up before the action, the action has been executed before the assertions and so on and so forth. Pain.</p>
<h3>Extension Function Literals</h3>
<p>We&#8217;ve <a href="http://hadihariri.com/2012/09/27/the-kotlin-journey-part-iv-adding-functionality/">already seen</a> that Kotin has extension functions, similar to C#. We&#8217;ve also seen that we can define extension functions as function literals:</p>
<p><script src="https://gist.github.com/4587057.js"></script></p>
<p>Combining this with high-order functions, that is a function that takes a function as a parameter, we can do:</p>
<p><script src="https://gist.github.com/4587074.js"></script></p>
<p><em>given </em>is still a top-level function. However, the diference is that <em>on</em> and <em>it</em> are no longer top-level. Instead, we&#8217;re creating three different classes: <em>Given</em>, <em>On</em> and <em>It</em>.</p>
<p>Let&#8217;s take a look at the <em>Given </em>class. This class has a method that takes two parameters: a string, which is the description and a second parameter which is the extension function literal we&#8217;ve been talking about:</p>
<p><script src="https://gist.github.com/4587271.js"></script></p>
<p>The parameter is an extension function on the <i>On </i>class, which takes no parameters and returns no value (<em>Unit</em> in Kotlin &#8211; void).</p>
<p>We repeat the same pattern with the <em>On </em>and <em>It </em>classes. By doing this, we now enforce a certain flow at compile time and prohibit out of order usage.</p>
<p>You can see also in the code, that the <em>It</em> class contains a series of assertion methods, exactly where they belong.</p>
<h3>Summary</h3>
<p>We can see that with some simple extension function literals, we can easily impose a series of restrictions on our DSL&#8217;s. Of course, in this case, the example is quite straightforward but the same thing can be applied to designing other DSL&#8217;s such as HTML builders et al.</p>
<p>[Thanks to <a href="http://twitter.com/orangy">@orangy</a> for highlighting the issue and refactoring of Spek to this]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2850/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2850/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2850&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2013/01/21/extension-function-literals-in-kotlin-or-how-to-enforce-restrictions-on-your-dsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>Making +1 mean what it really means</title>
		<link>http://hadihariri.com/2013/01/09/making-1-mean-what-it-really-means/</link>
		<comments>http://hadihariri.com/2013/01/09/making-1-mean-what-it-really-means/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 21:07:18 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[YouTrack]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2845</guid>
		<description><![CDATA[On YouTrack, you can vote for issues. There&#8217;s a button right at the top, beneath the title. It&#8217;s quite big. It doesn&#8217;t say &#8220;Vote&#8221; but it&#8217;s still pretty apparent The problem is, that not everybody seems to see the button. In addition, in a world of Like and +1, what tends to happen is that [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2845&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>On YouTrack, you can vote for issues. There&#8217;s a button right at the top, beneath the title. It&#8217;s quite big. It doesn&#8217;t say &#8220;Vote&#8221; but it&#8217;s still pretty apparent </p>
<p><img src="http://blog.jetbrains.com/youtrack/files/2013/01/VoteButton.png" alt="Vote Button" border="0" width="600" height="101" /></p>
<p>The problem is, that not everybody seems to see the button. In addition, in a world of Like and +1, what tends to happen is that we end up with a lot of comments like this:</p>
<p><img src="http://blog.jetbrains.com/youtrack/files/2013/01/NewImage.png" alt="NewImage" border="0" width="600" height="381" /></p>
<p>So how should we fix it? Make the vote button bigger? Place a couple here and there? I asked this question on Twitter a few days ago and one of the more common responses was: </p>
<p><em>&#8220;Can&#8217;t you add a feature to YouTrack to make +1 add a vote?&#8221;</em></p>
<h3>Workflows save the day&#8230;again</h3>
<p>Well, good news is that we can. But the even better news is that we don&#8217;t need to add a feature, and consequently you don&#8217;t need to wait for us to ship this feature if you&#8217;re also encountering this problem. We can actually solve this using Workflows. If you&#8217;re not familiar with workflows, think of it as a way to get <a href="http://blog.jetbrains.com/youtrack/2012/02/spicing-up-youtrack-with-workflows/">YouTrack to pretty much do whatever you want</a>.   </p>
<p>The workflow is actually quite simple:</p>
<p><img src="http://blog.jetbrains.com/youtrack/files/2013/01/workflow.png" alt="Workflow" border="0" width="600" height="116" /></p>
<p>With a simple rule like the above, attached as workflow to your project, any +1 comment will now be interpreted as a vote and a nice message displayed to the user. </p>
<p><img src="http://blog.jetbrains.com/youtrack/files/2013/01/MEssageonvote.png" alt="Message on Vote" border="0" width="600" height="84" /></p>
<p>Just write the workflow, upload it to the server and attach it. </p>
<h3>Shipping out of the box</h3>
<p>As of YouTrack 4.2, this workflow will <a href="http://youtrack.jetbrains.com/issue/JT-16359">already ship out of the box</a>. Until then, and using your current version of YouTrack, you can create the workflow, attach it and you&#8217;re good to go.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2845/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2845&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2013/01/09/making-1-mean-what-it-really-means/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://blog.jetbrains.com/youtrack/files/2013/01/VoteButton.png" medium="image">
			<media:title type="html">Vote Button</media:title>
		</media:content>

		<media:content url="http://blog.jetbrains.com/youtrack/files/2013/01/NewImage.png" medium="image">
			<media:title type="html">NewImage</media:title>
		</media:content>

		<media:content url="http://blog.jetbrains.com/youtrack/files/2013/01/workflow.png" medium="image">
			<media:title type="html">Workflow</media:title>
		</media:content>

		<media:content url="http://blog.jetbrains.com/youtrack/files/2013/01/MEssageonvote.png" medium="image">
			<media:title type="html">Message on Vote</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started with Kara</title>
		<link>http://hadihariri.com/2012/12/31/getting-started-with-kara/</link>
		<comments>http://hadihariri.com/2012/12/31/getting-started-with-kara/#comments</comments>
		<pubDate>Mon, 31 Dec 2012 07:14:55 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Kara]]></category>
		<category><![CDATA[Kotlin]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2844</guid>
		<description><![CDATA[Couple of days ago I discovered Kara, a Web Framework written in Kotlin. Here&#8217;s a short introductory screencast that gets you up and running.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2844&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Couple of days ago I discovered <a href="http://github.com/tinymission/kara">Kara</a>, a Web Framework written in <a href="http://kotlin.jetbrains.org">Kotlin</a>. </p>
<p>Here&#8217;s a short introductory screencast that gets you up and running. </p>
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='560' height='315' src='http://www.youtube.com/embed/pvzMh85_qWU?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2844/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2844&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/12/31/getting-started-with-kara/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows Phone 8: A user&#8217;s experience</title>
		<link>http://hadihariri.com/2012/12/16/windows-phone-8-a-users-experience/</link>
		<comments>http://hadihariri.com/2012/12/16/windows-phone-8-a-users-experience/#comments</comments>
		<pubDate>Sun, 16 Dec 2012 20:32:04 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2825</guid>
		<description><![CDATA[Around two months ago I received a Nokia Lumia 920. Having been a long time iPhone user (3G and 4), I decided it&#8217;s time to give another phone a try. After having used it for over a month, I&#8217;m back to my iPhone (my switch to Android lasted 8 months). This post is about the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2825&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Around two months ago I received a Nokia Lumia 920. Having been a long time iPhone user (3G and 4), I decided it&#8217;s time to give another phone a try. After having used it for over a month, I&#8217;m back to my iPhone <a href="http://hadihariri.com/2010/09/25/samsung-galaxy-s-from-a-recovering-iphone-user/">(my switch to Android lasted 8 months)</a>.</p>
<p>This post is about the overall experience with the phone. It is not about pointing fingers. From a user&#8217;s perspective, I don&#8217;t care if it&#8217;s a Nokia issue, an Operator one, Microsoft&#8217;s, Windows Phone Team or last but not least, App developers. I&#8217;m describing my experience as a user.</p>
<p>I also realise that many people might have a completely different experience to mine, and that&#8217;s fine. It might be I&#8217;m too picky or just have bad luck with electronics (does happen). Having said that, let&#8217;s move on.</p>
<p><em>Disclaimer: Maybe some of the issues I point out in this post are user error or sheer ignorance. If they are, please enlighten me. I&#8217;ve still not decided 100% if I&#8217;m going to stay with iPhone or switch back.</em></p>
<h2>The Hardware</h2>
<p>The device itself is actually very nice. It&#8217;s a slick, thin design and despite it&#8217;s dimensions, it does not feel uncomfortable to hold and have in your pocket. As <a href="http://twitter/tastapod">Dan North says</a>, it&#8217;s the thinness that matters, and I tend to agree. It has a nice screen size and having an external button to activate the camera and take shots feels very comfortable and natural. The camera itself is fantastic. Great quality video and pictures.</p>
<p><img title="photo (1).jpg" alt="Photo  1" src="http://hhariri.files.wordpress.com/2012/12/photo-11.jpg?w=200&#038;h=267" width="200" height="267" border="0" /></p>
<p>My device is a Developer edition, so it didn&#8217;t come with any charger other than an extremely short USB cable. Not much more to comment on the hardware, other than there was no headset. Not sure if the retail version comes with a decent one which includes a controller much like the iPhone. It is definitely something I missed having.</p>
<h2>Volume Control</h2>
<p>The downside of the hardware is not having a Vibrate/Mute button like the iPhone does. In addition, placing the phone on Vibrate requires 3 operations: Press the lock button, press the Volume down or up button and then click on an icon to toggle between Vibrate or Ring. As someone with a 10 month old baby or having to use the Vibrate button quite frequently &#8220;on the job&#8221;, this can be cumbersome.</p>
<p><img title="2012-12-16_20-12-49.png" alt="2012 12 16 20 12 49" src="http://hhariri.files.wordpress.com/2012/12/2012-12-16_20-12-491.png?w=400&#038;h=113" width="400" height="113" border="0" /></p>
<p>What is however much more annoying is that there is no separation of media from ring volume. If you want to hear the phone, you&#8217;re going to pop your ears out listening to music. There is only a single volume level which applies to Video, Audio, Notifications and Ringer. Honestly I don&#8217;t know why they&#8217;ve not thought of this.</p>
<h2>The Keyboard</h2>
<p>Initially the keyboard seemed fine. I was able to type, except for one,minor,issue,and,that,is,that,I,kept,pressing,the,comma,key,instead,of,the,spacebar. No matter how much I try, I can&#8217;t avoid it, to the point that lately I was avoiding using my right thumb to hit the space bar. Maybe I have a thick thumb. Don&#8217;t know. Other than that though, no real issues in key spacing or other.</p>
<p><img title="wp_ss_20121216_0006.jpg" alt="Wp ss 20121216 0006" src="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0006.jpg?w=200&#038;h=333" width="200" height="333" border="0" /></p>
<h2>Spellchecker</h2>
<p>Try and type <em>Hell</em> on the iPhone and you&#8217;ll always end up with <em>He&#8217;ll</em>. Can be annoying. I was somewhat relieved initially that this wasn&#8217;t the case with this phone. What it does offer is word completion. If it feels you&#8217;re writing a word incorrectly, often the first word on the autocomplete list is in bold, meaning that it will automatically replace the word you&#8217;re typing. It claims that it learns from your typing and offers suggestions based on it.</p>
<p>To be honest, I&#8217;m not sure how well this works. It doesn&#8217;t seem to offer a lot of autocorrect suggestions, and some that I&#8217;d really like it to offer, it does not. For instance, on the iPhone, every time you type <em>i</em>, it will interpret it as <em>I</em>. When I type<em> Ill</em>, it will replace it with <em>I&#8217;ll</em>. Not here. You type i, you have to explicitly correct with I. Same with Ill. Dear Windows Phone team, there is rarely ever a time when I type <em>i </em>and not mean <em>I</em>.</p>
<p><img title="wp_ss_20121216_0010.jpg" alt="Wp ss 20121216 0010" src="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0010.jpg?w=200&#038;h=333" width="200" height="333" border="0" /></p>
<p>The upsides to the spell checker not being over protective is that it doesn&#8217;t autocorrect too often, which I find can be useful when alternating between two languages (in my case English / Spanish) and not having to constantly switch keyboard layout. In addition, sometimes (I&#8217;ve still to figure out when), a + sign appears next to a suggestion, allowing you to add it to the dictionary.</p>
<h2>Form Navigation</h2>
<p>This one is really a fail in terms of usability, or I&#8217;m doing something completely wrong. While filing in a form on the browser, on the iPhone, you are normally provided with two additional buttons right on top of the keyboard: <strong>Next</strong>, <strong>Prev</strong> allowing you to easily navigate to the next or previous field. On WP8 you don&#8217;t get that. And this can be really problematic since as the keyboard overlaps half the screen, you often cannot click on the next field to move fields. In fact, this problem occurs on native applications also. Sometimes I honestly don&#8217;t know how to navigate back and forth between fields.</p>
<p><img title="2012-12-16_20-07-37.png" alt="2012 12 16 20 07 37" src="http://hhariri.files.wordpress.com/2012/12/2012-12-16_20-07-372.png?w=400&#038;h=419" width="400" height="419" border="0" /></p>
<h2></h2>
<h2>Battery Life</h2>
<p>Used extensively, the battery lasts me around a day. That is when I don&#8217;t get the sudden death feature, whereby the indicator displays half-charge and the phone just dies on me.</p>
<h2>Links and Discoverability</h2>
<p>Most applications use regular text as action items, not buttons. The problem is that there&#8217;s nothing that differentiates a link from regular text on the screen. And while often an action is apparent, many times I find myself clicking on different text items wondering if something&#8217;s going to happen. Of course, this isn&#8217;t aided by the fact that some application designers think it&#8217;s good to hide actions under pictures or avatars et al (Skype comes to mind). Not the most discoverable interface at times.</p>
<h2>Live Tiles</h2>
<p>One of the main features of the Windows Phone and a big selling point are Live Tiles. And they are fantastic. Of course, after the first couple of days, when the new factor wears off, you&#8217;re left with the annoyances of <em>caching </em>issues, by which I mean tiles not refreshing accordingly. I&#8217;ve had this occur with <em>WhatsApp</em> among other applications.  While not getting the latest headlines on a live tile isn&#8217;t detrimental, missing out on messages does put you in an compromising social position whereby you now have to explain that you really weren&#8217;t ignoring people.</p>
<p>I think that the Live Tiles have a lot of potential, but unfortunately many applications don&#8217;t take much advantage of them. Also, applications don&#8217;t offer much in terms of customisation. For instance, with Skype, it displays on the tile the number of notifications and you cannot switch it off. The only way to do so is to remove the tile from the main screen.</p>
<p><img title="wp_ss_20121216_0005.jpg" alt="Wp ss 20121216 0005" src="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0005.jpg?w=200&#038;h=333" width="200" height="333" border="0" /></p>
<h2>People Hubs</h2>
<p>Another central feature of the phone are Hubs, the idea that you connect different aspects of a person into one central place. For instance I have a live tile for my wife. I link Skype, Cell number, SMS et al all under her contact. Idea is that everything is now displayed on that tile. Fantastic. Unfortunately, at least for me, not everything works. I only manage to see SMS&#8217;s and phone calls under the tile. Not sure if this is a Live Tile cache problem again, or a lack of proper implementation from the intervening apps, but ultimately, it doesn&#8217;t work as expected.</p>
<p>In any case, even if this were to work correctly, I&#8217;m not sure that I&#8217;d want anyone other than my wife on the front screen in a tile. I honestly don&#8217;t picture my colleagues or other people representing an icon on the screen. There is the concept of creating a group of people and having them in a tile, but again, that seems to suffer from the same issues as a single person.</p>
<p>Having these people hubs also does away with some common features we&#8217;re used to in other phones, namely favourites. For instance, when clicking on the Phone application, there&#8217;s no Favourites. On Windows Phone it&#8217;s hubs. You want favourites, create a hub and link contacts up.</p>
<h2>The Apps and the Store</h2>
<p>When I first received the phone, I immediately tried to install all the apps I had on the iPhone. To my surprise, <em>Skype</em> wasn&#8217;t available, which is quite disappointing considering that <em>Skype</em> now belongs to Microsoft. It did arrive several weeks later and to be honest, except for the live tile issue, the overall experience with it is good. However, other apps are quite disappointing: <em>1Password</em> crashed (apparently now it&#8217;s fixed but still doesn&#8217;t work for me). <em>WhatApps</em> has issues of not receiving messages and/or updating the live tile. <em>Viber</em> doesn&#8217;t offer voice, only messages. In addition, the overall choice of applications is not that great. Yes, if you want RSS readers or background images, there are plenty.</p>
<p>When it comes to the actual quality of the applications, not too impressive.A lot of crashes, a lot of hangs, some awful user experiences. This is somewhat unfortunate since the ecosystem contributes significantly to the success of the device.</p>
<p>One feature I do like is the ability to search for an application and install it from the store without explicitly going to the store. When launching an application you can search for it by using the Search feature. If it doesn&#8217;t find any matches, it provides you the option to search the store. Installing applications from the store is straightforward. I&#8217;ve actually not bought any applications so cant&#8217; comment on the payment experience.</p>
<h2>The Hangs</h2>
<p>Apart from random application crashes (specially <em>Twitter</em>), I&#8217;ve had several hangs of the phone, causing me to switch it on and off.  Others don&#8217;t seem to suffer this problem, so it might be just me (again).</p>
<h2>Mail</h2>
<p>The mail application is OK, nothing special or any feature that really stands out. Gmail works fine, and I could sync my account, including contacts and calendar successfully. However, <a href="http://www.theverge.com/2012/12/14/3768274/google-gmail-activesync-windows-phone">that&#8217;s going to change</a>.</p>
<h2>Tap and Send</h2>
<p>Apparently the phone has a Tap and Send feature where you can get close (or Tap?) another phone to share information. Unfortunately I&#8217;ve not experienced this myself since I haven&#8217;t found anyone I can tap (the phone) with. NFC also provides wireless charging, but again, not experienced it personally.</p>
<h2>Music</h2>
<p>Nothing really stands out when it comes to the Music application. It&#8217;s quite decent, with album view, quick play, etc. However, one feature that is lacking is the ability to create playlists directly from the phone. This sucks, specially when you&#8217;re on the road, on a plane, on a train, when you actually have time to sit, listen, create a list.</p>
<h2>Connectivity</h2>
<p>When it comes to Internet Sharing, very easy. Switch it on and you have a WAP. One nice feature is that it automatically switches off the sharing if nobody is connected after a couple of minutes. Had no issues connecting via PC or Apple.</p>
<p>Can&#8217;t say the same about BlueTooth. For the life of me I couldn&#8217;t get it to work with my car. I&#8217;ve had no issues with two iPhones or two Androids, but Windows Phone doesn&#8217;t seem to like Toyota Auris. Additionally, the USB outlet of my car also isn&#8217;t apparently powerful enough to charge the phone.</p>
<p>For Data, the phone provides 3G and H+ and both work fine. I did have to explicitly set up the configuration for my telephone operator in Spain (Movistar) and much like the anything other than iPhone, hooking on to Movistar WiFi zones requires sending an SMS and getting a password. This is an operator issue I&#8217;m assuming, but again, the overall experience is not as smooth as with the iPhone / iPad whereby it automatically detects you and logs you on.</p>
<p>WiFi also seems to work OK except that every time the phone locks, it loses configuration for open WiFi&#8217;s that require you to log on via browser. Again, annoying.</p>
<h2>Editing</h2>
<p>The editing and positioning of the cursor is kind of strange in comparison to other phones. When positioning the cursor, you don&#8217;t get the magnifying glass. Instead you get a cursor offset from your actual finger&#8217;s position by about a couple of mm&#8217;s. You then move your finger around to position it. For a while I didn&#8217;t realize how this works, until finally I moved my hand further down to get the cursor back on screen. Somewhat strange, and on the fence about it. Copy/Paste operations I&#8217;ve found a tad cumbersome in some occasions,  specially with autoselect (i.e. click on a link and it autoselects it).</p>
<h2>Summary</h2>
<p>I switched to the Windows Phone with an open mind and tried it out for over a month. I&#8217;m now back to the iPhone and one of the reasons is to see if I actually miss anything from the Windows Phone (while I thought I&#8217;d really miss out on the screen size, I haven&#8217;t that much). The one thing I do miss is the Home button actually working (<a href="https://www.google.com/search?q=iphone+home+button+not+working&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t">yep I have this issue</a>).</p>
<p>Of course, many of the issues I&#8217;ve highlighted might boil down to minor things that need ironing out, a few rough edges here and there you might say. The problem is however, that this is not the first generation of Windows Phone. And to enter a market that is already dominated by two major players, you not only have to disrupt it by offering something fantastic and new, but you also have to make sure it&#8217;s perfect. Unfortunately as it stands today, for me at least, Windows Phone 8 is neither.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2825/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2825/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2825&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/12/16/windows-phone-8-a-users-experience/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/photo-11.jpg" medium="image">
			<media:title type="html">photo (1).jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/2012-12-16_20-12-491.png" medium="image">
			<media:title type="html">2012-12-16_20-12-49.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0006.jpg" medium="image">
			<media:title type="html">wp_ss_20121216_0006.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0010.jpg" medium="image">
			<media:title type="html">wp_ss_20121216_0010.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/2012-12-16_20-07-372.png" medium="image">
			<media:title type="html">2012-12-16_20-07-37.png</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/12/wp_ss_20121216_0005.jpg" medium="image">
			<media:title type="html">wp_ss_20121216_0005.jpg</media:title>
		</media:content>
	</item>
		<item>
		<title>ReSharper on the Server: Detecting Code Issues in the build</title>
		<link>http://hadihariri.com/2012/10/10/resharper-on-the-server-detecting-code-issues-in-the-build/</link>
		<comments>http://hadihariri.com/2012/10/10/resharper-on-the-server-detecting-code-issues-in-the-build/#comments</comments>
		<pubDate>Wed, 10 Oct 2012 10:22:10 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Code Qualty]]></category>
		<category><![CDATA[Inspections]]></category>
		<category><![CDATA[TeamCity]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2793</guid>
		<description><![CDATA[Did you know that you can run ReSharper Code Inspections on the server using TeamCity? In fact, we added support for this functionality in TeamCity just over a year ago but it seems that the feature is not widely known, specially by ReSharper users. The setup itself is extremely simple, and we’re going to walk [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2793&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Did you know that you can run <a href="http://www.jetbrains.com/resharper">ReSharper</a> Code Inspections on the server using <a href="http://www.jetbrains.com/teamcity">TeamCity</a>? In fact, we added support for this functionality in <a href="http://blogs.jetbrains.com/teamcity/2011/10/13/now-we-see-dead-code-too/">TeamCity just over a year ago</a> but it seems that the feature is not widely known, specially by ReSharper users.</p>
<p>The setup itself is extremely simple, and we’re going to walk through it, and additionally add some more goodies in the mix.</p>
<h3>Activating .NET Inspections in TeamCity</h3>
<p>Adding ReSharper inspections to the build process is merely adding the Build Step named <strong>Inspections (.NET)</strong><em>.</em> The only parameter required is the Visual Studio Solution file</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image.png?w=669&#038;h=702" alt="image" width="669" height="702" /></p>
<p>If we do not specify a <strong>Custom settings profile path</strong>, TeamCity takes the default ReSharper settings for code inspections. However, we can configure these to match our own/teams criteria. This is done via <strong>Options | Inspection Severity</strong>. We can change a specific setting severity, for instance, that of using <em>String.IsNullOrEmpty </em></p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image1.png?w=507&#038;h=174" alt="image" width="507" height="174" /></p>
<p>and save the settings to the Team Shared file. This then saves the settings in a file named <em>{Solution}.sln.DotSettings</em> which is normally checked in to source control so that it automatically applies to other team members when the solution is opened in Visual Studio. We can use this same settings file to indicate custom inspection settings for TeamCity</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image2.png?w=629&#038;h=104" alt="image" width="629" height="104" /></p>
<h3>Analyzing results</h3>
<p>When the build step runs, TeamCity generates a navigable report for us to analyze inspection results</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image3.png?w=695&#038;h=633" alt="image" width="695" height="633" /></p>
<p>We can navigate through the inspections for the entire project or a specific namespace. Inspections are grouped by Category, Issue Type and the corresponding files on the right pane. We can even navigate to the actual file by clicking on the line number. For this though, we need to have Visual Studio and the TeamCity plugin for Visual Studio installed (if you do not, clicking on the link will prompt you with a dialog box to download and install the plugin).</p>
<p><em>The checkbox <strong>Inspections with new problems only </strong>is used to highlight only new issues since the last build run. The numbers in bracket (+1 –1) are the variance since the last run. </em></p>
<h3>Taking action based on inspection severity</h3>
<p>One of the main benefits of adding inspections on the server-side is to put some level of code quality in place, whereby we can have the build process take action based on a series of conditions. For instance, we might like to have a build fail if too many warnings or errors are detected.</p>
<p>Under <strong>Build Failure Conditions </strong>in the Project Configuration window, we can add a new Build failure condition:</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image4.png?w=444&#038;h=293" alt="image" width="444" height="293" /></p>
<p>We select <em>Fail build on metric change </em>and then indicate whether we want a build to fail based on warnings or errors. In our case we’re going to select errors and have it fail if it is more than one.</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image5.png?w=612&#038;h=260" alt="image" width="612" height="260" /></p>
<p>It should be apparent that if we want inspections to have an impact on the status of our build, that is, have a build fail, we can only do so based on Warnings or Errors. Therefore, Hints and Suggestions cannot be used. As such, when configuring inspections severity in ReSharper, we should take this into account.</p>
<p>If we now run our build again, it should fail as the number of errors are greater than one. Below is the output of the same input and inspections, but one run with the Build failure condition and the other without it.</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image6.png?w=649&#038;h=54" alt="image" width="649" height="54" /></p>
<h3>Checking for copy/paste code</h3>
<p>Although strictly speaking, this isn’t related to ReSharper, but since we’re talking about code quality in the build process, it makes sense to also mention that TeamCity can check for code duplication.</p>
<p>Much like before, activating code duplication is simply a matter of adding a new build step, namely <strong>Duplicates finder (.NET)<em>.</em> </strong>We can indicate the folders to ignore, whether we want to take into account namespaces, type names, as well as a few other options.</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image7.png?w=716&#038;h=702" alt="image" width="716" height="702" /></p>
<p>The output is a nicely formatted navigable screen which allows us to go through the different files and see a side-by-side comparison of what TeamCity has detected as duplication (resized below for space limitations)</p>
<p><img style="margin:10px 0 0;display:inline;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image8.png?w=968&#038;h=524" alt="image" width="968" height="524" /></p>
<p>And as expected, we can also fail the build if we have too many code duplicates</p>
<p><img style="margin:10px auto 0;display:block;float:none;" title="image" src="http://hhariri.files.wordpress.com/2012/10/image9.png?w=613&#038;h=261" alt="image" width="613" height="261" /></p>
<h3>Summary</h3>
<p>It is refreshingly simple to add code quality detection features to the build process and have a build fail if something that shouldn’t be in production code slips through. The next step would be to provide Custom Patterns, which currently are not supported. If you feel this is a feature you’d like, <a href="http://youtrack.jetbrains.com/issue/TW-23996">let us know</a>, and as always, any and all feedback is welcome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2793/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2793/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2793&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/10/10/resharper-on-the-server-detecting-code-issues-in-the-build/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/10/image9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>TDD: your insurance policy</title>
		<link>http://hadihariri.com/2012/10/01/tdd-your-insurance-policy/</link>
		<comments>http://hadihariri.com/2012/10/01/tdd-your-insurance-policy/#comments</comments>
		<pubDate>Mon, 01 Oct 2012 14:58:09 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2771</guid>
		<description><![CDATA[Every now and again I read a post or comment around the topic of TDD and how it constitutes a somewhat futile effort. Forgetting for a moment TDD, let me say a few words around unit testing. I&#8217;m not going to argue or layout the benefits of why putting in place an automated test system [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2771&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Every now and again I read a post or comment around the topic of TDD and how it constitutes a somewhat futile effort. Forgetting for a moment TDD, let me say a few words around unit testing.</p>
<p>I&#8217;m not going to argue or layout the benefits of why putting in place an automated test system for your code is a good idea. I think we are well beyond that discussion and most of us accept it. As such, let us assume that we have unit tests.</p>
<h3>Test First or Test After</h3>
<p>In order to get these unit tests in place, we have to write them. Here we have two different approaches: test first or test after. In other words, we can either write code and then test or write a test and then implement the code.</p>
<p>With the first approach, that is, writing tests after writing the code, we not only face the challenge of writing a test for something that we perceive as &#8216;working&#8217;, but we also run the risk of creating code that is somewhat hard to test. As the project progresses and the deadlines approach, we tend to drop or &#8216;defer&#8217; some tests and start to rush more into getting code out the door. After all, what is a perfectly tested codebase if it is not shipped?</p>
<p>What potentially ends up happening, which I&#8217;ve seen far too many times, is that we never get round to implementing the missing tests, much like we do not normally go back and pay for technical debt. And of course, this means that our code is at a higher risk of malfunctioning and ultimately costing us money.</p>
<p>If we take a test first approach, we are forced to write a test prior to writing the code. As such we have the test in place. We don&#8217;t need to come back later after writing the code to write the test. In addition, since we write the tests first, we can immediately solve any issues that lead to untestable code, after all, we&#8217;re writing the code we want to test, so why write it in a way that is not testable if we know beforehand? It&#8217;s not like we have written all the code, then come to test it and realized, oops! Yet this is something that does occur in test after approaches and often requires even more effort and thus easier to &#8216;justify&#8217; skipping a test or two.</p>
<p>Taking the TDD route, we have less chances of ending up with code that is not tested. We have less risks of leaving a test for later, a moment that never arrives.</p>
<p>You could say that it&#8217;s a matter of discipline, that just like we commit to TDD and always writing tests first, we can also commit to writing tests after. And I agree, we can. But reality shows that we don&#8217;t. Psychologically, there is less chances of us writing a test for something that is &#8216;working&#8217; than for something that is not.</p>
<h3>TDD as an insurance you took out</h3>
<p>Now the reality is that TDD isn&#8217;t actually about testing as much as it is about design. It is not about test first versus test after. It is about trying to better understand a system, about trying to break things down into pieces our mind can cope with (divide and conquer). It is about specifications. And while I dislike using the word side-effect, the unit tests that emerge from TDD not only guarantee the correct implementation (different to understanding correctly the specification) but also, and more importantly, serve as a regression test.  You could therefore think of a unit test in TDD as having three different life forms.</p>
<p>This regression testing is where the analogy to insurance policies comes in, cause even f you don&#8217;t believe in the benefits of TDD as a whole, at least consider that it is like that insurance policy which you did take out on the first day, as opposed to the one you kept delaying until it was too late.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2771/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2771&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/10/01/tdd-your-insurance-policy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>The Kotlin Journey Part IV: Adding functionality</title>
		<link>http://hadihariri.com/2012/09/27/the-kotlin-journey-part-iv-adding-functionality/</link>
		<comments>http://hadihariri.com/2012/09/27/the-kotlin-journey-part-iv-adding-functionality/#comments</comments>
		<pubDate>Thu, 27 Sep 2012 11:45:27 +0000</pubDate>
		<dc:creator>Hadi Hariri</dc:creator>
				<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Kotlin]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2751</guid>
		<description><![CDATA[This is a multi-part series on Kotlin, a new statically typed language from JetBrains targeting the JVM and JavaScript Part I: Getting things set up Part II: A primer on classes Part III: Wrapping up classes Part IV: Adding functionality All the goodies you&#8217;d expect Up to now we&#8217;ve seen how to work with classes [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2751&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is a multi-part series on Kotlin, a new statically typed language from JetBrains targeting the JVM and JavaScript</p>
<p><a href="http://hadihariri.com/2012/02/17/the-kotlin-journey-part-i-getting-things-set-up/">Part I: Getting things set up</a><br />
<a href="http://hadihariri.com/2012/03/10/the-kotlin-journey-part-ii-a-premier-on-classes/">Part II: A primer on classes</a><br />
<a href="http://hadihariri.com/2012/07/21/the-kotlin-journeypart-iii-wrapping-up-classes/">Part III: Wrapping up classes</a><br />
<a href="http://hadihariri.com/2012/09/27/the-kotlin-journey-part-iv-adding-functionality" target="_blank">Part IV: Adding functionality</a></p>
<h3>All the goodies you&#8217;d expect</h3>
<p>Up to now we&#8217;ve seen how to work with classes and only slightly touched on the subject of functions in Kotlin, reason being that functions deserve their own section, as they play a very important role in Kotlin and expose a lot of the potential the language offers. Let’s dive in a bit more now.</p>
<p>Functions in Kotlin are declared using the keyword <em>fun</em>. By default, if we do not specify a return type, <em>Unit </em>is returned which would be the equivalent of <em>void, </em>although we do not need to explicitly indicate it. Parameters, much like constructors of classes that we’ve already seen, follow the Pascal convention of name colon type.</p>
<p>If you&#8217;re coming from a C# background, expect pretty much everything you have in C#, including:</p>
<p><strong>Optional parameters</strong></p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image5.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb5.png?w=410&#038;h=124" alt="image" width="410" height="124" border="0" /></a></p>
<p>The last parameter being passed in to the <em>logMessage </em>function is optional (like C# they always need to be at the end). If nothing is supplied, a default value is used. In this case, it’s using the current date time by instantiating an instance of Date.</p>
<p><strong>Named parameters</strong></p>
<p>We can also call functions using names to reference parameters, making the order of which we pass arguments in irrelevant</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image6.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb6.png?w=414&#038;h=90" alt="image" width="414" height="90" border="0" /></a></p>
<p><strong>Variable number of parameters</strong></p>
<p>If we want to pass in a random number of arguments, we can prefix a parameter with the keyword <em>vararg </em>which by default creates an array of the type of the parameter</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image7.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb7.png?w=250&#038;h=164" alt="image" width="250" height="164" border="0" /></a></p>
<p>As such the example above would be an array of Integers.</p>
<p><strong>Statics in Kotlin</strong></p>
<p>The concept of static methods doesn’t really exist in Kotlin as functions can be declared as top-level. As such, we can define a series of functions in a module and then have access to all of them by merely referencing the module. Therefore there’s no real need for statics. We can also declare one function local to another, much like in Pascal.</p>
<p><strong>Reducing amount of code with single-line functions</strong></p>
<p>If a function consists of single line of code, whether or not it returns a value, we can omit curly braces and reduce a little bit the number of characters. For instance, the previous <em>logMessage </em>could be written out as:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image8.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb8.png?w=445&#038;h=40" alt="image" width="445" height="40" border="0" /></a></p>
<p>The compiler can infer the return type, so even if we were to return a value, we wouldn’t need to explicitly declare it.</p>
<h3>enabling fluent code</h3>
<p>Kotlin allows us to reduce some of the noise that is usually associated with certain programming languages, by offering a series of features that enable us to write code that is somewhat a bit more fluent, or closer to natural languages.</p>
<p>To begin with, any function that takes two parameters can be called in infix notation. This means that we can do things such as:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image9.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb9.png?w=380&#038;h=124" alt="image" width="380" height="124" border="0" /></a></p>
<p>where <em>plus </em>and <em>equals </em>are functions that take two arguments (and defined as single-line for brevity):</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image10.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb10.png?w=270&#038;h=57" alt="image" width="270" height="57" border="0" /></a></p>
<p><a href="http://kotlin.jetbrains.org" target="_blank">Kotlin</a> also allows extensions functions, thus allowing us to extend a class with functionality without having to inherit from it. If you’re a C# programmer, you’re familiar with extension methods. Only difference is that in Kotlin, the declaration is more succinct:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image11.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb11.png?w=167&#038;h=59" alt="image" width="167" height="59" border="0" /></a></p>
<p>This adds a new function to the String class called <em>console </em>(takes no parameters). Inside the function, we can refer to the object itself using the keyword <em>this</em>. Notice how as opposed to C#, we do not have to create a static class, a static function, or pass <em>this </em>as the first parameter.</p>
<p>And of course, extension functions can also be called using infix notation. By defining the extension <em>then </em>to be:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image12.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb12.png?w=236&#038;h=82" alt="image" width="236" height="82" border="0" /></a></p>
<p>we can write code like this:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image13.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb13.png?w=269&#038;h=31" alt="image" width="269" height="31" border="0" /></a></p>
<p>not that I’m saying we should write the code above, but you get the point. It opens up many possibilities.</p>
<h2>Adding function literals and high-order functions to the mix</h2>
<p>Functions in Kotlin can take other functions as parameters. Combined with function literals (or lambda expressions), it allows us to write the following:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image14.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb14.png?w=361&#038;h=165" alt="image" width="361" height="165" border="0" /></a></p>
<p>Here we have a function <em>callFunctions</em> that takes as parameter a function that takes itself two parameters (of type Int) and returns an Int. We then call this function in two different ways: passing in as parameter a function previously declared (<em>sumNumbers</em>) or passing in a function literal.</p>
<p>Last but not least, we can even define extension functions using function literals:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/09/image15.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://hhariri.files.wordpress.com/2012/09/image_thumb15.png?w=385&#038;h=68" alt="image" width="385" height="68" border="0" /></a></p>
<p>Combining all of these things, we can then start <a href="http://confluence.jetbrains.net/display/Kotlin/Type-safe+Groovy-style+builders" target="_blank">building nice, fluent and statically typed DSL’s</a></p>
<h3>Summary</h3>
<p>We’ve seen a brief overview of some of the functionality Kotlin provides with functions (pun not intended). There are quite a few other important features such as the ability to override operators using conventions (i.e. to override +=, define a function called <em>plusAssign</em>), as well as some the ability to drop braces when functions only have one arguments, inline functions, local functions etc. For more information about these and other features, <a href="http://confluence.jetbrains.net/display/Kotlin/Functions" target="_blank">check out the function section</a> on the documentation page.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2751/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2751&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/09/27/the-kotlin-journey-part-iv-adding-functionality/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb11.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb12.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb13.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb14.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/09/image_thumb15.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
