<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sitati Kituyi on Medium]]></title>
        <description><![CDATA[Stories by Sitati Kituyi on Medium]]></description>
        <link>https://medium.com/@sitatik?source=rss-9da10d79d818------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3S19ksh84-K4sZXR.jpeg</url>
            <title>Stories by Sitati Kituyi on Medium</title>
            <link>https://medium.com/@sitatik?source=rss-9da10d79d818------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:48:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sitatik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Groovy developer peeks enviously at Kotlin]]></title>
            <link>https://medium.com/@sitatik/a-groovy-developer-peeks-enviously-at-kotlin-77da4e3cccaa?source=rss-9da10d79d818------2</link>
            <guid isPermaLink="false">https://medium.com/p/77da4e3cccaa</guid>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Sitati Kituyi]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 08:07:58 GMT</pubDate>
            <atom:updated>2018-09-10T08:08:22.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*ov0agTUyIUKOJ-qJZ665jA.jpeg" /></figure><p>I’ve spent years working in the <a href="http://groovy-lang.org/">Groovy</a> world, mostly using the Grails 2.x web framework but also as my go-to scripting language. It’s hard to objectively list pros/cons of a language without choosing another as a baseline, and in early days of Groovy it was mostly compared to using Java. The benefits stated were full interoperability with Java but with friendlier syntax, type inference, easy type extension, and earlier adoption of FP features like first-class function support, higher-order functions.</p><p>Fast forward just over a decade, and Groovy’s biggest successes are the now ubiquitous Gradle build automation tool and its use in Jenkins scripting. However <a href="https://github.com/benfred/github-analysis">by 2018</a> Groovy’s usage had been eclipsed by Scala (another JVM-backed language from the early 00s but with a different ethos), but also notably by a much newer kid on the block, Kotlin.</p><p>I‘ve been spending some time getting started with Kotlin and thought I’d share my notes publicly, for anyone else on my “learning Kotlin from Groovy” journey. Kotlin is so close to Groovy in both syntax and ethos that contrasting it to groovy is a tempting (and hopefully useful) way to get started for those who already know some Groovy.</p><p>Note: aside from this intro, these notes are copied from my private notepad, apologies if they’re hard to follow. I’ll keep updating this as I learn more into-level Kotlin.</p><h4>val and var</h4><p>var is variable: can change. val is a immutable value: once set, never changes</p><h4><strong>null-safe by default</strong></h4><p>Kotlin won’t let you have null values unless you explicitly state that it can be null by using a question mark in the declaration, e.g.</p><pre>var a: Int? = methodThatMayReturnNull()<br>fun methodThatMayReturnNull() : Int?<br>// You can use null-safe dereferencing like in groovy:<br>var b = a?.toDouble()</pre><p>Unlike groovy, elvis operator can be used on left-hand-side. If null, rhs expression is skipped</p><pre>person?.father?.job = getPersonJob() // not invoked if null on lhs</pre><p>Can cast to the non-null by using elvis operator</p><pre>val a: Int? = methodThatMayReturnNull()<br>var b: Int = a ?: 0</pre><p>Can do type-safe casting, to avoid class cast exception. You get null if it could not be cast</p><pre>var maybeANumber : String = “notanumber”<br>var b: Int? = maybeANumber as? Int</pre><p>The let operator lets you perform function only where non-null is found.</p><pre>var myStuff : List&lt;Int?&gt;= listOf(1, null, 3, null, 5)<br>for(item in myStuff) {<br>    item?.let { println(“it”) } // will only print 1, 3 and 5<br>}</pre><p>Last ditch: you can force casting, and get NPE if it fails</p><pre>var b: Int = a !! // throws NPE if a is null</pre><h4><strong>tuples</strong></h4><p>Comes with Pair and Triple tuples built in.</p><pre>var (a, b) = Pair(1,2)</pre><h4><strong>collection operators</strong></h4><p>associateBy is same as groovy’s .collectEntries:</p><pre>(1..10).associateBy( {it}, {it * 10 }) // gives you a map where entry with key 1 has value 10</pre><p>forEach is same as groovy’s .each</p><p>filter is same as groovy’s findAll</p><p>reduce:</p><pre>(1..3).reduce { x, y -&gt; x+y } == 6</pre><p>fold:</p><pre>(1..3).fold(100) { x, y -&gt; x+y) == 106</pre><h4><strong>when</strong></h4><p>This is Kotlin’s “case statement”:</p><pre>when(age) {<br>  0,1,2,3,4,5 -&gt; println “Underage”<br>  6 -&gt; println “require parent supervision”<br>  in 7..17 -&gt; println “require parent letter”<br>  else -&gt; println “approved”<br>}</pre><h4><strong>higher order functions</strong></h4><p>Functions that either take other functions as arguments, or return other functions.</p><p>reduce (in examples above) is an example of a higher order function, signature would look something like:</p><pre>fun reduce(theFunc: (x: Int, y: Int) -&gt; Int): Int<br>/* <br>  i.e. it’s a function that returns an integer, and takes as an argument a function that takes two integers and returns an integer */</pre><p>An example of the other kind of higher-order function (that itself returns a function):</p><pre>fun createMultiplier(x: Int): (Int) -&gt; Int = { y -&gt; x * y }<br>var multiplyByThree = createMultiplier(3)<br>multiplyByThree(5) == 15</pre><h4><strong>open keyword</strong></h4><p>Classes and their members are implicitly final (cannot be extended) unless the open keyword is used</p><pre>open class Animal(val name: String, var legCount: Int) { … }</pre><pre>class Dog(name: String, legCount: Int, val colour: String): Animal(name, legCount)</pre><h4><strong>override</strong></h4><p>In Kotlin this is not an annotation but a keyword:</p><pre>class Dog(…) {<br>  override fun makeNoise() {<br>     println(“WOOF!”)<br>  }<br>}</pre><h4><strong>Delegates.lazy</strong></h4><p>Reduces boilerplate in providing singletons. Where in Java you’d have a getX() that checks if private instance exists and initialises, in Kotlin you can use</p><pre>private val foo by Delegates.lazy { Foo(getContext()) }</pre><p>When foo is first accessed, the Foo(getContext()) constructor gets invoked, and all subsequent references get the foo that was already initialised. This is also thread-safe.</p><h4><strong>class init function</strong></h4><p>Can hold validation rules for a class:</p><pre>open class Animal(val name: String, var legCount: Int) {<br>  init {<br>    require(legCount &gt;= 0) // InvalidArgumentException thrown for any negative legCount<br>  }<br>}</pre><h4><strong>object vs class (Object Declaration)</strong></h4><p>Kotlin has an ‘object’ keyword that is similar to class, but only allows one instance of that entity to exist, i.e. it’s a shortcut to creating singletons.</p><pre>// Where in Java you’d use...<br>class CardFactory {<br>  public static CardFactory getInstance() { … }</pre><pre>  public Card getCard()</pre><pre>}<br>…<br>CardFactory.getInstance().getCard()</pre><pre>// ...in Kotlin you can do<br>object CardFactory {<br>  fun getCard() : Card<br>}<br>…<br>CardFactory.getCard() // note that we accessed the object by name (not instance name), but still got instance</pre><p>In Java speak this is sort of like a singleton, and/or a class with all-static members</p><h4><strong>Companion Object</strong></h4><p>If you have an object declaration <em>inside</em> another class, adding the companion keyword makes it a publicly accessible singleton. For instance:</p><pre>class MyClass {<br>  companion object Factory {<br>    fun create(): MyClass = MyClass()<br>  }<br>}<br>val instance = MyClass.create()<br>// note that create method is a member of the companion object of MyClass, but is accessed this way</pre><p>This is somewhat similar to static methods in Java, but a key difference is that this can be instances of real objects at runtime and implement interfaces, for example.</p><pre>interface Factory&lt;T&gt; {<br>  fun create(): T<br>}</pre><pre>class MyClass {<br>  companion object : Factory&lt;MyClass&gt; {<br>    override fun create(): MyClass = MyClass()<br>  }<br>}</pre><h4><strong>@JvmStatic</strong></h4><p>For certain scenarios of JVM operability, you may need to have companion objects compiled to static methods/fields. To do this, the @JvmStatic annotation is put on a companion object</p><h4><strong>Object Expressions</strong></h4><p>Like Java’s anonymous inner classes. Just like Java’s anonymous inner classes, code in object expressions can access variables from the enclosing scope. (Unlike Java, this is not restricted to final variables.)</p><pre>open class A(x: Int) {<br>  public open val y: Int = x<br>}</pre><pre>interface B { … }</pre><pre>val ab: A = object : A(1), B {<br>  override val y = 15<br>}<br>// ab here is an anonymous object that extends A and implements B</pre><h4><strong>The :: operator</strong></h4><p>Functions are first-class, so can be assigned to vars and vals like in Groovy. To refer to a function that was declared as fun rather than var/val, use the :: operator (i.e. similar to the `&amp;` operator in groovy).</p><pre>val f1 = {i:Int -&gt; i+1}<br>fun f2(i:Int) = i + 1<br>var f = f1<br>f = ::f2</pre><h4><strong>inline modifier</strong></h4><p>When defining a function, if you add the ‘inline’ keyword, then at compile time it is declared inline at the point in code where it is used, as opposed to using an anonymous class. This avoids the issue faced in Groovy where permgen space (java &lt;=7) is badly affected by use of multiple closures, especially in a loop. Inlining a function causes the size of generated code to grow, but pays off for performance by using less memory, which is especially beneficial when the inner function is called in a loop.</p><h4><strong>package-level function</strong></h4><p>Kotlin allows you to declare a function outside of a class, as a top-level function in that particular package. In practice you might put this in a source file that contains a class, but best practice says to create source files named for what the collection of functions do, and avoid using ‘util’ in the name.</p><p>Conceptually this is similar to Java’s static methods, but cleaner: ‘static’ methods in Java are a bit of a hack, because they bind functions to class names despite not being encapsulated by objects of that class. If you do want the functions to be static but contained in a class, use companion objects.</p><h4>Extension methods</h4><p>Similar to metaclassing in groovy, this allows addition of new functions to existing classes. In Kotlin (much like in C#) this is done directly on the class.</p><pre>fun String.getLastCharacter(): Char = get(length — 1)</pre><h4>Other useful resources</h4><ul><li>Kotlin conventions: <a href="https://kotlinlang.org/docs/reference/coding-conventions.html">https://kotlinlang.org/docs/reference/coding-conventions.html</a></li><li>“From Groovy to Kotlin”: <a href="https://dkandalov.github.io/groovy/kotlin/2016/06/06/From-Groovy-to-Kotlin.html">https://dkandalov.github.io/groovy/kotlin/2016/06/06/From-Groovy-to-Kotlin.html</a></li><li>Groovy vs Kotlin: <a href="https://causecode.com/kotlin-vs-groovy/">https://causecode.com/kotlin-vs-groovy/</a></li><li>A month of JVM langs: <a href="https://zeroturnaround.com/rebellabs/a-month-of-jvm-languages-groovy-ceylon-kotlin-and-scala/">https://zeroturnaround.com/rebellabs/a-month-of-jvm-languages-groovy-ceylon-kotlin-and-scala/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77da4e3cccaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sokoban, with Maths]]></title>
            <link>https://medium.com/@sitatik/sokoban-with-maths-9e89ecc38b28?source=rss-9da10d79d818------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e89ecc38b28</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[libgdx]]></category>
            <dc:creator><![CDATA[Sitati Kituyi]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 15:26:48 GMT</pubDate>
            <atom:updated>2018-08-16T15:26:48.693Z</atom:updated>
            <content:encoded><![CDATA[<h4>The making of my first Android game. <a href="https://play.google.com/store/apps/details?id=com.sitati.sandbox.android">Get it free on Google Play</a></h4><p><a href="https://en.wikipedia.org/wiki/Sokoban">Sokoban</a>, aka ‘warehouse keeper’, is a 2d puzzle game where you have to push moveable crates into designated slots. The player pushes a character around (often illustrated as a warehouse worker or a forklift) and get the crates into position. It’s a simple game mechanic but one that allows for a wide range of level difficulties — the challenge comes in when certain actions would ‘box you in’, preventing you from completing subsequent goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*7UV90CmyVG2Z4HRAeHu3sg.gif" /><figcaption>Carloseow at English Wikipedia [CC BY 3.0 (<a href="https://creativecommons.org/licenses/by/3.0">https://creativecommons.org/licenses/by/3.0</a>)], via Wikimedia Commons</figcaption></figure><p>The idea to add Maths to Sokoban is one I’d played with for a while, and I implemented during 10% time at my previous job at <a href="http://frontlinesms.com/">FrontlineSMS</a>. The first prototype was a <a href="http://lesikidev.com/maths-sokoban/">simple browser-based implementation</a>, but this helped a lot for level design later down the road: building &amp; testing levels in the browser was a much quicker feedback loop than doing so directly on Android.</p><p>Excited by the prototype and feedback I got from friends on the handful of hard-coded levels I provided, I went ahead and built a <a href="http://lesikidev.com/sokoban-builder/">level designer tool</a>. This simply pushes a URL parameter to the level playing tool, instructing it how to lay out the blocks in the grid.</p><p>I had long intended to port the game to Android and ultimately got round to building it over the past year. With simple grid-based game mechanics there’s always the temptation to home-brew your own game engine using the native API, but I instead took the opportunity to try out a few Android game engines. Ultimately, I settled on <a href="https://libgdx.badlogicgames.com/">Libgdx</a>, because it’s free, cross-platform and has a very intuitive 2d rendering API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*WmyIZZeqshos3G3lu_LUEA.gif" /><figcaption>Screen capture of a basic level from my Android game</figcaption></figure><p>The final step in gluing it all together was to make a JSON format for describing Sokoban levels that could tie my web-based builder and Android game together. Only later did I discover that Sokoban markup languages already exist — it would have been a good move to go with one of these instead and extend it to include my maths.</p><p>The game is now <a href="https://play.google.com/store/apps/details?id=com.sitati.sandbox.android">live in the play store</a>. When testing through I actually got stumped on some of the levels I had designed weeks earlier, so I wrote <a href="https://gist.github.com/lesiki/ccd700d931c15048eb8725b75629a213">a little Groovy script</a> to help generate potential solutions. It takes the list of number blocks and available operations as well as the target number as inputs, and spits out different permutations of those operations and operands that arrive at the target.</p><p>Next steps: I want to keep adding levels to it. My uncle (Maths professor with the convenient hobby of making math-inspired Android game) suggested building an algorithm for procedural level generation, which sounds like a fun tangential project. I’ve done a bit of research into this, there’s some interesting info on approaches and metrics for evaluating levels here.</p><p><a href="https://www.youtube.com/watch?v=ljj6rAaM4A8">https://www.youtube.com/watch?v=ljj6rAaM4A8</a></p><p>My uncle suggests procedural generation is as simple as “make a version of the game that drags instead of pushing”, but this paper suggests it’s a bit more involved than that!</p><p>Hope you enjoy the game.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e89ecc38b28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 5to8 Newsletter]]></title>
            <link>https://medium.com/@sitatik/the-5to8-newsletter-f3bb3db7d01d?source=rss-9da10d79d818------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3bb3db7d01d</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[nairobi]]></category>
            <category><![CDATA[newsletter]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Sitati Kituyi]]></dc:creator>
            <pubDate>Wed, 20 Sep 2017 17:39:48 GMT</pubDate>
            <atom:updated>2017-09-20T17:39:48.197Z</atom:updated>
            <content:encoded><![CDATA[<p>5to8 is a newsletter for developers. There’s plenty of quality engineering and engineering writing in Kenya, the motivation here is to draw more eyes to the content that’s already being put out, and occasionally share an upcoming event or two.</p><p>We’ll keep it simple: a few (5–8) links each issue, and for now we’ll do one every two weeks, though if/when we’re inundated with quality content suggestions, this could become weekly.</p><p>We’ll highlight any articles written by any of curators or their colleagues, in interest of transparency. You can see the list of curators on <a href="http://5to8.co.ke/">http://5to8.co.ke</a></p><p>Got a link you want to contribute? Please drop it on <a href="http://bit.ly/share5to8">http://bit.ly/share5to8</a></p><p>Know some good Kenyan tech content and want to help us curate? Email Sitati at <a href="/service/mailto:hello@5to8.co.ke">hello@5to8.co.ke</a> to get a Slack invite.</p><p>Thanks for checking it out and hope you find it useful.</p><p>Team 5to8</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3bb3db7d01d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>