divan's blog https://divan.dev/ Recent content on divan's blog Hugo en-us Tue, 26 Jul 2022 18:11:29 +0300 My experience with EdgeDB https://divan.dev/posts/edgedb/ Tue, 26 Jul 2022 18:11:29 +0300 https://divan.dev/posts/edgedb/ <p>Tomorrow is an announcement of EdgeDB 2.0, and I realized that I&rsquo;ve never shared my experience with it, and it&rsquo;s been more than a year since I switched every project I could to EdgeDB. So here is a short post on it.</p> <h1 id="what-is-edgedb">What is EdgeDB?</h1> <p>It&rsquo;s an open-source relational/graph database built on top of Postgres.</p> <p>Unlike many other databases, it doesn&rsquo;t reinvent the underlying engine and uses battle-tested Postgres. But it reinvents everything else for you as a database user. For me, the two most important innovations here are – query language and tooling.</p> War https://divan.dev/posts/war/ Fri, 04 Mar 2022 03:39:32 +0200 https://divan.dev/posts/war/ <p>It&rsquo;s 3AM of 4th of March, 2022, but it&rsquo;s just &ldquo;the eighth day&rdquo; for Ukrainians. We don&rsquo;t know what day it is any more because every day lasts at least ten lives.</p> <p>I was in Kyiv a day before the war started. On Wednesday, I flew to Estonia for a regular business trip. I had only a small backpack and planned to return in a few days.</p> <p>I&rsquo;m safe, but everything that makes me me – is not. My nation, country, culture, language, self-identity, people I love and the very right of existence are under brutal attack. Being in safety while millions of Ukrainians are sleeping in the bomb shelters or fleeing is killing me. Why did I choose precisely this day for flight?</p> I still ❤️ you, GOPATH https://divan.dev/posts/gopath/ Mon, 30 Sep 2019 09:04:59 +0200 https://divan.dev/posts/gopath/ <p><img src="https://divan.dev/images/gopath.png" alt="gopath"></p> <p>The newest release of Go – <a href="https://golang.org/doc/go1.13">Go 1.13</a> – finally introduced full support for <a href="https://blog.golang.org/using-go-modules">Go Modules</a> – brilliant and long-awaited solution for built-in dependency versioning problem. Modules now enabled by default, and virtually make GOPATH obsolete.</p> <p>Technically speaking, GOPATH is still supported, and <a href="https://golang.org/doc/go1.13">Go 1.13 Release Notes</a> uses term &ldquo;<em>GOPATH mode</em>&rdquo; (as being opposite to the &ldquo;<em>modules mode</em>&rdquo;), but still, to me this is a tectonic shift in the Go development ecosystem evolution. Now you or your static analysis tools no longer can assume that all code lives in one large directory.</p> Rethinking Visual Programming with Go https://divan.dev/posts/visual_programming_go/ Sat, 01 Jun 2019 14:55:00 +0200 https://divan.dev/posts/visual_programming_go/ <p>This is a blog version of the talk I gave at <a href="https://www.gophercon.es">GopherCon Europe 2019 (Canary Islands Edition)</a>, where I shared my thoughts on why Visual Programming Languages have failed and revealed for the first time my experiment on visualizing Go code.</p> <p><img src="https://divan.dev/images/vpl_cover.png" alt="cover"></p> <p>I could dive in straight into the project, but I do believe to truly appreciate it, I have to explain the thought line behind it first.</p> <p>It starts with an almost existential frustration of working with code as a text.</p> Thought Experiment: Flutter in Go https://divan.dev/posts/flutter_go/ Sat, 12 Jan 2019 14:55:00 +0200 https://divan.dev/posts/flutter_go/ <p>I&rsquo;ve recently discovered <a href="https://flutter.io">Flutter</a> – a new Google&rsquo;s framework for mobile development – for myself and even had an experience of teaching Flutter basics to the person who has never been doing programming at all. Flutter is written in Dart – programming language born in a Chrome browser and then escaped to the console land – and that made me think &ldquo;hey, Flutter could have been easily implemented in Go as well&rdquo;!</p> Creating WebGL apps with Go https://divan.dev/posts/webgl_go/ Mon, 10 Dec 2018 00:00:00 +0000 https://divan.dev/posts/webgl_go/ <p><em>TL;DR In this article I&rsquo;ll share my experience building an interactive 3D WebGL-based application for peer-to-peer messaging protocol simulation without writing any single line in JS. You&rsquo;ll learn how GopherJS and Vecty framework can dramatically lower the complexity of building WebGL-enabled web apps in Go.</em></p> <p><img src="https://divan.dev/images/go-webgl/demo.gif" alt="demo"></p> <p>It&rsquo;s often said &ldquo;A <em>picture</em> is <em>worth a thousand</em> words&rdquo;, but in the era of high-DPI screens and big data, the new idiom is now truer – <em>&ldquo;3D interactive visualization is worth a thousand pictures&rdquo;</em>.</p> Fountain codes and animated QR https://divan.dev/posts/fountaincodes/ Sat, 01 Dec 2018 16:55:00 +0200 https://divan.dev/posts/fountaincodes/ <p><img src="https://divan.dev/images/fountain.jpg" alt="fountain"> <sup>(source: <a href="https://olafureliasson.net/archive/artwork/WEK110140/waterfall">Anders Sune Berg</a>)</sup></p> <p>In the <a href="https://divan.dev/posts/animatedqr/">previous article</a> I&rsquo;ve described a weekend project called <a href="https://github.com/divan/txqr">txqr</a> for unidirectional data transfer using animated sequence of QR codes. The straightforward approach was to repeat the encoded sequence over and over until the receiver gets complete data. This simple repetition code was good enough for starter and trivial to implement, but also introduced long delays in case the receiver missed at least one frame. And in practice, it often did, of course.</p> Animated QR data transfer with Gomobile and Gopherjs https://divan.dev/posts/animatedqr/ Sun, 18 Nov 2018 11:55:00 +0100 https://divan.dev/posts/animatedqr/ <p>TL;DR: a weekend project for transferring data via animated QR codes, written in Go and using fountain erasure codes. The Go code is reused for mobile apps using Gomobile, and in a web application for automating testing QR codes parameters, built with GopherJS and Vecty framework.</p> <p><img src="https://divan.dev/images/txqr_send.gif#center" alt="Transfer file via QR code between two phones"></p> <p>I&rsquo;ll share my experience building it, some code and benchmark results of using animated QR as a data transfer method.</p> WakeMeUpInTheMiddleOfTheNight log level https://divan.dev/posts/wakemeupinthemiddleofthenight/ Fri, 26 May 2017 12:55:00 +0100 https://divan.dev/posts/wakemeupinthemiddleofthenight/ <p>On the last <a href="https://www.meetup.com/Golang-Barcelona/">Golang Barcelona meetup</a> we decided to try new format of conversation and after the talk started open discussion on logging, tracing and metrics. The idea was to encourage people to read a very nice blog post by Peter Bourgon on this subject - <a href="https://peter.bourgon.org/blog/2017/02/21/metrics-tracing-and-logging.html">&ldquo;Metrics, Tracing and Logging&rdquo;</a> and discuss it in a free format.</p> <p>It went surprisingly well, and while most of the people were conscious about the topic, one thing seemed to be still confusing - what to log and when. I think we&rsquo;re all more or less agree that we should log only when program requires human to take a look. It wasn&rsquo;t a case, let&rsquo;s say, 10 years ago - there were no ELK, solid solutions for metrics or tracing - we were using logs for everything, then were building &ldquo;log analyzers&rdquo; to deal with a vast amount of information. But now, when we have all these best practices, powerful time-series databases, visualization platforms, tracing tools - what should we print to the log?</p> Misusing error interface https://divan.dev/posts/misusing_error_interface/ Wed, 08 Mar 2017 12:07:40 +0100 https://divan.dev/posts/misusing_error_interface/ <p>I used to think that misunderstanding interfaces in Go can lead, at most, to not very readable code and worse maintainability. From my observations misusing interfaces becomes visible usually during refactorings, where you questioning what this type or abstraction actually represents. But, at least, the code tends to work and it&rsquo;s not buggy.</p> <h1 id="the-bug">The bug</h1> <p>But here is the interesting piece of code that actually was buggy:</p> <div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">SomeFunc</span>() </span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#a6e22e">_</span>, <span style="color:#a6e22e">ok</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">err</span>.(<span style="color:#a6e22e">MyError</span>); !<span style="color:#a6e22e">ok</span> { </span></span><span style="display:flex;"><span> <span style="color:#a6e22e">log</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#a6e22e">err</span>) </span></span><span style="display:flex;"><span>} </span></span></code></pre></div><p>Quite idiomatic, right? Error type naming is good, following <a href="https://github.com/golang/go/wiki/Errors#naming">recommended way to name error types and variables</a>. We use here normal <a href="https://golang.org/doc/effective_go.html#interface_conversions">type assertion</a>, &ldquo;extracting&rdquo; underlying static type from an interface. If an error doesn&rsquo;t have this type inside, we should log it.</p> How to avoid Go gotchas https://divan.dev/posts/avoid_gotchas/ Fri, 04 Nov 2016 13:25:35 +0100 https://divan.dev/posts/avoid_gotchas/ <h5 id="tldr--by-learning-internals">TL;DR by learning internals</h5> <blockquote> <p>a gotcha is a valid construct in a system, program or programming language that works as documented but is counter-intuitive and almost invites mistakes because it is both easy to invoke and unexpected or unreasonable in its outcome (source: <a href="https://en.wikipedia.org/wiki/Gotcha_(programming)">wikipedia</a>)</p> </blockquote> <p>Go programming language has some gotchas and there is a <a href="https://go-traps.appspot.com">number</a> of <a href="http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/index.html">good articles</a> <a href="https://medium.com/@Jarema./golang-slice-append-gotcha-e9020ff37374#.xvfl7r4ti">explaining</a> them. I find those articles very important, especially for the newcomers in Go, as I see people run into those gotchas every now and then.</p> My GopherCon experience https://divan.dev/posts/gophercon16/ Wed, 03 Aug 2016 19:28:46 +0200 https://divan.dev/posts/gophercon16/ <p>A couple of weeks ago I gave a talk at the largest Go conference, <a href="http://gophercon.com">GopherCon</a>, in Denver. It was the first time I attended GopherCon at all, and the first time ever I spoke in English in front of 1400+ people, and it was an absolutely incredible experience. Here is my story.</p> <p>My journey to GopherCon started on a cold winter day in the apartments in the center of Odessa, Ukraine, where I was living at that time. I was one of the organizers of the first Go meetup in Lviv (Ukraine) and have prepared one general talk about Go. We targeted mainly newcomers, so I wanted to make another talk that would share my passion and admiration of some of the coolest aspects of Go - concurrency.</p> go get for private repos in docker https://divan.dev/posts/go_get_private/ Wed, 01 Jun 2016 19:28:46 +0200 https://divan.dev/posts/go_get_private/ <p>As Go community slowly moving towards established and well understood patterns and practices of dependency management, there are still some confusing moments. One of them is automating repeatable build process using containers along with using dependencies in private repositories.</p> <p>Private repositories on Github are often is a <a href="https://github.com/golang/go/issues/9697">source of confusion</a> when using <code>go get</code>, but it has easy workaround by adding two lines to your <code>.gitconfig</code>:</p> <pre tabindex="0"><code>[url &#34;[email protected]:&#34;] insteadOf = https://github.com/ </code></pre><p>or as a oneliner:</p> LeftPad and Go: can tooling help? https://divan.dev/posts/leftpad_and_go/ Thu, 31 Mar 2016 04:30:29 +0300 https://divan.dev/posts/leftpad_and_go/ <p>You&rsquo;ve probably heard that story about NPM community and <a href="https://www.npmjs.com/package/left-pad">LeftPad</a> package, that broke thousands JavaScript projects worldwide. There was a nice follow-up article titled <a href="http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/">&ldquo;Have We Forget How To Program&rdquo;</a> and one guy even created <a href="http://left-pad.io">left-pad.io</a> - Left-Pad As A Service web service. People got a lot of fun discussing this story.</p> <p>I personally find this story amazing, because there is no single point of failure, but rather a set of things and coincidences resulted in a disaster. Every person I spoke about left-pad story sees it through it&rsquo;s own lens of concern. Some blame JS-community, some talks about how important vendoring is nowadays and others stands for absolutist views of the DRY principle.</p> Visualizing Concurrency in Go https://divan.dev/posts/go_concurrency_visualize/ Sun, 24 Jan 2016 18:31:12 -0300 https://divan.dev/posts/go_concurrency_visualize/ <p><em>If you prefer video over blog posts, here is my talk on this at GopherCon 2016:</em> <a href="https://www.youtube.com/watch?v=KyuFeiG3Y60">https://www.youtube.com/watch?v=KyuFeiG3Y60</a></p> <p>One of the strongest sides of Go programming language is a built-in concurrency based on <a href="https://en.wikipedia.org/wiki/Communicating_sequential_processes">Tony Hoare&rsquo;s CSP</a> paper. Go is designed with concurrency in mind and allows us to build complex concurrent pipelines. But have you ever wondered - how various concurrency patterns look like?</p> <p>Of course, you have. We&rsquo;re all thinking mostly by visualization in one form or another. If I ask you something involving &ldquo;numbers from 1 to 100&rdquo; you will have your own image of the series in your head, even without realizing it. For example, I imagine it as a line going from me with numbers from 1 to 20, then it turns 90 degrees to the right and continues to the 1000+. I recall from very young period of my life that in our kindergarten there were numbers in a cloakroom, written along the wall, and number 20 was exactly at the corner. You probably have your own image of numbers. Another common example is the visual representation of the full year with four seasons - some people see it as a box, other - as a circle.</p> How to complain about Go https://divan.dev/posts/go_complain_howto/ Mon, 14 Dec 2015 08:36:54 -0300 https://divan.dev/posts/go_complain_howto/ <p>Over the years of existence of Go programming language, the articles with its critique was always popular, bringing a lot of discussion from both sides. Recently, <a href="https://github.com/ksimka">Maksim Kochkin</a> even created GitHub repo with <a href="https://github.com/ksimka/go-is-not-good">curated list</a> of articles complaining about golang&rsquo;s imperfection.</p> <p>So, is it true that ranting about Go flaws is a trend nowadays? With carefully gathered links in the repository above, we can check this! :) Unfortunately, there are only 17 articles in the list, which is a bit disappointing because it&rsquo;s not enough for fine statistical analysis, but we can use this anyway.</p> Integration testing in Go using Docker https://divan.dev/posts/integration_testing/ Mon, 07 Dec 2015 08:36:54 -0700 https://divan.dev/posts/integration_testing/ <p><em>Note: this post was originally written for the <a href="https://blog.gopheracademy.com/advent-2015/introduction/">Go Advent 2015</a> series, but I discovered that a post with almost exactly the same subject (and even similar code!) already planned :) That&rsquo;s amazing.</em></p> <p>Golang is often used for writing microservices and various backends. Often these type of software do some computation, read/write data on external storage and expose it&rsquo;s API via http handlers. All this functionality is remarkably easy to implement in Go and, especially if you&rsquo;re creating <a href="http://12factor.net">12factor</a>-compatible app, Go is your friend here.</p> Explaining Go error handling https://divan.dev/posts/go_errors/ Mon, 02 Nov 2015 08:36:54 -0700 https://divan.dev/posts/go_errors/ <p>I recently translated great article — <a href="https://blog.golang.org/errors-are-values">Errors are values</a> by Rob Pike — and we discussed it in our <a href="https://golangshow.com/">podcast Golangshow</a> (in russian). One thing I was surprised about is that even experienced Go developers sometimes do not understand the core idea of that article.</p> <p>Looking back, I remember my first impressions when I read it for the first time. It was similar to <em>“It looks like Pike just adds some complexity to what could’ve been solved gracefully with exceptions”</em>. I have never been fond of exceptions, but that’s the first thought I remember. The example in the article was clearly asking for comparison with exceptions’ way to deal with errors and it didn’t look like a winner here.</p>