<?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[Reaktor Technology - Medium]]></title>
        <description><![CDATA[Best from the Reaktor blog Technology related - Medium]]></description>
        <link>https://medium.com/reaktor-technology?source=rss----9c8dfa15d600---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Reaktor Technology - Medium</title>
            <link>https://medium.com/reaktor-technology?source=rss----9c8dfa15d600---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:21:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/reaktor-technology" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Refactoring 30000 lines of JS with types]]></title>
            <link>https://medium.com/reaktor-technology/refactoring-30000-lines-of-js-with-types-f666748bd7d4?source=rss----9c8dfa15d600---4</link>
            <guid isPermaLink="false">https://medium.com/p/f666748bd7d4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Reaktor]]></dc:creator>
            <pubDate>Thu, 02 Feb 2017 08:52:16 GMT</pubDate>
            <atom:updated>2017-02-02T08:51:50.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zeQ8bKTMSAGzzre3BOS81A.png" /></figure><p>30000 lines of client-side JavaScript. No tests. Two difficult TV deployment platforms with poor tooling. Strong dependencies on poorly documented external APIs. The task: add support for a third TV platform to the two supported platforms and switch to a new backend with a different API. How can we do this without breaking things?</p><p>One approach is to add tests incrementally- end to end tests to avoid breaking functionality and unit tests to aid with refactoring. But this was mostly user interface code on TV platforms with poor and varied tooling. Automated user interface testing on each platform would be challenging if possible at all. Manual testing on each platform was time consuming due to slow and inconsistent deployment tools.</p><p>Some parts of the application could be tested and this was a part of how we made this change. But the more interesting idea we tried was to refactor with types.</p><h3>The approach: refactoring with types</h3><p>The idea: introduce minimal typing to the code base. Add strong typing around a specific area to be changed. Make the changes, leaning on the compiler as an aid. Move on to the next area, incrementally adding types as we go.</p><p>This seemed like a nice fit for the project:</p><ul><li>No run-time dependencies. Some of the platforms had strict dependency requirements (read: ancient JS versions), but types are used only at compile-time.</li><li>Shortens feedback loop. Deploying in this project was slow and flaky and tests were nonexistent, but compiler errors would come immediately and tell you how you broke things.</li><li>Documents external APIs. The platform APIs used in the project were sometimes poorly documented, and types tell the story more clearly.</li><li>Low typing overhead. The project was mostly vanilla JavaScript, so there was little time-consuming typing of libraries to worry about.</li></ul><p>To experiment with the idea, I added strong types to a full path of code from UI to server calls and made breaking changes to see if the process and feedback felt useful. I tried this with both <a href="http://flowtype.org/">Facebook Flow</a> and <a href="http://www.typescriptlang.org/">TypeScript</a>.</p><h3>Trying Flow</h3><p>Adding Flow to the project involved steps like the following:</p><ul><li>Tagging files to be checked by Flow with /* @flow weak */ (using Flow’s <a href="https://flowtype.org/docs/existing.html#weak-mode">weak mode</a>).</li><li>Adding type annotations as comments, e.g. var msg/*: string*/.</li><li>Fixing errors:</li><li>Unreachable code — delete it.</li><li>Unresolved names and properties — declare them as any types.</li><li>Null values — type as nullable or add null checks (see below).</li></ul><p>I typed out a path from server to the UI, tried to use a field that didn’t exist on a type, and Flow complained properly. Good. But I ran into a few larger issues:</p><p><strong>Flow wants sane modules</strong></p><p>Flow assumes you use rational modules. If one module depends on variables from another module, it can use the types declared for the other module as expected, assuming the module is defined as a standard ES or CommonJS module. In lieu of sane modules, this code used global singleton “module” objects in different files mashed together into one file as part of the build process.</p><p>Introducing Flow here meant introducing proper modules first. This would have meant many breaking changes before we even started adding types.</p><p><strong>Null tracking meant many changes</strong></p><p>Flow uses nullable types. If your variables can be null or undefined, this must be declared in the type e.g.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*bSfkgsaIO8YIKEG0.png" /></figure><p>In general this is a Good Thing. But this code made extensive use of null values, which Flow rightly complained about. Fixing null errors meant either removing the uses of null to make a variable non-nullable or typing variables as nullable and added null checks wherever the variable is used. In the long term this would clean up the code base. In the short term this meant a large number of potentially breaking changes to introduce Flow to the project.</p><p><strong>Tooling was limited</strong></p><p>The Flow type checker itself worked quickly from the command line. The tools were easy to set up and use. It allows starting a server daemon to incrementally re-check types when run. The type errors were explicit and useful. However, editor support was essentially non-existent. You couldn’t, for example, view errors inline within an editor like Intellij IDEA or Emacs.</p><h3>Trying TypeScript</h3><p>Adding TypeScript required similar steps as Flow, with the addition of adding the TypeScript compiler to the beginning of the build process. The steps were straightforward:</p><ul><li>Rename “.js” files to “.ts”.</li><li>Fix errors, mostly by sprinkling any notations.</li><li>Declare global variables from other files, initially in global “.d.ts” files.</li></ul><p>Typing out a path from server to UI and breaking the type guarantees worked as expected.</p><h3>Choosing TypeScript over Flow</h3><p>Ultimately I went with TypeScript, almost as much for the drawbacks of TypeScript as for the benefits.</p><ul><li>TypeScript namespaces were an easy match for the unconventional global object modules used in the project. This made it easier to add typing to our project modules as they were, while eventually transitioning to conventional ES modules.</li><li>No null-checking in TypeScript by default made it much easier to initially type our code base.</li><li>TypeScript tooling and support were much better.</li></ul><p>I like both TypeScript and Flow. Here are a few differences as I see them:</p><ul><li>TypeScript infers little and gives little value without type annotations, while Flow tells more out of the box.</li><li>TypeScript has much better tooling. The Flow type checker itself was easy to use and worked well from the command line, but editor support was bare bones or nonexistent. TypeScript Intellij IDEA and Atom support was decent. More on that later.</li><li>TypeScript has better documentation and support. The Flow documentation was sparse but decent and has been improving. But the TypeScript documentation is really good: <a href="http://www.typescriptlang.org/docs/handbook/basic-types.html">the TypeScript Handbook</a>, <a href="https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md">Language Specification</a>, <a href="https://github.com/Microsoft/TypeScript/wiki/Roadmap">roadmap</a>, and <a href="https://github.com/Microsoft/TypeScript/issues">openly commented issues</a> are incredibly useful. TypeScript as a project also seems to have much more momentum behind it and the compiler has received a number of significant improvements in the few months of this project.</li></ul><h3>How we introduced TypeScript</h3><p>Introducing TypeScript and types to all top-level module elements in the 30000 line code base took two to three days. Initially there were a large number of <em>any</em> types. As part of this process the existing modules, defined as objects in the global namespace, were converted one by one to <a href="https://www.typescriptlang.org/docs/handbook/namespaces.html">TypeScript namespaces</a> via Vim macros, find-and-replace tools, and carpal-tunnel inducing Vim fu.</p><p>After this effort, types were added incrementally as a part of normal development. Whenever a certain area of the code was modified, types were first added around the areas to be changed. Then the changes were made, leaning on the compiler to tell when data used was not available, variables were missing, and so forth.</p><p>Initially there were both explicit and implicit (inferred) <em>any</em> types throughout the code. At some point <em>any</em> types were required to be explicit (via tsconfig <em>noImplicitAny</em>) and gradually most <em>any</em> types were replaced with more specific types. After nine months of development there were still about 485 <em>any</em> types in the code base, mostly related to the interesting “class” structure that had been used for UI elements in the project. More on that later.</p><p>At some point the TypeScript namespaces were replaced in one go by normal <a href="https://www.typescriptlang.org/docs/handbook/modules.html">ES modules</a>. Browserify was introduced at the same time to merge these modules into one file with proper modules, as TypeScript doesn’t handle this.</p><h3>Where TypeScript worked</h3><p><strong>Refactoring</strong></p><p>Adding types and in particular using TypeScript in Intellij IDEA was a godsend for refactoring. It removed a huge amount of manual checking that would have been needed for even basic changes.</p><p>The compiler would tell things like:</p><ul><li>Is my function called with the correct number of parameters?</li><li>Is this variable being used?</li><li>Does the value I am using exist?</li><li>Does the field I am using on this value exist?</li></ul><p><strong>Understanding the code base</strong></p><p>Question: what data is being used from the backend APIs in your JavaScript application?</p><p>JavaScript answer: find the code that calls an API and receives data as an opaque object. See where the data is passed. Follow that data and see where it gets passed next. Track how the object is modified along the way. Grep to the eventual places where the object is used and write down in your notes each field that is used. The process requires careful, focused navigation through the entire code base, good notes, and significant amounts of grepping.</p><p>TypeScript answer: add types to the API call, initially giving it your best guess of the correct type e.g. an empty object type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/0*HhUMzR8u7neKdun4.png" /></figure><p>Add type annotations to every place this function is being called. The compiler will tell you if your type is wrong. In Intellij you get a red squiggly line under your incorrect assumptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/0*3naiqL9MxkbrnkVy.png" /></figure><p>So you update the type to match reality:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/0*-8AJuyHESSQlydlu.png" /></figure><p>Continue adding type annotations everywhere the data is used and updating your types until the types match reality. This still requires much of the same navigation as above, but you offload a large portion of manual grepping and note taking to the compiler.</p><p><strong>Making tools better</strong></p><p>TypeScript makes Intellij IDEA amazingly better. My tooling experience has started good and improved during the time I’ve used TypeScript. Inline errors point directly to code issues, short-circuiting the write-debug cycle. Tools like navigating to functions, renaming variables, inlining functions, autocompletion, and finding variable usages work immensely better than with vanilla JavaScript. Much as I appreciate minimalist editors, combining Vim keybindings with refactoring and navigation tools makes me an absurdly more effective developer. It would almost be worth it to ignore types and use TypeScript for this reason alone.</p><p><strong>Documenting external APIs</strong></p><p>Some of the external APIs we used had poor documentation or were entirely undocumented. Adding type annotations to these APIs documents our own knowledge about those APIs and helps later when using the APIs. It’s also a convenient place to put comments about the sources of documentation, implicit assumptions and so forth.</p><p><strong>Making code dependencies explicit</strong></p><p>Types document the flow of data throughout your app. In our case the UI and data were not clearly separated. It was a mess to trace the source of data down to the leaves of the app where the data was being used. Types made these dependencies explicit and much easier to follow.</p><p><strong>Finding bugs</strong></p><p>In some places adding types revealed bugs. For example, incorrect titles for images were being displayed in some cases because they relied on the old API data which no longer existed. Adding types caught this immediately because the new API data types did not contain this information.</p><p>In another example an image was fetched by passing in a string to a function and receiving the image URL. It turned out that the string contained a typo, which we found after making the function take a <a href="https://github.com/Microsoft/TypeScript/pull/5185">string literal type</a>.</p><p>In a number of places we could safely remove dead code only because we knew that the data did not exist on the new types.</p><p><strong>New tools, old environment</strong></p><p>Introducing TypeScript brought most of the ES6 benefits to a legacy JavaScript project without introducing runtime dependencies. It also did not require another heavy tool like Babel, although we did need Browserify to get proper modules.</p><h3>Where TypeScript failed</h3><p>You can’t always trust the compiler</p><p>TypeScript is <a href="https://www.typescriptlang.org/docs/handbook/type-compatibility.html">explicitly unsound</a>, which could lead to some surprising errors. In practice we did not run into these. There are other cases, however, where TypeScript works exactly as intended, but it might not be how you expect.</p><p>Here’s a type puzzle. Explain the type checks in 1–5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*O7Z8eF06pUOh6FbH.png" /></figure><p>Answers:</p><ul><li>1) is OK because all fields of the empty object type <em>{}</em> exist in value <em>{ foo: “hello” }</em>.</li><li>But 2) fails because even though we can assign an object with property <em>foo</em> to a variable of type <em>Empty</em>, the variable type doesn’t have <em>foo</em> in it so we can’t use it.</li><li>3) fails because it’s missing the <em>text</em> property of type <em>Msg</em>.</li><li>But 4) also fails even though it has the <em>text</em> property, because you can’t directly assign or declare an incompatible type (with the <em>foo</em> property).</li><li>But 5) is OK, because even though variable d of type <em>{ text: string; foo: string; }</em> is not assignable to type Msg, a value of type <em>{ text: string; foo: string; }</em> is compatible with type Msg.</li></ul><p>There are subtleties here that make it difficult to completely trust the compiler.</p><p><strong>Type inference doesn’t go very far</strong></p><p>The limitations of TypeScript’s type inference can be surprising. For example, TypeScript will rightly complain about this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/0*sO2VsJ5eojE0G1_y.png" /></figure><p>but is OK with this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*wQKOyVkSzdYk7Ptq.png" /></figure><p>It’s easy to see why this doesn’t generate a complaint, but this might be unexpected, which brings me to the next point.</p><p><strong>TypeScript requires many type annotations</strong></p><p>In the above example the two cases are semantically equivalent. The problem is that the compiler is able to infer the correct type of the callback parameter in one but not the other. In the second case the compiler infers the <em>any</em> type. To make it easier to trust the compiler, it’s useful to disable implicit <em>any</em> types (via tsconfig) and/or explicit <em>any</em> types (via TSLint). The compiler would then complain about the second example because of the inferred <em>any</em> type.</p><p>TypeScript doesn’t give you much support for free. If you add type annotations, your editors get better and the compiler will aid you in finding errors. If you don’t add type annotations or if you use many <em>any</em> annotations, TypeScript won’t help much. In practice this means you will be writing a lot of type annotations.</p><p><strong>Types are still your assumptions</strong></p><p>When receiving data from external sources, the type embodifies your assumptions about the data. You are expecting to receiving an object, with a field name <em>foo</em>, with an array of <em>bar</em>, and so forth. These assumptions are not checked by the compiler. You still need to validate input data if you want to be sure. The types are only as good as your assumptions.</p><p><strong>Typing can’t always be incremental</strong></p><p>In most cases we were able to add typing in small chunks, but not always.</p><p>A large portion of the UI code in this project used a hierarchy of view objects. This hierarchy would map well to TypeScript classes, but typing it as classes is difficult to do piecemeal. If you add types only to a parent class, the compiler complains when the child class uses its own fields that do not exist on the parent class (and are not yet typed on the child). If you add types only to a child class, the compiler complains when you use fields from the child that are only defined on the parent class. In practice it means that the typing of this whole hierarchy must be done in one go.</p><p><strong>Circular dependencies</strong></p><p>TypeScript doesn’t allow circular dependencies. Sort of. TypeScript was happily compiling our code, circular dependencies and all, for months until one day it broke. Maybe it was just serendipitous that the dependencies were loaded in the correct order before, but it stopped working. We painfully refactored the circular dependencies all away. Lesson learned: no circular dependencies in your TypeScript code.</p><h3>Was it worth it?</h3><p>Adding TypeScript to this project was an experiment to see if adding incremental types to our code would make it easier to do large refactorings without introducing large breaking changes. The experiment was a success.</p><p>Converting the project to TypeScript and adding the initial types took a few days. This was the only additional work that was required solely due to adding TypeScript. After this types were available as another development tool and were expanded incrementally to the rest of the code as a part of normal development. Refactoring was much easier with type checking and it removed a huge number of manual checks and careful grepping that was previously needed to change code.</p><p>A few items made this project a particularly good fit for TypeScript:</p><ul><li>Few dependencies meant little time typing out external libraries.</li><li>The environment was difficult to deploy to, so compile time checks gave dramatically faster feedback.</li><li>Tests were difficult to write, so types added a much needed safety net.</li><li>TypeScript support for older versions of JS allowed us to use new JavaScript features at compile time and remove at run time.</li></ul><p>The biggest drawbacks were the typing overhead of adding annotations nearly everywhere and the uncertainty about type guarantees in certain cases such as those discussed above. It’s not <a href="http://www.purescript.org/">PureScript</a>, but types were useful and they were easy to add incrementally. In this case it would have been more risky to continue with vanilla JavaScript than to introduce types.</p><p>4/5 stars. Would use again.</p><p>Original article published here: <a href="https://www.reaktor.com/blog/refactoring-30000-lines-js-types/">https://www.reaktor.com/blog/refactoring-30000-lines-js-types/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f666748bd7d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reaktor-technology/refactoring-30000-lines-of-js-with-types-f666748bd7d4">Refactoring 30000 lines of JS with types</a> was originally published in <a href="https://medium.com/reaktor-technology">Reaktor Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software projects differ, obstacles don’t — five key ways of tackling the most common issues]]></title>
            <link>https://medium.com/reaktor-technology/software-projects-differ-obstacles-dont-five-key-ways-of-tackling-the-most-common-issues-b71313bc9499?source=rss----9c8dfa15d600---4</link>
            <guid isPermaLink="false">https://medium.com/p/b71313bc9499</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Reaktor]]></dc:creator>
            <pubDate>Thu, 17 Nov 2016 08:01:11 GMT</pubDate>
            <atom:updated>2016-11-17T07:52:43.026Z</atom:updated>
            <content:encoded><![CDATA[<p>by Petteri Parkkila. He is a seasoned software architect with over ten years of experience in the software industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuk0BgjGT_t55NTvrHoxKw.jpeg" /></figure><p>I’ve been working for Reaktor for almost six years. During that time I’ve taken part in numerous projects. In a way, projects are always as unique as the customer and industry; the overall look and feel of the end results are usually different as well.</p><p>However, there are more similarities than one might think of — especially when it comes to obstacles that software developers bump into in their daily tasks. Fortunately, there are ways to tackle these common problems — here’s my top-five.</p><h3>1. Keep power and responsibility in your own hands</h3><p>When starting a project, I always have a hunch about the risks that it might include. Knowing the magnitude of each risk helps the team prioritize tasks. For example, there might be risks that could well jeopardize the whole project, and there’s no point in continuing the work before the team is absolutely sure that these risks are taken care of.</p><p>Integration points are commonly seen as risks: it’s hard to estimate the amount of work of the implementation when you’re not in control of all the variables. The number of integration points is directly proportional to the number of possible errors. In addition to common programming errors, integrations make errors in communication possible. Fixing these errors is not only difficult but also very time consuming.</p><p>The fact is that integrations can’t always be avoided. However, they can be done in a way that reduces the possibility of failure. Keep APIs simple, atomic and retryable. Avoid any magic behind the scenes. Aim for keeping power and responsibility at your end of the integration.</p><p>It’s usually easier to test your own code and fix your own bugs than the ones made by other people. And as we all know, bugs can’t be avoided since we’re only human — and humans make mistakes.</p><h3>2. If it’s possible to use something differently, it will be used differently</h3><p>Why? Simply because users behave differently.</p><p>A case in point: When developing an application to be used in a web browser, every possible way to use the software is going to be used. Separate tabs, windows, ad-blockers — you name it.</p><p>You don’t have to support all the possible combinations, but you should be aware of their existence. For example, if the software doesn’t work without a browser’s Local Storage and the support for it can be detected with code, it’s better to tell the end-user about it rather than letting the customer service correct the misuse. Communication always improves the customer experience.</p><h3>3. Test with real end users</h3><p>You are blind to your own creation and you should be aware of this. If you don’t test with real end-users you are testing your behavior — and you end up developing the application for yourself.</p><p>As said before, people behave differently. Test your design and user experience in real contexts and with real customers. The logic behind this is that acting out different scenarios yourself usually results in flawed data and the real need never reveals itself. Simple.</p><p>This realization should also affect the process of choosing the right test users. Basically, choosing a heterogeneous set of users is a crucial cornerstone of any successful service.</p><h3>4. Automate the things that should be automated</h3><p>Automating tests should be a no-brainer, so I won’t rant about that. However, automation can and should be done in other parts of software as well. A good rule of thumb is: if you do it daily or even weekly and it can be automated, you should definitely invest in it. It’s also good to automate large scale tasks that should be done precisely and that are error-prone when done manually.</p><p>Building up environments for your software is a great example of the latter one. Environments should always be prepared and attributed in the same way in order to make results similar and process robust. And these days when software is run in cloud, setup is a large task.</p><p>To namedrop a few of the tools I’ve used: There’s Terraform to automate creation of AWS infrastructure all the way from the network configurations to the Docker containers to be run in different clusters. I’ve turned to Ansible when there has been a need for building, for example, a Continuous Integration machine (CI) from scratch. And of course, I use Jenkins as a CI machine that tests the code and builds the artifacts to be deployed to cloud.</p><p>Automation can be seen as a big investment and sometimes it is. So pick your battles and consider carefully where the value of automation surpasses the investment.</p><h3>5. Keep your environments as close to production as possible</h3><p>Bugs and errors are likely to occur when software is run in many environments that don’t match the production environment. For example, there could be a different test account for a payment service and different hardware wiring at the production location. Or maybe the production environment doesn’t even exist yet.</p><p>The last case happened when we were building an in-flight entertainment system for Finnair. The first new Airbus A350 was still under construction somewhere in France, and our team had to rely on mere specifications of the aircraft.</p><p>When developing software there are usually many environments. There’s your local environment running on your laptop. There might be a couple of testing environments running in the cloud. And then there’s the production environment. You can’t always match the environments completely, but you should nevertheless aim for it.</p><p>As previously discussed automation is highly useful when setting up these different environments. A good automation tool will give the developer certainty as only the parameters of these environments differ. In a nutshell, automation with a good tool will enable a more transparent developing process and in the end, result in better digital products.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b71313bc9499" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reaktor-technology/software-projects-differ-obstacles-dont-five-key-ways-of-tackling-the-most-common-issues-b71313bc9499">Software projects differ, obstacles don’t — five key ways of tackling the most common issues</a> was originally published in <a href="https://medium.com/reaktor-technology">Reaktor Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using visualizations to communicate data science — Case cancer risk analysis]]></title>
            <link>https://medium.com/reaktor-technology/using-visualizations-to-communicate-data-science-case-cancer-risk-analysis-2d91d3b49213?source=rss----9c8dfa15d600---4</link>
            <guid isPermaLink="false">https://medium.com/p/2d91d3b49213</guid>
            <category><![CDATA[cancer]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Reaktor]]></dc:creator>
            <pubDate>Tue, 08 Nov 2016 05:48:23 GMT</pubDate>
            <atom:updated>2016-09-05T10:59:41.921Z</atom:updated>
            <content:encoded><![CDATA[<p>by Juuso Parkkinen and Kaarlo Haikonen. Juuso is a data scientist and freeskier currently especially interested in healthcare applications. Kaarlo is a co-founder and software developer at NetMedi, Finnish software company developing user-centered software for the future of healthcare.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c9j3FcUyf2vs3F3ulnmzbg.jpeg" /></figure><p><strong>Data science sounds complex, and it often is. However, the results of data analysis need not — and, indeed, should not — be complex. In this post, we show how interactive visualization can be used to effectively communicate risk estimates for cancer relapse.</strong></p><p>The applications of advanced number crunching, or data science, show huge potential in the field of healthcare. It was recently estimated that <a href="https://pivotal.io/big-data-for-healthcare">a one percent reduction in process inefficiency in healthcare would lead to $63 billion in savings.</a> In order to tap into this potential, data science and predictive analytics solutions need to be implemented and integrated as part of the clinical healthcare systems.</p><p>This requires applying the latest medical research results systematically to clinical care processes, and communicating the outcomes to the clinical staff and patients. Multiple experts are needed to bridge this gap between research and practice.</p><p><strong>The first big step is to integrate latest computational methods from scientific publications into actual production systems in healthcare. </strong>Implementing reliable computational software for healthcare requires understanding of the medical domain and the computational methods — a task for experienced data scientists.</p><p><strong>The second step is to make sure that the results are understood by their intended audience.</strong> In this case, that means patients and doctors. While state-of-the-art predictive analytics algorithms may be pure gibberish inside, their outcomes can often be nicely visualised for effective communication.</p><h3>Case: Online tool for evaluating the risk of GIST recurrence</h3><p>Together with Reaktor data scientists and user interface designers, Netmedi developed an online calculator visualising the risk of gastrointestinal stromal tumor (GIST) recurrence and helping the doctors to evaluate the need for additional treatment after surgery. GIST Risk calculator is based on a research containing an international sample of 2000 diagnosed GIST-patients, published in 2012 by HUCH Cancer Center and Aalto University.</p><p>“The nonlinear mathematic model predicts the combined effect of the main prognostic factors more accurately than any known model before”,<em> </em>describes Aki Vehtari, Professor at Aalto University and the researcher behind the mathematical model of the risk analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8Hy9XlIm1tAfSY_IGnP0Q.png" /></figure><p>GIST Risk calculator provides the user with a risk prediction based on four different parameters: size of the tumor, mitotic count (represents amount of dividing cells indicating the aggressiveness of the tumor), tumor site (location of the tumor) and whether the tumor has been ruptured or not.</p><p>The tool then computes and visualizes estimates of the probability of the tumor recurring after a given time period after the surgery (at max 10 years). In addition, the uncertainty in the estimates is indicated as the 90% credible interval (the light blue area between the grey curves), meaning that the risk probability lies within the given range with 90 % confidence, according to the model.</p><p>The method is based on Gaussian Processes and Bayesian inference, tailored for this specific application to be suitable for assessing nonlinear effects and implicit interactions between input variables. The model also gives a robust estimate of the uncertainty in the results it provides in the form of credible intervals.</p><p>As the computational method is customised for this specific application, we could not use the existing machine learning libraries directly, and had to implement the required linear algebra computations manually. While implementing the calculator, we wanted to explore how the technologies recently gathered popularity in the modern software development, such as Node.js and Docker, would fit for the task.</p><p>We began by experimenting if the results could be computed live with Node.js, but support to standard native libraries was not good enough yet. In the end, we came to the conclusion that Node.js’s event loop model does not suit compute-intensive linear algebra very well either, and ended up using a popular and order of magnitude faster solution: Python, fuelled with libraries such as NumPy and SciPy.</p><p><strong>One aspect that we wanted to pursue was to make the calculator and the results of the research widely available and easy to use for everyone. </strong>The <a href="http://gistrisk.com/">resulting web service</a> uses modern web technologies to combine the state-of-the-art computational biology research with a convenient user interface, and is available for all cancer care and research professionals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d91d3b49213" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reaktor-technology/using-visualizations-to-communicate-data-science-case-cancer-risk-analysis-2d91d3b49213">Using visualizations to communicate data science — Case cancer risk analysis</a> was originally published in <a href="https://medium.com/reaktor-technology">Reaktor Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we built our ESB using Node.js]]></title>
            <link>https://medium.com/reaktor-technology/why-we-built-our-esb-using-node-js-a9b6a7dd645e?source=rss----9c8dfa15d600---4</link>
            <guid isPermaLink="false">https://medium.com/p/a9b6a7dd645e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[bluebird]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Reaktor]]></dc:creator>
            <pubDate>Tue, 08 Nov 2016 05:41:17 GMT</pubDate>
            <atom:updated>2016-11-08T05:28:29.486Z</atom:updated>
            <content:encoded><![CDATA[<p>by Kari Kammonen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCI_w3E4DbWdBiUFWEbJmQ.jpeg" /></figure><p>Integration is one of the core problems in the IT industry. You know the drill — every business has legacy systems waiting to be connected to new services. Sometimes you need to compose a new application out of a fistful of microservices, at other times you agonize over the best platform on which to do your SOA orchestration.</p><p>This is where enterprise service buses, ESBs, come into play. Every big brand — Oracle, IBM, Microsoft, the list goes on — has their own, and there are multiple open source alternatives that compete with the big brands.</p><p>The thing is, all of them suck just as much.</p><p>In software development, the best tool for a certain task is often the one that offers the right amount of abstraction. Too much, and you limit the things you can do, or too little, and you end up wasting time.</p><p>Evaluating ESBs is no different. You want the one that enables you to solve the problem at hand, with minimal amount of work, and you know what: there is no particular reason why your ESB should be a product. Sometimes it is good to think outside the box or certain market niche.</p><h3>Making life a bit easier with Node.js</h3><p>Six months ago, we were tasked to help Houghton Mifflin Harcourt (HMH), world-leading educational publisher, to integrate their backend systems to two new services.</p><p>We set off by selecting Node.js as the platform for integration.</p><p>Speed of development was what we considered the most important factor of success. We also felt that Node.js would offer just the right level of abstraction for this case. You can build the most complicated and time-consuming features, and it is still easier to fetch and compose data with Node.js than with most traditional ESB products.</p><p>We marked that Node.js enjoys a bad reputation of being unstable and not “enterprise ready.” While partly true, no application platform is a hundred percent stable. Instead of relying on the platform to be reliable, it might be wiser to just assume the platform to be unstable and tackle such issues by design and cloud solutions.</p><p>Node.js is a surprisingly good integration platform in itself, but can be made better with a little bit of extra help. <a href="http://bluebirdjs.com/docs/getting-started.html">Bluebird</a>, one of the most popular promise libraries, offers that extra little bit of control in orchestrating asynchronous calls, whether you want things done in parallel or sequential fashion. <a href="https://baconjs.github.io/">Bacon.js</a> does the same, but we found Bacon.js buses to be at their best as the main structure of an integration. The asynchronicity of Javascript really plays well in integrations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4LiycOwpfXbaGDcFaQfNg.jpeg" /></figure><p>One of the advantages of using the Node.js ecosystem as an ESB is that you can boost the performance of your legacy services rather easily. It’s common to find that some of your existing APIs are lacking in performance, and improving them might either be costly or near impossible.</p><p>With Node, you can easily add things like Elasticsearch as a cache, and expose cached results through your API. Node.js makes a lot of sense as a composer of microservice architecture, as an integration tool and generally works as an ESB replacement everywhere.</p><p>Consider giving Node.js a try next time you’re evaluating ESBs or integration tools. You don’t have to go all in, start with a proof of concept and expand from there. It might be the best decision you ever made.</p><p>Take it from us:</p><p>Being an educational publisher, HMH has a strict yearly cycle — the back-to-school season is in the fall. Weeks before back-to-school start we had the first version running, tested and in production, ready to support eager students returning to school.</p><p>Oh, and we were a year early.</p><p>We attribute the success mostly on selecting the right tool, but also focusing on what was the absolutely minimum set of features for a viable product. <a href="https://www.reaktor.com/cases/hmh/">Read more about our work with Houghton Mifflin Harcourt.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9b6a7dd645e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reaktor-technology/why-we-built-our-esb-using-node-js-a9b6a7dd645e">Why we built our ESB using Node.js</a> was originally published in <a href="https://medium.com/reaktor-technology">Reaktor Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three JavaScript performance fundamentals that make Bluebird fast]]></title>
            <link>https://medium.com/reaktor-technology/three-javascript-performance-fundamentals-that-make-bluebird-fast-92f91d665b5c?source=rss----9c8dfa15d600---4</link>
            <guid isPermaLink="false">https://medium.com/p/92f91d665b5c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[bluebird]]></category>
            <dc:creator><![CDATA[Reaktor]]></dc:creator>
            <pubDate>Tue, 08 Nov 2016 05:38:51 GMT</pubDate>
            <atom:updated>2016-08-29T14:58:33.387Z</atom:updated>
            <content:encoded><![CDATA[<p>by <a href="https://reaktor.com/author/petka-antonov/">Petka Antonov</a> — Programmer and creator of the acclaimed Bluebird promise library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_PNFynBK6KYHh8a0ng2dA.jpeg" /></figure><p>Bluebird is a widely used promise library for JavaScript which got initially noticed back in 2013 due to being up to 100 times faster than other promise implementations with similar feature sets at the time. What makes bluebird so fast is the consistent application of some JavaScript optimization fundamentals throughout the library. This article will go over in detail 3 of the most valuable fundamentals that were used to optimize bluebird.</p><h3>1. Minimize function object allocation</h3><p>Object allocations, particularly function object allocations due to the heavy amount of internal data needed to implement them, can be very taxing to performance. Practical implementations of JavaScript are garbage collected so allocated objects are not simply just sitting in memory but the garbage collector is constantly looking for unused objects so that they can be deallocated. The more memory you use in JavaScript the more CPU is being used to power the garbage collector and less CPU becomes available to run actual code.</p><p>In JavaScript functions are first class objects. This means they have same features and properties as any other object. If you have a function which contains code declaring another function or functions, then every call to the parent function will create new unique function objects despite having the same code. A basic example of this would be:</p><pre>function trim(string) {<br>    function trimStart(string) {<br>        return string.replace(/^\s+/g, &quot;&quot;);<br>    }<br><br>    function trimEnd(string) {<br>        return string.replace(/\s+$/g, &quot;&quot;);<br>    }<br><br>    return trimEnd(trimStart(string))<br>}</pre><p>Now every time the trim function is called, two unnecessary function objects are created to represent the functions trimStart and trimEnd. The function objects are unnecessary because they are not being used for their unique object identities such as property assignment or closed over variables. They are only used for the functionality of the code that they contain.</p><p>This particular example is very easy to optimize, the functions can simply be moved outside of trim. As the example is contained in a module and the module is only loaded once for the program, only one representation will exist for the functions:</p><pre>function trimStart(string) {<br>    return string.replace(/^\s+/g, &quot;&quot;);<br>}<br><br>function trimEnd(string) {<br>    return string.replace(/\s+$/g, &quot;&quot;);<br>}<br><br>function trim(string) {<br>    return trimEnd(trimStart(string))<br>}</pre><p>However, more commonly function objects seem like a necessary evil and cannot be optimized out so trivially. For instance, any time you are passing a callback function somewhere to be called later, there is virtually always a need for a unique context for that particular callback. Typically such context is implemented in an easy and intuitive but inefficient way using closures. A simple example of this can be reading a file as JSON in node using the default asynchronous callback interface:</p><pre>var fs = require(&#39;fs&#39;);<br><br>function readFileAsJson(fileName, callback) {<br>    fs.readFile(fileName, &#39;utf8&#39;, function(error, result) {<br>        // This is a new function object created every time readFileAsJson is called<br>        // Since it&#39;s a closure, an internal Context object is also <br>        // allocated for the closure state<br>        if (error) {<br>            return callback(error);<br>        }<br>        // The try-catch block is needed to handle a possible syntax error from invalid JSON<br>        try {<br>            var json = JSON.parse(result);<br>            callback(null, json);<br>        } catch (e) {<br>            callback(e);<br>        }<br>    })<br>}</pre><p>Here the callback passed to fs.readFile cannot be moved out of readFileAsJson as it is creating a closure over the unique variable callback. It should also be noted that making the fs.readFile callback a named function declaration instead of an inline anonymous function will not make any difference.</p><p>An optimization that is used internally in bluebird to a great extent is the usage of an explicit plain object to hold contextual data. An operation that consists of callback passing through multiple layers will only require one allocation of such an object. Instead of each layer creating a new closure every time a callback is passed to another layer, the explicit plain object is passed as an extra argument. For example, if there are 5 callback steps in an operation, using closures would mean allocating 5 function objects and Context objects whereas only 1 plain object would be allocated in total when using the explicit plain object optimization.</p><p>If the fs.readFile API could be modified to accept a context object, applying the optimization on the example would look like this:</p><pre>var fs = require(&#39;fs-modified&#39;);<br><br>function internalReadFileCallback(error, result) {<br>    // The modified readFile calls the callback with the context object set to `this`,<br>    // which is just the original client&#39;s callback function<br>    if (error) {<br>        return this(error);<br>    }<br>    // The try-catch block is needed to handle a possible syntax error from invalid JSON<br>    try {<br>        var json = JSON.parse(result);<br>        this(null, json);<br>    } catch (e) {<br>        this(e);<br>    }<br>}<br><br>function readFileAsJson(fileName, callback) {<br>    // The modified fs.readFile would take the context object as 4th argument.<br>    // There is no need to create a separate plain object to contain `callback` so it<br>    // can just be made the context object directly.<br>    fs.readFile(fileName, &#39;utf8&#39;, internalReadFileCallback, callback);<br>}</pre><p>As is evident, you need to control both ends of an API which makes this optimization unusable with APIs that don’t take context object parameters. However, when you can utilize it (e.g. when you control multiple internal layers), the performance gains are substantial. A little known fact: some built-in JavaScript Array APIs, such as Array.prototype.forEach, take a context object argument as the second parameter.</p><h3>2. Minimize object size</h3><p>It is crucial to minimize the size of objects that are allocated often and in great quantities such as promises. The heap where objects are allocated in the most used JavaScript implementations is divided into segments and spaces. Smaller objects take longer to fill the spaces and segments than larger objects thus creating less work for the garbage collector. Smaller objects also generally have less fields for the garbage collector to visit when determining live and dead objects.</p><p>Boolean and/or restricted integer fields can be packed into much smaller space by utilizing bitwise operators. JavaScript bitwise operators operate on 32-bit integers so you can for example fit 32 boolean fields or 8 4-bit integers or 16 booleans and 2 8-bit integers etc into just one field. To keep the code readable, each logical field should have a getter and setter function pair that performs the proper bitwise operations on the physical field. Example of 1 boolean field packed into an integer (which can be expanded to contain more logical fields in the future) might look like this:</p><pre>// Use 1 &lt;&lt; 1 for the second bit, 1 &lt;&lt; 2 for the third bit etc.<br>const READONLY = 1 &lt;&lt; 0;<br><br>class File {<br>    constructor() {<br>        this._bitField = 0;<br>    }<br><br>    isReadOnly() {<br>        // Parentheses are required.<br>        return (this._bitField &amp; READONLY) !== 0;<br>    }<br><br>    setReadOnly() {<br>        this._bitField = this._bitField | READONLY;<br>    }<br><br>    unsetReadOnly() {<br>        this._bitField = this._bitField &amp; (~READONLY);<br>    }<br>}</pre><p>The accessor methods are so short that it is very likely they will be inlined at runtime so there is no function call overhead involved.</p><p>Two or more fields that are never used at the same time can be compressed into just one field when using a boolean to track which type of value the field holds. However, this will only result in space savings if the boolean field is implemented as a packed integer field as described in the previous trick.</p><p>In bluebird this trick is applied when storing the fulfillment value or rejection reason of a promise. There is no explicit field for it: if the promise is fulfilled then the fulfillment value can be stored in the rejection callback field and if the promise is rejected then the rejection reason can be stored in the fulfillment callback field.Again, all accesses should be made through accessor functions that hide the ugly details of this optimization.</p><p>If an object requires a list of items you might be able to avoid a separate array allocation by simply storing the values directly on the object’s indexed properties.</p><p>So instead of:</p><pre>class EventEmitter {<br>    constructor() {<br>        this.listeners = [];<br>    }<br><br>    addListener(fn) {<br>        this.listeners.push(fn);<br>    }<br>}</pre><p>You can avoid the array:</p><pre>class EventEmitter {<br>    constructor() {<br>        this.length = 0;<br>    }<br><br>    addListener(fn) {<br>        var index = this.length;<br>        this.length++;<br>        this[index] = fn;<br>    }<br>}</pre><p>If the .length field can be restricted to a small integer (e.g. 10-bit which would limit the event emitter to a maximum of 1024 listeners) it can be made part of a packed bit field along with other restricted integers or booleans.</p><h3>3. Use no-op functions and overwrite them lazily to implement costly optional features</h3><p>Bluebird has several optional features that cause a uniform performance loss throughout the library when used. Such features are warnings, long stack traces, cancellation, Promise.prototype.bind and promise state monitoring. These features require calls to hook functions throughout the library. For example, the promise monitoring feature needs a function to be called every time a promise is created.</p><p>Checking if the monitoring feature is enabled before making the call to the hook function would be better than just making the call regardless of if the feature is enabled. However, the cost can actually be completely eliminated for users that have not enabled the feature thanks to inline caches and function inlining. This can be done by making the initial hook method just an empty function:</p><pre>class Promise {<br><br>    // ...<br><br>    constructor(executor) {<br>        // ...<br>        this._promiseCreatedHook();<br>    }<br><br>    // Just an empty no-op method.<br>    _promiseCreatedHook() {}<br><br>}</pre><p>Now, if the user doesn’t enable the monitoring feature, the optimizer sees that the function call doesn’t do anything and eliminates it. So the call to the hook method inside the constructor effectively doesn’t exist.</p><p>To make the feature actually work, the act enabling of the feature must overwrite all the related no-op functions with the actual implementations:</p><pre>function enableMonitoringFeature() {<br>    Promise.prototype._promiseCreatedHook = function() {<br>        // Actual implementation here<br>    };<br><br>    // ...<br>}</pre><p>Overwriting the method like this will invalidate any inline caches built for objects of the Promise class so this should only be done at the startup of the application before any promise objects are created. If the overwriting happens before any usage, the inline caches that will be built from usage after the feature is enabled will not even realize the no-op functions even existed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92f91d665b5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reaktor-technology/three-javascript-performance-fundamentals-that-make-bluebird-fast-92f91d665b5c">Three JavaScript performance fundamentals that make Bluebird fast</a> was originally published in <a href="https://medium.com/reaktor-technology">Reaktor Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>