<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rafael Fiol on Medium]]></title>
        <description><![CDATA[Stories by Rafael Fiol on Medium]]></description>
        <link>https://medium.com/@rfiol?source=rss-8e722b6f410d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vpF_v7V3yoB66eWYavv11g@2x.jpeg</url>
            <title>Stories by Rafael Fiol on Medium</title>
            <link>https://medium.com/@rfiol?source=rss-8e722b6f410d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 12:33:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rfiol/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Open Graph meta tags with Angular on AWS]]></title>
            <link>https://medium.com/swlh/open-graph-meta-tags-with-angular-on-aws-744277b8c55c?source=rss-8e722b6f410d------2</link>
            <guid isPermaLink="false">https://medium.com/p/744277b8c55c</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[open-graph]]></category>
            <category><![CDATA[meta-tags]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Rafael Fiol]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 02:34:48 GMT</pubDate>
            <atom:updated>2022-08-05T13:58:04.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhjV4WtmqghUlS2kL3cxHQ.jpeg" /></figure><p>Meta tags are fun. Meta tags are cool. Meta tags are useful, especially for SEO and for social sharing applications.</p><p>When a web page is shared on Facebook, Facebook will inspect that page looking for <a href="https://ogp.me/">Open Graph</a> meta tags in the HTML. As a site developer, you should add these Open Graph tags to stipulate the title, description, and image (and potentially other data elements) that Facebook should use when rendering a preview of your page in the Feed.</p><p>Open Graph meta tags look something like this.</p><pre>&lt;meta property=&quot;og:type&quot; content=&quot;website&quot;&gt;<br>&lt;meta property=&quot;og:title&quot; content=&quot;My Amazing Website&quot;&gt;<br>&lt;meta property=&quot;og:description&quot; content=&quot;A terrible description.&quot;&gt;<br>&lt;meta property=&quot;og:image&quot; content=&quot;https://example.com/logo.png&quot;&gt;</pre><p>As an Angular developer, you probably know that you can dynamically add and update meta tags using the <a href="https://angular.io/api/platform-browser/Meta">Meta</a> service. But, the limitation with this approach is that Facebook and Twitter do not execute your Angular application’s Javascript when crawling your site. This means that only the meta tags in your static index.html will be visible. This, of course, is a problem.</p><h3>But I Don’t Like Angular Universal</h3><p>One often-cited solution to this problem is to use <a href="http://Angular Universal">Angular Universal</a> for server -side rendering (SSR) of your pages. I personally do not like this option, for a variety of reasons. But this article is not about the merits (or failings) of Angular Universal, and I will therefore simply present an alternative. This particular alternative leverages a feature in AWS CloudFront, and therefore assumes that you are hosting your Angular site in an S3 bucket on AWS with CloudFront.</p><h3>The AWS Way</h3><p>Amazon Web Services (AWS) makes it easy and <em>very</em> inexpensive to host your Angular apps using S3 and CloudFront. CloudFront, as you probably know, is a Content Delivery Network that can cache content and improve your site’s overall content access speeds. And it has a magnificent feature which allows you to run a function before/after any request for content. You can leverage this <em>hook</em> to inspect each request to see if the request is from Facebook or Twitter. If it is, you can instruct CloudFront to return alternative content — not our Angular page.</p><h3>My Use-Case</h3><p>I run a <a href="https://3-www.kompoz.com/">website</a> that makes it easy for musicians to collaborate and publish finished songs online. Sharing the songs on Facebook and Twitter is a key feature.</p><p>My site’s front-end is built with Angular, which is hosted in an S3 bucket, fronted by CloudFront. We also leverage <a href="https://www.contentful.com/">Contentful</a> — a truly wonderful headless CMS. The backend and experience API are REST-based Spring Boot apps hosted on EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mi_RDgS-D0P2iMP_wtYYog.png" /><figcaption>Architecture Figure 1</figcaption></figure><p>When a user visits the site, the request first goes to CloudFront. Within our CloudFront instance, we’ve installed a custom <a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html">Viewer Request</a> Lambda function that executes as soon as the request is received and before any content is returned to the user. It’s a simple Lambda function with a singular task: inspect the User-Agent http header, and <a href="https://developers.facebook.com/docs/sharing/webmasters/crawler/">if it’s Facebook</a>, then return a pre-published static HTML file that has our Open Graph tags. If it’s not Facebook, then do nothing, which instructs CloudFront to return the default content (which is the Angular app).</p><p>In our use-case, when a user publishes a new song through the UI, that UI calls a RESTful service, which queues a simple batch process to generate and write an HTML page to S3 with the relevant Open Graph tags. That is the HTML page that the Lambda function will return when the Facebook crawler comes crawling. The HTML page is practically empty, containing only the Open Graph Tags and required structural tags.</p><blockquote>We use Contentful to store the HTML structure. The HTML includes placeholders for the dynamic parts (title, image URL, etc.), which we replace using <a href="https://www.baeldung.com/spring-boot-mustache">Mustache</a>.</blockquote><h3>The Lambda Function</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5e5ae7048a14746b8ab57959083acbb/href">https://medium.com/media/c5e5ae7048a14746b8ab57959083acbb/href</a></iframe><p>The important bits are in the <strong>handler</strong> function. It starts by grabbing the User-Agent header, then matching that against the Facebook and Twitter crawler agents. If there is a match, it then checks to see if the request is for a “song page”. If so, the function calls loadSongResponse(), which calls loadResponse() with the bucket and key for the static HTML file.</p><h3>Install the Lambda Function</h3><p>To install this function, go to your CloudFront instance (the one that fronts your Angular application), then click on the <em>Behaviors</em> tab. Edit the default behavior (created automatically if you setup redirects from HTTP to HTTPS) or create a new Behavior. Go to the <em>Function associations</em> section and choose Lambda@Edge from the drop-down next to Viewer Request. It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REmZIQDm9VWRRbRJqbmUeA.jpeg" /><figcaption>Installing the Function in CloudFront</figcaption></figure><p>Paste in your Lambda function’s ARN and name. Be sure to include the version number of your function (if applicable).</p><h3>How do I Know It’s Working?</h3><p>Facebook provides a <a href="https://developers.facebook.com/tools/debug/">Sharing Debugger</a> tool that makes this easy. Enter the URL to your page and go. The debugger will show you the Open Graph tags it has found, and make recommendations on any corrections or missing tags.</p><p>Try it with this URL:</p><pre><a href="https://3-www.kompoz.com/radio/release/1225476">https://3-www.kompoz.com/radio/release/1225476</a></pre><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=744277b8c55c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/open-graph-meta-tags-with-angular-on-aws-744277b8c55c">Open Graph meta tags with Angular on AWS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Designed and 3D-Printed a Newtonian Reflector Telescope. The Views Are Amazing]]></title>
            <link>https://medium.com/swlh/i-designed-and-3d-printed-a-newtonian-reflector-telescope-the-views-are-amazing-2b41ed42bf58?source=rss-8e722b6f410d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b41ed42bf58</guid>
            <category><![CDATA[fusion-360]]></category>
            <category><![CDATA[3d-printing]]></category>
            <category><![CDATA[telescope]]></category>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[3d-modeling]]></category>
            <dc:creator><![CDATA[Rafael Fiol]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 23:03:11 GMT</pubDate>
            <atom:updated>2021-01-14T14:20:22.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Newtonian reflector telescope (rendered model)" src="https://cdn-images-1.medium.com/max/950/1*KeZr-eoj5YD4tmfkudZVww.jpeg" /></figure><p>When I pointed this thing towards the sky for the first time and peered through the eyepiece, two thoughts immediately struck me: 1) holy s*** it works!, and 2) wow, space is awesome.</p><p>Regarding my first thought… I wasn’t so much shocked that it worked, but I was shocked that it worked <em>so very well</em>. There’s a lot that goes into engineering a good telescope, and I was not sure if 3D-printing with plastic filaments would measure up. To my surprise, this thing works great.</p><p>To be fair, with its 6&quot; (153 mm) primary mirror, this is considered a small reflector telescope, and the engineering problems increase dramatically with larger telescopes. Nevertheless, even in this size class, mirrors have to be collimated, the optical tube can’t flex when you tilt it, the focal length has to be measured and engineered accurately, and the primary mirror has to have proper plate and edge support.</p><p>I’ll show you how I solved for these engineering requirements, but first it’s time for a little background.</p><h3>What’s a Newtonian Telescope?</h3><p>A Newtonian telescope is a type of <em>Reflector</em> telescope invented by Sir Isaac Newton in or around 1668. Today, this type of telescope is popular with amateur and DIY telescope makers because it has a relatively simple design (when compared to <em>Refractor</em> telescopes). Newtonian telescopes are usually less expensive than comparable quality/size telescopes of other types.</p><p>Generally speaking, there are two broad categories of telescopes: <em>Reflector</em> and <em>Refractor</em>. As a reminder, the 3D printed telescope we will be discussing is a Reflector. There are tons of great resources online that go into great detail about differences (and similarities) between the two. But for this article, I’ll keep it simple and say that Refractors use lenses to gather and focus light, while Reflectors instead use mirrors.</p><p>A Reflector telescope has two mirrors: the Primary (also called the <em>Objective</em>) and the Secondary. The primary mirror has a concave or parabolic surface and it is located at the tail end of the telescope. Its job is to reflect incoming light (which enters through the front of the telescope) towards a smaller secondary mirror positioned closer to the front of the telescope. Because of the parabolic shape of the primary mirror’s surface, the light is reflected along a cone-shaped path, towards a very specific focal point near (but just beyond) the secondary mirror. That secondary mirror is positioned at a 45-degree angle so as to reflect that light out towards the side of the telescope tube, where an eyepiece is attached. If the positions of the mirrors are accurate, the cone-shaped light comes to a point (the <em>focal point</em>) within the viewing limits of the eyepiece.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxgJQlavJqWBugu1Ie-FiQ.jpeg" /><figcaption>Light enters the tube and is reflected from the primary mirror, to the secondary mirror, to the eyepiece.</figcaption></figure><h3>Downloading and 3D Printing My Telescope.</h3><p>I designed this telescope using Autodesk <a href="https://www.autodesk.com/products/fusion-360/overview">Fusion 360</a>. It’s an absolutely amazing piece of software. If you’re a Fusion 360 user, you can download my Fusion 360 project file and customize the design as needed. Or, you can simply download the STL files and send them directly to your 3D printer.</p><p>All of the project files are available on my website <a href="https://www.bigbigspace.com/">www.BigBigSpace.com</a>. You’ll see two telescopes (at the time of this writing) on that website. The article you are reading now will focus on the telescope titled “Newton to See Here.” This scope is the second iteration of my 6&quot; Newtonian telescopes, and a significant improvement over the first scope.</p><blockquote>My first scope, named “<em>Reflector? I Hardly Newt Her!</em>”, is available for free. It’s a fine scope and works great, but I’ve learned a lot since then through field tests and studying proper telescope design. Those learnings are applied in the newer scope.</blockquote><h3>Is Everything 3D-printed?</h3><p>The two mirrors and the eyepiece (focuser) are not 3D-printed. Additionally, the truss tubes are also not 3D printed. The truss tubes in my project are 16mm (outer diameter) x 500mm (length) carbon fiber tubes which I purchased from Amazon. I chose them because they are light and very strong. You can substitute extruded aluminum tubes if you want to save a few bucks. Everything else (except for some screws and fasteners) is 3D-printed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sx2tkEpe0Ri8H4YPJng7EQ.jpeg" /></figure><h3>The Primary Mirror</h3><p>Obviously, you can’t print a mirror (yet). You’ll have to purchase a mirror or source one from a refurbished or discarded telescope. I purchased my mirror new from <a href="https://www.angenaastro.com/">AngenaAstro.com</a>. <a href="https://agenaastro.com/gso-parabolic-primary-secondary-mirror-set-6-f-5.html">This one</a> is guaranteed to fit the dimensions of the telescope, and has the proper focal length (750mm) for the truss tube design in this project.</p><p>Knowing the focal length of your mirror is critical. The focal length and tube diameter will determine your mirror placement. For our mirror with a 750mm focal length, we’ve placed our secondary mirror 540mm away from the primary mirror, leaving us 210mm to account for the radius of the tube and the length of the focuser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKaMcnfp9gFqzXSc-b_AKA.jpeg" /></figure><p>The 3D-printable mirror box and upper optical assembly (UOA) includes truss tube connectors angled precisely so that our truss tubes (positioned at angles for rigidity) separate our mirrors by 540mm.</p><h3>Primary Mirror Cell</h3><p>The primary mirror rests securely in the <em>Primary Mirror Cell</em>. This is an important part of the telescope that has a lot of responsibility. It must hold the mirror in place, making sure that it does not misalign as the telescope is moved on your <a href="https://en.wikipedia.org/wiki/Altazimuth_mount">alt-azimuth mount</a>.</p><figure><img alt="Primary Mirror Cell with 3-point Support and Whiffle Tree Edge Support" src="https://cdn-images-1.medium.com/max/1024/1*iNpGOsZWnJWppuELjyaSeg.jpeg" /><figcaption>Primary Mirror Cell with 3-Point PLOP and Whiffletree Edge Support</figcaption></figure><p>The mirror cell has to hold the mirror very gently and only touch the mirror in certain spots. Because as it turns out, mirrors are solids but not solid enough! They actually flex and change shape as pressure is applied. If the primary mirror flexes too much or in the wrong way, your view of the stars and planets will go from <em>Wow!</em> to <em>Blah.</em></p><p>Fortunately, people way smarter than me have created formulae and software to help us design the optimal mirror cell. The most popular software is <a href="https://www.davidlewistoronto.com/plop/">PLOP</a> (PLate OPtimizer). PLOP can be used to calculate floating support points for the rear of the mirror. In other words, the primary mirror will rest on the support points (which are calculated to precise locations) in order to minimize deflection.</p><figure><img alt="3-point PLOP / 150mm Primary Mirror" src="https://cdn-images-1.medium.com/max/994/1*LKbKSIR1SD67d0LyN7a2Sg.png" /><figcaption>3-point PLOP with 31.4 radius for 150mm Primary Mirror</figcaption></figure><p>Using PLOP, I opted for a simple 3-point support design. PLOP tells us that the support points should be 31.4mm from the center. With our 6&quot; primary mirror, this is more than adequate. Larger mirrors typically require more complex arrangements and floating 18-point designs are very common.</p><p>In addition to the rear support, the edge of the mirror must also be supported so that as the telescope is tilted, the mirror stays in place and does not warp (too much) as the pressure shifts to the edges. PLOP won’t help us here, but there are <a href="https://www.cruxis.com/scope/mirroredgecalculator.htm">other tools</a> and well-established best practices that will. Read <a href="https://www.cruxis.com/scope/mirroredgecalculator.htm">this</a> if you want to learn more. With our scope, I went with a modified whiffletree design — four edge support points separated by 45° (22.5° and 67.5° from the vertical).</p><blockquote>Note that a true whiffletree design should pivot at the midpoint (45°), but I opted to keep it simple (no pivot), since this is a small mirror.</blockquote><h3>The Optical Tube (a/k/a Truss Tube)</h3><p>I chose to use Carbon Fiber tubes on this telescope, which I purchased from Amazon. I chose them because they are light and very strong. You can substitute extruded aluminum tubes if you want to save a few bucks. The trusses need to be 480mm. The <a href="https://www.amazon.com/gp/product/B00RX5LNSI/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;psc=1">tubes I found on Amazon</a> are 500mm, which means you’ll need to cut those down 20mm. No big deal. Easy to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h659RONvlCvQ-BJ3UUXUOA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISw-H2QV2dUNpOf9eCDkXA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhqCErLYzU9iQSPb4PKXYw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NT5nEU8O-dQ61HXTLpPLKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SclIUxA84myC3sdv2x7PAg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgecimwUVh9FSKRILjvVaw.jpeg" /></figure><h3>Build Video</h3><p>Here’s a short video showing the assembly. It took me about 45 minutes. Most of that time was spent fighting the screws on the Upper Optical Assembly (UOA), because I didn’t have the right tools.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQ1Hgw48FfT8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ1Hgw48FfT8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQ1Hgw48FfT8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/51eebcb1e63f1d2641a61efee941cfa7/href">https://medium.com/media/51eebcb1e63f1d2641a61efee941cfa7/href</a></iframe><h3>The Views are Amazing</h3><p>Enjoy a few photos taken with this telescope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D09PSZ_qc9anIBiAg3MjkA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7U46MtjpA3s24aTmY5q2w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSZ8K4rqtiZQzstTZD4kkQ.jpeg" /><figcaption>Conjunction 2020 — Jupiter, four Galilean Moons, Saturn + Earth’s Moon</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZvmRLm9rqflnggqQmfE_aQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PXecB8Inc2PkC7KPvr0jw.jpeg" /></figure><h3>So How do I Download and Print?</h3><p>Head over to <a href="http://www.bigbigspace.com/">www.BigBigSpace.com</a>. You’ll find all the files and a parts list. If you make one, leave me a message and let me know! Enjoy.</p><p>UPDATE: I posted step-by-step build instructions on <a href="https://www.instructables.com/3D-printed-Newtonian-Reflector-Telescope">Instructables.com</a>. Oh, by the way, this project won the Grand Prize on a <a href="https://www.instructables.com/contest/plastics2020">recent contest</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b41ed42bf58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/i-designed-and-3d-printed-a-newtonian-reflector-telescope-the-views-are-amazing-2b41ed42bf58">I Designed and 3D-Printed a Newtonian Reflector Telescope. The Views Are Amazing</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why You Should Ask IT People to Write Limericks During Job Interviews]]></title>
            <link>https://rfiol.medium.com/why-you-should-ask-it-people-to-write-limericks-during-job-interviews-b33c5f49a844?source=rss-8e722b6f410d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b33c5f49a844</guid>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[limerick]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Rafael Fiol]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 21:04:35 GMT</pubDate>
            <atom:updated>2020-11-29T21:04:35.739Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why you should ask IT people to write limericks during job interviews</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mq3BUzSYrBfafC7FBogpxg.jpeg" /></figure><p>This past month, it was announced that the CIO of a publicly-traded company (where I just happen to work) would be stepping down in a few months. This was devastating news to me, and to many of the 200+ IT members of the company. She is an amazing CIO — someone who I respect for her strong leadership, her drive, and her intellect. When the news broke, I didn’t know what to say to her, so I avoided her for a few days while I thought about it.</p><p>And then I came up with an idea.</p><p>I decided to write her a <a href="https://en.wikipedia.org/wiki/Limerick_(poetry)">limerick</a>. <strong>I also asked everyone in the IT department to write her a limerick</strong>. My goal was to compile the submitted limericks into a book to present to her on behalf of her department, and to select a handful to read aloud during the upcoming semi-annual IT department meeting. I thought this would be a fun send-off for a special individual.</p><p>I believed my idea to be brilliant, because:</p><ol><li>Limericks are fun and light-hearted.</li><li>Limericks are short and easy to write.</li><li>There are countless examples easily found online.</li><li>Limericks follow a very specific pattern. IT people like patterns and formulas, and therefore should be comfortable adhering to the simple <a href="http://poetscollective.org/poetryforms/limerick/">system requirements<em> </em>of a limerick</a>.</li></ol><p>I put a plan in motion and, over the next several days, the limericks trickled in via email. By the end of the week I had received 63 limericks from 59 IT people (four people submitted two limericks). While I was a bit disappointed by the poor response rate (recall that my IT department is about 200 people), I was more surprised and disappointed by the limericks themselves.</p><p><strong><em>They kinda mostly sucked.</em></strong></p><p>To be fair, there were some truly outstanding submissions. One in particular was so well-written and poetic that it gave me chills when I first read it. But sadly, about 50% of them just plainly sucked.</p><p>Before you beat me up for applying such a negative value to subjective <em>art</em>, keep in mind that I did the math. That’s right, objective measurements can be applied to a limerick. And that’s what I did to each of the 63 that I received.</p><blockquote>I started noticing that the best limericks were submitted by the star employees.</blockquote><p>You may be thinking, ‘<em>You did the math? Why bother?</em>’</p><p>Because I wanted to test a hypothesis I was beginning to formulate in my head. I started noticing that the best limericks were submitted by the star employees. Star employees get things done, win <em>Employee of Quarter</em> awards, and are out-of-the-box thinkers. So if there truly is a correlation, then maybe I can use limerick writing in the interview process as a possible predictor of future success. So I did the math.</p><p>To be as objective as possible, I created a spreadsheet with three columns:</p><ol><li><strong>Column 1</strong>— Does the limerick follow the proper structural pattern? Does it have 5 lines? Does each line have a balanced number of syllables?</li><li><strong>Column 2</strong> — Does the limerick follow the correct rhyming pattern? Do lines 1,2, and 5 rhyme, and do lines 3 and 4 rhyme?</li><li><strong>Column 3</strong> — Do the 5 lines of the limerick work together contextually to form a story? Is it cohesive and somewhat creative?</li></ol><p>Admittedly, column 3 is not very objective, but I was very lenient in my grading of this factor. For the most part, as long as all of the lines worked together to tell a story, then I gave a favorable score.</p><p>Column 1 is worth one point. You either get it right and earn a 1, or get it wrong and earn a 0. Column 2 is exactly the same — a 1 or a 0. Column 3, however, is worth 2 points. You can get a 2 for a creative story, or a 1 for a story where at least all of the lines work together contextually, or a 0 for a complete creative failure (which is hard to achieve).</p><p>Using this grading system, a perfect score is a 4, with 50% of the score based on just getting the structure right (i.e., following directions), and 50% for creativity (i.e., actually telling a discernible story).</p><h3>Native Language is a Factor</h3><p>Obviously, English is not everyone’s native language. In my instructions to the IT team members I clearly stated that they could submit their limerick in the language of their choice. And a few people did. In fact, the one limerick which I cited earlier as giving my chills was written in Spanish.</p><h3>How They Did</h3><p>Overall, only 55% got the structure right (column 1). But 82% got the rhyming right (column 2). When I added in the creativity column, the grade distribution came out as follows (An “A” is a 4 … an “F” is a 0).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgCC2WHaiqcQH27BudN0sg.jpeg" /><figcaption>All Limericks (n=63)</figcaption></figure><p>The chart shows that just under 40% of the limericks were great — a perfect score. And another 14% were pretty good. Add those two together and you can say that about half of the IT professionals (53%) in this sample can write a decent limerick. Sadly, 47% cannot.</p><blockquote>…what does stand out to me is that when I looked at the limericks with a perfect score, the authors of those limericks are indeed top performing employees.</blockquote><p>I also looked at the breakdown by roles (programmers, designers, DBAs, etc), but these numbers should be <a href="https://en.wikipedia.org/wiki/Grain_of_salt"><em>taken with a grain of salt</em></a>, since the sample sizes get pretty small. Here’s what it looks like for the larger roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yl-1F4anvu1DN1JL4CYq2A.jpeg" /><figcaption>Programmers (n = 15)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xx4hMtyrOgZUrrxFHmsMHg.jpeg" /><figcaption>UI/UX Designers (n=6)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6tVLeWDD58vJ_POolKtXA.jpeg" /><figcaption>BA &amp; QA (n=12)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DojcB02mvZORT0oxRoA-A.jpeg" /><figcaption>Help Desk and Networking (n=11)</figcaption></figure><p>The charts are interesting, but again, the sample sizes are too small to draw definitive conclusions. However, what does stand out to me is that when I looked at the limericks with a perfect score, the authors of those limericks are indeed top performing employees. It’s clear.</p><p>On the opposite end, for the most part, low scores correlate to lower performing (or less engaged) employees, with one or two very notable exceptions (I was surprised to see two high achievers in this category).</p><h3>You Want to Hire Creative People</h3><p>I’ve hired many IT professionals. Until now, I have relied on a combination of interviews (phone, video, on-premise), skills tests, and reference calls. For the most part, those tools have helped weed out the unqualified candidates, but they do little to help find creative out-of-the-box thinkers. And that’s what I want — creative people who are self-starters, problem solvers, and innovators. I believe that asking a candidate to write a limerick could be a valuable data point, which may useful in the hiring process.</p><p>And conversely, it just might help in avoiding a bad hire.</p><p>Creativity is a difficult trait to measure. Are limericks the solution? Certainly not as a singular measure. But I will be asking future candidates to complete one, as a glimpse into their creative process. If nothing else, I’ll enjoy reading them and adding them to my statistical analysis.</p><p>Finally, I’ll leave with you with two hiring-related limericks and one computer science-related limerick, all of which I penned for this article. Grade me. And please leave a limerick for me in the comments.</p><blockquote>A programmer was recently hired<br>Whose resume was greatly admired<br>Null pointer exceptions<br>Revealed the deception<br>And the recruiter was hurriedly fired</blockquote><blockquote>He coded a function recursive<br>So blatantly out-right subversive<br>Though highly outdated<br>And equally hated<br>A GOTO would be less perversive</blockquote><blockquote>One zero one zero is ten<br>Letter ‘a’ is the same, ten again<br>In octal, one two<br>But the common purview<br>Is one zero base ten, my friend</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b33c5f49a844" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement an Alexa Skill with Spring Boot]]></title>
            <link>https://medium.com/free-code-camp/implementing-an-alexa-skill-with-spring-boot-also-why-would-you-do-such-a-thing-9992c0797646?source=rss-8e722b6f410d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9992c0797646</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[amazon-echo]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Rafael Fiol]]></dc:creator>
            <pubDate>Tue, 03 Jul 2018 13:06:28 GMT</pubDate>
            <atom:updated>2018-08-13T19:46:03.367Z</atom:updated>
            <content:encoded><![CDATA[<h4>And why you would do such a thing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agCi2IBtbBlRZsDfy6KRxA.jpeg" /></figure><p>There are two ways to implement custom <a href="https://en.wikipedia.org/wiki/Amazon_Alexa#Alexa_Skills_Kit">skills</a> for Alexa.</p><p>The first is the most common and is the Amazon-recommended way. Use <a href="https://aws.amazon.com/lambda/">AWS Lambda</a>, a server-less computer service. There is no shortage of articles and tutorials on the topic. This is not one of them.</p><p>The second way is far less common. This is hosting an endpoint using a HTTPS web service that you manage. It is a bit more difficult to find good examples of this approach. This article will attempt to do just that, and will use <a href="https://spring.io/projects/spring-boot">Spring Boot</a> as the basis for the implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*CBS-TT_JYEOWhYsdyr0OWQ.jpeg" /><figcaption>Endpoint configuration in the Alexa Skills Developer Console</figcaption></figure><p>But before we jump into the <strong>how</strong>, let’s talk about the <strong>why</strong>:</p><ul><li>Why would you not use AWS Lambda?</li><li>Why ignore an Amazon recommendation?</li></ul><p>These questions are important. You’ll find reams of great examples and documentation on building Skills with Lambda, and not so much for the alternative. It’s also important if you buy into the premise — which I do — that the world is going <a href="https://en.wikipedia.org/wiki/Serverless_computing">server-less</a>. This is a <a href="https://read.acloud.guru/six-months-of-serverless-lessons-learned-f6da86a73526">great article</a> on that topic by James Beswick. Going the HTTPS route will lead you down a lonely path, but sometimes that’s OK.</p><p>Here are some reasons why you may want or need to take that lonely path.</p><ul><li>You can write your Alexa web services using any programming language.</li><li>If you have existing RESTful services already deployed and you want to leverage that infrastructure/investment.</li><li>If your <a href="https://en.wikipedia.org/wiki/Chief_information_security_officer">CISO</a> does not allow off-premise or cloud-based infrastructures.</li><li>If you like lonely paths.</li></ul><p>In my case, I decided to explore the non-Lambda path primarily because I already had an existing services tier, which I wanted to leverage. There are <a href="https://en.wikipedia.org/wiki/Plain_old_Java_object">POJOs</a> and methods I wanted to reuse, without having to expose new endpoints. Of course, I could have created Lambdas that simply fronted those services, and that is a valid pattern. But I didn’t want to add another layer of deployment scripts, testing, and monitoring.</p><p>You probably have your own reasons. If I were building a new <a href="https://en.wikipedia.org/wiki/Greenfield_project">greenfield</a> application, I’d probably head down the Lambda path.</p><h3>Prerequisites</h3><p>You’ll use the <a href="https://developer.amazon.com/alexa">Alexa Developer Console</a> to register your skill, define the intents and utterances, and test it. I’ve assumed that you’ve already created a developer account, and that you can setup a new custom Skill within the console.</p><h3>A Spring Boot Alexa Skill</h3><p>The rest of this article will show you how easy it is to add an Alexa Skill to your existing Spring Boot applications. To demonstrate this, we’ll create a skill that will lookup fun facts about either a specific year, or a random year. You’ll be able to interact with our skill by saying things such as:</p><pre>Alexa, ask my demo app to tell me trivia about a random year.<br>Alexa, ask my demo app, what happened in the year 1984? </pre><p>Okay, yes, this is a pretty useless skill. But it will demonstrate all of the important aspects of an Alexa app, including:</p><ul><li>custom intent handling</li><li>using slots, session management</li><li>built-in intent handling</li></ul><p>To accomplish this, our example skill will call a free third-party API to lookup the trivia information, using the wonderful <a href="http://numbersapi.com/#42">NumbersAPI</a>. Many thanks to <a href="https://twitter.com/divad12">David</a> and <a href="https://github.com/mduan">Mack</a> for creating this fun service.</p><h3>Getting started</h3><p>First things first. Add the <a href="https://mvnrepository.com/artifact/com.amazon.alexa/alexa-skills-kit">Alexa Skills Kit SDK</a> to your “pom.xml” file. At the time of writing, the latest version of the SDK is 1.8.1.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;com.amazon.alexa&lt;/groupId&gt;<br>    &lt;artifactId&gt;alexa-skills-kit&lt;/artifactId&gt;<br>    &lt;version&gt;1.8.1&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>The SDK includes a special servlet, named SpeechletServlet, which you will need to load as part of the app bootstrap. This is actually very easy to do.</p><p>The servlet is a workhorse. It handles all of the messy <a href="https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html">requirements for hosting a skill</a>, such as verifying that the request was sent by Alexa, validating the signature, and checking the timestamp. Fortunately for us, we don’t have to deal with any of those headaches. We just need to load the servlet. Here’s how we do that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bc0de698f750ad620a6726c88cded84/href">https://medium.com/media/1bc0de698f750ad620a6726c88cded84/href</a></iframe><p>Simple. You can see above that we’ve created a configuration class that loads our servlet. On line 10, you can see that SpeechletServlet is instantiated, and then on line 13 it is registered with Spring.</p><p>That’s pretty much all you need to do to load the servlet.</p><p>As I noted, the servlet takes care of all the complicated handshake communications with Alexa. And after it does that, the servlet delegates the actual interaction business logic to a <strong>Speechlet</strong>, which you must implement. You can see on line 11 that the Speechlet, which I named HandlerSpeechlet, is assigned to the servlet. This Speechlet will be invoked with every Alexa interaction.</p><p>A Speechlet is just a POJO that conforms to the SpeechletV2 interface that is defined in the Alexa Skills SDK. Here is what the interface looks like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a79a9f7e6e09fb177d5fae2a04abb53/href">https://medium.com/media/1a79a9f7e6e09fb177d5fae2a04abb53/href</a></iframe><p>It’s your job to implement those four methods.</p><p>They’re all important, but most of the work happens in OnIntent(), which is invoked when the user says something meaningful. If you’re new to the vocabulary of Alexa programming, you should read <a href="https://medium.com/screenmedia-lab/utterances-slots-and-skills-the-new-vocabulary-needed-to-develop-for-voice-7428bff4ed79">Intents, Utterances, and Slots: The New Vocabulary Needed To Develop For Voice</a>.</p><h3>Defining intents</h3><p>Jump into the <a href="https://developer.amazon.com/alexa">Alexa Developer Console</a>. Set up a new custom skill within the console — that part is very easy. I’ve named my skill “MyDemoApp”, and under the Invocation menu, I set the Skill Invocation Name to “my demo app”.</p><p>Recall earlier in this article I said that you can interact with our skill by saying things such as:</p><pre>Alexa, ask my demo app to tell me trivia about a random year.<br>Alexa, ask my demo app, what happened in the year 1984?</pre><p>You can see that each of the above sentences start with the wake word (“Alexa”) and the Skill Invocation Name (“my demo app”).</p><pre>Alexa, ask my demo app ...</pre><p>Everything after the Skill Invocation Name is known as an <strong>utterance</strong>. It’s your job to list utterances in the developer console, and map those to an intent. A single intent normally has many utterances, representing the variations a user might say. For example, all of the following utterances are essentially the same:</p><pre>tell me trivia about a random year.<br>say something about any year.<br>pick a random year.<br>tell me some trivia.<br>say anything about any year.</pre><p>All of these utterances mean the same thing, and therefore can map to a single intent. In my application, I’ve called this the “RandomYearIntent”. Here’s what it looks like in the developer console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jAvV7iIAAnBDazM_TGgTA.png" /></figure><h3>Back to writing code</h3><p>With our first intent defined, it’s now time to jump back into our Spring application and write some code. Let’s edit our “HandlerSpeechlet”. For the moment, let’s skip the onSessionStarted and onLaunch methods of the Speechlet, and jump right into the onIntent method.</p><p>Because our application will eventually handle multiple intents, we’ll first need to determine which intent is being invoked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aa4e0c524668ea03c2157873ac425ed/href">https://medium.com/media/9aa4e0c524668ea03c2157873ac425ed/href</a></iframe><p>On line 10, we now have the name of the intent. In our example so far, this should be RandomYearIntent. At this point, you might be tempted to write a bunch of if-else statements against the intent name, but let’s try something a little smarter.</p><p>By making sure that our intents follow a specific naming convention, we can use some Spring magic to load and invoke specialized handlers for each intent. What follows is not something specific to the Alexa Skills SDK. It’s just my own way of handling multiple intents. There are many ways to implement this logic. Here’s mine.</p><p>Let’s start by defining an interface which we’ll use for all of our handlers. Let’s create IntentHandler as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b26e38d513671ffd12af5c915a1db3ac/href">https://medium.com/media/b26e38d513671ffd12af5c915a1db3ac/href</a></iframe><p>Next, for each intent, we’ll create a class that implements this interface. We’ll also be careful to name our classes the same as the intent name, with the word “Handler” appended. For example, for the intent “RandomYearIntent”, we’ll create a class named RandomYearIntentHandler<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a1ba066fd8ad61290726639ba363d19/href">https://medium.com/media/7a1ba066fd8ad61290726639ba363d19/href</a></iframe><p>Okay, let’s leave this unimplemented for now. We’ll go back to our “HandlerSpeechlet”<em> </em>to add code that will pass control to our new “RandomYearIntentHandler”. The basic strategy is to rely on our naming convention of “IntentName” + “Handler”.</p><p>I have removed some details and error handling from the code below so that we can focus on the important bits. At the end of this article, you can find a link to my GitHub repo with the complete code.</p><p>Check out lines 12 and 13 below, which construct the class name, then ask Spring to find a registered bean with that name. Then, finally, on line 17, we pass control to that handler.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2064728fb27afafecf7f6dfaed52e42d/href">https://medium.com/media/2064728fb27afafecf7f6dfaed52e42d/href</a></iframe><h3>RandomYearIntentHandler</h3><p>We now have the plumbing in place to call our specialized intent handlers. Let’s go back to the implementation of our “RandomYearIntentHandler”. This particular intent is simple. Here’s the complete implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/414ec069a19bbe924f8140a0c5049157/href">https://medium.com/media/414ec069a19bbe924f8140a0c5049157/href</a></iframe><p>Simple! Did you catch the annotation on line 1? That @Component annotation is a cool little trick that will tell Spring to create an instance of this class as a Bean. This is how we’re able to access the handler in our Speechlet, using beanFactory.getBean(handlerBeanName).</p><p>On line 11 we create a random number between 1900 and the current year. Then we call the <a href="http://numbersapi.com/#42">Numbers API</a> to get trivia about that year.</p><p>On lines 14 and 15 we create a Card and a Speech. The Card is what is displayed in your Alexa mobile app — or on the screen in the Echo Show. The Speech is what is spoken back to the user.</p><p>AlexaUtils is a simple class I created. I won’t go into the details here, but you can review it on <a href="https://github.com/raf66/AlexSpringBootWeb/blob/master/src/main/java/net/fiol/demo/alexa/utils/AlexaUtils.java">GitHub</a>.</p><h3>That was easy — what about slots?</h3><p>Slots are basically <strong>variables in utterances</strong>. Look back at the two intents in our application. The second intent, which I’ll name “SpecificYearIntent”, allows the user to say any year. For example:</p><pre>Alexa, ask my demo app, what happened in the year 1984?</pre><p>In the above utterance, the year is highly variable. We do not want to define an utterance for every possible year. Instead, we’ll define this utterance using a slot, as:</p><pre>Alexa, ask my demo app, what happened in the year {Year}?</pre><p>{Year} represents a number. Jumping back into our developer console, we’ll setup a new “SpecificYearIntent” intent with its associated utterances as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CDFfMDV8z_cQQeoSeMaisw.jpeg" /><figcaption>SpecificYearIntent utterances</figcaption></figure><p>I’ve defined a Slot named “Year”, which is of type “AMAZON.NUMBER”. Now, in my handler, I can fetch the slot value easily by name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33b502f900480a48efc3b7c4c1613af5/href">https://medium.com/media/33b502f900480a48efc3b7c4c1613af5/href</a></iframe><p>Line 13 is where we resolve the year Slot. The rest is all boilerplate Java code, which follows the same pattern as the first intent — call the NumbersAPI service for the year and handle the response.</p><h3>Sessions and state</h3><p>I didn’t get into the OnSessionStarted or OnLaunch methods of the Speechlet in this article, but I did include an implementation for OnLaunch in the <a href="https://github.com/raf66/AlexSpringBootWeb">sample project in GitHub</a>.</p><p>You can use the Session object to store variables that will be retained across invocations when in conversation mode. Conversation mode occurs when the user invokes your skill but does not speak a recognized utterance. For example:</p><pre>Alex, open my demo app.</pre><pre>&gt;&gt; Hello.  Here are some things you can say: Tell me something about a random year.  Or, what happened in nineteen eighty-nine?</pre><pre>What happened in the year 1984?</pre><pre>&gt;&gt; 1984 is the year that the European Economic Community makes £1.8 million available to help combat the Ethiopian famine on October 25th. </pre><pre>&gt;&gt; What else can I tell you? Say &quot;Help&quot; for some suggestions.</pre><pre>Cancel.</pre><pre>&gt;&gt; OK.  Goodbye.</pre><p>You’ll notice in my source code that I have a method named setConversationMode. It simply sets a variable in the Session, letting me know that we are in conversation mode.</p><h3>Summary</h3><p>Writing Alexa skills with Spring Boot is quite easy, and can be a powerful way to reuse your existing infrastructure. <a href="https://github.com/raf66/AlexSpringBootWeb">Download the complete app from GitHub</a> for more details.</p><p>And if you’re in the South Florida area, you can use my <a href="https://www.amazon.com/Rafael-Fiol-Cutler-Stew/dp/B0793FRYJG">Cutler Stew Skill</a> (built with Spring Boot) to learn when and where my band Cutler Stew is performing next.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9992c0797646" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/implementing-an-alexa-skill-with-spring-boot-also-why-would-you-do-such-a-thing-9992c0797646">How to implement an Alexa Skill with Spring Boot</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement Xamarin.Forms navigation using delegates and coordinators]]></title>
            <link>https://medium.com/free-code-camp/xamarin-forms-navigation-using-delegates-and-coordinator-a01fb7e3c120?source=rss-8e722b6f410d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a01fb7e3c120</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Rafael Fiol]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 17:36:13 GMT</pubDate>
            <atom:updated>2018-08-08T19:43:00.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQnSCD-sqgoSDH9ucrFRKA.jpeg" /></figure><p>Recently I have been thinking a lot about how to best implement page navigation within a Xamarin.Forms mobile app. My deep-dive into this topic started when a colleague sent me an article entitled <a href="http://khanlou.com/2015/10/coordinators-redux/">The Coordinator</a>, written by <a href="http://khanlou.com/">Soroush Khanlou</a>. Initially, I was a very happy passenger on the Coordinator bandwagon. I guess I still am. It’s a wonderful way to think about and implement <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a><em> </em>with respect to UI/UX and general navigation.</p><p>The following notes represent my thoughts on the subject, learnings with regard to an implementation in Xamarin.Forms, and how <strong>delegates</strong> in C# can help.</p><h3>Why Coordinators?</h3><p>Soroush’s solution focuses primarily on the problems with overstuffed view controllers (citing the iOS UIViewController as a primary example), and suggests that a Coordinator’s primary responsibility should be to take over navigation and model mutation. He states that:</p><blockquote>When we take those tasks out of a view controller, we end up with a view controller that’s <em>inert</em>. It can be presented, it can fetch data, transform it for presentation, display it, but it crucially can’t alter it.</blockquote><p>This is good. This is what we want. It means that we can reuse our view controllers as participants in multiple workflows, with purpose-built Coordinators for each workflow. Our Pages and View Models — in our MVVM applications — will no longer have messy navigation concerns.</p><p>Consider this common scenario. Let’s imagine that your app includes a login page. After a user completes the login page, your app then displays a dashboard page. Then, in a later design incarnation of your app, you decide that not all pages require a login. What if you want to reuse that login page elsewhere, and go to a different post-login page depending on the workflow that triggers the login?</p><p>The obvious (and ugly) solution is to start littering your Pages or View Models with conditional logic — normally in the form of IF/THEN statements. That never scales, and in large applications you end up with very brittle code.</p><h3><strong>Coordinators to the Rescue.</strong></h3><p>When I began my experiments to implement Coordinators in Xamarin.Forms, I had several design goals in mind.</p><p>First, this is not about MVVM. I have no desire to implement yet another MVVM framework for Xamarin. Further, navigation is not an MVVM concern. I assert that View Models (and for that matter, Pages) should not be aware of other View Models (and pages) within an application.</p><p>Second, Coordinators should not know anything about the underlying View Model that supports a page. My desire is for a Coordinator to simply launch pages, and respond to <strong>hooks</strong> exposed by those pages. This is somewhat analogous to the idea of <a href="https://en.wikipedia.org/wiki/Webhook">webhooks</a> (more on this in a bit).</p><p>Third, I wanted the implementation to be straightforward, without a lot of coercing of objects, and without diminishing any of the features that make RAD with Xamarin.Forms so amazing.</p><h3>Delegates to the Rescue.</h3><p>Before getting into building Coordinators, we have to first address a fundamental issue that comes up with every MVVM project. Specifically, how does a View Model, which is handling UI interactions, signal to the workflow that it has completed its intended task?</p><p>Using the login example I cited earlier, how does the View Model signal that the user logged in successfully (or unsuccessfully), and pass the generated access token and user information to the workflow that instantiated the page? And more importantly, how does the View Model publish that information? Is there a contract that can be inspected without having to dig through reams of code?</p><p>For me, the solution was to use <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/delegate">delegates</a>. In C#, a <strong>delegate</strong> is a reference type variable that holds a reference to a method. Delegates are similar to function pointers in C++. However, delegates are type-safe and secure. Using delegates, I create <strong>hooks</strong>, that the caller can use to participate in and influence the workflow.</p><p>For example, in my LoginViewModel, I declare a delegate definition, as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4148ad722ccd8bca9f3fb32b893cd044/href">https://medium.com/media/4148ad722ccd8bca9f3fb32b893cd044/href</a></iframe><p>I added this in the namespace, just above the actual declaration of my LoginViewModel class. This defines the pattern for the delegate, not the actual implementation. It tells a programmer that this View Model will perform a callback when the login is completed, and defines what parameters will be passed. In my LoginViewModel, I expose a property of this type. Users of this View Model can <em>attach</em> to it, to get a callback when the login completes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a45c0652d2f9c031b5a603c120ba738/href">https://medium.com/media/1a45c0652d2f9c031b5a603c120ba738/href</a></iframe><p>In the LoginViewModel, there is no implementation of this delegate. Instead, the View Model’s caller will implement the method — usually as an anonymous method or lambda — creating a sort of callback (or <strong>webhook</strong>) pattern.</p><p>Also in the LoginViewModel is an implementation of an <strong>ICommand</strong> which is invoked when the login button is pressed. It is in this command, after the login is successful, that we invoke the delegate. Below is a snippet of the command implementation. I’ve omitted much of the boilerplate code related to exception handling, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ede078c8d90b1751f00d4fc5d549f92/href">https://medium.com/media/2ede078c8d90b1751f00d4fc5d549f92/href</a></iframe><p>Notice the last line, which invokes the delegate. Also notice the <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators">null conditional</a>. The delegate is only invoked if it exists. So let’s see how we can use this.</p><h3>Threading the Hook.</h3><p>We’re not quite ready to create our Coordinators yet. But we have solved for a major design goal. We’ve defined a strategy for our View Models to expose important lifecycle events to anyone who cares. Continuing with the LoginViewModel example, we can hook into this as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/463555a696d47df0ddb7bdc909e0ea77/href">https://medium.com/media/463555a696d47df0ddb7bdc909e0ea77/href</a></iframe><p>Simple. The above demonstrates how we can create an anonymous method that will be invoked by our View Model. The method will receive the access token and user object, so that we can <em>do something important</em> with it, such as storing that data and navigating to the next page, for example. This is where our Coordinators come in. They will use these hooks to do something important.</p><h3>What About the Code-behind Pages?</h3><p>Earlier I said that w<em>e’ve defined a strategy for our View Models to expose important lifecycle events to anyone who cares</em>. The question is: exactly who cares when the login completes? Well, our <em>as-of-yet-undefined</em> Coordinates will care. But, recall that my second design goal stated:</p><blockquote>Coordinators should not know anything about the underlying View Model that supports a page.</blockquote><p>I’ve made a decision that this is to be a hard-and-fast rule. My Coordinators know about the pages that make up a workflow, but do not know or interact with the View Models of those pages. In fact, my code-behind pages create their View Models as <em>protected</em> properties. So, to keep the contracts clean, my code-behind pages simply relay delegate invocations. For example, my LoginPage code-behind looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f100acb46c9b7be83baa8760502d186/href">https://medium.com/media/2f100acb46c9b7be83baa8760502d186/href</a></iframe><p>Notice that the code-behind page registers itself as the object interested in a callback from the View Model (line 12), and then — because the code-behind does not concern itself in matters of navigation — it simply relays the callback to its own delegate (line 13).</p><p>This might seem redundant, but it has practical applications. First, it means that the View Model can expose delegate methods that are private to the code-behind page. Second, it means that there is very loose coupling between the Coordinators and pages.</p><h3>A Xamarin Coordinator Implementation</h3><p>With this, and my third design goal in mind, which is…</p><blockquote>I wanted the implementation to be straightforward, without a lot of coercing of objects, and without diminishing any of the features that make RAD with Xamarin.Forms so amazing.</blockquote><p>…I decided that pages can live on their own, or they can have attached Coordinators. It took me a while to arrive at this decision. I actually first started with a Coordinator-first design approach, whereby everything was driven by a Coordinator. I quickly found that this was terribly limiting and super complicated. It required a complex push/pop pseudo-navigation manager, and it limited my ability to easily use TabbedPages, MasterDetailPages, and modals. I also found myself pushing navigation logic into View Models. I didn’t like it.</p><p>So instead, I opted for a Page-first approach, whereby Pages can have a Coordinator attached to them. This solves a big issue related to <a href="https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals">garbage collection</a>, since the Xamarin.Forms framework already handles retaining and disposing of Pages based on visibility lifecycles. Had I gone down the Coordinator-first approach, I would have had to add a bunch of ugly logic to manage the stack myself.</p><p>With the Page-first approach, you can create a Page as you normally do, and you can pass (attach) a coordinator via the page constructor. So for the login page, it looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/773da210167d4e605f7275f3bc8f29bb/href">https://medium.com/media/773da210167d4e605f7275f3bc8f29bb/href</a></iframe><p>The nice thing about this approach is that I can also inject a Coordinator in XAML. This is especially useful in MasterDetailPage or TabbedPage situations, wherein you don’t normally create the instances in code. Such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15e093e4d43ef8373cb21bfd83620660/href">https://medium.com/media/15e093e4d43ef8373cb21bfd83620660/href</a></iframe><p>Before we get into the mechanics, let’s take a look the implementation of LoginCoordinator. Specifically, we’ll focus on what responsibilities this coordinator takes on, which is all encapsulated within the Coordinator’s Start() method. This is where all of the magic — navigation logic — happens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e6e48b92dcd7326c7e3aecbe356043a/href">https://medium.com/media/2e6e48b92dcd7326c7e3aecbe356043a/href</a></iframe><p>Before we go further, let me briefly explain a portion of the <a href="https://en.wikipedia.org/wiki/Business_logic">business logic</a> of the app. In this app (built for musicians), each user can belong to one or more bands. So after authenticating (logging in), the user is presented with a list of their bands. The user then selects one, and the app then completes the login workflow, and shows the post-login master detail page.</p><p>So, this LoginCoordinator actually orchestrates the presentation of two separate pages — the LoginPage and the BandPickerPage. Each of the pages can be used independently or as part of other workflows.</p><p>For example, the BandPicker page is used in another part of the app when the user wants to switch between their active bands, without having to login again. The BandPicker page is completely unaware of how it is being used. It just has to focus on doing what it does — pick bands.</p><h3>The Framework Stuff</h3><p>The implementation of the Coordinator itself is pretty easy. In my approach, there is one interface (called ICoordinator) and an abstract base class that partially implements that interface. The interface looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1aa44a83ba96ffb04ce8ea7f1fd12bd/href">https://medium.com/media/b1aa44a83ba96ffb04ce8ea7f1fd12bd/href</a></iframe><p>Each coordinator has to only implement the Start() method. The other two methods — AttachToPage() and DetachFromPage() — are implemented in the abstract base class. Here’s what that looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/100c53f5aec7c4ad6b9c785b139bb807/href">https://medium.com/media/100c53f5aec7c4ad6b9c785b139bb807/href</a></iframe><p>The application’s coordinators simply need to extend this base class and override the Start() method. That’s pretty much it. There’s only one other piece to the <strong>framework</strong>, which is a simple base class for ContentPage subclasses. It does nothing more than call the AttachToPage() and DetatchFromPage() methods of the Coordinators passed in to the constructor. That’s it.</p><h3>Summary</h3><p>Many thanks to Soroush Khanlou for the inspiration. I’d love to hear about how you’re using Coordinators in your own Xamarin projects, and any ideas you might have to improve upon the implementation I’ve presented here.</p><p>You can <a href="https://github.com/raf66/CoordinatorExampleApp">download my sample</a> app from GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a01fb7e3c120" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/xamarin-forms-navigation-using-delegates-and-coordinator-a01fb7e3c120">How to implement Xamarin.Forms navigation using delegates and coordinators</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>