<?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[Palatinate Tech - Medium]]></title>
        <description><![CDATA[The tech blog of Palatinate Group - Medium]]></description>
        <link>https://medium.com/palatinate-group-tech?source=rss----1cb7e149612b---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Palatinate Tech - Medium</title>
            <link>https://medium.com/palatinate-group-tech?source=rss----1cb7e149612b---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:49:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/palatinate-group-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Running Selenium Javascript Tests Through Docker Containers]]></title>
            <link>https://medium.com/palatinate-group-tech/running-selenium-javascript-tests-through-docker-containers-6dd33ebb16c1?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/6dd33ebb16c1</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Mon, 21 May 2018 19:57:37 GMT</pubDate>
            <atom:updated>2018-05-21T20:06:05.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Just writing the title to this blog post makes me shiver. It makes me shiver because I spent 6 hours on a lovely sunny afternoon in London, punishing myself in a coffee shop for being unable to test my Javascript effectively. It got pretty intense in that coffee shop. At one point a tense exchange with an employee occurred:</p><p>Employee: <em>“Hey there, can I get you anything el..”</em></p><p>Me: <em>“I just want this f*****g thing to work, can you do that for me!”</em></p><p>Ok that exchange didn’t actually happen, but it’s representative of the stress I was going through to get my tests running. Attempting to learn online about Selenium browser testing also presents you with additional headaches. If you were to ask 10 developers how they did this, you’ll get 137 different solutions. It seems there is no agreed upon standard on how to do this stuff, and every developer seems to require a different setup. The lack of cohesiveness in the world of browser testing makes this an incredibly tough challenge. But a worthwhile one!</p><p>I’ve been working on a side project lately, which has only just recently introduced Javascript to the party. Test coverage up until now has been 99.92% with a lot of care taken to avoid test mutants in the process. Now with Javascript playing a role in user interactions, it was time to rethink how I went about testing.</p><p>Previously, when users would submit an enquiry they would have to go to a separate page with a separate form to fill out. On successful submission of this form, they would encounter a redirect. All in all, this is very easy to test because you can just make simple assertions in Capybara to say</p><p>expect(page).to have_content(&quot;Enquiry submitted. Thank you&quot;)and your test suite would confirm the user made the enquiry successfully and all is well with the world.</p><p>The game starts to change when you want to have an “in-page enquiry” feature, with an AJAX-ified form that submits asynchronously and keeps the user on the same page. It’s time to bring in the Javascript, and I knew things were about to get messy.</p><p>As I move forward in my developer career, I shudder at the thought of not writing tests. I used to be very relaxed about the topic, until I concluded from personal experience that the amount of time saved in <em>not</em> writing tests was exceeded by the amount of time<em> wasted</em> debugging and fixing seemingly endless amounts of bugs; on top of the many manual steps one has to go through in the browser to validate their code does the right thing.</p><p>I completely understand why inexperienced developers and those just entering the industry will avoid writing tests. It takes some pain to realise that giving up some time in the short term (in the form of writing good, quality rock solid tests) will save you a lot more time in the long term, as well as allowing you to sleep peacefully at night.</p><p>Running RSpec / Capybara tests through Docker containers so far had been a dream. But now with Javascript playing a role, it’s time to change strategy.</p><p>The world of browser testing isn’t for the faint hearted. It requires bringing together a range of tools to carry out the job, from a test runner like RSpec to a web testing framework like Capybara, to a browser automation tool like Selenium. On top of this, running tests through Docker containers and ensuring they can interact with each other adds another layer of up front complexity for the end goal of reproducibility and portability.</p><p>My docker-compose file initially looked like this with a very simple Ruby Docker image to run the tests from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*U0Iu7psDsbWiiQzLjcAsqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wh2eqI8P9OrXMYdLvBsQsw.png" /></figure><p>The main change to get the current system (otherwise known as ‘feature’) tests working was to set a driver in the rails_helper. Rack Test is the fastest and most popular for Rails system tests as it doesn’t need an actual browser to perform the tests. It’s super fast (at least compared to Selenium) as it makes requests at the Rack level, and requires no dependencies as opposed to Poltergeist which requires PhantomJS or Capybara::Webkit which requires a QtWebkit to be installed. For this reason, Rack Test has served me well, and required barely anything in terms of set up as it ships with Capybara. The only change required is to specify the driver as Capybara will attempt to use selenium-webdriver by default. To erase this error message Capybara&#39;s selenium driver is unable to load &#39;selenium-webdriver&#39;, please install the gem and add &quot;gem &#39;selenium-webdriver&#39;&quot; to your Gemfile if you are using bundler , just add the below block to your rails_helper. This error message sucks I feel, because they’re forcing users to install a gem (which in addition will require more installation overhead), when a simple block of configuration is all that’s needed. Shame on you, Capybara!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*siVySUGUmPkhyFZAjUtefQ.png" /></figure><p>Now that the user could submit an in page enquiry, with no redirect to another page on submission, the system test did not reflect the true state of the application and how users interacted with it. It was time to add the js: :true flag to the RSpec configuration to allow us to specify “this test requires you to drive this interaction through the browser instead of through a Rack interface”.</p><p>In the spirit of keeping everything running through containers, I added a new service to my docker-compose.yaml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ghY2K-cdamNwfBQ8Ftg2Fw.png" /></figure><p>This uses a Selenium image, which uses a real browser window which executes commands against a real Javascript engine. This is very powerful stuff, as now we’re bringing our tests one step closer to how users interact with our application. Users don’t use Rack Test and make requests through a REST client; they use browsers and browsers only. Using Selenium delivers an extra comforting layer of confidence which Rack Test cannot offer. The downside is it’s much more difficult to use, it’s slower and requires more dependencies. On the plus side, you’ve just automated a lot of your Q&amp;A.</p><p>There are a lot of benefits to running Selenium tests through Docker containers. The most obvious one is portability and reproducibility. Getting Selenium set up locally on multiple different environments is a pain, with a notorious level of installation overhead. Discrepancies between operating environments lead to inconsistent behaviour, and developers often find themselves having to install the world just to get something running. Docker makes set up extremely comforting and provides ease of set up unrivalled on any other platform.</p><p>Now we have a Selenium Docker image to work with, we need to register a driver with Capybara. This instructs Capybara to connect to the remote browser in the Selenium instance we’ll be running in another container with a separate IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dV0kxWfubFCvrIYqVESL4w.png" /></figure><p>To register the driver, you need to pass an initial argument which will either be app or if not required, can be anything you want (in my case I passed nil). app in this case is a type of Rack::Builder that can be used to construct a Rack application for the driver to use. After trying to figure out what this was and why every instruction online told me to use it (with zero explanation as to why), I decided to not pass it through because it requires further explanation; it was nothing but a distraction.</p><p>A url is required to tell Capybara where the Selenium hub is being run; the hub being the central point in the Selenium grid where we will ultimately send our Javascript tests. The Selenium documentation states: <em>“The hub receives a test to be executed along with information on which browser and ‘platform’ (i.e. WINDOWS, LINUX, etc) where the test should be run”. </em>And the desired_capabilities option specifies what browser to run the test in.</p><p>These ENVs are set within the docker-compose file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*9FEdRU0goe6pwnxdWz_jHQ.png" /></figure><p>Now we have a driver registered with Capybara, it’s time to specify a separate configuration for JS tests that are flagged with js: true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79tTjjOeWUyJCeh3v-XtiA.png" /></figure><p>By specifying driven_by: :selenium_remote, we are telling Capybara to use a separate driver for JS tests. Without this, it’ll attempt to use Rack Test as the driver which will run the tests in a headless browser so no Javascript will be executed.</p><p>Finally, a Make task that spins up the test container and executes the RSpec tests against the running instance whilst tearing them down afterwards. The $(SPEC) parameter is just so I can pass spec/directory/test_file arguments to the Make command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*u2ObRk8lKcbGjl3AwkhlpA.png" /></figure><p>This is the part I did not understand and still do not, but was ultimately what got this working. With Docker, you can usually run one time commands against a container using docker-compose run service-name COMMAND , yet attempting to run RSpec in this way (as I had been doing up until that point), gave me a <em>Failed to open TCP connection to test:3005 </em>error, meaning the service in the compose file, test , was not found. So by running docker-compose run test rspec @js:true (that last part to run only JS tests), a TCP connection couldn’t be made by the Capybara server. If anyone knows why this is the case I would appreciate some insight. But what ultimately worked was to spin up the test container in a demonised process and then execute an rspec command against it and subsequently tear down the container plus the Selenium one it automatically spins up due to the linking.</p><p>Overall, this was a real pain to set up. I still don’t fully understand all of it, but now I have a higher degree of confidence that when my tests all pass the application is working as expected, from the model layer to the transportation layer and now from the user interface layer. Having tests that fail if an enquiry form is not visible after clicking a button is extremely valuable, as bugs like this cannot be caught with standard Rack tests with a headless browser, and this can save a lot of Q&amp;A clicking around time that ultimately no longer needs to be done. Despite the struggles, I have to say hurray for Selenium and Docker for allowing me to set up a solid and reproducible testing environment for this application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dd33ebb16c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/running-selenium-javascript-tests-through-docker-containers-6dd33ebb16c1">Running Selenium Javascript Tests Through Docker Containers</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing a Repository Layer to a Ruby gRPC Client]]></title>
            <link>https://medium.com/palatinate-group-tech/introducing-a-repository-layer-to-a-ruby-grpc-client-4ee38f8e358e?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/4ee38f8e358e</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[repository-pattern]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 11:51:39 GMT</pubDate>
            <atom:updated>2018-03-12T11:51:02.128Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever started a big refactor, and mid way through realised you need <em>even more refactoring</em> to make it an easier job? Our team did recently, and our adventures in code improvements exposed underlying flaws with our design.</p><p>I love situations like this, as it assists you in understanding why a particular design pattern is beneficial and how specific patterns can protect you against further pain programming. There’s nothing more disheartening than standing in front of your project manager during daily stand-up, looking up like a naughty child that’s stolen from the cookie jar, and admitting that the refactoring you thought would take 2 days has turned into a refucktering that’s lasted an entire sprint; their eyes leering over you with a gaze of disappointment.</p><p>We had one of these situations just recently, when we decided to change some fields in a gRPC API message to allow nullable values for ids (they’d previously default to 0 if not provided, as the default value for an int that is declared but not assigned in Golang is 0). Our gRPC API is written in Golang and the API definitions are specified in a proto file like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*7DFQVKFzm031j9R8gZn6QA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tm5j9OxvqaS7zWfozRmumA.png" /></figure><p>The proto file is where the API specification is defined for the Remote Procedure Calls defined in the API. See the 2nd example above, CreateAccommmodationType which takes an AccommodationType and returns an AccommodationType, which is defined as a message in the first image.</p><p>Notice how the fields on the AccommodationType message are typed, so as a client you could not pass an int in the name field, for instance.</p><p>Our task was to change the id field across all our message types to be google.protobuf.UInt64 values, which are wrappers that either have a value or do not. In other words, they are nullable. Before this, all of our id fields were uints which meant that if you did not send an id across as a client, you would get a message similar to cannot set id to 0, even though you didn’t send 0, it just defaulted to that when the value was nil .</p><p>Changing the primary ids for each type involved an enduring swath of changes across the entire codebase (reminding us that we should think very carefully before setting the types of these values). Change the type of one field used in a message across the code, and not only will it fail to compile in the case of Golang, but hundreds of tests will fail in the process as well. A one line change can break <em>everything.</em></p><p>We went through the code methodically to make the appropriate changes, praying for green specs to appear at some point. Every time we thought we’d got them all, there were sources of more breakage. The issue was a leakage of knowledge of gRPC and the types returned by the API to the client. Everywhere from the controller, models, presenters and views were dealing with the return types from gRPC, which were not Ruby models but funny weird types that would often get confused with Ruby types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYgjkYEhpBa2Fu2FRNZUtw.png" /></figure><p>As you can see, passing around these types in a Ruby application is bound to lead to confusion and many type errors at runtime.</p><p>We decided to introduce a repository layer to the Ruby client, to ensure that the moment an API call is made the response is converted into a Ruby object (PORO) immediately. The rest of the application has exactly zero knowledge that this data is coming from a gRPC Golang API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3hSfEukhdnYYGM0ZXrv1sg.png" /></figure><p>Now we see that all of the Remote Procedure Calls to the API are dealt with in a single module, with conversions of the gRPC types being transformed into Ruby models before the method can even finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h79M4PqGqVu6u-a4zNtNvQ.png" /></figure><p>Now our controller has been simplified, and we are confident that any API changes to any of the types can be dealt with in a single place. Every single part of the Ruby application now only deals with POROs, which makes reasoning about this code and changing it in the future much less painful.</p><p>Another advantage of this is the client now <em>doesn’t care how </em>the data gets retrieved. The client remains stupid and ignorant of where this data is coming from and the type of API we’re dealing with. The Repository acts as a layer between the client and the data source, so the client has no knowledge of the implementation details of data storage and retrieval. If we were to eventually switch the API to be an Elixir API that returns JSON, we would only have to make changes to the repository module and a few adjustments to how the Ruby models are instantiated.</p><p>It’s only when going through the pain of making a change that involves changes in dozens of different places does the solution become more obvious. It’s my first time using this pattern, and definitely not my last.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ee38f8e358e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/introducing-a-repository-layer-to-a-ruby-grpc-client-4ee38f8e358e">Introducing a Repository Layer to a Ruby gRPC Client</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Human Cost of Messy Code]]></title>
            <link>https://medium.com/palatinate-group-tech/a-common-misconception-we-have-as-developers-is-that-the-consequences-of-bad-code-are-localised-to-7599c7031b69?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/7599c7031b69</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 13:04:20 GMT</pubDate>
            <atom:updated>2019-04-25T01:30:52.330Z</atom:updated>
            <content:encoded><![CDATA[<p>A common misconception we have as developers is that the consequences of bad code are contained to only our department. We are the ones who have to wrestle with the beast; we are the ones who suffer when our innocent little change appears to break a whole swathe of integration tests. The rest of the business is ignorant of the horrible mess that’s brewing deep inside our legacy systems. They get a wonderful feature, unbeknownst to the dark reality lying beneath it all. In truth, this isn’t really the case.</p><p>I‘ve recently been reading through “Becoming a Better Programmer: A Handbook for People Who Care About Code” by Pete Goodliffe. One chapter that stood out was his descriptive (and tragically hilarious) chapter on “A Tale of Two Systems”, where he walks through the development of two projects he’d worked on in the past; one with a careful, considerate and thoughtful approach to the design of the code, both from an architectural standpoint and on a micro level. The other was your typical legacy system, that had grown “organically” in a company where delays were intolerable (“The Messy Metropolis”). No single person had stood up and imposed a sane design on the code, because why bother? The code was already a mess, and developer turnover was high. The incentive was there to please managers and ship feature after feature, not to take some time out to reflect on missing abstractions and potentially shared functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*y_5fmiIWApEpNgJ67CB5Gw.gif" /></figure><p>The Messy Metropolis, as he refers to it, had a number of problems with it.</p><p><strong>Lack of Cohesion</strong></p><p>There was no clear pattern for where system components belonged. To track down a piece of functionality, a developer would be performing the equivalent of surgery on an alien life form. Where’s the heart? Is this a brain? How critical is this organ? Both functionality and data were sprayed all over the code, with no unifying approach to tie them together.</p><p>The lack of cohesion in the code turned out to be reflective of the lack of cohesion within the team itself. Goodliffe explains that there had been <em>“personality struggles in the original team, and so a few key programmers had begun to build their own little software empires”</em>. Logic that should have been performed at the core was being placed in satellite modules that were difficult to reason about in the context of the whole application. An important lesson that Goodliffe teaches is that the health of the working relationships in the team will directly impact the health of the software.</p><p><strong>Code problems at the micro level</strong></p><p>Neglect at the high level of the code will typically seep into lines at the micro level. In the Messy Metropolis there was no consistent naming, no common coding standards and a whole concoction of various coding styles that would send any linter into a tail spin. Goodliffe complains that<em> “There was not even a common build system; duct tape, shell scripts, and Perl glue nestled alongside makefiles and Visual Studio project files. Compiling this monster was considered a rite of passage!”</em></p><p>The main lesson here was that a lack of thought into the high level design of the software can lead to an incomprehensible mess at the low level. Much like a city that undergoes no planning, with badly planned roads causing a build up in traffic, a messy and inconsistent architecture begets a messy and inconsistent code base.</p><p><strong>Problems outside the code</strong></p><p>My favourite part in this chapter was the least obvious, but probably the most important. As I said in the beginning, it’s easy to reason about the effects of a bad design when it comes to the code. We work with code every day, and we know the pain of wrestling with code that isn’t on our side. We understand the toil and hardship of reasoning about a system that has no reasoning behind it. But the most overlooked aspect of all this is the impact on relationships with other people; mainly stakeholders.</p><p>In the Messy Metropolis, staff turnover was high. Developers came onto the project stunned by the horrid complexity and inability to get simple things done. The low morale and high stress levels induced by the rigid codebase caused a continuous revolving door of developers, which compounded the problem even more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5SqX6Qoza_nY8DpCWZl-rw.jpeg" /></figure><p>Slow development cycles were the norm, with features taking an unpredictable length of time. Stakeholders were often left waiting, with no clues as to when something would be ready. The inability to estimate sensibly meant the business couldn’t plan effectively. This brewed tension between the Tech team and the company management. The Sales and Marketing team lost trust in the developers. Credibility was lost from the Product team, who were waiting on a feature to allow customers to select their latest range of online offers. The costs of a toxic codebase are not just felt in the development team, they’re felt company wide.</p><p><a href="https://hackernoon.com/what-does-hacker-news-care-about-e364fb87431c">Lynne Tye has performed interesting surveys of software developers, and asked the question “What do developers want from a job?”</a>. Work flexibility scored highly, with “Work/Life Balance, Remote-Ok and Flexible Work Arrangements” being amongst the most valued. But unrelated to those was a “High-Quality Code Base”. It’s clear why a codebase of low quality can significantly impact a developers’ satisfaction with the job. A tense relationship with stakeholders, a low sense of morale at being incapable of delivering simple features in a timely manner. <a href="https://blog.qualified.io/the-hidden-cost-of-hiring-engineers-22-750-hire-3a53e16b78c3">Given how much it costs to actually hire new developers</a>, companies should be aiming to keep their staff turnover as low as possible. A high quality code base can reduce a lot of the hidden costs of hiring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAP0NrWttW_fB9RbaqZoIA.png" /></figure><p><strong>On to Design Town</strong></p><p>Goodliffe contrasts his experience with the Messy Metropolis with a project he calls “Design Town”.</p><blockquote>“Decisions about some of the basic housekeeping concerns were made early to ensure that the code would grow easily and cohesively: the top-level file structure, how we’d name things, a “house” presentation style with common coding idioms, the choice of unit test framework, and the supporting infrastructure.”</blockquote><p>Having a well thought out design and architecture allowed the team to progress forward with no road blocks. Functionality was easily traceable, and adding new features was as simple as “slotting in” the required lines of code to get something working.</p><p>A template was formed which required little cognitive effort on behalf of the developers, and allowed progress to run smoothly. The codebase was uniform and consistent. It had structure and elegance. It had beauty and aesthetics. There were no alien lifeforms mutating across the code; every line made sense in its’ context and, like a family of functionality, had a sense of belonging.</p><p>Estimating how long a feature would take proved trivial, as adding similar features in the codebase took approximately the same amount of time. Relationships with stakeholders flourished, and developers remained within the company for a long duration. Why leave when they’re blessed with such a wonderful codebase to work in.</p><p>After reading through this chapter I started to think of the systems I’ve worked on at Palatinate Tech, and which category they fall into. Our current project, Neptune, matches Design Town to a tee. On-boarding a new developer involves a seamless integration, with a fully Dockerized development environment. Clone the repo, run a single command and you’re good to go.</p><p>Explaining the overall architecture is child’s play, and after 30 minutes of running through the code a developer can start adding value right away. There’s no funny business, or tricky corners to navigate in the code. A pattern is established, with a consistent high level architecture to accompany a uniform styling at the micro level. Rubocop, ESlint and Golint enforce a disciplined sense of order to the codebase, erasing any styling inconsistencies that might slip in.</p><p>Adding a new feature usually involves slotting in very similar code to its’ appropriate place and making a pull request. Due to its’ consistency, it’s very easy to spot when something is out of place, or when a line of code is added to a file it doesn’t belong to.</p><p>Admittedly I only learned the importance of these lessons recently. I always knew “clean code” was what we should strive for, but I never properly thought through the implications of having messy code, other than it’s harder to work with. I’m just as guilty of “cowboy coding”, as the dopamine rush from getting a feature out is often too tempting to resist. I’m learning that the best developers place their focus on the less glamorous side of software development. They take on the role of a janitor, cleaning up the mess and refactoring where necessary. Maintainability first, features second. Deadlines be damned.</p><p>The human cost of software riddled with code sins and design warts has large implications for a business that could last for years. Paying a cost up front to ensure that doesn’t happen is a price worth paying.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7599c7031b69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/a-common-misconception-we-have-as-developers-is-that-the-consequences-of-bad-code-are-localised-to-7599c7031b69">The Human Cost of Messy Code</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Happens When You Run ‘git add …’]]></title>
            <link>https://medium.com/palatinate-group-tech/what-happens-when-you-run-git-add-8fce3f93e449?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/8fce3f93e449</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Thu, 28 Dec 2017 20:11:21 GMT</pubDate>
            <atom:updated>2017-12-29T12:14:50.252Z</atom:updated>
            <content:encoded><![CDATA[<p>There comes a point in a programmers career where you realise that you rely heavily on certain tools every day, whether it be the browser, the terminal or git, and your understanding of them has only just scratched the surface. My goal for this year is to dive deeper into the internals of the tools I use, and hope to demystify some of the magic behind them.</p><p>I cannot think of a tool that’s more integral to a software developers workflow than Git. We use it every day, without fail and take it completely for granted how it works under the hood. If we were to have a concussion and wake up from a coma having forgot everything we know about Git, we couldn’t do our jobs. Git is such a fundamental part of our day to day, yet we often neglect to understand how it really works.</p><p>One tutorial I’ve been going through is Mary Rose Cook’s awesome “<a href="https://maryrosecook.com/blog/post/git-from-the-inside-out">Git from the Inside Out</a>”, which goes into some depth on what happens when you run specific git commands.</p><p>I’d like to focus in this article on git add, as what I learnt about this command is worth a blog post in itself. Some of it has drawn inspiration from Cook’s article, but this is also the result of more research pored over from other writers. So let’s begin.</p><p>Firstly, what happens when you run the command git init. It might have been a while since some of you have run this, but it’s typical to run this command whenever a new project is started. All this command does is make the current directory a Git directory, which contains a bunch of files you can read and write to. Go ahead and poke around in the .git/ directory to get a flavour of what’s inside.</p><p>Once you’ve done that, you’re ready to start making changes. Any change you make in any of the files will now be tracked by Git.</p><p>To start understanding git add, it’s worth looking inside the .git/objects directory of a git project you already have set up. Go ahead, I’ll wait.</p><p>No seriously, go and explore the directory.</p><p>Ok I believe you now.</p><p>So you should have seen something like this (at least for a large project).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLEAgb00MWJQVQu8coCqtA.png" /></figure><p>This is showing a list of directories which contain every single addition and commit the project has ever had. Whenever you run git add or git commit , Git will create what’s known as a ‘blob’ file or a ‘commit’ for you inside the .git/objects/ directory. That’s right; <strong>whenever you run </strong><strong>git add on a file, Git will store that change forever, regardless of whether you delete the branch or run </strong><strong>git reset or </strong><strong>git checkout on the file. A blob will be stored forever regardless of whether the branch exists that it was added on or not.</strong></p><p>So what is a blob? A blob file is just the compressed content of a set of files.</p><p>When you run git add &lt;filename&gt; , Git will hash the contents of the file and return you back the unique key. You could do this another way by writing git hash-object -w &lt;filename&gt; which returns you the unique key <em>and </em>writes the contents to git’s object database. Note that this will only create a blob object, but not add this to the staging area ready for commit. There’s more work to be done for that to happen.</p><p>Git’s object database is what you saw when you looked inside the .git/objects directory. This directory contains different types of Git objects, mainly blobs, trees and commits. If we ever wanted to see the contents of a file we just added, we could use <a href="https://git-scm.com/docs/git-cat-file">Git’s internal </a><a href="https://git-scm.com/docs/git-cat-file">cat-file </a>command which presents us with content, type or size information on Git objects.</p><p>So go to any of the objects in your .git/objects/ directory and use git cat-file -p &lt;hash-value&gt; to view the contents of the object. You can also use git cat-file -t &lt;hash-value&gt; to inspect the type.</p><p>Here’s what blew my mind when I discovered this; Git will forever keep track of the contents of a file you added, even if you never explicitly committed it and even if you deleted the branch where you added the files.</p><p>To prove that, I suggest you make a new project and follow along with these instructions:</p><p>Firstly, run mkdir git-tutorial and cd into it.</p><p>Now run that magical command to make this a Git repository git init</p><p>Now run the following commands:</p><p>printf ‘I AM ADDING SOMETHING TO GIT!’ &gt; test.txt</p><p>git add test.txt; git commit -m&quot;first commit&quot;</p><p>Now we have a simple Git repository with 1 file under 1 commit. Why don’t you go ahead and peak inside the blob by running git cat-file -p 1f0db4e54d315dced514ef5f7bb6b3f0f87a7e00 . It should return just the text you just inserted, and the hashed value of this will always be the same. You could even check so by runningecho -n I AM ADDING SOMETHING TO GIT! | git hash-object --stdin.</p><p>Now here’s my favourite part. Run the following commands</p><p>git checkout -b new-branch</p><p>printf ‘I AM REMOVING SOMETHING FROM GIT!’ &gt; test.txt</p><p>git add test.txt</p><p><em>Realised you don’t want to commit the change</em></p><p>git reset test.txt; git checkout test.txt</p><p>git checkout master</p><p>git branch -D new-branch</p><p>Now, if you were to ask me a few weeks ago what I thought happened in this process I would say “We made a change to a file, added the change to the staging area but then backtracked and deleted the branch completely. <strong>That change is now lost forever</strong>”.</p><p>Though remember what I said above; Git stores every addition and commit inside the objects database, so whatever you add will be there permanently.</p><p>This can be proven by running <a href="https://git-scm.com/docs/git-fsck">git fsck</a> . You should have a dangling blob there with the hash value of the contents. A dangling blob is a change that made it to the staging area, but never got committed. Now by printing the contents of the file with git cat-file -p c46b315e76a5892fee0b47c1283c27df8a259843you’ll see that the change was never lost, despite the revert you made above.</p><p>git add is just one command, and probably one of the simplest. As you can see there’s a lot more happening than meets the eye. I’d highly recommend <a href="https://maryrosecook.com/blog/post/git-from-the-inside-out">Mary Rose Cooks article</a> to become more familiar with this stuff, where she goes into a lot more detail on Git’s internals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fce3f93e449" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/what-happens-when-you-run-git-add-8fce3f93e449">What Happens When You Run ‘git add …’</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing a Golang gRPC API with RSpec]]></title>
            <link>https://medium.com/palatinate-group-tech/testing-a-golang-grpc-api-with-rspec-c4036ad2aeb7?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/c4036ad2aeb7</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Tue, 14 Nov 2017 11:56:23 GMT</pubDate>
            <atom:updated>2017-11-14T11:52:36.731Z</atom:updated>
            <content:encoded><![CDATA[<p>The title of this blog post might appear weird for those in the Ruby and Golang communities. Rarely do you hear of developers writing an API in Go and testing it using the darling of the Ruby testing world, RSpec.</p><p>With RSpec’s wonderful tooling and support, we figured we could write more readable tests than with any of the Go testing frameworks. We were mainly interested in testing the API as a whole unit in itself; seeing it as a blackbox that accepts a request and returns a response. This way we are able to make large changes and dramatic refactors to the internal implementation without breaking any tests. We can still be confident it does exactly as we expect when it comes to the database layer.</p><h3>So how are we even testing this?</h3><p>We’re creating a new application built on top of an existing Microsoft SQL Server database, so naturally we need some way to connect to that. We need to be able to query the DB, as well as iterate over any results we receive back. FreeTDS is the standard piece of software in the industry for allowing applications to connect to a Microsoft SQL Server, and we use <a href="https://github.com/rails-sqlserver/tiny_tds">TinyTDS</a> which is a Ruby wrapper around FreeTDS.</p><p>TinyTDS comes with many benefits, such as converting SQL Server datatypes to lovely Ruby primitives, and allowing you to iterate over the results returned from a database call.</p><p>The first part in our specs is to open a connection to our test database. Because TinyTDS does not differentiate between a database connection and being able to accept queries, we assume that any errors mean no database connection could be made, and therefore no queries can be submitted</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*Y7ro-i-US0HWj_OMwxinCA.png" /></figure><p>Once a DB connection is established, we can start setting up our test database so it’s in a clean, consistent state on each test run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*GRmKfyXy609dA6TPa9Cmwg.png" /></figure><p>Here we are executing some SQL queries to the test DB through a Factory. Our Factory class provides a range of methods that clears and inserts values into the DB before the specs run. In the case above, we want to ensure all of the data in the tables that the supplier references through a foreign key are removed, hence the .clear methods invoked in the before do block, which return the id of the supplier just created in this case.</p><p>Our Factory class provides a nice abstraction for executing queries to our test database before our specs run, so our spec files don’t need to have knowledge of the database schema and can focus only on setting up assertions on the data returned from the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytTl5_rLtO4_hUVcBD9vgQ.png" /></figure><p>Using TinyTDS we can pass through our db_client(which is our TinyTDS client instantiated through our open_database method above). This TinyTDS client now has methods attached to it that can execute SQL queries to our test database. The typical approach is to use the execute function of the TinyTDS library, pass in the SQL as a string, then call either insert if you’re inserting into the DB (.insert), or do to ensure that we execute the statements synchronously in order to prevent race conditions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoHfKd4eZ10AE64B-VtCpQ.png" /></figure><h3><strong>How Does RSpec communicate to the Golang API?</strong></h3><p>This is where things become interesting (as if you didn’t find the stuff above equally as interesting). How do we communicate to the Golang API through our RSpec test suite? At some point once the test database is set up and appropriately seeded, we need to make a call to the appropriate APIs to actually execute the action under test.</p><p>We’re using gRPC for the API, a Google RPC (Remote Procedure Call) framework. Remote Procedure Calls are a technique used in computer science for calling functions in a different address space; so essentially you can have a server on one machine, and a client that communicates with the server by calling functions defined on the API as if they were local. This pattern is becoming increasingly popular as the industry moves towards a microservices over monolithic architectural pattern.</p><p>With gRPC you start with a proto file, which defines exactly how the client and server can communicate and with what information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cz8BbTi6vBx7L5XaRgxgQ.png" /></figure><p>Above we define some remote procedure calls that can be called from the client to the server, what messages the request takes and what the server will respond with. We define this within the Neptune service (our internal application).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*1lQBEZP5RMme5H4H3WHHEw.png" /></figure><p>These response messages typically contain a repeated field of errors and a payload with the contents of the response returned back to the client. In the case above, when we call the GetSuppliers RPC, we receive back a response with possible errors or a payload containing information pertaining to the Supplier; like name, id, country etc. The numbers (e.g = 1 and = 2), represent the unique “tag” that the specific field uses in the binary encoding. So the name of the field itself does not get transferred over the wire, but its binary representation does.</p><p>gRPC uses protocol buffers (created by Google) to pass information across the wire. Unlike JSON, protocol buffers are a binary Interface Definition Language (IDL) which make them impossible to read by humans, but much faster for computers to process.</p><p>Especially for microservices where you have multiple services talking over a network, a binary transport format is much more efficient compared to transporting potentially large JSON strings or XML everywhere. Compared to XML, Google claim that protocol buffers are <a href="https://developers.google.com/protocol-buffers/docs/overview#whynotxml">3–10 times smaller and 20–100 times faster</a>. Google have now gone full proto, claiming that protocol buffers are now their “<a href="https://developers.google.com/protocol-buffers/docs/overview#whynotxml"><em>lingua franca</em> for data — at time of writing, there are 48,162 different message types defined in the Google code tree across 12,183 </a><a href="https://developers.google.com/protocol-buffers/docs/overview#whynotxml">.proto files</a>”</p><p>Google’s protobuf compiler allows us to auto-generate client and server stubs which take care of a lot of work for us. We don’t have to worry about serializing and deserializing the requests and responses. The client / server code necessary for a client to talk to an API is all generated for us through the protoc compiler and placed in their appropriate directories. In our case, we direct them to the Golang API and the RSpec api tests directory.</p><pre>protoc --ruby_out=lib --grpc_out=lib --plugin=protoc-gen-grpc=`which grpc_ruby_plugin` ./neptune.proto</pre><pre>protoc --go_out=plugins=grpc:pb ./neptune.proto</pre><p>Now that the stubs have been generated for both the Golang API and the Ruby client in RSpec, we can now call the RPCs defined in the Go files through our spec files, just as if they were local Ruby methods. The automatic code generation done through the protoc compiler makes this extremely easy to do. A get_suppliers method will be generated in a Ruby file that, when invoked, will call the GetSuppliers function in the Golang API.</p><p>Remember this example from above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzIp9fB2Vic_S5AbUe828w.png" /></figure><p>Our RPC_STUB here is defined in the spec_helper and sets up a connection to the Golang API so we can call RPCs on it with ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*heu9sKp0S1W1D0jtB2i8Jw.png" /></figure><p>In this example test, we want to test functionality on the Golang API for getting suppliers. We want to ensure that when we call the get_suppliers remote procedure call, we receive back the suppliers in a protobuf message that contain the suppliers. Under the hood, the get_suppliers Ruby method call is calling the GetSuppliers function defined on the Go API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b00PoqnOxcKlQU1NH7b2Rg.png" /></figure><p>In summary, this function is exposed to our client through gRPC. It doesn’t take any parameters (represented by google_protobuf.Empty), and returns a a *pb.GetSuppliersRespoinse and any possible errors. This goes deeper into our store package which eventually executes the necessary SQL query to fetch the suppliers from the Microsoft SQL Server database. Once the results are retrieved they’re appended to the response payload and returned to the client.</p><p>In the case above where we test the API that returns us a list of suppliers, the error messages are just as clear as they would be if the API were written in Ruby. We make an assertion on what we expect to be returned from an RPC call, and if the returned value does not equal our expected value we’re told exactly what the difference is.</p><p>In this case, I removed the “Name” field from the Supplier struct on the Go side and our failure message clearly specifies what the difference is. Bugs are usually very easy to track down</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSj-nywIFVDyNATviikR8w.png" /></figure><p>It isn’t all sunshine and daffodils when using this structure. One notable thing we’re missing is the ability to debug the API on the test run. We can’t just binding.pry into the API, or halt execution as easily as we could if we just used Ruby.</p><p>Measuring test coverage has also been an issue. We can’t just install SimpleCov and get a quick idea of where we’re missing tests. There’s no simple way to do automated mutation testing either, so it’s difficult to assess the quality of our tests through automated tooling.</p><p>Overall we feel we made the right choice despite the drawbacks. Golang has been wonderful to program in for this API, and RSpec has been a breeze to test with as always. If you do have an idea of how we can solve our test coverage problem, then do get in touch. <a href="https://tech.palatinategroup.com/were-hiring-8dd6a26e6b8c">We are hiring after all</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4036ad2aeb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/testing-a-golang-grpc-api-with-rspec-c4036ad2aeb7">Testing a Golang gRPC API with RSpec</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I Wish I Knew About Software Development Before Starting Out]]></title>
            <link>https://medium.com/palatinate-group-tech/what-i-wish-i-knew-about-software-development-before-starting-out-c1b55180b83b?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/c1b55180b83b</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Mon, 23 Oct 2017 08:46:31 GMT</pubDate>
            <atom:updated>2017-10-05T08:23:50.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Once upon a time, when I started to get my fingers wet by learning to code I assumed there were just 4 things I had to get <em>really really </em>good at; HTML, CSS, Javascript and a backend language like Ruby. I told myself, “Adrian, nail those 4 things and you have it. A successful, industrious career as a software developer”. Any developer who spoke to me back then must have been silently dying of laughter at my naivety. How could I be so foolish?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*SY0ZkRbL0jvkbrZONFVA0w.jpeg" /></figure><p>I need to get awesome at HTML; that’s what web pages are ultimately made out of, right? So I need to read entire books on this, attend courses, go to night school. I also need to read everything I can on CSS. How on earth can I make a website look pretty? And Javascript! Users expect swift, dynamic behaviour on their websites; I must learn everything!</p><p>Junior developers and those just starting out believe it’s <em>all </em>about the code. It’s not about the infrastructure. It’s not about database performance. It’s not about security. It’s not about page weight. It’s not about input validation. It’s not about authentication. It’s not about maintainability. It’s not about testing. It’s not about browser differences. It’s not about time / space complexity. It’s not about asynchronous requests. It’s not about deployments. We just want to make things that look pretty and make our friends and family go “oooooo….aaaaahhhh”.</p><p>Sure, you could argue that a lot of these issues I mentioned above <em>require </em>code to fix them, but learning the language inside out won’t make you better at actually fixing them. It was only when I began to measure my performance of the job with my knowledge of the programming language that I realised I need to alter my mindset. I would spend my free time practising Javascript katas and advancing my Ruby knowledge, all the whilst seeing no significant impact on my job performance. The fact was I could learn these tools inside out, and <em>still </em>suck at my job.</p><p>So what does it require? If becoming really great at a programming language isn’t a sufficient enough skill to become a great software developer, then what is?</p><p>Unfortunately, I’m still trying to figure that out myself. I know all great developers have a few key characteristics that I’ve tried to emulate. One being a sense of downbeat, cynical pessimism. Great developers are heavily distrustful of code. They understand that code is brittle, and any unexpected behaviour by users can bring down an entire system. They approach each pull request with a suspicious eye, knowing full well that it’s likely riddled with bugs the author did not foresee.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*X5cvvQ4HFToEY-OCbeSxAg.jpeg" /></figure><p>Great developers can break down problems. They show little in the way of intimidation by a big problem. If it’s too big, they make it smaller. If that turns out too large, they reduce it even more. Great developers understand the limits of their cognitive abilities, and reason about how a problem can be broken down to individual components.</p><p>Great developers understand the bigger picture, from server performance to browser intricacies. They understand the deployment pipeline of their application, and how it ultimately gets served to users. They empathise with users on old browsers, and attempt to code with the intention of allowing those stuck on old versions to use their software.</p><p>There are still many things I’m learning about what makes a great software developer. In the past year I’ve learnt it’s not about the code. It’s not about having an encyclopaedic knowledge of the tools you use. There’s much more to it and I’m learning new things every day. Let me know if you think of any more, and what you believe makes for a great software developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1b55180b83b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/what-i-wish-i-knew-about-software-development-before-starting-out-c1b55180b83b">What I Wish I Knew About Software Development Before Starting Out</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up An Awesome Pairing Environment]]></title>
            <link>https://medium.com/palatinate-group-tech/setting-up-an-awesome-pairing-environment-ba011439d451?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/ba011439d451</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Mon, 23 Oct 2017 08:46:04 GMT</pubDate>
            <atom:updated>2017-10-02T09:14:27.155Z</atom:updated>
            <content:encoded><![CDATA[<p>Pair programming is something we take quite seriously at Palatinate Tech, and the tools we use make all the difference to our enjoyment and productivity.</p><p>Pairing is something I never enjoyed up until recently. Having just one laptop between two people, with one person leaning over uncomfortably squinting at the screen is no way to work. Add to that the general awkwardness of using somebody else&#39;s keyboard and a configuration that you’re not used to, and all of a sudden your brain is no longer thinking about the code; you’re just trying to get your head around a new environment with a different set of keybindings that you’re used to.</p><p>For pair programming, we use Google’s Compute Engine to set up Virtual Machines that allow for easy SSH access, so we can collaborate much more efficiently. Setting one up is mind numbingly simple, and with just a few clicks you’ve made a fresh new virtual machine. Add whatever junk you want to it. Download all the corrupt garbage you wish; you can destroy it as easily as you created it and start again. Let Google take care of the mess you made.</p><p>Each of us on the team have our own VM instance, labelled as “neptune-dev-name-of-owner”. Neptune is our current in-house project for a new internal application, so we name the machines based on that.</p><p>It’s normal to come into the office in the morning, and find a group working on a story together. My first question will be “who’s machine are you in?”. If it turns out they’re working on Luca’s machine, I just simply run a command to SSH into the VM and attach to the existing Tmux session that’s been created.</p><blockquote>gcloud compute — project “dev-servers-170213” ssh — zone “europe-west2-a” “developer@neptune-dev-luca”</blockquote><p>This is an awkward command to type out each time, so we each have custom aliases in our local bash profiles to prevent typing this out each time. To connect to Luca’s machine and begin collaborating, I just have to run “neptune-dev-luca -&gt; tmux a”, and now I can view what he’s working on and even start writing on the screen.</p><h3><strong>How we agree on dotfiles configuration</strong></h3><p>Developers live and die by their dotfile configuration. Insulting another programmers configuration is the “Yo mama” equivalent of developer smack talk. It’s easy to think that tensions could arise as one programmer always wants colleagues to work on their machine so they can continue to use their custom configuration. We realised early on that this would be a problem, so we set a team standard for what dotfiles will be used on each VM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YV9yfAFHHe6i9KY6Ioo0_w.png" /></figure><p>If a new developer were to join the team (we’re hiring, by the way), then creating a new virtual machine and running a few setup scripts should get them up and running in no time. We have a script in the dotfiles repo that can run on each new VM instance and provide the developer with everything they need to collaborate on the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AsaHyVwQdm-n0IxWxRft0w.png" /></figure><p>With every VM having the same set of configuration, it’s painless to move from one machine to another. There have been cases where we’ll move around to multiple machines in a day. In the morning it might be Eva’s machine, we all SSH into that using a simple bash alias and attach to her existing Tmux session. In the afternoon it might be Tom’s machine we all connect to in order to continue working on a feature. The whole process is simplistically painless, and makes pair programming a much more enjoyable experience.</p><p>Taking the time to set up these tools incurs a small cost in the beginning, but it’s worth making the effort. The benefits of being able to pair effortlessly regardless of whether you’re working remotely or in the office are worth it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba011439d451" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/setting-up-an-awesome-pairing-environment-ba011439d451">Setting Up An Awesome Pairing Environment</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Split-testing a Ruby on Rails application]]></title>
            <link>https://medium.com/palatinate-group-tech/split-testing-a-ruby-on-rails-application-7232da4da835?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/7232da4da835</guid>
            <category><![CDATA[split-testing]]></category>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Nicholas Hibberd]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 14:50:53 GMT</pubDate>
            <atom:updated>2017-08-10T14:50:52.199Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post is an adaption of a presentation given to the </em><a href="https://www.meetup.com/en-AU/Ruby-On-Rails-Oceania-Sydney/"><em>Ruby on Rails Oceania Sydney meetup</em></a><em> on 13 June 2017</em></p><p>At Spabreaks.com we have been performing regular split-testing of our code for a number of years and we have learned a lot about our customer preferences along the way. Today I’m going to explain what split-testing is, talk about why we chose to write our own server-side split testing utility rather than using one of the off-the-shelf client-side tools on the market, I’ll provide a walk-through of the custom implementation that we have been using, and finally I’ll present a few examples of some of the things we’ve split-tested and the surprising results that we have received.</p><h3><strong>What is Split testing?</strong></h3><p>Split-testing, or A/B testing is the practice of creating two or more versions of a webpage, or some component on your website, serving one version to one set of customers, and another to another set of customers, recording who has seen each one and comparing which is the more successful.</p><p>It is an effective technique because you are able to compare different versions under identical conditions, whereas if you completely replace a page and try and compare results over different time periods then you may be introducing other variables that could have a bearing on the results.</p><p>It is important that visitors have no way of knowing that they are part of the experiment and just believe they are visiting your standard page, and it is important that the test is conceived with a measurable goal in mind and that you have the appropriate analytical tools in place before the test starts to be able to measure the results.</p><p>The reporting platform that we use is Google Analytics and our implementation uses the Experiments API that they provide, but there is no reason that the techniques I’ll describe wouldn’t work with any other kind of reporting setup. The only requirement is that you have a way of associating sessions, as understood by the platform, with split-test variants, as understood by you, and your webserver.</p><h3><strong>Why did we write our own implementation?</strong></h3><p>There are a few split-testing tools on the market, and you can set up Experiments directly in the Google Analytics interface, or via their Google Optimise product, and in these cases the platform takes responsibility for deciding which version of your page to show each customer, for rendering the appropriate content, and for feeding that information back to the reporting engine, but none of the techniques we looked at satisfied all of the criteria we drew up.</p><p>We specifically wanted an implementation that:</p><h4><em>Did not require a redirect between pages</em></h4><p>One technique that Google Analytics recommends involves making different versions of your page available under different URLs and it will perform redirects from the original page to the variant page, but this does not provide an optimal user experience.</p><h4><em>Was suitable for pages with dynamic URLS</em></h4><p>The redirect solution is also only suitable for pages with fixed URLs, whereas we wanted to be able to run experiments on groups of pages such as all of our venue pages, or all of our region pages where the content is rendered dynamically based on a URL parameter.</p><h4><em>Did not result in a visible flash when switching between page variants</em></h4><p>Another technique recommended in the Analytics documentation involves providing all of your experiment variants as JavaScript functions that modify the page on the client-side, but this can result in the user viewing the original page and then seeing it redrawn when the experiment JavaScript executes, again not ideal</p><h4><em>Was suitable for experiments where the content is modified on the server</em></h4><p>The client-side solution also restrict the experiments you can run, whereas many useful things that we wanted to test required some kind of modification of the response on the server-side, such as pulling alternative data out of the database.</p><h4><em>Is simple to reconfigure for a new experiment</em></h4><p>For a long time the perceived overhead of running experiments was the thing that prevented us from doing them at all, so we wanted something that we really simple to reconfigure whenever we planned to deploy a new experiment.</p><p>Ultimately we wanted to end up with something like the below where we could tweak a few configuration variables such as a path regex identifying the pages on which the experiment was to be run, and the percentage of customers who would be exposed to it, and it would automatically generate global variables that we could access from anywhere in our controllers and views that would allow us to render alternative content.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93c3e770b034b253a88b8f11758c0af3/href">https://medium.com/media/93c3e770b034b253a88b8f11758c0af3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5078d062ceeddb5d23316d529d15f11/href">https://medium.com/media/f5078d062ceeddb5d23316d529d15f11/href</a></iframe><p>So we basically worked backwards from that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fda063de4129f57f032fd2abc79a7f50/href">https://medium.com/media/fda063de4129f57f032fd2abc79a7f50/href</a></iframe><p>We made the config information accessible by setting the value to a constant called EXPERIMENTS_CONFIG, and we set about designing the utility that would handle our experiment logic.</p><h3><strong>The Experiments Utility</strong></h3><p>Now this utility had a number of responsibilities:</p><ul><li>To respect our caching infrastructure</li><li>To be able to identify sessions that are part of the experiment</li><li>To allow us to specify an even or controlled split between page variants</li><li>To ensure that a customer sees the same page every time they visit</li><li>To provide us a way of serving different content depending on the variant that was chosen</li><li>To provide the data back to the reporting engine, in our case Google Analytics</li></ul><h3><strong>Where should it live?</strong></h3><p>The first consideration for this new code is where we’re going to keep it, where it’s going to be called from and where it’s going to sit in the lifecycle of a request to our application.</p><p>You might think this would logically sit within the rails application and be called as an ActionController before filter for example, but what about requests that are served directly out of the cache and never hit the rails app?</p><p>This is absolutely critical to get right, because if your caching layer isn’t conscious of your experiment variants then you lose control over the proportion of customers that see each variant, and it becomes a lottery based on whichever variant was served when the cache was empty.</p><h3><strong>The Rack Middleware</strong></h3><p>Our cache layer is provided by a Rack middleware component, so it follows that our experiment code has to be executed earlier in the request lifecycle, so that our cache client has the ability to select a response not just based on the URL of the current request, but also on the variant of that page that has been identified for this customer.</p><p>Here is an example of how we would instruct Rack to insert the experiment code immediately before the cache layer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9481f954300abc90f69c339df6aa5b64/href">https://medium.com/media/9481f954300abc90f69c339df6aa5b64/href</a></iframe><p>And that in turn will load a simple rack app called Experiments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/525ec4b0d005122ab7c7b46cdadfbc4a/href">https://medium.com/media/525ec4b0d005122ab7c7b46cdadfbc4a/href</a></iframe><p>Rack provides an environment hash containing information about the request, which is made available to the rails app, and the thing we’re trying to do here is add our experiment information to that hash.</p><p>In the call method we first extract information from the existing environment hash, the path of the current request, and the cookies that have may have been set in previous requests to our domain.</p><p>We then instantiate a new class ExperimentManager passing in the config file and the two environment variables, and we call a method on this class called experiment_info, modifying the environment hash with the return value.</p><p>Now we’ll look at ExperimentManager in more detail</p><h3><strong>The Experiment Manager</strong></h3><p>The ExperimentManager is initialised with 3 bits of data, the config file, the path of the current request and the cookies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5c7771db041a8bf655e6adea5439598/href">https://medium.com/media/e5c7771db041a8bf655e6adea5439598/href</a></iframe><p>The first thing we have to determine is whether the experiment should be run at all.</p><p>This code is called on every single request to the site, but not every page will be relevant to the experiment, and if you’re sending data to Analytics from sessions that don’t include visits to your experiment pages you’re just going to be adding noise to the results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9c6ae2a817cec1971c043e2e5eec139/href">https://medium.com/media/e9c6ae2a817cec1971c043e2e5eec139/href</a></iframe><p>And the thing we’re checking here is whether the path of the current request matches the path regex stored in the config file</p><p>Now that we’ve established that the experiment is to be run we can start building up the information hash that we will provide to the rails app. The first thing we can do is read the experiment_id from the config file, and after that we can provide the variant, and that’s going to be derived by calling a method of the same name</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d25186fa8f2bd0b23ae6df23a7b83a/href">https://medium.com/media/26d25186fa8f2bd0b23ae6df23a7b83a/href</a></iframe><p>The thing we’re doing here is ensuring that a single customer sees the same variant on every visit and we do that by setting a cookie. We check whether a cookie has already been set, and if so extract the variant id, and if not we assign a new random variant</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0e702e64563310843b7dceb814ea55a/href">https://medium.com/media/b0e702e64563310843b7dceb814ea55a/href</a></iframe><p>The variant_from_cookie method is pretty straightforward. We are setting a cookie called cxapi, so it just checks to see if an existing cookie has been set with that name and whose value matches the experiment_id set in our config file. If there is one then we extract the integer value that we know will appear at the end of the string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ce805c2e652e85a97cffcfe2ab28bb8/href">https://medium.com/media/9ce805c2e652e85a97cffcfe2ab28bb8/href</a></iframe><p>But if that method returns nil then we will execute the second part of the expression which is assign_random_variant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cfb3de2e359bb7ef7b49dfc231ca5ea/href">https://medium.com/media/7cfb3de2e359bb7ef7b49dfc231ca5ea/href</a></iframe><p>All this method does is generate a number between 0 and 99 and compares it to the percentage specified in the config file, setting either a 1 or a 0 in each case.</p><p>So at the end of all that our experiment_info method will return a value looking something like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63b5dea2d8cac3011ddce17c5656ffab/href">https://medium.com/media/63b5dea2d8cac3011ddce17c5656ffab/href</a></iframe><p>And just as a reminder, we’re going to be setting this onto the environment variable that rack will provide to rails here</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/525ec4b0d005122ab7c7b46cdadfbc4a/href">https://medium.com/media/525ec4b0d005122ab7c7b46cdadfbc4a/href</a></iframe><h3><strong>Modifying experiment content inside Rails</strong></h3><p>Now that we have added the experiment info to the environment, we need to access it inside rails and make it available to our controllers and views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/864b525bbd9aac5808bbe0e4d1da961f/href">https://medium.com/media/864b525bbd9aac5808bbe0e4d1da961f/href</a></iframe><p>We do this by setting a before_filter in application controller that sets the value to an instance variable called @experiment_info. We also set a variable called @variant1 which is a boolean value telling us whether the customer is to see the new version of the page, or the original version.</p><p>And now that we have this, producing different versions of a webpage is as simple as checking for the variant number and displaying the corresponding content.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5078d062ceeddb5d23316d529d15f11/href">https://medium.com/media/f5078d062ceeddb5d23316d529d15f11/href</a></iframe><p>The final thing we have to do is make sure that once we’ve displayed the right content, we tell Google Analytics which variant we used, by loading the Content Experiments JavaScript API, and calling the setChosenVariation function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0598b30c238b44a84f6804f0417f9e02/href">https://medium.com/media/0598b30c238b44a84f6804f0417f9e02/href</a></iframe><p>We also set a cookie which is a string made up of the experiment_id and the variant, and this will be read the next time the user visits another page on the site</p><p>And that is the entirety of our implementation. We’ve had it in place without modification for a couple of years now and we’ve run numerous experiments with it. I’m going to finish up by talking about some of the experiments that we’ve run and the results that we’ve had.</p><h3><strong>What experiments have we run?</strong></h3><h4><strong>Experiments for risky features</strong></h4><p>Sometimes we run a test because we’re a little nervous about a new feature and want to test the water on a small proportion of users before releasing it more widely.</p><p>We were looking to showcase venues on the homepage that were from the same geographical region as the customer, and we do this by deriving coordinates from the customer’s IP address and uses them to fetch relevant venues from our database.</p><p>We knew that this was an element of risk attached to this as geolocation via IP is not always accurate, particularly on mobile networks. In our research we realised that in some cases we were geolocating people from the far north of England to London, and if there’s one thing that’s guaranteed to piss-off a northerner, it’s assuming that they want to go to London!</p><p>Luckily the split test narrowly found in favour of displaying the new content, so if there were any grumpy northerners they were in the minority!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkzqfSJMgLSmd7gNoRmGDQ.png" /></figure><h4><strong>Experiments for design changes</strong></h4><p>Sometimes we run a test because we want to test changes in layout and design. It’s very important to test these things because designers are usually very familiar with the site they are working on, and inclined to make assumptions about how users perceive the site that aren’t always substantiated.</p><p>Our design team had revamped our venue page addressing a number of long running concerns we had about the layout of the page. We had positive feedback from all the stakeholders in the business, and from pretty much everyone that we showed the page to, and if you ask me I still prefer the page now.</p><p>We ran the split test on 3 occasions, each time adjusting the new page in response to findings from the previous test, but in the end abandoned the new designs altogether because they were consistently outperformed by the existing page across a range of browsers and devices.</p><p>Had we gone with our intuition we would have ended up costing the company thousands of pounds in lost revenue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CR8Uau77oVGaC5aPLMx4nQ.png" /></figure><h4><strong>Experiments for political reasons</strong></h4><p>Sometimes we run split tests to maintain cordial relations with other departments!</p><p>The marketing team at Spabreaks were keen to hit customers with a popup window a few seconds after they’d landed on the site to get them to sign up to our email newsletter. Our feeling was that this was more likely to just antagonise customers rather than persuade them to do business with us, but we could see the argument from the marketing team who were keen to keep in touch with less motivated visitors who we might be able to attract over the long term.</p><p>We were hoping that the test would support our objection to it, but it actually ended up alerting us to a hard to detect UX bug.</p><p>Click throughs from the homepage were relatively unaffected which was surprising to us, but we noticed that people that saw the popup were less likely to make a booking once they got to the venue page.</p><p>When we investigated we realised that there was a interaction issue between our booking calendar, which also displayed in a popup-modal window, and the newsletter popup. If a customer already had the booking calendar open when the newsletter popup displayed, clicking to close the newsletter popup took the mouse focus away from the booking calendar, and meant that the customer could no longer scroll the page to reach the book button.</p><p>The compromise we reached was that we would continue to show the newsletter popup on the homepage, but we would remove it from all other pages.</p><p>We sadly weren’t able to prove that the popup was hindering the customer journey from the homepage, but it shows the incidental benefit of analysing features of your website in isolation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oA3mGz9uy0oOzrP0_TtuWw.png" /></figure><h4><strong>Experiments for refactored code</strong></h4><p>And finally sometimes we run tests purely to verify code that we have rewritten without necessarily changing the customer facing behaviour.</p><p>All the major transactions on our site take place with at least some interaction with a calendar, and our old implementation consisted of rails partials that were loaded by AJAX every time the customer clicked to switch months, and it was clunky and slow to operate and the codebase was getting extremely complicated to maintain to the point that we were reluctant to make changes to it. We rewrote all of our calendars in React which was a significant investment in time, and made the codebase a lot nicer, but for such a fundamental change we wanted to be sure that we hadn’t broken anything.</p><p>And a good job we did, because we had!</p><p>When we ran the split test the first time, the results were disappointingly in favour of the original implementation, which didn’t seem right so we investigated, and discovered that the conversion rate had dropped down to 0% for certain Internet Explorer browsers because of some incompatible javascript that we hadn’t provided a polyfill for.</p><p>When we fixed the issue and ran the split test for a second time, and the results evened out, so we were happy to deploy our new changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6hUtZw4fT87Dl9cVMU0Bg.png" /></figure><p>We did so with a confidence that we wouldn’t have had if we had just gone ahead and deployed, and that is the most important thing to take home from this, that by adopting a regular program of split-testing our code we have gained a higher level of confidence in our own code and our decision making, and I’d encourage anyone to do the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7232da4da835" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/split-testing-a-ruby-on-rails-application-7232da4da835">Split-testing a Ruby on Rails application</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everyone should write boring code]]></title>
            <link>https://medium.com/palatinate-group-tech/everyone-should-write-boring-code-a578ed186732?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/a578ed186732</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Rory Grieve]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 15:24:59 GMT</pubDate>
            <atom:updated>2017-07-11T15:24:59.112Z</atom:updated>
            <content:encoded><![CDATA[<p>That might sound like a strange thing to say but it’s the message of Adam Niedzielski’s <a href="https://speakerdeck.com/adamniedzielski/boring-ruby-code-2">talk</a> at Brighton Ruby Conference 2017. His point is simple, boring code, as opposed to smart code, is easier to understand and therefore easier to modify and delete.</p><p>Here’s one example of so-called smart code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2160VPqqLPu1LSLD6VcO6Q.jpeg" /></figure><p>While a boring version would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aE-Mk2CM64JtZ-9uABAWig.jpeg" /></figure><p>The first one may abide by the famous do not repeat yourself mantra but at the cost of being much harder. It’s so caught up in its own cleverness that it misses something as simple as splitting up a method. In contrast the modified version is far more ‘boring’, it looks like something a new junior might write. This simplicity is a virtue not a weakness.</p><p>Here’s another example of a an overcomplicated method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7YPPdWo8djRYOxPsBYSnw.jpeg" /></figure><p>Here’s another one to decipher:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrhKgoKIhr21hMTmYF61JQ.jpeg" /></figure><p>And one more for luck:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBQTPdFyCpWdajebDXkb_Q.jpeg" /></figure><p>All of these methods may indeed work but they are all unnecessarily ‘smart’. This means any programmer will have to spend that much longer trying to work out what each part does particularly for more junior members of the team. It’s always important to remember who you’re writing for and remember that code will always change. Boring code is code that’s easy to read, easy to modify and easy to delete.</p><p>So next time you’re tempted to use some obscure bit of programming or are reviewing a pull request with complicated code, take a step back and ask yourself is there a way this could be more boring?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4zrSs84iRT1jBHCq02kig.jpeg" /><figcaption>some of those interesting people</figcaption></figure><p>If you are looking to work somewhere full of interesting people that write ‘boring’ code <a href="https://tech.palatinategroup.com/were-hiring-8dd6a26e6b8c">we are hiring</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a578ed186732" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/everyone-should-write-boring-code-a578ed186732">Everyone should write boring code</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Used React To Help Improve Our Product Team’s Efficiency]]></title>
            <link>https://medium.com/palatinate-group-tech/how-we-used-react-to-help-improve-our-product-teams-efficiency-5751eb12c994?source=rss----1cb7e149612b---4</link>
            <guid isPermaLink="false">https://medium.com/p/5751eb12c994</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Adrian Booth]]></dc:creator>
            <pubDate>Fri, 02 Jun 2017 13:22:57 GMT</pubDate>
            <atom:updated>2017-06-02T13:22:57.241Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the darlings of the Palatinate Tech family is <a href="http://www.yourgolftravel.com/">Your Golf Travel</a>; a website that specialises in golf holidays in the UK and all over the world. It’s our focus to bring up to date pricing and all the relevant information users need to make a decision on where to go on holiday.</p><p>One challenge we faced recently was the amount of packages that were not loaded dynamically, and instead were hard coded <em>(hard coded!)</em> onto dozens of pages across the site. These hardcoded packages included information on pricing, board basis, and the number of reviews given to a venue on the package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmbX5QlQ1eRSrrm4Jzk8zQ.png" /></figure><p>For some of our landing pages, the content is delivered through an internal admin system that product and marketing staff spend time writing content in. Most of the site’s pages have structured layouts that use the same template, but there are still some landing pages that have no defined templates and just use the HTML written in the admin system.</p><p>The page above, for instance, is our page about <a href="http://www.yourgolftravel.com/all-inclusive-golf-holidays">all-inclusive-golf-holidays</a>page that has information on all inclusive packages we sell. Up until a few months ago, internal staff would have to manually go into the internal admin system and hard code all the HTML necessary to place these packages onto the site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1aL3WgWp89sOKGpYFxTeg.png" /></figure><p>This is a highly inefficient and frustrating thing to have to do. Not only is it time consuming, it’s also dangerous. Pricing for packages stored in our database change with regular frequency, and if our internal staff are coding packages in this way, with hard coded pricing information, you can imagine the frustration from users when they enquire on a package with out of date pricing!</p><p>We realised these packages had to be loaded dynamically, post-render, and loaded straight from the database. No more nasty HTML hardcoding horribleness.</p><p>We decided to create an API that would serve up packages to our React app on the frontend. We gave our internal staff specific instructions that they are to no longer hard code these packages, and instead use a magic short code that would generate a package for them dynamically.</p><blockquote>&lt;span class=”package-box” data-slug=”cornelia-diamond-resort”&gt;</blockquote><p>That’s it. From over 30 lines of disgusting HTML to just one simple span tag. Now the cheapest package for the Cornelia Diamond Resort will be loaded onto the page that they place this tag in.</p><p><strong>How did React help us with this?</strong></p><p>We first created a PackageGenerator component which we instantiated in a static_pages.js file. This function below would run on any page that is served up through our internal admin system, and on line 2 you can see it gets all the elements that have the class “package-box”, essentially grabbing all the magic tags our internal staff have placed in the body of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLEA5XBCOPRA1huzjtLF7A.png" /></figure><p>Next we used React’s lovely lifecycle method, componentDidMount, to make sure that when the page renders and the component is instantiated that we make API calls to fetch the packages specified in the data attribute in the span tag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1JC__5zSTYEAV6TyoYE1g.png" /></figure><p>If the magic tag contains a specific package id in the data attribute, it will retrieve that specific package from the backend. If it just contains the slug in the data attribute, it would return the cheapest package for that particular venue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNHQih29r5DxMv_BXc_siQ.png" /></figure><p>Once the API calls are done, we call this.setState which calls React’s render function, which then instantiates a new Package component inside the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSj2uCoE93qfdVvI7iApDA.png" /></figure><p>This component fortunately already existed for us at the time, as we were loading packages dynamically on our search pages on the site, so we were able to efficiently re-use a component that was being used elsewhere. It’s so wonderful and efficient I could cry.</p><p>And the result was a more efficient use of staff’s time, a more up to date website with no outdated pricing information, and gleefully satisfied users that lived happily ever after. It was a pleasure working with React to solve this specific business problem.</p><p>We’re constantly looking to improve our internal systems and build a more sustainable infrastructure. If you’re interested in tackling these challenges with us then get in touch, <a href="https://tech.palatinategroup.com/were-hiring-8dd6a26e6b8c#.t9cmkvwsr">we’re hiring</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5751eb12c994" width="1" height="1" alt=""><hr><p><a href="https://medium.com/palatinate-group-tech/how-we-used-react-to-help-improve-our-product-teams-efficiency-5751eb12c994">How We Used React To Help Improve Our Product Team’s Efficiency</a> was originally published in <a href="https://medium.com/palatinate-group-tech">Palatinate Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>