<?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 Nicolay Hvidsten on Medium]]></title>
        <description><![CDATA[Stories by Nicolay Hvidsten on Medium]]></description>
        <link>https://medium.com/@nicohvi?source=rss-1fa8d55ef198------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*G6Dz0CkoZyeITCFn.png</url>
            <title>Stories by Nicolay Hvidsten on Medium</title>
            <link>https://medium.com/@nicohvi?source=rss-1fa8d55ef198------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:39:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicohvi/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[Rails like you mean it]]></title>
            <link>https://medium.com/@nicohvi/working-with-rails-like-you-mean-it-12299d1953af?source=rss-1fa8d55ef198------2</link>
            <guid isPermaLink="false">https://medium.com/p/12299d1953af</guid>
            <dc:creator><![CDATA[Nicolay Hvidsten]]></dc:creator>
            <pubDate>Thu, 23 Oct 2014 09:57:02 GMT</pubDate>
            <atom:updated>2014-10-28T07:14:56.727Z</atom:updated>
            <content:encoded><![CDATA[<p>Rails is amazing. Not only does it let you utilise what is undoubtably the sexiest programming language on earth (name omitted due to obviousness) — it also lets you be productive in that language. Totes amaze.</p><p>If you’ve never heard the gospel according to Heinemayer Hansson I’m afraid this article isn’t for you. This is the first post in a series covering how <em>I </em>work with Ruby on Rails, and it assumes that you have some experience with Rails. If you do not, <a href="http://tilde.club/~waxpancake/running/">then there really are better ways to spend your time.</a></p><p>This series will tackle all kinds of subject matter: which programs I use to edit and test code; how I structure code running client-side; which gems I employ for solving common problems; which application servers I prefer (hint: It’s Passenger. Not the singer-songwriter, although he’s pretty cool as well.) and how I set them up with nginx/apache; which bear gifs I prefer to leave in as easter eggs — the list goes on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*Nb2OEr0dljhB4R7RLGQpUA.gif" /><figcaption>This is the preferred bear gif, obviously.</figcaption></figure><p>My approach is obviously just one of many, but it has always been my opinion that if you’ve found something that makes you happy you’re obligated to share it with the world.</p><p>Who knows, it just might work for someone else as well.</p><p>Anyway, I’ll kick the series of covering the <strong>sexiest </strong>topic of them all: testing.</p><h4>Getting off on the right foot</h4><p>We’ve all been there: Snoozing 5 more minutes (actually make that 15), eating that last piece of chocolate cake (and hate your diabetes 2-ridden self afterwards) even if you <a href="http://www.urbandictionary.com/define.php?term=chocolate%20face">literally have chocolate all over your face</a> (don’t click that), put off writing the relevant test until you’ve completed that final finicky part of the controller action you’re working on — actually, you’ll test it sometime next week, when the weather’s nicer and the omens more favorable.</p><p>Dude, it’s okay. But also — dude, you can do better.</p><p>Writing tests is important, pretty much everyone agrees on that point (and if you don’t, odds are you’re not reading this) — but unless you’ve hard-wired your brain into writing them (by making a habit out of it) it’s hard to motivate yourself to actually write them, even if you know damn well how important they are. Why?</p><p>Well, unfortunately <a href="http://www.petrikainulainen.net/software-development/processes/the-cost-of-context-switching/">brains are assholes</a> (no medical implications intended), and context switching is <em>really hard</em>. When you’re coding an exciting new feature (if you’re like me) <a href="http://m.memegen.com/2ipxkl.jpg">you really want to keep going </a>. <em>Flow </em>is easily induced while programming — “Hey man, I know Michael is bleeding from his ears, but he’s wired in so there’s no talking to him” — and not easily broken out of.</p><p>TDD is a good way to keep the context switching of testing and coding at a constant pace, but it requires a lot of discipline to maintain if you’re not pairing or a <a href="https://twitter.com/r00k">programming god</a>.</p><p>If you should find yourself stranded in an ocean of code in a small skiff of tests, don’t feel too bad — <em>everyone </em>has sinned against writing good tests for their code. And there is always a way to get back to shore.</p><blockquote>Everyone sucks.<br>- Me</blockquote><p>If you’re a regular mortal programmer, much like myself, a situation like this isn’t uncommon. A good way to avoid being stuck in the middle of my imaginary code ocean however, is to <strong>minimise the context switch between coding and testing.</strong> “But how?” you may ask aloud, attracting stares from co-workers for talking at your screen.</p><p>First of all, you need a good testing framework.</p><h4>Picking the right tools</h4><p>I’m a big fan of <a href="http://rspec.org/">rspec</a>, it provides a lot of great short-hands, has many <a href="https://github.com/jnicklas/capybara">friends</a> it plays well with and it avoids the verbose mess that is cucumber.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e527586cd6b067abac61d8917619de2/href">https://medium.com/media/8e527586cd6b067abac61d8917619de2/href</a></iframe><p>I mean, just look at how pretty it is!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*vlKhS_YEhV9pRwCmVVeHaw.png" /><figcaption>Glorious.</figcaption></figure><p>I <strong>really </strong>enjoy working with rspec, and a tool you enjoy working with is a good first step. When it feels like you’re writing code, <a href="http://cukes.info/">and not an essay</a>, it’s easier to switch contexts.</p><p>Even if I’m tooting rspec’s horn (man, idioms are fun) — what truly matters is that you find a testing framework <strong>you like.</strong> For me rspec is that framework (many developers love MiniTest, for example).</p><p>Once you have your testing framework of choice, we can <em>really</em> get down to business.</p><h4>Rspec and friends</h4><p>First off, wouldn’t it be sweet to automatically run your tests while you’re coding — but in the background? Is this a leading question? Yes. Yes, it is.</p><p><a href="https://github.com/guard/guard">Guard</a> watches for changes in certain files and then runs a command you decide. So, if you make it watch your <em>spec</em> files (and associated controllers/models as well if you want, which you do), you can <em>automatically</em> run your specs whenever a relevant file changes.</p><p>This is an extremely helpful way to avoid <a href="http://i.imgur.com/fprOm49.webm">blowing your feet off</a>.</p><p>Didn’t dare click that link did you? Good on you. If you did though, wasn’t that dog/table hilarious? Man, dogs are funny.</p><p>The granularity of the specs run is entirely up to you — by default it runs the single spec file you’re either working in, or the ones who are associated with the model/controller you’re modifying. You can even run single specs identified by line numbers if you’re really OCD about it.</p><h4>Spring</h4><p>Spring loads your rails application in memory (and keeps it there). This makes running your own local webserver using the good ol’ <strong>rails s </strong>command much faster than usual. It also significantly speeds up your test suite.</p><p>Since you no longer have to interpret and run your application codebase from scratch each time you run a test spec, but rather use the in-memory instance of your application, testing can be <strong>really fast.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*u2CGO0jCE0LImWNALR6EwA.png" /></figure><p>This is by no means an extensive test suite (only 34 specs after all), but it tests 98.83% of the code-base of the project, and in less than two seconds. Pretty sweet!</p><p>When you can write tests using a tool you like (regardless of preference), and run them in the background without ever worrying about them <em>while </em>you code features (and complete <strong>all</strong> suites in less than two seconds), the context switch is minimised and incorporating testing in your workflow is <strong>a lot</strong> easier.</p><blockquote>Regardless of <strong>when</strong><em> </em>you write your tests, rspec with spring and guard is a pretty good answer to <strong>how</strong><em>.</em></blockquote><p>Even if you employ these tools, and try your very best to strictly enforce the habit of continuously writing tests (you might even practice TDD if that’s your cup of hot beverage), you might still find yourself immersed in a caffeine-induced coding spree only to snap out of it hours later realising you haven’t written a single test all day.</p><p>Don’t feel bad — you might be stuck in the middle of the ocean again, but this time you’re not in a skiff, you’re in a goddamn cruise liner. And there’s bound to be an open bar somewhere.</p><p>Next time around I’ll dive into how I use these testing tools with the programs I use to stay productive — Vim and Tmux.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12299d1953af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you even AJAX, brah?]]></title>
            <link>https://medium.com/@nicohvi/do-you-even-ajax-brah-b6b2d046c62f?source=rss-1fa8d55ef198------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6b2d046c62f</guid>
            <dc:creator><![CDATA[Nicolay Hvidsten]]></dc:creator>
            <pubDate>Wed, 04 Jun 2014 14:37:13 GMT</pubDate>
            <atom:updated>2014-06-17T13:36:11.084Z</atom:updated>
            <content:encoded><![CDATA[<h4>The ‘X’ stands for Xtreme. </h4><p>If you’re creating a web app these days you’d be hard pressed not to encounter asynchronous programming, either in the form of event handlers, callbacks, promises or what-have-you. It’s essential for providing end users real-time feedback, and the most common way to accomplish it is by using <strong>AJAX </strong>(the technology, not the K-Pop band).</p><p>An unfortunate consequence of this asynchronicity (which is totally a word), however, is that applications tend to get bogged down with an inordinate amount of javascript, the main culprit of which is usually client-side templates and MV* frameworks.</p><p>Last December, 37signals posted a<a href="http://asynchronicity/"> </a><a href="http://signalvnoise.com/posts/3697-server-generated-javascript-responses">blog post</a> about <em>their</em> AJAX approach, which generated a fair bit of responses. Apparently, they use <em>server-generated </em>javascript templates, which are then passed to the user over HTTP and executed client-side. This is quite <a href="http://www.google.com/trends/explore#q=javascript%20mvc">contrary to the norm</a>, and the post did cause some controversy.</p><p>A more common approach, it seems, is to essentially divide your application in <em>two: </em>one client-side application, often using a javascript MV* framework, and one server-side application running on whatever platform you prefer. Said server then returns JSON to any AJAX calls, and the client utilises client-side templating to show the updated data.</p><p>I’m generally not a big fan of this approach as I feel it considerably raises the learning curve (a math-wiz might even say its derivative is <em>doubled ) </em>for any application.</p><p>It also has the unfortunate side effect of enforcing you to create and maintain <em>two </em>sets of templates: one set for client-side, one for server-side, which in my opinion is just inviting trouble. Anyway, whatever doesn’t sink your floatation device, right? Totes.</p><p>Floatation device sinking aside, your choice of application structure <em>will</em> affect how you approach AJAX, and as I stated initially, you’d be hard pressed to create something today without it (unless you’re using something cooler, like <a href="http://www.html5rocks.com/en/tutorials/websockets/basics/">websockets</a> — in which case, good on you, brah).</p><blockquote>Websockets is like that cool guy you knew in school, who smoked cigarettes and got all the chicks.</blockquote><blockquote>-Me</blockquote><p>As stated in the 37signals’ blog post, server-generated javascript templates have some nice benefits, the most important of which (in my opinion) is template re-usage and the obvious code flow. I just love the thought of having <em>one </em>directory structure contain <em>all </em>view logic — no more <em>assets/javascripts </em>induced suicides.</p><p>37signals employs an approach where they store <em>both </em>javascript and HTML templates in the same directory structure though, and I’m not a big fan of this. I prefer to have all templates written in the same language, and keep javascript and server code separate.</p><p>Code speaks louder than at least a couple of words, so rather than try to <em>explain</em> my approach with my limited vocabulary I’ll show you instead, using the same (tastefully upgraded) example as from the 37signals blog post.</p><blockquote>Code speaks louder than at least a couple of words.<br>- Also me</blockquote><h3>Example</h3><ol><li>Using the <em>kitten_mitten</em> template we render the kitten mittens (<a href="https://github.com/haml/haml">haml</a> <strong>&gt;</strong> erb any day of the week).</li></ol><pre>%h1 All kitten mittens<br>-# renders kitten_mittens/_kitten_mitten.html.haml <br>= render @kitten_mittens </pre><p>2. Submitting form through AJAX.</p><pre>= form_for @kitten.kitten_mittens.new, remote: true do |f|</pre><pre># ... </pre><pre>= f.submit &#39;Create kitten mitten!&#39;</pre><p>3. Server creates the message model object.</p><pre># KittenMittensController<br> <br>def create  <br>  kitten = Kitten.find(params[:kitten_id])<br>  @kitten_mitten = kitten.kitten_mittens.build(km_params)<br>  <br>  if @kitten_mitten.save<br>    render @kitten_mitten, layout: false<br>  else<br>    render json: { errors: @kitten_mitten.errors.to_json },<br>           status: 400<br>  end<br>end</pre><p>Now, what’s going on here? For anyone who isn’t familiar with Rails, I simply create a new nested model and attempt to store it to the database. If the model is successfully saved, the application returns the <strong>HTML template representing the model </strong>(the same template called in Step 1), otherwise we return a JSON structure containing the errors.</p><p>This particular step deviates from the approach suggested in the 37signals blog post, mainly because I feel that a separate <em>create.js.haml </em>template is unnecessary.</p><p>“Hold up!” you might say out loud to yourself, attracting awkward stares from others in the room. “Now you’re just returning HTML or JSON, how does the view get updated?” Enter Step 4:</p><p>4. Client-side code handles the returned HTML/JSON</p><pre># An appropriate coffeescript class, like for instance<br># kitten_mittens.js.coffee<br><br>$(&#39;#new_kitten_mitten&#39;).on &#39;ajax:success&#39;, (event, html) -&gt;<br>  # append the new kitten mitten<br>  $(&#39;#kitten-mittens).append(html)<br>  # Be totes amaze.</pre><p>This final step leverages <em>rails_ujs </em>by listening to the events for either <em>success </em>or <em>failure </em>(<em>ajax:error</em>, not shown in this example for brevity) and updates the view accordingly. If I wasn’t using rails I’d (for instance) use <em>promises</em> and update the view in a call to <em>next() </em>instead.</p><p>The main difference between the two approaches is that I use the client-side javascript (which allows me to use <a href="https://medium.com/on-coding/youve-got-some-code-in-your-coffee-bc22a3ea1be3">coffeescript</a>, the best thing since Emma Stone) to handle the response (which would’ve been the case anyway had I chosen the common client-side approach) and I let the server do what its really good at — render templates.</p><p>In my opinion this approach employs the best of both worlds, and avoids cluttering the <em>views </em>directory with javascript templates — separating server code (ruby, in this case) and client code. No racist.</p><p>I want to emphasise that I don’t think an approach with client-side templating and javascript MV* frameworks is necessarily <em>bad, </em>I just feel that an application needs to be rather <a href="http://data.story.lu/2011/10/28/definition-%E2%80%9Cdirty%E2%80%9D-term">DIRTy</a> in order for it to be justified. In the end what it all comes down to is what <em>you’re comfortable with, </em>with some caveats — obviously.</p><p>If you prefer coding in javascript (or, even better, coffeescript) as opposed to server-side languages, then you could totally use the server as a glorified database (manipulating sensitive data as well, if applicable) and do it all client-side.</p><p>Hate javascript? Fine, you won’t get away with never writing a line of it (you know, unless you’re creating websites for a tech university or something, they seem to disdain this whole asynchronous, real-time feedback thing), but you can minimise the javascript you write by creating javascript templates on the server.</p><p>If it doesn’t really matter to you one way or the other, I think an approach like the one outlined in this article is a good way to go. In the end, listen to the vampire known as Pharrel and do what makes you happy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6b2d046c62f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You’ve got some code in your coffee]]></title>
            <link>https://medium.com/@nicohvi/youve-got-some-code-in-your-coffee-bc22a3ea1be3?source=rss-1fa8d55ef198------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc22a3ea1be3</guid>
            <dc:creator><![CDATA[Nicolay Hvidsten]]></dc:creator>
            <pubDate>Thu, 22 May 2014 15:17:34 GMT</pubDate>
            <atom:updated>2014-05-24T09:15:33.324Z</atom:updated>
            <content:encoded><![CDATA[<h4>Organising coffeescript like a person of executive position.</h4><p>I fucking love coffeescript.</p><p>Yeah, even though I refuse to camelcase its name, much like I don’t for javascript (JavaScript, really?), because fuck that, coffeescript is about syntax you’re comfortable with.</p><p>If you’ve <em>never</em><strong> </strong>tried coffeescript, and you’re somehow reading this simply because you saw the words ‘code’ and ‘coffee’ in the title, I <strong>strongly</strong> suggest heading over to <a href="http://coffeescript.org/">coffeescript.org</a> to give it a once-over — it’s okay, I’ll wait.</p><blockquote>Coffeescript is like that cool cousin you never had.<br>- Me</blockquote><p>Using vanilla javascript is fine and dandy, hell many people <a href="http://procbits.com/2012/05/18/why-do-all-the-great-node-js-developers-hate-coffeescript"><em>prefer</em></a><em> </em>javascript, though I suspect that’s more because most of these people know the intricate details of javascript so well that they can basically create <a href="https://github.com/visionmedia">anything</a> they damn well please. I’m not one of those people. I’m an idiot.</p><p>Being an idiot, I like the syntactic elegance and simplicity of coffeescript, and how I don’t have to write <strong>Prototype </strong>or spew out function definitions like Will Smith’s acting career depended on it every damn time I want to create a class (or, you know, rather javascript’s replacement for classes).</p><p>I especially like how the <strong>this </strong>keyword, which can be an absolute fucking mystery the first time you encounter it in a certain situation, doesn’t have to be explicitly set using <strong>bind </strong>or stored in a variable when you need it inside a closure.</p><pre>var this = that;</pre><p>Yeah, that’s intuitive.</p><p>In coffeescript, it actually represents what you think it does by using a simple character (spoiler alert: it’s ‘=’ ).</p><p>Now that we’ve established the coolness of coffeescript, it’s time to talk about how you can use it to make some cool code-heavy stuff without triggering your gluten-intolerance (get it? Get it?).</p><p>For instance, maybe you want to create an awe inspiring (don’t you just hate it when a word you like loses its thunder due to over/misuse, much like Will Smith’s acting career?) website for your mediocre product? You’d be hard pressed to create something like that without coffee/javascript — though I’ve heard that Flash and Silverlight are all the rage with the kids these days.</p><blockquote>That last sentence was totally a joke.<br>- Also me</blockquote><p>One thing you’ll learn though (or very probably already know) is that once you go javascript, it’s very easy to go <em>full </em>javascript.</p><p>You never want to go full javascript much in the same way you never want to watch <em>After Earth </em>or eat a KFC Double Down ‘sandwich’.</p><p>Coffeescript only hides the warts and gives some nice syntactic shortcuts on top of javascript, so to avoid the aforementioned state of full javascript you need more than a nicer language — you need organisation.</p><p>It seems very popular these days to use the MV* pattern for client-side code, which in my opinion might be overkill unless your application is <em>very </em>heavy javascript-wise (say, if you’re using websockets for a real-time chat application or something). A more light-weight homemade solution might be more appropriate.</p><p>The following is an approach I often employ when I’m writing something which requires <em>some </em>coffeescript (which is basically every project these days), and something <em>I </em>like doing — implying that if <em>you</em> don’t, then feel free to do whatever you damn please, just don’t watch After Earth — it’s really bad.</p><p>Anyway, I like having <em>one </em>entry point for my coffeescript code, usually in a class called <strong>app</strong>. It can look something like this:</p><pre>class App<br>  constructor: -&gt;<br>    @totallySwaggerUIGrid = new TotallySwaggerUIGrid()<br><br>  reloadGrid: -&gt;<br>    Q($.get &#39;grid/&#39;)<br>    .then(<br>      (html) =&gt;<br>        $(&#39;#app).html(html)<br>        @totallySwaggerUIGrid.reload()<br>     )<br><br>@App = App</pre><p>Though imaginary (much like <a href="https://www.youtube.com/watch?v=4PwVy15YgTA">Bret’s children</a>), this amazing website would feature a kick-ass UI grid, much in the vein of the widely popular Windows 8 grid — represented by the App class’ instance variable, <strong>@totallySwaggerUIGrid</strong>.</p><p>In our theoretical website we would use AJAX to reload the grid whenever something calls the <em>reloadGrid</em> function of our global <em>app</em> instance. Once it’s been loaded, we would then ensure that all the bindings are in place for the new DOM elements, which is taken care of by the <em>reload</em> function on our @totallySwaggerUIGrid.</p><p>I like to organise my code by having classes represent the various units of the application’s views, so my theoretical UI grid class could look something like this:</p><pre>class TotallySwaggerUIGrid<br>  constructor: -&gt;<br>    @initBindings()<br><br>  reload: -&gt;<br>    @initBindings()<br>    # maybe do other cool stuff<br><br>  initBindings: -&gt;<br>    $(&#39;.grid-cell&#39;).on &#39;click&#39;, -&gt;<br>      while true<br>        alert(&quot;YOU SHOULDN&#39;T HAVE CLICKED ME, BRAH&quot;)<br>    $(&#39;.banana-stand&#39;).on &#39;click&#39;, -&gt;<br>      console.log &#39;money&#39;<br>      app.reloadGrid()<br><br>@TotallySwaggerUIGrid = TotallySwaggerUIGrid</pre><p>Now, once you initialise App using <em>App.new()</em> somewhere when your DOM is nice and ready you’re pretty much good to go! You’ve got your theoretical <em>app</em><strong><em> </em></strong>object, holding a reference to your theoretical grid, mad kudos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*r58wXzN0joz0K6rBPW2mUQ.png" /><figcaption>In your browser, it might look something like this.</figcaption></figure><p>What I like about this approach is that I have a global instance of my application (<em>app</em>) which holds references to all units of my application (just <em>@totallySwaggerUIGrid</em> in this particular case) — the respective units don’t need to know about each other, they only need to know about <em>app.</em></p><p>This can of course be achieved in many ways, for instance through a global pub/sub-system — It’s just not my cup of coffee. <em>Drops mic.</em></p><p>I also ensure that all classes I want to create instances of are available globally so the App class can reference them upon instantiation. Of course it’s never a good idea to litter the global namespace with variables, so this must be used sensibly — but I think it’s a solid approach.</p><p>If your codebase is on the <a href="http://www.slacktory.com/wp-content/uploads/2012/01/fat_emo-12292.jpeg">large</a> side it might be a good idea to introduce something like <a href="http://backbonejs.org/">backbone</a>, or even <a href="http://facebook.github.io/react/">react</a> (you know, if you’re into that whole functional programming thing), to keep things from getting out of hand — but if, like is often the case with me, your codebase isn’t <em>that</em> unwieldy, this might just be a good fit for you.</p><p><strong>PS: </strong>A friend of mine recently created something he claims is <em>even</em> <em>better </em>than coffeescript (aptly called <strong>baily.js</strong>), which you can read about <a href="http://haeric.github.io/bailey.js/">here</a>. I don’t believe him for one second of course — but that might just be because I don’t like baileys.</p><p>Also Will Smith’s recent movies. I don’t like Will Smith’s recent movies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc22a3ea1be3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TDD, whatever that means.]]></title>
            <link>https://medium.com/@nicohvi/tdd-whatever-that-means-8b3932ddddd6?source=rss-1fa8d55ef198------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b3932ddddd6</guid>
            <dc:creator><![CDATA[Nicolay Hvidsten]]></dc:creator>
            <pubDate>Sat, 10 May 2014 15:43:23 GMT</pubDate>
            <atom:updated>2014-05-10T15:53:09.013Z</atom:updated>
            <content:encoded><![CDATA[<h4>Thoughts that fell into my head while watching the talk on friday.</h4><p>If you didn’t know already, David Heinemeier Hansson, Kent Beck and Martin Fowler hosted a <a href="https://plus.google.com/events/ci2g23mk0lh9too9bgbp3rbut0k">talk</a> about Test Driven Development this past friday. I strongly suggest watching it, but if you haven’t got 30 minutes to spare however, feel free to peruse my mind-blowing thoughts about the talk instead.</p><p>So, apparently, TDD came about because Kent Beck read about it in a book when he was 10. No, <a href="https://www.youtube.com/watch?v=z9quxZsLcfo#t=354">really.</a> Still, regardless of its origins, there’s no denying that TDD has been widely popular (perhaps to a fault, which is what sparked this talk in the first place), indicating that many developers enjoy the workflow it encourages (or are just afraid of doing anything else, because this is the <em>right</em> way to do something).</p><p>I want to really emphasise the semantics of that last sentence. Beck explains that <em>he </em>really enjoys the workflow of writing tests first and then the accompanying code, due to <em>his </em>personality.</p><p>“Lame! This is going to be another ‘whatever works for you might not work for everyone else’-opinion,” you might think at this point. Fuck you, you’re only half right.</p><h3>Wait, you wanted what?</h3><p>At one point, Kent states that he “tends to get overwhelmed by big, complex problems”. Sound familiar? I think that’s a common problem for any developer (‘Hey, create a Facebook clone for us. Also, can you make it better?’) — complex problems (in any discipline, really) need to be broken down in order to seem surmountable.</p><p>So, what has this got to do with TDD? Kent said that “Even if I don’t know how to implement something, I almost always know how to write a test for it.” So <em>for Kent Beck</em>, TDD goes hand in hand with disassembling complex problems — it’s more of a way to approach a certain situation rather than a dogmatic approach he always adheres to.</p><p>I think that’s important: Kent Beck uses TDD in his approach to break down complex problems because <em>he fucking feels like it</em>, and that doesn’t mean that you necessarily do too.</p><p>For instance, David says that even though he understands how Beck reaches his conclusion of ‘at least I can write a test for it’, <em>he</em> does not feel the same way about development at all. His approach of disassembly consists of writing code rather than tests first, and you have to give it to the man — it seems to be working.</p><p>I feel the following quote from Kent captures the differences of his and David’s approaches very well.</p><blockquote>“TDD is one way (of feeling confident that the code does what you think it does), but there’s lots of other ways.”</blockquote><h3>That doesn’t go there, brah.</h3><p>So, while the benefits of TDD might be more dependant upon your personal preferences rather than a universal truth established by some programming deity wearing an ironic t-shirt, one thing all three participants agreed upon was that there were definitively certain scenarios more suited to TDD than others.</p><p>A common approach to remedy this problem (i.e. isolating components of code) is to use <a href="http://blog.codeship.io/2013/06/11/testing-tuesday-9-stubbing-and-mocking-with-rspec.html">mocking</a>, something which <a href="http://david.heinemeierhansson.com/2014/test-induced-design-damage.html">David is a big opponent of</a>. His point being that if you mock everything, then you’re not really testing anything worthwhile.</p><p>Regardless of his views, mocking is very common in TDD environments and surprisingly enough (at least to me), both Martin and Kent agreed with David on this point — stating that neither of them usually employed mocking, as this felt like a way to shoehorn a problem to fit with TDD.</p><p>Martin and Kent went on to say that while they enjoy the TDD process and the short feedback-loop, they had both recently encountered problems where they couldn’t utilise it — for instance when you don’t know the user input — which does lend credence to the idea that TDD is not something that fits every situation.</p><p>You want to be sure that Random Insulting Statement bot you made works with the given input? TDD the hell out of that shit. However, it might be an idea to take a different approach if you want to test how your bot interfaces with that tumblr feed of overweight people wearing fedoras.</p><h3>Don’t worry, be that other thing.</h3><p>During the talk, David brought up a concept which in my opinion is the single most important point of the entire debate: <em>programming happiness. </em>An important facet of which is that there are <em>different ways of achieving it, </em>TDD being one<em>.</em></p><p>Apparently, differently styles work for different kinds of people (hold the press!), and TDD <strong>is just one style, which can be applied in a variety of different ways</strong>.</p><p>Want to unit test the shit out of everything, refactoring your code (and tests) as things become more complicated? Go the fuck ahead! Maybe you prefer writing high-level acceptance tests, testing the <em>whole </em>shebang of the functionality you’re implementing — touching (perhaps) a view, a controller, some helper classes and hell, even the database before writing your code? Knock yourself the fuck out!</p><p>Want to write the entire functionality up front, and <em>then </em>start testing it? Go for it, just beware that you’ll be the ugly duckling of the office for a while.</p><p>In the end, to me anyway, TDD is just a tool — albeit a valuable one. What really matters is what makes you, much like the vampire known as Pharrel would have it, <em>happy</em><strong><em>.</em> Programming happiness &gt; TDD any day of the week</strong>, but for many people this inequality might, in fact, be an equality.</p><p>Even if you are one of those people who really enjoy writing your tests before you write your code, it might be an idea to keep in mind that it’s not necessarily suited for every scenario — so don’t give yourself too hard of a time if you happen to print ‘Hello world’ before writing ‘console.should.contain’, just chill out and have a beer instead.</p><p>A final point on which there was full agreement was that a piece of functionality is not done until <em>both </em>the code <em>and</em> tests have been written, something which isn’t exactly a world shattering opinion. I mean, if you disagree with this statement, you’re probably not reading this — in which case it’s safe for me to say that I think you’re an idiot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b3932ddddd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>