<?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 Francesc Campoy on Medium]]></title>
        <description><![CDATA[Stories by Francesc Campoy on Medium]]></description>
        <link>https://medium.com/@francesc?source=rss-d32302f8a956------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FHghJla45wJ6Keyk0GOqEQ.jpeg</url>
            <title>Stories by Francesc Campoy on Medium</title>
            <link>https://medium.com/@francesc?source=rss-d32302f8a956------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:44:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@francesc/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[Serialization Versioning: the Semantic Versioning for Databases]]></title>
            <link>https://medium.com/@francesc/serialization-versioning-the-semantic-versioning-for-databases-eea5aece0355?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/eea5aece0355</guid>
            <category><![CDATA[semver]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Wed, 26 Jun 2019 23:34:32 GMT</pubDate>
            <atom:updated>2019-06-27T21:55:54.462Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: This post was written as part of our efforts on finding a new versioning schema for </em><a href="https://github.com/dgraph-io/badger"><em>BadgerDB</em></a><em> and heavily inspired by Manish Jain’s post on this </em><a href="https://discuss.dgraph.io/t/go-modules-on-badger-and-dgraph/4662/7?u=mrjn"><em>Discuss thread</em></a><em>.</em></p><p>Semantic Versioning, commonly known as SemVer, is a great idea that has been very widely adopted as a way to decide how to name software versions. The whole concept is very well summarized on semver.org with the following lines:</p><blockquote>Given a version number MAJOR.MINOR.PATCH, increment the:<br>1. MAJOR version when you make incompatible API changes,<br>2. MINOR version when you add functionality in a backwards-compatible manner, and<br>3. PATCH version when you make backwards-compatible bug fixes.<br>Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.</blockquote><p>I have used and benefitted from this clear naming schema for many years, but recently I did find a small concern which drove me to propose a slightly different naming schema, specifically designed for libraries that provide encoding and decoding mechanisms which are not part of their API.</p><p>Let’s imagine that you’re the maintainer of a little library that handles a TODO list. The API for version `v1.0.0` is the following (I went with Go, but hopefully you get what it’s doing).</p><pre>package todo</pre><pre>type TaskManager struct {<br>   Path string<br>}</pre><pre>type Task struct {<br>   ID int<br>   Text string<br>   Done bool<br>}</pre><pre>func (tm *TaskManager) Get(id int) (*Task, error)<br>func (tm *TaskManager) Add(text string) (*Task, error)<br>func (tm *TaskManager) Save(id int, task *Task) error<br>func (tm *TaskManager) Remove(id int) error</pre><p>These tasks are transparently stored in a file with the path given to the TaskManager.</p><p>A new version appears where, for performance sake, the format in which the tasks are stored on disk changes from XML to JSON. The API has not changed at all, has it? So you release a new version, and following the Semantic Versioning naming schema, you call it `v1.0.1`.</p><p>Now imagine you have a user with a couple of billion tasks already stored on their huge disks, they see that a new patch version has been released, and automatically update to the next version. Surprise, all of their systems are down!<br>What happened? Well, the new version expects all files to contain JSON, but the ones on disk are still in XML so they won’t be parsed.</p><h4>Is SemVer flawed or am I holding it incorrectly?</h4><p>There are two different points of view on this issue: either semantic versioning is a flawed naming strategy, or we’re missing something out.</p><p>The easy way is to blame others, so let’s say that Semantic Versioning is wrong. How is it wrong? Well, it fails to identify that “major” changes are not necessarily major or even visible on a library’s API.<br>But there’s a second way of seeing this, maybe our API *should* include the way data is serialized — regardless of whether the data is going to be sent through the network, or stored in disks, there’s a clear impact of that format changing over time.</p><p>Do you know what kind of libraries suffer from this? Key value stores like BadgerDB definitely do.</p><p>But there’s one more aspect in which Semantic Versioning doesn’t necessarily match what databases do most of the time. It turns out that a backward-incompatible change on the API, e.g. renaming the <em>Done</em> field in <em>Task</em> to <em>Accomplished</em>, might be actually a minor change — as it can be easily automated with little risk. Why should we call say our library is now <em>v2</em> just because a field name has changed?</p><h4>Serialization Versioning</h4><p>This is why I’m proposing a new naming mechanism, heavily inspired by Semantic Versioning, but optimized for database libraries and similar: Serialization Versioning.</p><p>Serialization Versioning also uses 3 numbers and also calls them <em>MAJOR.MINOR.PATCH</em>, but the semantics of the numbers are slightly modified:</p><p>Given a version number <em>MAJOR.MINOR.PATCH</em>, increment the:</p><ol><li>MAJOR version when you make changes that require a transformation of the dataset before it can be used again.</li><li>MINOR version when old datasets are still readable but the API might have changed in backward-compatible or incompatible ways.</li><li>PATCH version when you make backward-compatible bug fixes.</li></ol><p>Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.</p><p>Following this, renaming the <em>Done</em> field would lead us to <em>v1.1.0</em> which implies a minor migration cost. On the other hand, migrating from XML to JSON as our encoding format would directly move the package to <em>v2.0.0</em> as the cost of this migration could be quite large depending on the dataset size.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eea5aece0355" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[justforfunc: just for everyone]]></title>
            <link>https://medium.com/@francesc/justforfunc-just-for-everyone-ddad12126fd2?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddad12126fd2</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[justforfunc]]></category>
            <category><![CDATA[volunteering]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Sat, 02 Mar 2019 19:19:33 GMT</pubDate>
            <atom:updated>2019-03-02T19:26:47.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FwmGW7bSqhiz5i8S.jpg" /><figcaption>justforfunc is expanding!</figcaption></figure><p>Many of you have noticed how <a href="http://justforfunc.com">justforfunc</a> has had no new episodes for a while now. Some have asked about what the future holds for the channel, and I’m here to answer today.</p><p>The biggest problem with justforfunc, since its inception, has been the time required to build <strong>good</strong> content. It’s not only the recording but also planning, scripting (yes, I write scripts sometimes), and finally editing, publishing, and promoting. After adopting the role of VP of Product at source{d}, in addition to VP of DevRel, the delicate balance in between personal life, work hours, and personal projects went south.</p><p>I tried to decide how to balance my increasingly busy professional life with my personal goal: give back to the developer community by sharing what I’ve learned from some of the most talented people in the industry.</p><p>At first, it seemed impossible but then I started thinking about this from a slightly different perspective. I realized egocentrism had driven me to think justforfunc was about me. It’s not, justforfunc is about giving back to the community and helping those trying to learn.</p><p>This is why justforfunc is evolving into a community project. I’m going to build a community of hosts and editors with a shared passion for education and a shared mission of technical knowledge sharing in video form. I will still be sometimes on screen, but much more often behind it: mentoring hosts and ensuring consistency and content quality that meets everyone’s expectations and occasionally exceeds our wildest dreams too.</p><blockquote>Do you want to join the justforfunc team?</blockquote><p>I’m looking for:</p><ul><li>🎥🤩 <strong>hosts</strong>: You’ll need a camera and a decent microphone, I’ll provide mentoring to make sure the videos we release are stellar.</li><li><strong>🎞🧐editors</strong>: I’m not counting on hosts to be able to edit videos, so you’ll be the one getting the raw video contents and be responsible to make them look awesome … and add a touch of fun. <a href="https://www.youtube.com/watch?v=LSzR0VEraWw&amp;feature=youtu.be&amp;t=13m46s">Editing puns</a> are part of the justforfunc brand, yes.</li><li><strong>🎯🙃 project managers</strong>: Bring your ideas to the table, help decide what topics should be covered, and help hosts and editors collaborate to release amazing content that the audience will love.</li></ul><p>Would you like to contribute in a different way? Let me know how!</p><blockquote>Let’s make it clear: this is not about 💰</blockquote><p>I hate to say this but you’d be doing this mostly “for exposure” and to put in practice your passion for teaching. The <a href="http://patreon.com/justforfunc">Patreon</a> account I set up provides enough money to pay for some hardware (lights, mics, etc) but it’s definitely far from being a decent salary.</p><p>I’m not saying justforfunc will never become an international brand of universal recognition, but it’s not guaranteed. If we ever end up making enough money, the team will get to decide what to do with it. I’m personally in favor of donating all of it to <a href="https://github.com/gobridge/about-us/blob/master/README.md">Go Bridge</a> and <a href="https://womenwhogo.org/">Women Who Go</a> but it’s something we’ll be decided once there’s any money to donate!</p><blockquote>Do you still want to join the adventure?</blockquote><p>Then go fill this form and I’ll be in touch with you soon: <a href="http://join.justforfunc.com">join.justforfunc.com</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddad12126fd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One year a sourcerer]]></title>
            <link>https://medium.com/@francesc/one-year-a-sourcerer-1c8b2147659e?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c8b2147659e</guid>
            <category><![CDATA[developer-relations]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Tue, 06 Nov 2018 07:30:29 GMT</pubDate>
            <atom:updated>2018-11-07T00:52:43.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7a13Ttlq2ZIT99vZR-cUA.jpeg" /><figcaption>I still get to enjoy the views from the Google office in SF, now as a visitor 😎</figcaption></figure><p>On November 1st 2017 I gave back my phone, laptop, and other fancy hardware back to TechStop (Google’s IT department), <a href="https://www.youtube.com/watch?reload=9&amp;v=IIdZ125CBIs">said good bye to very sad music (thanks Broady)</a> to my many friends I was leaving at the office, and got on my way to SFO right on time for my flight to Paris to talk about dotGo about Machine Learning and Go.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FlcyNjgEG9H8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlcyNjgEG9H8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FlcyNjgEG9H8%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/2b9fdf57eb78e72581dea60fa0e93c3a/href">https://medium.com/media/2b9fdf57eb78e72581dea60fa0e93c3a/href</a></iframe><p>That was my first flight as a Xoogler (Google alumnus) and as a sourcerer (<a href="http://sourced.tech">source{d}</a> employee). This blog post is my attempt to recap the many experiences I went through since that day.</p><p><em>Note: if you’re wondering who I am, days before leaving I published </em><a href="https://medium.com/@francesc/thanks-and-goodbye-google-friends-3caf770a66dc"><em>Thanks, and good bye Google friends</em></a><em> and a month later I wrote </em><a href="https://medium.com/@francesc/source-d-why-i-left-google-71240c0f0204"><em>source{d}: why I left Google</em></a><em>. Those two articles might give you some extra context!</em></p><h4>Rediscovering Developer Relations</h4><p>At Google I was a small fish in a big big pond. While it was an amazing place to learn the basics, I always felt I was missing out on the many other ways people understood and practiced Developer Relations.</p><p>At source{d}, I became VP of Developer Relations. The VP part of the title, although nice, wouldn’t have any value if it didn’t mean the CTO, COO, and I all are exactly at the same hierarchy level, reporting directly to the CEO. This meant I had the opportunity to have enough power and freedom to put in place the practices I sought necessary, taking risks as well as their consequences.</p><p>I gotta admit that since I joined, my opinion on what Developer Relations is has changed a lot. Developer Relations is, in my opinion, a field of work that connects a range of other domains: from software engineering to developer marketing, support, technical writing, and, of course, public speaking.</p><p>If you are in Developer Relations and you’re not writing any code, you’re probably not doing Developer Relations: you’re doing Developer Marketing. But if you’re only writing code and not thinking about how your users might feel while using your product … I’m sorry to tell you that’s not Developer Relations either! Finally, if you’re not writing blog posts answering the questions your users might have … not DevRel! Oh, and are you making sure the pizza makes it on time for your meetup? If not … probably not DevRel enough.</p><blockquote>So … what is Developer Relations?</blockquote><p>I think that the common skill involved with all Developer Relations is about empathy towards your users. You’re not trying to convince them of using your product (Marketing) although you really are a little bit. You’re trying to find the best way to empower your users to achieve their goals, sometimes by figuring out which features should be part of your product (Product Management), sometimes by making sure the interactions areas intuitive as possible (Developer Experience), or sometimes you’re giving talks with cool demos to show the potential of your product (Developer Advocacy).</p><p>I might write a follow up post on this topic, so if you’re interested on knowing more about this make sure you comment below asking for more details.</p><p>One of the ways my impact shows at source{d} is the creation of source{d} Engine, a product created as a result of crafting messaging around the many Open Source projects that we had created over the years. It is my opinion that good Developer Relations lead into good Product Management and that the two fields should work together as much as possible.</p><p>If you’re interested on knowing more what source{d} Engine is, I recently created this five minutes video that might answer some of your questions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYLxvK027Npo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYLxvK027Npo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYLxvK027Npo%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2aa89a5b5a4ead68fbb744bc25e01b68/href">https://medium.com/media/2aa89a5b5a4ead68fbb744bc25e01b68/href</a></iframe><h4>justforfunc: a worthwhile effort</h4><p>It was back in 2016, after <a href="https://youtu.be/O-bJ4s8OdcA">failing a live demo</a> at GOTO Chicago, that I, after profusely apologizing, promised the audience in the room that I would record a screencast of what my demo should have been.</p><p>The resulting video was a huge success with over 63k views so far.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FuBjoTxosSys%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuBjoTxosSys&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FuBjoTxosSys%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/903bbfeace740a6d9b39b10abcc41c8c/href">https://medium.com/media/903bbfeace740a6d9b39b10abcc41c8c/href</a></iframe><p>This proved to me that there was a clear interest on more developer content on YouTube. Soon after I started <a href="https://youtube.com/justforfunc">justforfunc</a>, and over the years it has become a biweekly (as in once every two weeks, otherwise I’d be dead by now) series where I share my successes and failures while trying to code cool stuff mostly in Go.</p><p>When I left Google many thought I would stop publishing new videos, but I decided that even though it would be a huge effort to keep the pace while becoming an executive at a new startup and trying to get up to speed with Machine Learning, Language Analysis, and the intersection of both fields: ML on Code.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0NTKMKDsCTE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0NTKMKDsCTE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0NTKMKDsCTE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c743837944f2c5a2976318e210b26a4a/href">https://medium.com/media/c743837944f2c5a2976318e210b26a4a/href</a></iframe><p>This was a great idea in hindsight, because thanks to the audience of justforfunc I’ve been able to broaden my brand into Machine Learning without losing visibility on the Go community. This has allowed me to teach Go workshops at conferences and companies while meeting the people I wanted to know to discuss on topics like Code as Data and ML on Code.</p><p>My piece of advice here is the following piece of totally obvious idea:</p><blockquote>If you’re successful at something, don’t stop doing it.</blockquote><p>If a personal project is successful, but changes in your career make it seem like a less profitable way to invest your time, you need to consider much more than the direct benefits of the project itself. Consider how the success of a project could be used as leverage for your new adventures. Successful companies like Google use successful projects like Google Ads as a way to fund more risky but potentially very beneficial projects. Similarly, you should not let go the audiences you create along the way, instead make sure your changes are communicated clearly and implemented smoothly and you’ll be able to keep them as your partners for your future projects.</p><p>Today, over 18k people subscribe to justforfunc, and they have supported me all the way while migrating into more Machine Learning oriented episodes. I like to believe that honesty and openness on my career are to be thanked for this.</p><h4>ML on Code</h4><p>This is not only about what ML on Code stands for, but for the term itself. More specifically … #MLonCode. Yes, the hashtag!</p><p>As I was saying before, Developer Relations is about many things and one of those things is Developer Marketing and … social media! Yes, it’s important to have a following when you work in Developer Relations (no, it’s not OK to make it your only hiring criterion). Not for the obvious ego boosting reasons, but because in Developer Relations having an audience is very powerful, both for communicating with them and getting help when you need it.</p><p>Hashtags are part of that social media / influencer thing you need to play with when working in DevRel, and I gotta say that creating the hashtag #MLonCode and some months later seeing it adopted by members of academia feels like a nice achievement.</p><p>I could spend hours talking about what ML on Code is and what it entails, but instead I’ll just invite you to read this post:</p><p><a href="https://medium.com/sourcedtech/machine-learning-on-go-code-829e85e2d2c6">Machine Learning on Go Code</a></p><p>Or, if like me, you’re more into watching videos:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLt3qZAwQX3w%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLt3qZAwQX3w&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLt3qZAwQX3w%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/f63c2aaa7ea8563a6ae3d869a0d4372f/href">https://medium.com/media/f63c2aaa7ea8563a6ae3d869a0d4372f/href</a></iframe><p>Last, but not least I wanted to talk about what leaving Google really is like.</p><h4>Leaving Google vs leaving Googlers</h4><p>I left Google but that didn’t stop me from continuing the great relationships I forged in there. One of the most successful projects I created while at Google, even though Mark would probably tell you he created it all by himself, is the <a href="http://gcppodcast.com">Google Cloud Platform Podcast</a>. Leaving it was hard even though I knew I was leaving it on the great hands of <a href="http://twitter.com/neurotic">Mark Mandel</a> and <a href="http://twitter.com/nyghtowl">Melanie Warrick</a>. But I think it serves as a proof of the connections I left that I was invited back in two different occasions for <a href="https://www.gcppodcast.com/post/episode-107-a-year-in-review-with-francesc-campoy-flores-and-greg-wilson/">107: A Year in Review</a> and <a href="https://www.gcppodcast.com/post/episode-142-agones-with-mark-mandel-and-cyril-tovena/">142: Agones</a>.</p><p>One of the relationships I’m lucky to keep is my friendship with <a href="http://twitter.com/gregsramblings">Greg Wilson</a>, my previous manager and now Director of Cloud Platform Developer Relations. I like to think of Greg as a mentor since he supported my decision of leaving for sourced{d}. The free lunches at Google are another perk, and the conversation never fails to inspire me to do better.</p><p>In addition to all of the personal relationships I kept there’s also one more way I stayed connected: by becoming a <a href="https://developers.google.com/experts/">Google Developer Expert</a>. It wasn’t too hard to become one after a hundred episodes of Google Cloud Platform Podcast!</p><h4>The future</h4><p>The future is uncomfortably exciting at source{d}, with the recent additions of the previous Head of Community at Docker <a href="http://twitter.com/vcoisne">Victor Coisne</a> and the previous team leader for the <a href="http://kythe.io">Kythe</a> project at Google <a href="https://twitter.com/creachadair">Michael Fromberger</a>, without forgetting the <a href="https://medium.com/sourcedtech/open-source-veterans-join-source-d-as-advisors-2b48717b1748">amazing lineup of advisors</a> we have.</p><p>Our product keeps on evolving while its adoption keeps growing and more and more big players start noticing us. The coolest part of ML on Code is still to arrive!</p><p>Oh, and guess what!? I’m hiring! If you’re interested in working with me in Developer Relations or you’re a senior manager looking for a fun challenge contact me at francesc@sourced.tech.</p><blockquote>Happy 1st year at source{d} to me, cheers to many more 🎉</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c8b2147659e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gitbase: exploring git repos with SQL]]></title>
            <link>https://medium.com/sourcedtech/gitbase-exploring-git-repos-with-sql-95ec0986386c?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/95ec0986386c</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[code-as-data]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Tue, 30 Oct 2018 01:06:10 GMT</pubDate>
            <atom:updated>2018-10-30T15:45:20.861Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: a video version of this content is available at the bottom.</em></p><p>Git has become the de-facto standard for code versioning, but its popularity didn’t remove the complexity of performing deep analyses of the history and contents of source code repositories.</p><p>SQL, on the other hand, is a battle-tested language to query large codebases as its adoption by projects like Spark and BigQuery shows.</p><p>So it is just logical that at source{d} we chose these two technologies to create gitbase: the Code as Data solution for large scale analysis of git repositories with SQL.</p><p>Gitbase is a fully open source project (github.com/src-d/gitbase) that stands on the shoulders of a series of giants which made its development possible, this blog post aims to point out the main ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zsQu2koNnsRaR3JB" /><figcaption><em>The gitbase playground (github.com/src-d/gitbase-web) provides a visual way to use gitbase.</em></figcaption></figure><h4>Parsing SQL with vitess</h4><p>Gitbase’s user interface is SQL: this means we need to be able to parse and understand the SQL requests that arrive through the network following the MySQL protocol. Fortunately for us, this was already implemented by our friends at YouTube and their <a href="https://github.com/vitessio/vitess">vitess</a> project.</p><p>We simply grabbed the pieces of code that mattered to us and made it into an open source project github.com/src-d/go-mysql-server that allows anyone to write a MySQL server in minutes (as I showed in my <a href="http://justforfunc.com">justforfunc</a> episode <a href="https://youtu.be/bcRDXAraprk">CSVQL — serving CSV with </a>SQL).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1vC7DTXcmH3JpJ9kx3RdTw.png" /><figcaption>Vitess is a database clustering system for horizontal scaling of MySQL.</figcaption></figure><h4>Reading git repositories with go-git</h4><p>Once we’ve parsed a request we still need to find how to answer it by reading the git repositories in our dataset. For this we integrated source{d}’s most successful repository <a href="https://github.com/src-d/go-git">go-git</a>.</p><p>This allowed us to easily analyze repositories stored on disk as <a href="https://github.com/src-d/siva">siva</a> files (again an Open Source project by source{d}) or simply cloned with <em>git clone</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*umjKA3RHdVQl4w3H" /><figcaption>A highly extensible Git implementation in pure Go.</figcaption></figure><h4>Detecting languages with enry and parsing files with babelfish</h4><p>Gitbase does not stop its analytic power at the git history. By integrating language detection with our (obviously) Open Source project enry (<a href="https://github.com/src-d/enry">src-d/enry</a>) and program parsing with babelfish (<a href="https://github.com/bblfsh/bblfshd">bblfsh/bblfshd</a>).</p><p>These two features are exposed in gitbase as the user functions <em>LANGUAGE</em> and <em>UAST</em>. Together they make requests like <strong>“find the name of the function that was most often modified during the last month”</strong> possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*TFlUMkXVI5uNwfd7.png" /><figcaption>babelfish is a self-hosted server for universal source code parsing, turning code files into Universal Abstract Syntax Trees (UASTs)</figcaption></figure><h4>Making it go fast</h4><p>Gitbase analyzes really large datasets — e.g. Public Git Archive, with 3TB of source code from GitHub (<a href="https://blog.sourced.tech/post/announcing-pga/">announcement</a>) and in order to do so every CPU cycle counts.</p><p>This is why we integrated two more projects into the mix: Rubex and Pilosa.</p><p><strong>Speeding up regular expressions with Rubex and Oniguruma</strong></p><p>Rubex <a href="https://github.com/moovweb/rubex">moovweb/rubex</a> is a quasi drop-in replacement for Go’s <em>regexp</em> standard library package. I say quasi because they do not implement the <em>LiteralPrefix</em> method on the <em>regexp.Regexp</em> type, but I also had never heard about that method until right now.</p><p>Rubex gets its performance from the highly optimized C library Oniguruma (<a href="https://github.com/kkos/oniguruma">kkos/oniguruma</a>) which it calls using <a href="https://golang.org/cmd/cgo/">cgo</a>.</p><p><strong>Speeding up queries with Pilosa indexes</strong></p><p>Indexes are a well-known feature of basically every relational database, but Vitess does not implement them since it doesn’t really needs to.</p><p>But again Open Source came to the rescue with Pilosa (<a href="https://github.com/pilosa/pilosa">pilosa/pilosa</a>), a distributed bitmap index implemented in Go which made gitbase usable on massive datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*KRWRR_C2HbQVSlXnCqma3Q.png" /><figcaption>Pilosa is an open source, distributed bitmap index that dramatically accelerates queries across multiple, massive data sets.</figcaption></figure><h3>Conclusion</h3><p>I’d like to use this blog post to personally thank the Open Source community that made it possible for us to create gitbase in such a shorter period that anyone would have expected. At source{d} we are firm believers in Open Source and every single line of code under github.com/src-d (including our OKRs and investor board) is a testament to that.</p><p>Would you like to give gitbase a try? The fastest and easiest way is with source{d} Engine. Download it from sourced.tech/engine and get gitbase running with a single command!</p><p><a href="https://sourced.tech/engine">source{d}</a></p><p><strong>Want to know more?</strong></p><p>Check out the recording of my talk at the <a href="https://www.meetup.com/golangsf/events/251690574/">Go SF meetup</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DOXL2KxOTmBQ&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FOXL2KxOTmBQ%3Ffeature%3Doembed&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/86297ad135c18cbee50a83dca98724b0/href">https://medium.com/media/86297ad135c18cbee50a83dca98724b0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95ec0986386c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sourcedtech/gitbase-exploring-git-repos-with-sql-95ec0986386c">gitbase: exploring git repos with SQL</a> was originally published in <a href="https://medium.com/sourcedtech">sourcedtech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning on Go Code]]></title>
            <link>https://medium.com/sourcedtech/machine-learning-on-go-code-829e85e2d2c6?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/829e85e2d2c6</guid>
            <category><![CDATA[mloncode]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[gophercon]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Tue, 25 Sep 2018 16:02:01 GMT</pubDate>
            <atom:updated>2018-09-25T18:27:55.727Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post is the written form of my recent talk at GopherCon 2018: Machine Learning on Go Code, which you can now enjoy directly on YouTube <a href="https://youtu.be/Lt3qZAwQX3w">Machine Learning on Go Code</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLt3qZAwQX3w%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLt3qZAwQX3w&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLt3qZAwQX3w%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/5efe81fa6e654fd297e8ebc0a9d178c1/href">https://medium.com/media/5efe81fa6e654fd297e8ebc0a9d178c1/href</a></iframe><p>You can also follow the slides on <a href="https://speakerdeck.com/campoy/machine-learning-on-go-code">SpeakerDeck</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2F86b3023441b64d7894470e3eb60ee400&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fcampoy%2Fmachine-learning-on-go-code&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2F86b3023441b64d7894470e3eb60ee400%2Fslide_0.jpg%3F461010&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/637004a49cfa10a6588c8d3c66590e8f/href">https://medium.com/media/637004a49cfa10a6588c8d3c66590e8f/href</a></iframe><h4>Software is eating the world</h4><p>I’m sure you’ve all heard the famous phrased coined by Marc Andreessen “Software is eating the world” (<a href="https://a16z.com/2016/08/20/why-software-is-eating-the-world/">Why Software Is Eating the World — Andreessen Horowitz</a>). I definitely had heard about it, but I didn’t realize how much this was the case until recently, when I found this article (<a href="http://www.visualcapitalist.com/millions-lines-of-code/">Infographic: How Many Millions of Lines of Code Does It Take?</a>) which shows the number of lines of code in popular pieces of software and its evolution over time.</p><p><a href="http://www.visualcapitalist.com/millions-lines-of-code/">Infographic: How Many Millions of Lines of Code Does It Take?</a></p><p>I invite you to review the amazing graphics included in that article now, but just in case you’d rather continue here the most impressive facts are how Windows NT 3.1 had already 4 to 5 million lines of code, the latest version of Chrome has 18M, or how a Ford Pickup has 150M lines of code. If this doesn’t send a shiver down your spine you are definitely a brave individual.</p><blockquote>The number of lines of code we manage keeps growing at explosive rates, while the evolution of our tools is barely incremental.</blockquote><p>So the number of lines of code we manage keeps growing at explosive rates, while the evolution of our tools is barely incremental. This needs to change, we need better tools not only to have better code but to write it in better conditions. In comparison, our transportation tools have evolved greatly to the point that our cars now understand their surroundings and are able to warn us in situations of danger, or even to take actions to avoid imminent accidents.</p><p>This is why, I argue that it is time to start applying Machine Learning to our code. The title of this talk is Machine Learning *on* Go code, not *in* Go code, and this is a very important distinction. I will not be discussing how we can implement ML algorithms with Go code, but rather how we can use ML algorithms to improve the way we write, read, and maintain our Go codebases.</p><h4>Machine Learning on Go Code</h4><p>Let’s talk about how Machine Learning can change the way we write code, by focusing on what are the principles that can take use there, the current research fields that apply, and the use cases of this technology.</p><p>Machine Learning on Source Code (aka ML on Code) is Machine Learning that we apply on top of Source Code, so rather than having an input consisting in images, videos, or natural text, we will feed source code to our models in order to train them to predict interesting characteristics of codebases.</p><blockquote>Extracting the meaning of programs is easy, extracting the intention of the developer is harder, and when those two differ is when bugs occur.</blockquote><p>Machine Learning on Source Code is closely related to the following fields:</p><ul><li><strong>Data Mining</strong> techniques are useful since we are handling really large codebases, it’s easy to imagine training a model with trillions of lines of code.</li><li><strong>Natural Language Processing</strong> techniques are obviously useful to source code, even though the generation of natural language is a much for flexible target than the generation of valid programs in a specific programming language. Extracting the meaning of programs is easy, extracting the intention of the developer is harder, and when those two differ is when bugs occur.</li><li>Finally, source code is full of cross references, which we can naturally represent with graphs, this is why <strong>Graph Based Machine Learning</strong> techniques appear often on ML on Code research.</li></ul><p>Let’s talk now about the four challenges of ML on Code.</p><p><strong>Challenge #1: Data Retrieval</strong></p><p>Retrieving source code seems like an easy task, but actually is a common pain for many researchers. This is why we decided to create a public dataset named Public Git Archive (<a href="https://pga.sourced.tech">https://pga.sourced.tech</a>) which based on GH Archive downloads all of the contents of every repository with 50 GitHub stars or more and makes them available in a convenient format.<br>The dataset contains over 4TB of source code including hundreds of programming languages.</p><p>Once we have all of these repositories we need to identify what programming languages each file is written in, in order to then parse it and extract the relevant pieces of information. This often needs to be done not only on the latest version of the files, but also over the previous revisions in order to understand the evolution of source code.</p><p>For these tasks some open source tools are available (some of them by source{d}):</p><ul><li>Language Classification: <a href="http://github.com/src-d/enry">enry</a> by source{d} and <a href="https://github.com/github/linguist">linguist</a> by GitHub</li><li>File Parsing: <a href="http://bblf.sh/">Babelfish</a> by source{d}, <a href="https://github.com/tree-sitter/tree-sitter">tree-sitter</a> by GitHub, and other ad-hoc parsers</li><li>Token Extraction: XPath (<a href="https://github.com/bblfsh/libuast">libuast</a> by source{d})</li><li>Reference Resolution: <a href="http://kythe.io/">Kythe</a> by Google</li><li>History Analysis: <a href="https://github.com/src-d/go-git">go-git</a> by source{d}</li></ul><p>As an effort to make many of these tools available in an easy and unified way, to provide a simple way to analyze source code repositories we’re working on the <a href="https://github.com/src-d/engine"><strong>source{d} engine</strong></a> a simple server that provides a SQL interface to your git repositories.</p><p><a href="https://medium.com/sourcedtech/announcing-source-d-engine-beta-for-code-retrieval-and-analysis-and-source-d-lookout-alpha-for-d5d6702e0a48">Announcing source{d} Engine beta for Code Retrieval and Analysis and source{d} Lookout Alpha for…</a></p><p><strong>Challenge #2: Data Analysis</strong></p><p>Once we’ve extracted the pieces of source code we care about, we need to start analyzing those in order to train our ML models. But, what is source code?</p><p>Source code can be seen at, at least, four different levels of abstraction:</p><ul><li>a sequence of bytes</li><li>a sequence of tokens</li><li>an Abstract Syntax Tree</li><li>a graph showing relationships across code snippets, such as Control Flow Graphs</li></ul><p>The highest level of abstraction provide with more information to the model, therefore giving a better chance to predict advanced concepts. But there’s a trade-off since for instance an analysis by token will never predict new identifiers, since only those that we have seen can be predicted, while analyzing it as a sequence of tokens can provide brand new identifiers never seen before.</p><p><strong>Challenge #3: Learning from source code</strong></p><p>Once we have analyzed the source code we need to decide how we’re going to learn from it. Depending on the different ways we represent the source code some models will be more appropriate, so let’s see some of the most common ones.</p><p><strong><em>Neural Networks</em></strong></p><p>Neural Networks are statistical objects able to learn how to predict specific outputs given some inputs and a really large number of examples. I like to think of them as puppies, but inside computers. Like puppies you need to give feedback on how they should behave until they eventually learn how to do so.</p><p>The traditional example is MNIST, a dataset of images containing hand-written digits. We can give the 26x26 pixels of the image as inputs to the neural network and have ten outputs corresponding to the probabilities of the given digit being 0 to 9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*cwI_y-lRLeKarfVh" /></figure><p>These neural networks can be used for ML on Code to predict a given character or token given the surrounding ones. I trained a neural network that would predict the character that appears in the middle of sequence given the 10 to the left and the 10 to the right.</p><p>After lots of training, and achieving an accuracy close to 80%, we can use it to predict the missing character (represented with the ☐ character) in the following piece of code.</p><pre>i := 0; i ☐ 10; i++ {</pre><p>The resulting 5 highest probabilities are:</p><pre>‘&lt;’ 0.99858105<br>‘=’ 0.00053220615<br>‘ ‘ 0.00024154336<br>‘d’ 0.00019700211<br>’n’ 8.995945e-05</pre><p><strong><em>Recurrent neural networks</em></strong></p><p>If you’d like to generate sequences of characters, or analyze sequences of variable length, the previous approach will fail. Instead we can use recurrent neural networks, which similarly to recursive functions, are able to create a loop by feeding their result as an input to the following iteration.</p><p>The traditional example for Recurrent Neural Networks is the charRNN, which allows you to train it with long texts and then use it to reproduce pieces of text that resemble the original one in style. My ex-colleague Martin Gorner gave a great talk about how this could be used to generate Shakespearian text in his “Tensorflow without a PhD” talk at Google I/O.</p><p>I decided to do the same with all of the Go code in the standard library to see whether I could generate code that looked like code that could be found in there. The results are … interesting. After many tries I was able to reach around 61% accuracy which, although not great, it can already power some useful tools.</p><p>Before training the neural network generates code that is pretty far from the standard Go program.</p><pre>r t,<br> kp0t@pp kpktp 0p000 xS%%%?ttk?^<a href="http://twitter.com/p0rk">@p0rk</a>^@%ppp@ta#p^@ #pp}}%p^@?P%^@@k#%@P}}ta S?@}^<a href="http://twitter.com/t">@t</a>%@% %%aNt i ^<a href="http://twitter.com/SSt">@SSt</a>@@ pyikkp?%y ?t k L P0L t% ^<a href="http://twitter.com/i">@i</a>%yy ^<a href="http://twitter.com/p">@p</a> i? %L%LL tyLP?a ?L@Ly?tkk^@ @^<a href="http://twitter.com/ykk">@ykk</a>^<a href="http://twitter.com/i">@i</a>#P^<a href="http://twitter.com/iL">@iL</a>@??@%1tt%^<a href="http://twitter.com/tPTta">@tPTta</a> L ^<a href="http://twitter.com/LL">@LL</a>%% %i1::yyy^@^<a href="http://twitter.com/t">@t</a> tP @?<a href="http://twitter.com/a">@a</a>#Patt 1^@@ k^<a href="http://twitter.com/k">@k</a> ? yt%L1^<a href="http://twitter.com/tP">@tP</a>%k1?k? % ^<a href="http://twitter.com/i">@i</a> ^<a href="http://twitter.com/ta1">@ta1</a>?1taktt1P?a^@^<a href="http://twitter.com/Pkt">@Pkt</a>?#^<a href="http://twitter.com/t">@t</a>^@##1?## #^<a href="http://twitter.com/t11">@t11</a>#:^@%??t%1^<a href="http://twitter.com/a">@a</a> 1?a at1P ^@^<a href="http://twitter.com/Pt">@Pt</a> #%^@^@ ^<a href="http://twitter.com/aaak">@aaak</a>^@#a#?P1Pa^<a href="http://twitter.com/tt">@tt</a>%?^<a href="http://twitter.com/kt">@kt</a>?#akP ?#^<a href="http://twitter.com/i">@i</a>%%aa ^<a href="http://twitter.com/1">@1</a>%t tt?a?% t^<a href="http://twitter.com/k">@k</a>^@^<a href="http://twitter.com/k">@k</a>^@ a : ^<a href="http://twitter.com/1">@1</a> P# % ^@^@#t% :% kkP ^@#?P: t^<a href="http://twitter.com/a">@a</a> ?%##?kkPaP^@ #a k?t?? ai?i%PPk taP% P^@ k^<a href="http://twitter.com/iiai">@iiai</a>#?^@# #t ?# P?P^@ i^<a href="http://twitter.com/ttPt">@ttPt</a> # 1%11 ti a^<a href="http://twitter.com/k">@k</a> P^<a href="http://twitter.com/k">@k</a> ^<a href="http://twitter.com/kt">@kt</a> %^@%y?#a a#% @? kt ^<a href="http://twitter.com/t">@t</a>%k? ^<a href="http://twitter.com/PtttkL">@PtttkL</a> tkLa1 ^<a href="http://twitter.com/iaay">@iaay</a>?p1% Pta tt ik?ty k^<a href="http://twitter.com/kpt">@kpt</a>%^<a href="http://twitter.com/tktpkryyp">@tktpkryyp</a>^@?pP# %kt?ki? i <a href="http://twitter.com/t">@t</a>^<a href="http://twitter.com/k">@k</a>^@%#P} ?at}akP##Pa11%^<a href="http://twitter.com/i">@i</a>% ^@?ia ia%##%tki % }i%%%}} a ay^@%yt }%t ^<a href="http://twitter.com/tU">@tU</a>%a% t}yi^@ ^@ <a href="http://twitter.com/t">@t</a> yt%? aP @% ^@??^@%? ^@??k#% kk#%t?a: P}^<a href="http://twitter.com/t">@t</a> :#^@#1t^@#: w^<a href="http://twitter.com/P">@P</a>#%w:Pt t # t%aa%i@ak@@^<a href="http://twitter.com/ka">@ka</a>@^<a href="http://twitter.com/a">@a</a> # y}^@# ^@? % tP i? ?tk ktPPt a tpprrpt? a^@ pP pt %p ? k? ^@^@ kP^@%%?tk a Pt^@# tP? P kkP1L1tP a%? t1P%PPti^@?%ytk %#%%t?@?^<a href="http://twitter.com/ty">@ty</a>^<a href="http://twitter.com/iyk">@iyk</a>%1#^@@^<a href="http://twitter.com/1">@1</a>#t a t@P^@^@ P@^<a href="http://twitter.com/1P">@1P</a>^@%%#@P:^@%^@ t 1:#P#@LtL#@L L1 %%dt??^<a href="http://twitter.com/L">@L</a> ^<a href="http://twitter.com/iBt">@iBt</a> yTk%p ^<a href="http://twitter.com/i">@i</a></pre><p>But after training the neural network with all of the files in the standard library we start to see code that looks much more familiar.</p><pre>if testingValuesIntering() {<br>                t.SetCaterCleen(time.SewsallSetrive(true)<br>                if weq := nil {<br>                        t.Errorf(&quot;eshould: wont %v&quot;, touts anverals, prc.Strnared, error<br>                }<br>                t, err := ntr.Soare(cueper(err, err)<br>                if err != nil {<br>                        t.Errorf(&quot;preveth dime il resetests:%d; want %#&#39;,&quot;, tr.test.Into<br>                }<br>                if err != nil {<br>                return<br>                }<br>                if err == nel {<br>                        t.Errorf(&quot;LoconserrSathe foot %q::%q: %s;%want %d&quot;, d, err)<br>                },<br>                defarenContateFule(temt.Canses)<br>        }<br>        if err != nil {<br>                return err<br>        }<br>        // Treters and restives of the sesconse stmpeletatareservet<br>        // This no to the result digares wheckader. Constate bytes alleal</pre><p>After more epochs we keep on generating code that looks more and more like something we could find in the standard library, but unfortunately the resulting rarely compiles.</p><p>This is one of the main differences between generating natural language or programs, while slightly wrong natural language can be considered artsy, slightly wrong programs are just wrong.</p><p>There’s also many research papers that are worth reading in order to learn more about how ML on Code can learn from source code, but I’d like to mention two more of them.</p><p><strong><em>Learning to Represent Programs with Graphs</em></strong></p><p><a href="https://arxiv.org/abs/1711.00740">[1711.00740] Learning to Represent Programs with Graphs</a></p><p>By Miltiadis Allamanis, Marc Brockschmidt, Mahmoud Khademi introduces the <em>VARMISUSE</em> task, which consists in, given a program from which a single variable usage has been removed, predict which variable was there.</p><p>For instance, can you predict what token should appear in lieu of <em>???</em> in the following code snippet?</p><pre>from, err := os.Open(&quot;a.txt&quot;)<br>if err != nil {<br>  log.Fatal(err)<br>}<br>defer from.Close()</pre><pre>to, err := os.Open(&quot;b.txt&quot;)<br>if err != nil {<br>  log.Fatal(err)<br>}<br>defer <strong>???</strong>.Close()</pre><pre>io.Copy(to, from)</pre><p>This problem, while simple to explain, is very hard to solve making it a great candidate for becoming a benchmark of different algorithms applied to ML on Code.</p><p><strong><em>code2vec: Learning Distributed Representations of Code</em></strong></p><p><a href="https://arxiv.org/abs/1803.09473">[1803.09473] code2vec: Learning Distributed Representations of Code</a></p><p>By Uri Alon, Meital Zilberstein, Omer Levy, Eran Yahav, <a href="https://code2vec.org/">code2vec</a> maps code snippets into an embedding together with funcion names and provides a way to predict what names should be given to a function given its body.</p><p><strong><em>More ML on Code research?</em></strong></p><p>For more papers I recommend you visit our repository github.com/src-d/awesome-machine-learning-on-source-code.</p><h4>Challenge #4: What can we build?</h4><p>So, what can we build with all of these techniques? Is predicting the best we can do? I don’t think so. If instead of predicting tokens we use the train models to evaluate how “expected” a piece of code is we can then start to create very useful tools for our daily tasks.</p><p>Imagine you receive a very large pull request and you are requested to code review it. By using the models we saw before that are able to predict characters or tokens we could instead create a heat map of “expectedness” highlighting those sections of the code that are the least expected. This doesn’t mean those lines are wrong but rather they are interesting and should be reviewed in more detail.</p><p>Given this program below:</p><pre>func sum() int {<br>   s := 0<br>   for i := 0; i &gt; 10; i++ {<br>      s += i<br>   }<br>   return s<br>}</pre><p>we would highlight the <em>&gt;</em> in <em>i &gt; 10</em>, since the probability for that character to be there is below 0.01%.</p><p>In a similar way, by using a model solving the <em>VARMISUSE</em> problem introduced above we could detect a mistake on the code below:</p><pre>from, err := os.Open(&quot;a.txt&quot;)<br>if err != nil {<br>  log.Fatal(err)<br>}<br>defer from.Close()</pre><pre>to, err := os.Open(&quot;b.txt&quot;)<br>if err != nil {<br>  log.Fatal(err)<br>}<br>defer from.Close()</pre><p>Can you see it? Clearly someone copy pasted some code and missed a replacement. The second file, <em>to</em>, will never be closed since the <em>defer</em> statement closes <em>from</em> twice instead.</p><p>Microsoft has added this kind of prediction to Intellisense and they successfully identified many mistakes on large C# codebases. See <a href="https://arxiv.org/abs/1711.00740">the original paper</a> for more details.</p><p>Lastly, with <em>code2vec</em> we could identify when the name of a function is not adequate, therefore minimizing the possibility of mistakes in later code using these functions where their stated intention (through their name) and the actual implementation do not match.</p><p><strong>source{d} lookout</strong></p><p>Integrating all of these analyzers powered by Machine Learning with existing linters using more traditional techniques, we’ve developed source{d} lookout: a GitHub bot that will review your PRs and help you identify possible mistakes with higher accuracy.</p><p>This is what we call assisted code review, and it’s just the beginning of the many use cases we believe can benefit from ML on Code.<br>In the future we’d like to also predict bugs, enforce style guides automatically, and maybe one day we will be even able to generate code automatically from unit tests, specifications, or even natural language descriptions.</p><h4>So does this mean developers will be obsolete?</h4><p>No. Developers will be empowered.</p><p>In the same way architects did not disappear when CAD tools came to be, developers will simply become more efficient and we hope this will empower them to create even better software that will, at its time, improve how the rest of society performs their own tasks.</p><h4><strong>Learn More about source{d} products</strong></h4><ul><li>Request a demo of <a href="http://go.sourced.tech/engine">source{d} Engine</a> or <a href="http://go.sourced.tech/lookout">source{d} Lookout</a></li><li>Sign up for <a href="https://www.meetup.com/mloncode">upcoming Online Meetups</a></li><li>Sign up for <a href="http://go.sourced.tech/newsletter">source{d} bi-weekly Newsletter</a></li><li>Get involved with the <a href="https://sourced.tech/community/">source{d} community</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=829e85e2d2c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sourcedtech/machine-learning-on-go-code-829e85e2d2c6">Machine Learning on Go Code</a> was originally published in <a href="https://medium.com/sourcedtech">sourcedtech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing the performance of Go functions with benchmarks]]></title>
            <link>https://medium.com/justforfunc/analyzing-the-performance-of-go-functions-with-benchmarks-60b8162e61c6?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b8162e61c6</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[benchmark]]></category>
            <category><![CDATA[justforfunc]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 17:40:04 GMT</pubDate>
            <atom:updated>2018-02-12T23:23:52.127Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post is complementary to <a href="https://www.youtube.com/watch?v=t9bEg2A4jsw">episode 28 of justforfunc</a> which you can watch right below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2AulMm-hsdI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2AulMm-hsdI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2AulMm-hsdI%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/e1dd9bbc599093beea74e92a590e2a00/href">https://medium.com/media/e1dd9bbc599093beea74e92a590e2a00/href</a></iframe><p>In the <a href="https://medium.com/justforfunc/two-ways-of-merging-n-channels-in-go-43c0b57cd1de">previous blog post</a> I discussed two different ways of merging n channels in Go, but we did not discuss which ones was faster. In the meanwhile a third way of merging channels was proposed in <a href="https://www.youtube.com/watch?v=B64hIRjNvLc&amp;lc=Ugzegqi-_YDVei6e0Kp4AaABAg">a YouTube comment</a>.</p><p>This blog post will show that third way and compare all of them from a performance point of view, analyzed using benchmarks.</p><h3>A third way of merging channels</h3><p>Two episodes ago we discussed how two channels could be merged, using a single goroutine and nil channels. We’ll refer to <a href="https://github.com/campoy/justforfunc/blob/master/26-nil-chans/main.go#L19">that function</a> here as <a href="https://github.com/campoy/justforfunc/blob/master/26-nil-chans/main.go#L19">mergeTwo</a>. A <a href="https://justforfunc.com/">justforfunc</a> viewer proposed a way to use this function and recursion to provide a way to merge n channels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*lUC7eOZR-V1U8msU_8M39w.png" /><figcaption>merging N channels using recursion</figcaption></figure><p>The solution is quite smart. If we have:</p><ul><li>one channel, we return that channel.</li><li>two channels or more, we merge a half of the channels and then merge them using the result of those using the efficient function.</li></ul><p>What about no channels? We will return an already closed channel.</p><p>Written in code it would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da247f5960233a635ef63f3d1a66ecf4/href">https://medium.com/media/da247f5960233a635ef63f3d1a66ecf4/href</a></iframe><p>This is a nice solution that avoids using reflection and also reduces the number of goroutines needed. On the other hand, it uses more channels than before!</p><p>So, which one is fastest? Time for benchmarks!</p><h3>Writing a benchmark</h3><p>Testing and benchmarks are integrated very tightly with the Go tooling, and writing a benchmark is as simple as writing a function with a name starting with Benchmark and the appropriate signature.</p><p>The only parameter a benchmark receives is of type testing.B and it defines the number of times we should perform the operation we’re benchmarking. This is done for statistical significance, by default benchmarks are given a number of iterations that will make the function run for a whole second.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/582d8d554fc6c022bf36a9b166526426/href">https://medium.com/media/582d8d554fc6c022bf36a9b166526426/href</a></iframe><p>Ok, so now we know pretty much everything we need to know to write a benchmark for one of our functions.</p><h3>Benchmarking all our functions</h3><p>Ok, so we’re ready to write benchmarks for each function!</p><p>One for merge:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/472d8ff929fe4a5553cca361b7edf889/href">https://medium.com/media/472d8ff929fe4a5553cca361b7edf889/href</a></iframe><p>One for mergeReflect:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfb9360939379f11662f4b77ed9c75a5/href">https://medium.com/media/dfb9360939379f11662f4b77ed9c75a5/href</a></iframe><p>And finally. one for mergeRec:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d76c0dea8e02e0ca2a468de6b254505f/href">https://medium.com/media/d76c0dea8e02e0ca2a468de6b254505f/href</a></iframe><p>And now we can finally run them!</p><pre>➜ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/campoy/justforfunc/27-merging-chans<br>BenchmarkMerge-4                  200000              7074 ns/op<br>BenchmarkMergeReflect-4           100000             11904 ns/op<br>BenchmarkMergeRec-4               500000              2475 ns/op<br>PASS<br>ok      github.com/campoy/justforfunc/27-merging-chans  4.077s</pre><p>Great, so using recursion is the fastest possible option. Let’s believe it for now!</p><h3>Using sub-benchmarks and b.Run</h3><p>Unfortunately, in order to benchmark three functions we’re repeating lots of code. Wouldn’t it be nice if we could write our benchmark once?</p><p>We can write a function that iterates over our three functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8edaba7fd72de85cb8d7c15615549d3/href">https://medium.com/media/b8edaba7fd72de85cb8d7c15615549d3/href</a></iframe><p>Unfortunately, that simply gives a single and pretty meaningless measure, mixing all performances.</p><pre>➜ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/campoy/justforfunc/27-merging-chans<br>BenchmarkMerge-4           50000             22440 ns/op<br>PASS<br>ok      github.com/campoy/justforfunc/27-merging-chans  1.386s</pre><p>Luckily, we can easily create subbenchmarks by calling testing.B.Run, similarly as subtests with testing.T.Run. In order to do so, we need a name, which is actually a pretty good idea from a documentation point of view, anyway.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4202336cec9b9d3e2f4906f4575e9c0/href">https://medium.com/media/b4202336cec9b9d3e2f4906f4575e9c0/href</a></iframe><p>When we run these benchmarks we’ll now see three different results as we wished.</p><pre>➜ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/campoy/justforfunc/27-merging-chans<br>BenchmarkMerge/goroutines-4               200000          6145 ns/op<br>BenchmarkMerge/reflect-4                  200000         10962 ns/op<br>BenchmarkMerge/recursion-4                500000          2368 ns/op<br>PASS<br>ok      github.com/campoy/justforfunc/27-merging-chans  4.829s</pre><p>Sweet! With way less code we’re still able to benchmark all of our functions.</p><h4>Benchmarking multiple values of N</h4><p>So far we’ve seen that for a single channel the recursive algorithm is the fastest, but what about other values of N?</p><p>We could probably just change the value of N many times and see how it goes. But we could also just use a for loop!</p><p>In the code below we iterate over the powers of 2 from 1 to 1024, and use a combination of the function we’re benchmarking and the value of N as the benchmark name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2270630d73375f0e85dba8392f9a44f3/href">https://medium.com/media/2270630d73375f0e85dba8392f9a44f3/href</a></iframe><p>Let’s run the benchmarks!</p><pre>➜ go test -bench=.<br>goos: darwin<br>goarch: amd64<br>pkg: github.com/campoy/justforfunc/27-merging-chans<br>BenchmarkMerge/goroutines/1-4             200000          6919 ns/op<br>BenchmarkMerge/goroutines/2-4             100000         13212 ns/op<br>BenchmarkMerge/goroutines/4-4              50000         25469 ns/op<br>BenchmarkMerge/goroutines/8-4              30000         50819 ns/op<br>BenchmarkMerge/goroutines/16-4             20000         88566 ns/op<br>BenchmarkMerge/goroutines/32-4             10000        162391 ns/op<br>BenchmarkMerge/goroutines/64-4              5000        299955 ns/op<br>BenchmarkMerge/goroutines/128-4             3000        574043 ns/op<br>BenchmarkMerge/goroutines/256-4             1000       1129372 ns/op<br>BenchmarkMerge/goroutines/512-4             1000       2251411 ns/op<br>BenchmarkMerge/goroutines/1024-4             300       4760560 ns/op<br>BenchmarkMerge/reflect/1-4                200000         10868 ns/op<br>BenchmarkMerge/reflect/2-4                100000         22335 ns/op<br>BenchmarkMerge/reflect/4-4                 30000         54882 ns/op<br>BenchmarkMerge/reflect/8-4                 10000        148218 ns/op<br>BenchmarkMerge/reflect/16-4                 3000        543921 ns/op<br>BenchmarkMerge/reflect/32-4                 1000       1694021 ns/op<br>BenchmarkMerge/reflect/64-4                  200       6102920 ns/op<br>BenchmarkMerge/reflect/128-4                 100      22648976 ns/op<br>BenchmarkMerge/reflect/256-4                  20      90204929 ns/op<br>BenchmarkMerge/reflect/512-4                   3     383579039 ns/op<br>BenchmarkMerge/reflect/1024-4                  1    1676544681 ns/op<br>BenchmarkMerge/recursion/1-4              500000          2658 ns/op<br>BenchmarkMerge/recursion/2-4              100000         14707 ns/op<br>BenchmarkMerge/recursion/4-4               30000         44520 ns/op<br>BenchmarkMerge/recursion/8-4               10000        114676 ns/op<br>BenchmarkMerge/recursion/16-4               5000        261880 ns/op<br>BenchmarkMerge/recursion/32-4               3000        560284 ns/op<br>BenchmarkMerge/recursion/64-4               2000       1117642 ns/op<br>BenchmarkMerge/recursion/128-4              1000       2242910 ns/op<br>BenchmarkMerge/recursion/256-4               300       4784719 ns/op<br>BenchmarkMerge/recursion/512-4               100      10044186 ns/op<br>BenchmarkMerge/recursion/1024-4              100      20599475 ns/op<br>PASS<br>ok      github.com/campoy/justforfunc/27-merging-chans  61.533s</pre><p>We can see that even though the recursive algorithm is the fastest for a single channel, very quick the solution with many goroutines outperforms the others.</p><p>We can also this by plotting these numbers with some quick Python. Stop acting shocking I somtimes write in Python too!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a86948eb9044fd70dac56f3ddc4bf386/href">https://medium.com/media/a86948eb9044fd70dac56f3ddc4bf386/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*fIMkZRkqlkp09Tm5.png" /></figure><p>It’s hard to see the difference, so let’s use a logarithmic scale for the Y axis (simply add plt.yscale(&#39;log&#39;)).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/0*nKZQ1pwXMQ1UeheD.png" /></figure><h3>Managing the benchmark timer</h3><p>There’s an obvious issue with the way we’re measuring performance. We’re also counting the time it takes to create the N channels for our tests, which adds cost that is not relevant to our algorithms.</p><p>We can avoid this by using b.StopTimer() and b.StartTimer().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8abd411187d36fad19c4945220c55139/href">https://medium.com/media/8abd411187d36fad19c4945220c55139/href</a></iframe><p>The results are not that different to our previous benchmark, but we can see the timing difference increases with the value of N.</p><h3>Can we make them faster?</h3><p>We finally have a good view of how each function performs for different sizes of N. This is great, but doesn’t really help us making our functions faster.</p><p>How could we know more? Well, benchmarks take us only so far, but the next tool we we can use is profiling! Wanna know more? Next episode coming up in two weeks.</p><h3>Thanks</h3><p>If you enjoyed this episode make sure you share it and subscribe to <a href="http://justforfunc.com/">justforfunc</a>! Also, consider sponsoring the series on <a href="https://patreon.com/justforfunc">patreon</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b8162e61c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/justforfunc/analyzing-the-performance-of-go-functions-with-benchmarks-60b8162e61c6">Analyzing the performance of Go functions with benchmarks</a> was originally published in <a href="https://medium.com/justforfunc">justforfunc</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two ways of merging N channels in Go]]></title>
            <link>https://medium.com/justforfunc/two-ways-of-merging-n-channels-in-go-43c0b57cd1de?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/43c0b57cd1de</guid>
            <category><![CDATA[justforfunc]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[channel]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Mon, 29 Jan 2018 16:01:01 GMT</pubDate>
            <atom:updated>2018-02-12T17:49:41.890Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using goroutines and reflection</h4><p>This blog post is complementary to <a href="https://www.youtube.com/watch?v=B64hIRjNvLc">episode 27 of justforfunc</a> which you can watch right below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FB64hIRjNvLc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DB64hIRjNvLc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FB64hIRjNvLc%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/1bd59975e343f25b5a94c96300db66c7/href">https://medium.com/media/1bd59975e343f25b5a94c96300db66c7/href</a></iframe><p>Two weeks ago I explained how nil channels were useful for some important concurrency patterns, specifically when <a href="https://medium.com/justforfunc/why-are-there-nil-channels-in-go-9877cc0b2308">merging two channels</a>. As a result, because this is the internet, many replied telling me there’s better ways to merge two channels than that. And guess what, I agree!</p><p>The algorithm I showed is useful for only two channels. Today we’re going to explore how to handle nchannels where n is not known at compilation time. This means we can’t simply use select over all the channels, so what are the options?</p><h4>First way: using N goroutines</h4><p>The first approach is to create a new goroutine per channel. Each one of these goroutines will range over a channel and send each one of those elements to the output channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oNO9-NZHuTerKDym.png" /><figcaption>schema: we create a new goroutine (circle) per channel (channel looking thingy)</figcaption></figure><p>Or in code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84915b143624036cae37199e3e0ca996/href">https://medium.com/media/84915b143624036cae37199e3e0ca996/href</a></iframe><p>This code is wrong in a couple of ways. Can you see them?</p><p>Let’s first see one of the issues. In order to run it I define a new asChan function, which is explained in the <a href="https://medium.com/justforfunc/why-are-there-nil-channels-in-go-9877cc0b2308">previous justforfunc episode</a>, and use it from the main function as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7207390587187ea1720e7e6d5b98a96/href">https://medium.com/media/a7207390587187ea1720e7e6d5b98a96/href</a></iframe><p>Ok, so what’s the problem when we run it when the data race detector enabled, aka -race?</p><pre>$ go run -race main.go<br>==================<br>WARNING: DATA RACE<br>Read at 0x00c420090018 by goroutine 9:<br>  main.merge.func1()<br>      /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:35 +0x3f</pre><pre>Previous write at 0x00c420090018 by main goroutine:<br>  main.merge()<br>      /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:33 +0xf0<br>  main.main()<br>      /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:13 +0x282</pre><pre>Goroutine 9 (running) created at:<br>  main.merge()<br>      /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:34 +0x9b<br>  main.main()<br>      /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:13 +0x282<br>==================</pre><h4>Fixing a data race</h4><p>Indeed, we’re accessing the c variable defined in the for loop from many goroutines. This is dangerous, but luckily there’s a common idiom that solves the problem. Simply pass the variable as a parameter, that way it will be duplicated and each goroutine will end up with a different variable to itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fe6643d84276987ee6dfac846638743/href">https://medium.com/media/7fe6643d84276987ee6dfac846638743/href</a></iframe><p>Now that the data race has been removed, let’s run the program again.</p><pre>$ go run main.go<br>20<br>10<br>0<br>...<br>9<br>fatal error: all goroutines are asleep - deadlock!</pre><pre>goroutine 1 [chan receive]:<br>main.main()<br>        /Users/francesc/src/github.com/campoy/campoy.cat/site/content/blog/main.go:13 +0x24a<br>exit status 2</pre><p>Ok, this is better and it looks pretty good until the end when everything crashes. What’s going on? Well, the main goroutine is blocked waiting for anyone to close the channel on which it’s ranging. Unfortunately we forgot to close the channel at all.</p><h4>Closing the output channel</h4><p>When should we close the channel? Well, once all goroutines have finished sending values into it. When exactly is that? We don’t really know, but we can simply “wait” for them to be done.</p><p>And how do you wait for a group of things? A WaitGroup, defined in the sync package.</p><p>A WaitGroup has 3 main methods: - Add adds a given number of things to be done. - Done indicates one of those things is done. - Wait blocks until the number of things to be done goes down to zero.</p><p>Let’s fix our program and close the output channel when it’s appropriate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e46946fc7775b7151c9019ba5ac35c48/href">https://medium.com/media/e46946fc7775b7151c9019ba5ac35c48/href</a></iframe><p>Note that Wait is called in a different goroutine.</p><h4>Second way: using reflect.Select</h4><p>A second way of solving the same problem is using reflect.Select which provides a Select operation on a slice of SelectCases.</p><p>In order to call it we’re going to create a slice of SelectCase that contains an element per channel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f72cce62e5dd2b480a7a4f59f66f09a/href">https://medium.com/media/0f72cce62e5dd2b480a7a4f59f66f09a/href</a></iframe><p>Then we can call reflect.Select and send the value we receive to the out channel. Unless channel we received from was closed, in which case we should remove the case from the slice. This is very similar to what we did setting the channel to nil in the previous episode.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07f987a215cf79f4ffab4f323184767b/href">https://medium.com/media/07f987a215cf79f4ffab4f323184767b/href</a></iframe><p>This should be done for as long there’s at least a non closed channel. In our case this is equivalent to the slice not being empty.</p><p>So the full code is as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1958b67b616700700ceb66c7d1174d48/href">https://medium.com/media/1958b67b616700700ceb66c7d1174d48/href</a></iframe><p>Running this code will also work and finish without panicking.</p><h4>Which one is fastest?</h4><p>The first solution uses a linear number of goroutines (one per channel) so that could somehow get slow at some point.</p><p>But the second solution uses reflection and we all know that’s pretty slow, right?</p><p>So which one is fastest? I sincerely don’t know! And that’s the question I’ll solve in the next episode when we’ll talk about benchmarks.</p><p>You can now read it <a href="https://medium.com/justforfunc/analyzing-the-performance-of-go-functions-with-benchmarks-60b8162e61c6">here</a>!</p><p><a href="https://medium.com/justforfunc/analyzing-the-performance-of-go-functions-with-benchmarks-60b8162e61c6">Analyzing the performance of Go functions with benchmarks</a></p><h3>Thanks</h3><p>If you enjoyed this episode make sure you share it and subscribe to <a href="http://justforfunc.com/">justforfunc</a>! Also, consider sponsoring the series on <a href="https://patreon.com/justforfunc">patreon</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43c0b57cd1de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/justforfunc/two-ways-of-merging-n-channels-in-go-43c0b57cd1de">Two ways of merging N channels in Go</a> was originally published in <a href="https://medium.com/justforfunc">justforfunc</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Documentation at source{d}]]></title>
            <link>https://medium.com/@francesc/documentation-at-source-d-4251b0419108?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/4251b0419108</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[dsrc]]></category>
            <category><![CDATA[devrel]]></category>
            <category><![CDATA[documentation]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Thu, 18 Jan 2018 18:19:42 GMT</pubDate>
            <atom:updated>2018-01-18T18:19:42.471Z</atom:updated>
            <content:encoded><![CDATA[<h4>What we write and how we write it</h4><p><em>Originally posted on the </em><a href="https://github.com/src-d/guide/blob/master/engineering/documentation.md"><em>source{d} guide</em></a><em>.</em></p><p>Our company has been a big believer in Open Source from very early on. Most of our repositories are visible to anyone in the world. We agree this is for our own benefit, but public source code is not enough to support and develop an Open Source community.</p><p>The goal of this document is to help source{d} engineers understand what pieces of documentation they should write for an open source project, and how they should be written.</p><p>The main audience of this document is source{d} engineers, but it might be a useful resource for many others inside and outside our company.</p><p>This document is divided into two sections:</p><ol><li>The first section covers somes best practices for technical writing which apply to any piece of documentation you might be writing.</li><li>The second section lists the main documentation artifacts all source{d} projects should provide.</li></ol><h3>General Best Practices</h3><p>People read documentation in order to achieve a goal. Whenever you write a new piece you should keep their goal in mind.</p><p>For instance, you’re currently reading this document. What is your goal? Maybe you want to improve the documentation of your own project, or perhaps you’ve been told this is an awesome document and your goal is simply to enjoy reading a beautiful text of astonishing beauty.</p><p>On the other hand I know you’re a developer, so there’s no point explaining what source code is. That would seem patronizing or a waste of time.</p><p>I also know that most of us don’t speak English as a first language. Unnecessarily complicated words or sentences are then an obstacle to our communication.</p><p>Finally, I know you’re a diverse group. Among the readers of this document you’ll find people everywhere in the gender spectrum, different races, and different sensibilities. I do not wish to alienate any of them, so I need to be careful with the words I choose.</p><p>All of these concrete examples can be boiled down to the following best practices.</p><h3>State a clear goal</h3><p>A piece of documentation has a clearly stated goal and audience.</p><p>For instance, a README.md should be an overview of the project, maybe including some basic usage instructions. On the other hand CONTRIBUTING.md should cover what contributors care about.</p><p>Do not make a first time visitor read through how to contribute a project before they understand what the project is about.</p><h3>Define a scope</h3><p>As Carl Sagan <a href="https://www.youtube.com/watch?v=7s664NsLeFM">famously said</a> “If you wish to make an apple pie from scratch, you must first invent the universe”. Would you start an apple pie recipe with quantum physics? Hopefully not.</p><p>Same goes for documentation. You need to define the scope of concepts that deserve to be explained in a document. Those considered either too advanced or as prerequisites should be ommited. You can always link to some other document explaining them.</p><p>For instance, if a project uses Go and gRPC feel free to link to the homepages of those projects. Do not use more than one short sentence to explain what Go or gRPC are.</p><h3>Keep it simple</h3><p>Short sentences win. Avoid having overly complex sentences. It might seem weird at first. You might find the resulting text immature. But keeping your sentences short help the readers, and that should trump everything else.</p><p>Following the same logic, avoid overly complicated words.</p><p>As a rule of thumb, sentences longer than a printed line are probably too long.</p><h3>Don’t alienate the reader</h3><p>Avoid gendered pronouns. “He or she” should be rewritten as “they”. There is no reason for your document to make assumptions on the reader’s identity.</p><p>Avoid sexist connotations. For instance, “mom-proof” implies women are not technical. Tell that to Grace Hopper. You can read more about sexist language and how to avoid it <a href="https://www.hamilton.edu/academics/centers/writing/writing-resources/avoiding-sexist-language">here</a>.</p><p>Avoid ableist language. Avoid words like “crazy” or “insane”. More on ableist language <a href="https://www.copyediting.com/disabling-ableist-language/#.Wk6yeFQ-dE4">here</a>.</p><p>In general, if someone would find what you wrote offensive it’s time to change it. There’s no excuse to offend anyone in a technical document.</p><h3>Take accessibility in mind</h3><p>It is probably impossible to write documentation that is fully accessible to every single person in the world. This doesn’t mean we should not strive for documentation that is as accessible as possible.</p><p>Many readers might have different degrees of visual impairments. While using images avoid attaching meaning to colors that are traditionally hard to distinguish. You can read more on what color combinations to avoid <a href="http://blog.usabilla.com/how-to-design-for-color-blindness/">here</a>.</p><p>For more extreme cases the user will not be able to see the image at all. Take that into account and try to add captions explaining the image where possible. At least make usage of the alt attributes on HTML and markdown.</p><h3>Documentation Artifacts</h3><p>Now that we’ve covered how to write, let’s talk about what to write. This section lists the pieces of documentation we care about at source{d}.</p><h3>README.md</h3><p>The README.md file in the root of your repository is the entrypoint to your project. At this point you still don&#39;t know whether the reader is a new-comer, an experienced user, or the most prolific contributor.</p><p>Give an overview of the project goal and its current state. Is this a demo, a library, or maybe some tool? Should it be used in production? Is too soon, or maybe too late because it’s been deprecated?</p><p>Is this code distributed in any other way? Docker images, aptitude packages, installation scripts, etc. should be mentioned here.</p><p>For tools, it is also worth including basic installation instructions. If the instructions are long they should be part of a different document linked from this one.</p><p>This document also serves as the index for all other documentation. README.md can also be found in folders other than the root of the repository. In that case it should document what the subtree below the folder contains. This is useful when you have libraries and binaries in a single repository.</p><p>A README.md template is available <a href="https://github.com/src-d/guide/blob/master/engineering/documents/README.tmpl.md">here</a>.</p><p>TL;DR:</p><ul><li>Audience: Everyone.</li><li>Content: Description of the project and its current state. Links to other resources.</li><li>Template: <a href="https://github.com/src-d/guide/blob/master/engineering/documents/README.tmpl.md">README.tmpl.md</a></li><li>Example: <a href="https://github.com/twbs/bootstrap/blob/v4-dev/README.md">https://github.com/twbs/bootstrap/blob/v4-dev/README.md</a></li></ul><h3>CONTRIBUTING.md</h3><p>This document describes what contributors should know in order to contribute to the project.</p><p>This document should contain all the details required for anyone to send a contribution. It often contains instructions on how to build the project from source code and validate the source code by running unit and integration tests.</p><p>This is also the place where style guides and other code conventions and requirements should be documented or at least referenced. Examples of these include code coverage requirements, adopted unit testing frameworks, and documentation conventions.</p><p>A very good example of CONTRIBUTING.md is the one from <a href="https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md">angular.js</a>.</p><p>If you’re starting from scratch, considering using this <a href="https://github.com/src-d/guide/blob/master/engineering/documents/CONTRIBUTING.md">template</a>.</p><p>TL;DR:</p><ul><li>Audience: Contributors.</li><li>Content: Steps necessary to modify the project, verify the changes, and contribute back to the project.</li><li>Template: <a href="https://github.com/src-d/guide/blob/master/engineering/documents/CONTRIBUTING.md">CONTRIBUTING.md</a></li><li>Example: <a href="https://github.com/angular/angular.js/blob/master/README.md">https://github.com/angular/angular.js/blob/master/README.md</a></li></ul><h3>Reference material</h3><p>This is the documentation that users will reguarly consult while using your project. The actual form depends on whether the project is a library or a tool.</p><p>For libraries, this document tends to be autogenerated from source code. Tools like godoc, javadoc, etc. provide an easy way to do this. For tools, the document will be often hand written, think about man pages.</p><p>In both cases, this kinds of document tend to grow quite fast as they provide detailed information on each feature and the feature’s options. They do not require a sequential structure. Users often search and read single section. Therefore it’s recommended to have a good table of contents and search features when possible.</p><p>TL;DR:</p><ul><li>Audience: Users of the project.</li><li>Content: List of all of the features of the project with full information on arguments, flags, and others.</li><li>Example: <a href="https://docs.angularjs.org/api">https://docs.angularjs.org/api</a></li></ul><h3>Release Notes</h3><p>Every new release of your project should be versioned following <a href="https://semver.org/">semantic versioning principles</a>. Each new release should come with release notes. These notes are not a list of every single PR and issue that have been closed during the release. Instead, the document should explain what are the most important changes in the release, such as critical bugs, breaking changes, or new features.</p><p>TL;DR:</p><ul><li>Audience: Contributors and users of the project.</li><li>Content: New features, bug fixes, and other relevant changes since the previous version released.</li><li>Example: <a href="https://golang.org/doc/go1.9">https://golang.org/doc/go1.9</a></li></ul><h3>Guides/Tutorials</h3><p>For complex tools it is sometimes useful to write guides showing how to perform some specific use case. These guides can be short and useful for early beginners, also known as quick starts. But often we want to show a complex use case, or show how the project interacts with other technologies. In that case we will write a tutorial, or even a codelab if we want the readers to put the concepts to practice.</p><p>All of these documents have a goal in common: teach how to do something. They follow a step-by-step structure. Users often read these guides from top to bottom, unlike reference documentation.</p><p>TL;DR:</p><ul><li>Audience: New users of the project.</li><li>Content: Detailed guide on how to accomplish something specific using the project.</li><li>Example: <a href="https://docs.angularjs.org/tutorial">https://docs.angularjs.org/tutorial</a></li></ul><h3>Code of Conduct</h3><p>All projects under the source{d} organization should mention the Code of Conduct available in <a href="https://www.contributor-covenant.org/">https://www.contributor-covenant.org/</a>.</p><p>You can simply copy paste this markdown into your README.md and inside .github/CODE_OF_CONDUCT for each repository.</p><pre><strong># Code of Conduct</strong></pre><pre>All activities source{d} projects are governed by the [source{d} code of conduct](https://github.com/src-d/guide/blob/master/.github/CODE_OF_CONDUCT.md).</pre><p>TL;DR:</p><ul><li>Audience: Contributors</li><li>Content: Rules governing the contributor community and their interactions with each other.</li><li>Example: <a href="https://www.contributor-covenant.org/">https://www.contributor-covenant.org/</a></li></ul><h3>Issue templates</h3><p>Following the same philosophy of good documentation, good issue templates help users and contributors interact more efficiently.</p><p>Consider adding a ISSUE_TEMPLATE.md file either under the repo root or a direct descent of it named either .githubor docs. (More info <a href="https://help.github.com/articles/creating-an-issue-template-for-your-repository/">here</a>).</p><p>Consider using <a href="https://github.com/src-d/guide/blob/master/engineering/documents/ISSUE_TEMPLATE.md">this template</a>.</p><h3>Other pieces documentation</h3><p>Many other pieces of documentation are possible: from design documents to workflow descriptions or UML diagrams. Whenever you’re working on one of these pieces keep in mind your audience and their own goals when reading the document.</p><h3>Resources</h3><ul><li><a href="https://developers.google.com/style/">Google Developer Documentation Style Guide</a></li><li><a href="https://www.hamilton.edu/academics/centers/writing/writing-resources/avoiding-sexist-language">Avoiding sexist language</a></li><li><a href="http://blog.usabilla.com/how-to-design-for-color-blindness/">How to Design for Color Blindness</a></li><li><a href="https://www.copyediting.com/disabling-ableist-language/#.Wk6yeFQ-dE4">Disabling Ableist Language</a></li><li><a href="https://semver.org/">Semantic Versioning</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4251b0419108" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why are there nil channels in Go?]]></title>
            <link>https://medium.com/justforfunc/why-are-there-nil-channels-in-go-9877cc0b2308?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/9877cc0b2308</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[channel]]></category>
            <category><![CDATA[justforfunc]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Mon, 15 Jan 2018 16:01:02 GMT</pubDate>
            <atom:updated>2018-02-12T17:49:04.574Z</atom:updated>
            <content:encoded><![CDATA[<h4>A practical example</h4><p>This blog post is complementary to <a href="https://www.youtube.com/watch?v=t9bEg2A4jsw">episode 26 of justforfunc</a> which you can watch right below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ft9bEg2A4jsw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dt9bEg2A4jsw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ft9bEg2A4jsw%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/b9c3f645a8a4be76235ca20033440ebb/href">https://medium.com/media/b9c3f645a8a4be76235ca20033440ebb/href</a></iframe><p>Everybody that has written some Go knows about channels. Most of us also know that the default value for channels is nil. But not many of us know that this nil value is actually useful.</p><p>I got this same question on <a href="https://twitter.com/francesc">twitter</a>, from a developer learning Go, wondering whether Go nil channels existed just for completeness.</p><p>It does makes sense to wonder whether they’re useful, as their behavior seems to indicate otherwise.</p><p>Given a nil channel c:</p><ul><li>&lt;-c receiving from c blocks forever</li><li>c &lt;- v sending into c blocks forever</li><li>close(c) closing c panics</li></ul><p>But I still insist they are useful. Let me introduce a problem whose solution seems obvious at first, but it is actually not as easy as one might think and actually benefits from nil channels.</p><h3>Merging channels</h3><p>Your mission, should you choose to accept it, is to write a function that given two channels a and b of some type returns one channel c of the same type. Every element received in a or b will be sent to c, and once both a and b are closed c will be closed too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aKHj7JJ0UCDEYu23.png" /></figure><h3>An auxiliary function</h3><p>Before we start, let’s write a function that will help us test our solution. This function returns a channel that will eventually receive, at random intervals, all of the given values and finish by being closed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/383641af3734230100b885710febb95b/href">https://medium.com/media/383641af3734230100b885710febb95b/href</a></iframe><p>This function creates a channel, starts a new go routine that sends values to the created channel, and finally returns the channel.</p><p>This is pretty common pattern when dealing with channels, so make sure you understand how it works before you continue reading.</p><h3>Let’s get started</h3><p>Since we don’t really have a preference over a or b we’re going to avoid creating a preference by choosing on which channel we should range first. Let’s instead keep the symmetry and use an infinite loop and select over both channels.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bee18364a88d170ff6b6a70622757653/href">https://medium.com/media/bee18364a88d170ff6b6a70622757653/href</a></iframe><p>This looks pretty good, let’s write a quick test and run it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e27602d04e133b4696d4af1acd9ee753/href">https://medium.com/media/e27602d04e133b4696d4af1acd9ee753/href</a></iframe><p>This should print 1 to 8 in some order and end successfully. Let’s see what happens.</p><pre>&gt; go run main.go<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>😱</pre><p>Ok, so clearly this is not good because the program doesn’t ever finish. Once it has printed the values from 1 to 8 it starts printing zeros forever.</p><h3>Handling closed channels</h3><p>What happens when we receive from a closed channel? We get the default value of the type of the channel. In our case, the type is int so the value is 0.</p><p>We could check for channels being closed by comparing to zero, but what if one of the values we received was a zero? Instead we can use the “value comma ok” syntax:</p><pre>v, ok := &lt;- c</pre><p>When using this syntax ok is a boolean that will be true for as long the channel is open. Knowing this we can avoid sending superfluous zeros into c.</p><p>We should also stop iterating at some point … so let’s keep track of when both channels are closed too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3653b4bfc354b66bfab4033e42062948/href">https://medium.com/media/3653b4bfc354b66bfab4033e42062948/href</a></iframe><p>This looks like it might work! Let’s run it.</p><pre>&gt; go run main.go<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>fatal error: all goroutines are asleep - deadlock!</pre><pre>goroutine 1 [chan receive]:<br>main.main()<br>        /Users/francesc/src/github.com/campoy/campoy.cat/site/static/code/nilchans/main.go:13 +0x186<br>exit status 2</pre><p>Ooops, we forgot something. What could that be? Well, we can see that there’s only one go routine running and it’s blocked on line 13. That line is:</p><pre>for v := range c {</pre><p>Can you see what the problem is? Well, a range statement iterates over all the values in a channel until the channel is closed. But who is closing the channel?</p><p>We forgot! Let’s add a defer statement in our go routine to make sure the channel is closed eventually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99b6e8080e35de5c8207174e77276247/href">https://medium.com/media/99b6e8080e35de5c8207174e77276247/href</a></iframe><p>Note that the defer statement is inside of the anonymous function called in a new go routine, rather than inside of merge. Otherwise c would be closed as soon as we exited merge and sending a value into it would panic.</p><p>Let’s run it and see what happens.</p><pre>&gt; go run main.go<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8</pre><p>This looks great … but is it?</p><h3>Busy loops</h3><p>The code we wrote so far is pretty good. It is functionally correct, but if you deployed this in production you might end up running into performance troubles.</p><p>In order to show you where the problem is, let’s add a bit of logging.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1236b98b1bb8dd5f0291eff990aa082/href">https://medium.com/media/e1236b98b1bb8dd5f0291eff990aa082/href</a></iframe><p>Let’s run it and see what happens.</p><pre>&gt; go run main.go<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>a is done<br>2018/01/14 20:47:22 b is done<br>... 😱<br>2018/01/14 20:47:23 b is done<br>2018/01/14 20:47:23 a is done</pre><p>Uh oh! It seems once a channel is done we keep on iterating non-stop!</p><p>It does make sense after all. As we saw at the beginning reading from a closed channel never blocks. Therefore the select statement will block as long as both channels are open until a new element is ready, but once one of them closes we will iterate and waste CPU. This is also known as a busy loop, and it’s not good.</p><h3>Disabling a case in a select statement</h3><p>In order to avoid the busy loop describe previously we would like to disable a part of the selectstatement. Concretely, we’d like to remove case v, ok := &lt;- a when a is closed and similarly for b. But how?</p><p>As we mentioned at the beginning, receiving from a nil channels blocks forever. So to disable a casereceiving from a channel, we can simply set that channel to nil!</p><p>We can then stop using adone and bdone and instead check for a and b being nil.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ca8efe1113e28708cceca4ef530b519/href">https://medium.com/media/5ca8efe1113e28708cceca4ef530b519/href</a></iframe><p>Ok, hopefully this will avoid unnecessary loops. Let’s try it.</p><pre>&gt; go run main.go<br>2<br>1<br>4<br>3<br>6<br>5<br>8<br>7<br>b is <strong>done</strong><br>a is <strong>done</strong></pre><p>The code for the final solution is on <a href="https://github.com/campoy/justforfunc/blob/master/26-nil-chans/main.go">GitHub</a>.</p><h3>Victory!</h3><p>This is just one of the many concurrency patterns that can benefit from nil channels. Have you used nil channels to solve some other problems? Share your story! You can get in touch with me on <a href="https://twitter.com/francesc">twitter</a> or simply dropping a comment here.</p><p>And you might wonder … how dow e merge more than two channels?<br>Well, wonder no more and go read the <a href="https://medium.com/justforfunc/two-ways-of-merging-n-channels-in-go-43c0b57cd1de">next episode</a> that covers exactly that!</p><p><a href="https://medium.com/justforfunc/two-ways-of-merging-n-channels-in-go-43c0b57cd1de">Two ways of merging N channels in Go</a></p><p>If you enjoyed this episode make sure you share it and subscribe to <a href="http://justforfunc.com/">justforfunc</a>! Also, consider sponsoring the series on <a href="https://patreon.com/justforfunc">patreon</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9877cc0b2308" width="1" height="1" alt=""><hr><p><a href="https://medium.com/justforfunc/why-are-there-nil-channels-in-go-9877cc0b2308">Why are there nil channels in Go?</a> was originally published in <a href="https://medium.com/justforfunc">justforfunc</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The justforfunc 2017 top 5]]></title>
            <link>https://medium.com/justforfunc/justforfunc-a-year-in-review-af4003d56179?source=rss-d32302f8a956------2</link>
            <guid isPermaLink="false">https://medium.com/p/af4003d56179</guid>
            <category><![CDATA[justforfunc]]></category>
            <category><![CDATA[top-5]]></category>
            <category><![CDATA[year-in-review]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[youtube]]></category>
            <dc:creator><![CDATA[Francesc Campoy]]></dc:creator>
            <pubDate>Thu, 11 Jan 2018 16:01:02 GMT</pubDate>
            <atom:updated>2018-01-11T18:05:34.578Z</atom:updated>
            <content:encoded><![CDATA[<p>I was just checking the stats on the justforfunc channel and … whoa over 4 years of watch time during 2017! That means there’s been four people continuously watching my videos for a whole year.</p><p>To those four incredibly dedicated fans, huge thanks and … are you OK?</p><p>Anyway, I thought it would be a good moment to see how the channel has evolved during 2017 and what videos have been the most successful.</p><h3>First some stats</h3><p>The channel is doing great. We recently passed 10k subscribers (which I celebrated with <a href="https://www.youtube.com/watch?v=kuted8F2KJw">this video</a>) and the number keeps growing! Look at these numbers, stat!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3UrkC8Ue0IVW1J7xOlcjg.png" /></figure><p>So without any more ado, let’s go with the top five videos of 2017!</p><h4>#5: Unit Testing HTTP servers</h4><p>This video was a fun one to do and I think it’s been very successful because it covers something people care about.</p><p>Testing HTTP servers is not necessarily easy and most people have no idea on how to use <a href="https://golang.org/pkg/net/http/httptest/#ResponseRecorder">http.ResponseRecorder</a> or even that it exists!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhVFEV-ieeew%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhVFEV-ieeew&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhVFEV-ieeew%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/07dd1ec70581b7b410dd3859f398a8c5/href">https://medium.com/media/07dd1ec70581b7b410dd3859f398a8c5/href</a></iframe><h4>#4: Flappy Gopher</h4><p>The first episode of a series of three videos that I started after attending GoLab.io in Florence early 2017. Why was this one successful? I mean … it shows you how to develop a Flappy Bird clone in Go!</p><p>The best thing of this episode is that I got many people sending me messages sharing their own projects. And the code was used in a program to teach children Go.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FaYkxFbd6luY%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaYkxFbd6luY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FaYkxFbd6luY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c133c62e014bf3a4089313d4b360098/href">https://medium.com/media/0c133c62e014bf3a4089313d4b360098/href</a></iframe><h4>#3 A Text to Speech server with gRPC and Kubernetes</h4><p>Was this episode the answer to “how many buzzwords can you include in a title”? We’ll never know … well, you’ll never know!</p><p>But the result is a fun video where I develop a distributed version of the <strong>say</strong> command available on Mac, using flite, Docker, Kubernetes, Go, and all of the other things cool kids do.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXaMr--wAuSI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXaMr--wAuSI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXaMr--wAuSI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8b6581a9d1e8cfda4f1f270a7dc37f7/href">https://medium.com/media/f8b6581a9d1e8cfda4f1f270a7dc37f7/href</a></iframe><h4>#2 The Context Package</h4><p>I’ve received so many notes regarding this episode. Many many people tell me it’s the clearest introduction to the context package they’ve ever seen.</p><p>Maybe it’s because this episode was the result of a talk I gave four times before? Probably, but I want to believe it’s because I’m wearing the coolest t-shirt I own.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLSzR0VEraWw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLSzR0VEraWw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLSzR0VEraWw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/97ef00cf73b33f28426557310bed6982/href">https://medium.com/media/97ef00cf73b33f28426557310bed6982/href</a></iframe><p>And last and definitely not least (because we’re counting down, so …)</p><h4>#1 Go Tooling in Action</h4><p>This video is the one that inspired me to create the channel. Its success is not really surprising as I keep on building on it by developing a <a href="http://github.com/campoy/go-tooling-workshop">full day workshop</a> based on the materials I once developed for GOTO Chicago.</p><p>The video is so old that it doesn’t even have the justforfunc branding, since it didn’t exist yet!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FuBjoTxosSys%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuBjoTxosSys&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FuBjoTxosSys%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f41cfea665bcf386ee6b2bc402c1cee8/href">https://medium.com/media/f41cfea665bcf386ee6b2bc402c1cee8/href</a></iframe><h4>What’s your favorite?</h4><p>So what’s your favorite episode? Is it on this list or maybe it’s another one of the 26 episodes I’ve released so far!</p><p>Let me know on <a href="https://twitter.com/francesc">twitter</a> @francesc and send any feedback or suggestions for the channel to form.justforfunc.com.</p><h4>Thanks (and super thanks to my patrons!)</h4><p>Thanks to all the subscribers for an amazing 2017, and to my patrons for allowing me to improve the recording material (now that I don’t work for Google anymore).</p><p>You can become one of my patrons on <a href="http://patreon.com/justforfunc">patreon.com/justforfunc</a>, and in exchange you’ll have my eternal gratitude!</p><figure><a href="https://patreon.com/justforfunc"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNCuxnrgfApvIIcYRVKdKA.png" /></a><figcaption><a href="https://patreon.com/justforfunc">https://patreon.com/justforfunc</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af4003d56179" width="1" height="1" alt=""><hr><p><a href="https://medium.com/justforfunc/justforfunc-a-year-in-review-af4003d56179">The justforfunc 2017 top 5</a> was originally published in <a href="https://medium.com/justforfunc">justforfunc</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>