<?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 Antonis Christofides on Medium]]></title>
        <description><![CDATA[Stories by Antonis Christofides on Medium]]></description>
        <link>https://medium.com/@aptiko?source=rss-55580151393d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*jLNj4xiZO17RsjLU4maXZw.jpeg</url>
            <title>Stories by Antonis Christofides on Medium</title>
            <link>https://medium.com/@aptiko?source=rss-55580151393d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:56:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aptiko/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[Introduction to Nuxt plugins and modules]]></title>
            <link>https://medium.com/testing-nuxt-applications/introduction-to-nuxt-plugins-and-modules-7f10887ef31b?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f10887ef31b</guid>
            <category><![CDATA[nuxtjs]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 17:45:39 GMT</pubDate>
            <atom:updated>2021-09-15T13:23:23.370Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0rHuWGOIrSq5RKAZ" /><figcaption>Not a Nuxt module, but a module nevertheless. Photo by <a href="https://unsplash.com/@markkoenig?utm_source=medium&amp;utm_medium=referral">Mark König</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://medium.com/testing-nuxt-applications/testing-backend-communication-84a5bf02ae10">I have already explained</a> how we can use MSW to test our Nuxt application’s communication with the backend. I made it work by importing axios and assigning wrapper.vm.$axios = axios.</p><p>However, this is actually a bad hack, since @nuxtjs/axios and axios aren’t the same. The former is a Nuxt.js module that wraps axios and offers more functionality on top of it. @nuxtjs/axios and axios happen to have a similar API which enables us to use the latter in place of the former and mock any additional methods we use (such as setToken). But what will we do in other cases where we use a Nuxt.js module that does not wrap something with a similar API? How can we use a Nuxt.js module in our tests? To answer that we need to know some internals of Nuxt.js modules.</p><p>A Nuxt.js module is often a wrapper around a Nuxt.js plugin.</p><p>A Nuxt.js plugin is often a wrapper around a Vue plugin.</p><p>Let’s go through these from the bottom up.</p><h3>Vue plugins</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ddcbdc8a7efdfcb52ac9073644ba1af/href">https://medium.com/media/9ddcbdc8a7efdfcb52ac9073644ba1af/href</a></iframe><p>After the snippet above executes, myVueInstance.$hello will have the value “world”.</p><p>A Vue plugin is an object (or module) containing an install() function (the plugin can also be a function itself instead). What Vue.use() does is register the plugin and, if it is not already registered, execute the function.</p><p>Vue plugins can be installed (with Vue.use()) either before or after creating the Vue instance.</p><h3>Nuxt plugins</h3><p>A Nuxt plugin is a JavaScript file (typically in the plugins directory) whose name is specified in the plugins property in nuxt.config.js. The file may or may not export a function.</p><h4>Nuxt plugins that do not export a function</h4><p>Here is an example of a Nuxt plugin that does not export a function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb936441eb8a7832985f2f90edb5ceec/href">https://medium.com/media/fb936441eb8a7832985f2f90edb5ceec/href</a></iframe><p>When Nuxt starts, it merely imports the file.</p><p>When a Nuxt plugin merely wraps a Vue plugin, it can simply execute Vue.use(theVuePlugin).</p><h4>Nuxt plugins that export a function</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a2a695a08048b344c8f0878d58ee905/href">https://medium.com/media/4a2a695a08048b344c8f0878d58ee905/href</a></iframe><p>When Nuxt starts, it will import the file and execute the function, passing it the Nuxt context and the inject function. In this particular case, inject(&#39;hello&#39;, &#39;world&#39;) will do something similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5afafe7ae36a1e00af7174f4d888e24e/href">https://medium.com/media/5afafe7ae36a1e00af7174f4d888e24e/href</a></iframe><p>Why not simply write the above instead of exporting a function that receives a callback inject function and calls it? Because the inject function is smart. Depending on Nuxt configuration and environment (e.g. SSR or client), it might decide to add the attribute only to Vue, or only to the context, or also add it to the store, etc. By just executing inject(&#39;hello&#39;, &#39;world&#39;), we tell Nuxt to add (“inject”) the $hello attribute to wherever it needs to be added.</p><h3>Nuxt modules</h3><p>A Nuxt module is a JavaScript file that exports a function and is specified in the modules property of nuxt.config.js. Nuxt calls the function when it starts.</p><p>The difference between a Nuxt module and a Nuxt plugin is that a module runs earlier. Nuxt first loads and executes modules, then creates the Vue instance and the Nuxt context, and then executes Nuxt plugins. As a result, Nuxt modules can do more customization; for example, they can add plugins. I’m still not entirely clear on that, but for the purposes of this post it doesn’t matter, because it is given that we have a module (@nuxtjs/axios) and we need to load it for testing.</p><h3>How @nuxtjs/axios works</h3><p>@nuxtjs/axios is a Nuxt module—a .js file that exports a function. Nuxt loads the file and executes the function.</p><p>One of the things the function does is execute Nuxt’s addPlugin() method. This is the way to programmatically load a plugin without needing to add it to the plugins property of nuxt.config.js. Since this plugin does not have a name, we will call it “the Nuxt axios plugin”.</p><p>So, Nuxt starts. It initializes the @nuxtjs/axios module. The module, among other things, executes Nuxt’s addPlugin(), thus registering the Nuxt axios plugin. Later (after finishing loading all modules, creating the Vue instance and Nuxt context, and possibly doing other initialization work) Nuxt will initialize the Nuxt axios plugin. What the plugin initialization does is create an Axios instance, extend it with some additional methods (such as setToken), and then call Nuxt’s inject to add it as the $axios property of Vue (and of the Nuxt context).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f10887ef31b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testing-nuxt-applications/introduction-to-nuxt-plugins-and-modules-7f10887ef31b">Introduction to Nuxt plugins and modules</a> was originally published in <a href="https://medium.com/testing-nuxt-applications">Testing nuxt applications</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing custom Vue events]]></title>
            <link>https://medium.com/testing-nuxt-applications/testing-custom-vue-events-f2ed10e740fb?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2ed10e740fb</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Mon, 31 May 2021 13:16:42 GMT</pubDate>
            <atom:updated>2021-05-31T13:16:42.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e4Q8xGFKYKQweh9M" /><figcaption>Photo by <a href="https://unsplash.com/@testalizeme?utm_source=medium&amp;utm_medium=referral">Testalize.me</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This isn’t a Nuxt testing issue; it’s a Vue testing issue. All the same, it’s going to affect people working in Nuxt as well.</p><p>However, whenever you have a Vue (rather than a Nuxt) testing issue, the answer is likely to be in the excellent book “Testing Vue.js applications” by Edd Yerburgh, which you should really read. It’s going to save you from lots of headaches.</p><p>I have a LoginForm component that uses a modal. LoginForm looks like this (I’ve deleted everything that isn’t relevant to the issue at hand):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd127a8ec1acb3f4c3c42364988b0275/href">https://medium.com/media/cd127a8ec1acb3f4c3c42364988b0275/href</a></iframe><p>I want to test that when the modal appears, focus goes to the username field. This is how to achieve this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/774f2199add42b5dd34f0d8bd020500f/href">https://medium.com/media/774f2199add42b5dd34f0d8bd020500f/href</a></iframe><p>This works alright.</p><p>However, there is a subtle catch here. Suppose that in the next bootstrap-vue version, the b-modal component is changed so that instead of emitting the shown custom View event, it emits a renamed event, say showmodal. Now, after installing the new bootstrap-vue version and running the test suite, this test will pass.</p><p>Unit testing purists might say that I’ve done everything correctly. I’ve tested LoginForm in isolation, and I’ve verified it receives and handles the shown event. BModal should also be tested in isolation (and that’s what the bootstrap-vue people do), and it should be verified it emits the shown event. Verifying that LoginForm and BModal work correctly together is an integration test.</p><p>However, I think writing yet another test for this detail would be overkill. Therefore, I’d like to write this test a bit differently. Rather than asking the BModal component to emit a shown event, I’d prefer to ask the BModal component to show itself. However I don’t know (yet) how to do this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2ed10e740fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testing-nuxt-applications/testing-custom-vue-events-f2ed10e740fb">Testing custom Vue events</a> was originally published in <a href="https://medium.com/testing-nuxt-applications">Testing nuxt applications</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing backend communication]]></title>
            <link>https://medium.com/testing-nuxt-applications/testing-backend-communication-84a5bf02ae10?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/84a5bf02ae10</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[axios]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Tue, 18 May 2021 11:23:05 GMT</pubDate>
            <atom:updated>2021-05-18T11:23:05.093Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DgrRckXUZTyfgOrx" /><figcaption>The River Axios; Photo by <a href="https://unsplash.com/@dpantos?utm_source=medium&amp;utm_medium=referral">dimitris pantos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Using MSW</h3><p>The most common answer to the problem of how to test communication with the backend is to mock fetch or axios or whatever library you use for making http requests. However, StackOverflow user <a href="https://stackoverflow.com/users/3001761/jonrsharpe">jonrsharpe</a> <a href="https://stackoverflow.com/questions/67101502/how-to-mock-axios-with-jest/67107497#67107497">proposes a better method</a>: use <a href="https://mswjs.io/">msw</a>, the Mock Service Worker. It works by essentially creating a server that intercepts requests on the network level. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8d6e2726127ddff6a4ebd1a0e34a76c/href">https://medium.com/media/e8d6e2726127ddff6a4ebd1a0e34a76c/href</a></iframe><p>The server we have created responds to login requests:</p><ul><li>If the username and password are alice and topsecret, it responds with a token</li><li>If the username and password are alice and wrongpassword, it responds with an error message</li><li>Otherwise, it throws an exception, effectively simulating a network error.</li></ul><p>That’s it, essentially. You don’t need to mock anything. Whenever your main code attempts to talk to the network, MSW will intercept the request and provide a response.</p><p>But there are a few problems.</p><h3>Initializing Axios</h3><p>As I explained in <a href="https://medium.com/testing-nuxt-applications/testing-functionality-that-involves-the-store-c0bfd69adc98">my previous post</a>, it isn’t trivial to initialize Nuxt at the beginning of testing, so certain things like the store don’t exist. Likewise, if you are using @nuxtjs/axios, this.$axios will also not exist. Therefore, when your component or any part of your code tries to make a request by using this.$axios, it will stop and give you a message like “Cannot read property ‘post’ of undefined”. I haven’t solved that problem yet. Until I do, what you can do is something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fc3a58fed7645ead2b49e83760d2dfb/href">https://medium.com/media/4fc3a58fed7645ead2b49e83760d2dfb/href</a></iframe><p>(I have left the MSW part out to concentrate on the problem at hand; but you need to combine the two parts for it to actually work.)</p><p>So we kind of “mock” axios, but not with a mock function such as jest.fn(); instead, we assign it a real instance of Axios.</p><p>Unfortunately, this won’t solve all problems. The problem is that @nuxtjs/axios is not the same as axios; the former has a little bit more functionality. If your main code uses that additional functionality, such the .setToken() method, it won’t work during the tests. What you need to do in that case is to mock this additional functionality; for example,</p><pre>wrapper.vm.$axios.setToken = jest.fn()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84a5bf02ae10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testing-nuxt-applications/testing-backend-communication-84a5bf02ae10">Testing backend communication</a> was originally published in <a href="https://medium.com/testing-nuxt-applications">Testing nuxt applications</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing functionality that involves the store]]></title>
            <link>https://medium.com/testing-nuxt-applications/testing-functionality-that-involves-the-store-c0bfd69adc98?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0bfd69adc98</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[vue-test-utils]]></category>
            <category><![CDATA[nuxt]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[vuex]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Mon, 17 May 2021 16:54:36 GMT</pubDate>
            <atom:updated>2021-05-17T16:57:03.156Z</atom:updated>
            <content:encoded><![CDATA[<p>I wanted to test this loggedOnUser() function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81235a61698287d45c0e1a57c6883794/href">https://medium.com/media/81235a61698287d45c0e1a57c6883794/href</a></iframe><p>So at first I tried this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e9bf4ca4b863b6dd358dfdecc965e79/href">https://medium.com/media/2e9bf4ca4b863b6dd358dfdecc965e79/href</a></iframe><p>Unfortunately this fails with a loud bang. It isn’t even able to mount the component. The reason is that the component needs to use loggedOnUser() during mounting, and this.$store is undefined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*my18GOmZt4WISkWJoLOkKg.png" /></figure><p>When Nuxt runs normally, it automatically loads machinery that causes things like this.$store to exist. This machinery isn’t loaded when we try to run the test above; you need to load it manually. Unfortunately, the documentation is silent about how to do this, and <a href="https://github.com/nuxt/nuxtjs.org/issues/1190">people have complained about this silence</a>. <a href="https://medium.com/u/cffae3791947">Brandon Aaskov</a> has actually <a href="https://medium.com/@brandonaaskov/how-to-test-nuxt-stores-with-jest-9a5d55d54b28">written an article</a> on this.</p><p>Now, purists might stop me and point out that in unit tests you are supposed to be testing the functionality of a unit (in this case the loggedOnUser() function) without any interaction with the rest of the system (in this case the store). If the unit being tested depends on another part of the system, that part (the store in this case) should be mocked. If we follow this advice, my test becomes like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d642a8ae0ed666f87b689a2e7fac965c/href">https://medium.com/media/d642a8ae0ed666f87b689a2e7fac965c/href</a></iframe><p>This one passes alright. Other tests might need you to also mock $store.commit(), but if you are comfortable with mocking this is no big deal.</p><p>Are the purists right? My opinion is no. If you have function A that calls function B, you aren’t going to mock B whenever you’re testing A. The purpose of writing tests is to develop faster and cheaper, and this means avoiding mocking wherever possible. In fact, as a Django developer, I’m delighted at the fact that Django connects to the RDBMS and creates a test database at the beginning of each test run, relieving me of the duty of having to mock the RDBMS, although the RDBMS is a textbook case of a big external system that needs to be mocked. Django only takes a few seconds to create the database, and the savings are much more significant. The vuex store is not a big external system; it’s a small internal system. I don’t believe it should be mocked on every occasion.</p><p>Brandon’s solution wouldn’t work without a fight though, and since I’m a Nuxt beginner, I settled with mocking, waiting to get more experience before retrying. I’ll be writing more of these posts as I learn; think of them as a kind of personal notes that I’m writing in public.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0bfd69adc98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testing-nuxt-applications/testing-functionality-that-involves-the-store-c0bfd69adc98">Testing functionality that involves the store</a> was originally published in <a href="https://medium.com/testing-nuxt-applications">Testing nuxt applications</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An open letter to the signatories of the open letter about Stallman]]></title>
            <link>https://aptiko.medium.com/an-open-letter-to-the-signatories-of-the-open-letter-about-stallman-2b8f5c08018b?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b8f5c08018b</guid>
            <category><![CDATA[richard-stallman]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 07:28:03 GMT</pubDate>
            <atom:updated>2021-04-12T08:50:12.656Z</atom:updated>
            <content:encoded><![CDATA[<p>On 23 March, a number of organizations and individuals signed an <a href="https://rms-open-letter.github.io/">open letter</a> asking to remove Richard M. Stallman from all leadership positions. It also asks the FLOSS community to boycott the Free Software Foundation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*E57ICF9HME9TKZeUIOYbEg.png" /></figure><p>Dear signatories,</p><p>I am very sad about the letter, and it doesn’t have much to do with Stallman. It has to do with the letter and only with the letter. If I hadn’t met some of you personally, I would have dismissed it and moved on. But since I know and respect many of you, I’m just sad.</p><p>I know Stallman can be a difficult person. I have attended three talks by him—in fact I helped organize one of them—and I have talked to people who made a huge effort to make such an important guest feel at home, and were then outraged by behaviour they perceived as rude and ungrateful. I am also aware that Stallman is a hardliner. All software should be free and that’s it. No negotiation.</p><p>When I first saw the open letter, my reaction was “things are more serious than I thought”. When I actually read it, I was taken aback by the characterizations. Misogynist, ableist, transphobic, having repugnant ideas and dangerous ideology, and demonstrating intolerance, bigotry and hate. Wow! Things are really more serious than I thought. I became curious to learn what Stallman had done to deserve these, so I turned to your appendix. At this point I was shocked and awed.</p><p>I was shocked and awed because you present zero evidence of Stallman being misogynist, ableist, transphobic, intolerant, hateful, or of his ideas being repugnant and dangerous. (See the Appendix below for an extensive commentary.) I’m not saying Stallman isn’t any of these things—maybe he is, I don’t know—but that you have provided zero evidence.</p><p>But the most important thing is that, even if Stallman <em>is</em> these things, your letter still violates every code of conduct I can think of. Here is an example from <a href="https://www.djangoproject.com/conduct/">Django</a>:</p><blockquote><strong>Be respectful.</strong> Not all of us will agree all the time, but disagreement is no excuse for poor behavior and poor manners. We might all experience some frustration now and then, but we cannot allow that frustration to turn into a personal attack. It’s important to remember that a community where people feel uncomfortable or threatened is not a productive one. Members of the Django community should be respectful when dealing with other members as well as with people outside the Django community.</blockquote><p>I see prominent Django people signing that letter. What is the point in having a code of conduct if we are going to violate it in a manner that sets such a bad example for our community?</p><p>Finally, what purpose does that letter serve other than divide the community and magnify whatever bitter feelings exist?</p><p>Please revoke your support for that letter. And please explain to me what the problem is with Stallman.</p><p>Regards,</p><p>Antonis</p><h3>Appendix</h3><h4>Marvin Minsky</h4><p>First of all, I read <a href="https://selamjie.medium.com/remove-richard-stallman-fec6ec210794">Stallman’s email</a> concerning the accusations against Marvin Minsky.</p><ul><li>He doesn’t actually say that the victim was willing — on the contrary, he seems to agree that she was being coerced.</li><li>What he <em>is</em> saying is that there is no evidence she was being coerced by Minsky. She was being coerced by Epstein, who sent her to Minsky, and it’s likely — according to Stallman— that she had been instructed by her coercer to present herself to Minsky as entirely willing.</li><li>Therefore, he concludes, Minsky may have done something wrong, but the word “assault” doesn’t seem to be correct—it inflates the accusation.</li></ul><p>Stallman makes all this so abundantly clear that I am at a loss at how people are interpreting “the most plausible scenario is that she presented herself as entirely willing” as a statement that she was willing or that she was not being coerced.</p><p>Another interesting thing from that thread is the definition of rape. Apparently <a href="https://apps.rainn.org/policy/policy-crime-definitions.cfm?state=virgin%20islands&amp;group=9&amp;_ga=2.39249895.512450349.1568822825-1611446995.1568822825">in the Virgin islands</a>, if you are 23 and have sex with a 17-year-old, you are raping her (or him). This makes me wonder whether Charlie Chaplin would have been a rapist in the Virgin islands. To answer this question, because it isn’t entirely clear what the law means by “17 years old” (i.e. on which exact moment you stop being 16 and start being 17—is it the time of your birth on your birthday anniversary? Is it midnight of 31 December?), we’d need to check the law and his wives’ birthdays and the dates of his first sexual act with each of them to find out. Absurd? That’s what Stallman says: “I think it is morally absurd to define “rape” in a way that depends on minor details such as which country it was in or whether the victim was 18 years old or 17.”</p><p>“I was shocked”, <a href="https://selamjie.medium.com/remove-richard-stallman-fec6ec210794">writes Selam G.</a> at this point of her story. The <a href="https://rms-open-letter.github.io/appendix">appendix to the open letter</a> finds Stallman’s email “especially chilling”. Since nothing in what Stallman says appears to be remotely shocking or chilling to me—on the contrary, I see someone who likes to be careful in his choice of words—I conclude that this must not be an isolated incident. Maybe this exchange becomes shocking or chilling when you add it to a context of other things Stallman has done in the past.</p><p>So let me read on.</p><h4>Cody Wilson</h4><p>Stallman’s <a href="https://web.archive.org/web/20210325013706/https://stallman.org/archives/2018-jul-oct.html#23_September_2018_(Cody_Wilson)">views on the Cody Wilson case</a> echo his views on the Marvin Minsky case. I happen to agree with them. I can imagine someone could disagree but I don’t see, beyond it being healthy disagreement, how it could be deduced that Stallman defends rape or child trafficking, and it doesn’t seem that these views of him could suffice in creating this outrage. No, surely something else is going on here. Let’s read on.</p><h4>Laws about rape</h4><p>The appendix continues with this:</p><blockquote>He regularly and repeatedly makes comments about “the dishonest law that labels sex with adolescents as ‘rape’ even if they are willing.” He compares United States law to Sudanese law in saying that “US laws that define ‘rape’ to include voluntary sex with under N years of age (where N varies)” and that “both laws falsify the meaning of ‘rape.’”</blockquote><p>I haven’t followed the links. I don’t need to see these statements in context, because I don’t see any problem with them. He isn’t defending sex with adolescents, even if they’re willing—all he’s saying is that it isn’t rape.</p><p>While I can imagine someone could disagree with these views, such disagreement could hardly cause this outrage. Something else must be going on. Let’s read on.</p><h4>Sex with adolescents</h4><p>“I wish an attractive woman had ‘abused’ me that way when I was 14,” <a href="https://web.archive.org/web/20210325014110/https://stallman.org/archives/2015-mar-jun.html#5_June_2015_(Law_being_an_ass)">writes </a>Stallman referring to <a href="https://web.archive.org/web/20210102220922/https://www.theguardian.com/uk-news/2015/jun/03/woman-who-had-sex-with-14-year-old-boy-is-jailed">a case where</a> a 25-year-old woman seduced a 14-year-old boy and was jailed because of this “abusing”.</p><p>Contrary to the previous cases concerning rape and assault, this one isn’t clear to me. His arguments seem thoughtful and honest. I can’t recall clearly how it was when I was 14. It’s almost certain that I was fantasizing similar “abusing” to be happening to me. Whether I would have liked my fantasies to become reality, or whether this would have been good for me, I don’t know. I can imagine that this issue could be the subject of many hours of interesting exchanges over beers. It doesn’t seem bad to me that Stallman expressed these thoughts. And it’s certainly not enough to cause this outrage. Something else must be going on. Let’s read on.</p><h4>Child pornography</h4><p>“Making such photos should be a crime, and is a crime, but that is no reason to prohibit possessing copies of the photos,” <a href="https://web.archive.org/web/20210325014131/https://stallman.org/archives/2014-jul-oct.html#26_October_2014_(Prison_for_cartoon)">writes Stallman</a> referring to child pornography. He continues: “To criminalize possession of copies of anything published — no matter what it is — is oppressive, and leads to many other forms of tyranny.”</p><p>This is a bold argument, and I can think of counter-arguments. It would have been interesting to hold this discussion with him. What is certain is that he does not defend child pornography. He clearly considers it a crime. He also doesn’t express any desire to possess such photos—he’s mentioning the story in the context of someone who was sentenced to prison for having a cartoon depicting a fictional child in some sort of sexual situation (I happen to possess a copy of <a href="https://en.wikipedia.org/wiki/Andreas_Embirikos#Megas_Anatolikos">Megas Anatolikos</a>, maybe I should also go to prison?)</p><p>It’s freedom of information he is concerned with here.</p><p>Whether we agree or disagree with him on possessing child pornography photos (I think I disagree with him), this isn’t enough to cause this outrage. Something else must be going on. Let’s read on.</p><h4>Pedophilia</h4><p>This one deserves the full text of what Stallman wrote:</p><blockquote>There is little evidence to justify the <a href="https://web.archive.org/web/20210325014249/https://www.theguardian.com/society/2013/jan/03/paedophilia-bringing-dark-desires-light">widespread assumption that willing participation in pedophilia hurts children</a>.</blockquote><blockquote>Granted, children may not dare say no to an older relative, or may not realize they could say no; in that case, even if they do not overtly object, the relationship may still feel imposed to them. That’s not willing participation, it’s imposed participation, a different issue.</blockquote><p>I admit this one is a problem. His second, well-thought paragraph, actually cancels the first one; because how can you distinguish between willing and imposed participation? And, anyway, the stories I’ve heard through victims all seem to point to a strong case that pedophilia does hurt children.</p><p>Is this enough to cause this outrage? Hardly. Given that all previous cases seem to be the carefully reasoned thoughts of an intelligent person, my automatic response to this statement is curiosity: why do you say this?</p><p>Five years later, he wrote this:</p><blockquote>Many years ago I posted that I could not see anything wrong about sex between an adult and a child, if the child accepted it.</blockquote><blockquote>Through personal conversations in recent years, I’ve learned to understand how sex with a child can harm per psychologically. This changed my mind about the matter: I think adults should not do that. I am grateful for the conversations that enabled me to understand why.</blockquote><p>OK. He’s coming to my words. I still don’t have the answer to my question: what was he thinking in the first place?</p><p>Still, I appreciate the fact that he questions everything. He doesn’t accept anything as given just because people say so.</p><p>This incident is something which could annoy people. But such outrage? Making people call him “dangerous”? I don’t think it explains it. Let’s read on.</p><h4>Down syndrome</h4><p>“When a fetus has Down’s syndrome, you should abort it and try again,” says the Appendix said Stallman. I think most obstetricians I went to with my wife when she was pregnant would have said the same. In fact, I read in Wikipedia that 92% of such pregnancies in Europe and 75% in the U.S. are aborted. Therefore Stallman appears simply to agree with mainstream opinion here.</p><p>As to Stallman likening having a child with Down’s syndrome to having a pet, here is exactly what he said while advocating abortion of fetuses with Down’s syndrome:</p><blockquote>If you’d like to love and care for a pet that doesn’t have normal human mental capacity, don’t create a handicapped human being to be your pet. Get a dog or a parrot. It will appreciate your love, and it will never feel bad for being less capable than normal humans.</blockquote><p>I don’t understand what’s the problem with that statement.</p><h4>Singular pronouns</h4><p>“There are various ways to express gender neutrality in third-person singular pronouns in English; you do not have to use ‘they.’”</p><p>and</p><p>“‘They’ is plural — for singular antecedents, use singular gender-neutral pronouns.”</p><p>According to the Appendix, these statements are transphobic. I fail to understand why.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b8f5c08018b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying encodings — part 3]]></title>
            <link>https://medium.com/django-deployment/demystifying-encodings-part-3-470ca70f79f5?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/470ca70f79f5</guid>
            <category><![CDATA[utf-8]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[gnu-linux]]></category>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 06:25:52 GMT</pubDate>
            <atom:updated>2021-01-12T06:25:52.826Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demystifying encodings — part 3</h3><p>Do you ever have trouble with encodings? I used to in the past, but now I rarely do, because I do a simple thing. While knowing the things I explained in <a href="https://djangodeployment.com/2017/06/19/encodings-part-1/">part 1</a> and <a href="https://djangodeployment.com/2017/08/16/encodings-part-2/">part 2</a> of this series is necessary, otherwise I wouldn’t be able to fix problems, such problems rarely arise, because the first thing I do when I setup a GNU/Linux machine is set the system locale to UTF-8.</p><p>The “locale” is the regional settings, among which the character encoding used. The procedure to set it up is this:</p><ol><li>Open the file /etc/locale.gen in an editor and make sure the line that begins with “en_US.UTF-8” is uncommented.</li><li>Enter the command locale-gen; this will (re)generate the locales.</li><li>Open the file /etc/default/locale in an editor, and make sure it contains the line LANG=en_US.UTF-8. Changes in this file require logout and login to take effect.</li></ol><p>Let me now explain what all this is about. The locale consists of a language, a country, and a character encoding; “en_US.UTF-8” means English, United States, UTF-8. This tells programs to show messages in American English; to format items such as dates in the way it’s done in the United States; and to use encoding UTF-8.</p><p>Different users can be using different locales. If you have a desktop computer used by you and your spouse, one could be using English and the other French. Each user does this by setting the LANG environment variable to the desired locale; if not, the default system locale is used for that user. For servers this feature is less important. While your Django application may display the user interface in different languages (and format dates and numbers in different ways), this is done by Django itself using Django’s internationalization and localization machinery and has nothing to do with what we are discussing here, which affects mostly the programs you type in the command line, such as ls. Because for servers the feature of users specifying their preferred locale isn’t so important, we usually merely use the default system locale, which is specified in the file /etc/default/locale. Since you can understand English, “en_US.UTF-8” is fine. If you prefer to use another country, such as “en_UK.UTF-8”, it’s also fine, but it’s no big deal, as I will explain later on.</p><p>Although the system can support a large number of locales, many of these are turned off in order to save a little disk space. You turn them on by adding or uncommenting them in file /etc/locale.gen. When you execute the program locale-gen, it reads /etc/locale.gen and determines which locales are activated, and it compiles these locales from their source files, which are relatively small, to some binary files that are those actually used by the various programs. We say that the locales are “generated”. If you activate all locales the binary files will be a little bit over 100 M, so the saving is not that big (it was important 15 years ago); however they will take quite some time to generate. Usually we only activate a few.</p><p>To check that everything is right, do this:</p><ol><li>Enter the command locale; everything (except, possibly, LANGUAGE and LC_ALL) should have the value en_US.UTF-8.</li><li>Enter the command perl -e &#39;&#39;; it should do nothing and give no message.</li></ol><p>The locale command merely lists the active locale parameters. LC_CTYPE, LC_NUMERIC etc. are called “locale categories”, and usually they are all set to the same value. In some edge cases they might be set to different values; for example, on my laptop I use “en_US.UTF-8”, but especially for LC_TIME I use “en_DK.UTF-8”, which causes Thunderbird to display dates in ISO 8601. This is not our concern here and it rarely is on a server. So we don’t set any of these variables, and they all get their value from LANG, which is set by /etc/default/locale.</p><p>However, sometimes you might make an error; you might specify a locale in /etc/default/locale, but you might forget to generate it. In that case, the locale command will indicate that the locale is active, but it will not show that anything is wrong. This is the reason I run perl -e &#39;&#39;. Perl is a programming language, like Python. The command perl -e &#39;&#39;, does nothing; it tells Perl to execute an empty program; same thing as python -c &#39;&#39;. However, if there is anything wrong with the locale, Perl throws a big warning message; so perl -e &#39;&#39; is my favourite way of verifying that my locale works. Try, for example, LANG=el_GR.UTF-8 perl -e &#39;&#39; to see the warning message. So locale shows you which is the active locale, and perl -e &#39;&#39;, if silent, indicates that the active locale has been generated and is valid.</p><p>I told you that the country doesn’t matter much for servers. Neither does the language. What matters is the encoding. You want to be able to manipulate all characters of all languages. Even if all your customers are English speaking, there may eventually be some remark about a Chinese character in a description field. Even if you are certain there won’t, it doesn’t make any sense to constrain yourself to an encoding that can represent only a subset of characters when it’s equally easy to use UTF-8. So you need to make sure you use UTF-8.</p><p>PostgreSQL will use the default locale for its databases (unless told to do otherwise). Your best bet is to do all the above before apt install postgresql.</p><p>The programs you run at the command line will be producing output in your chosen encoding. Your terminal reads the bytes produced by these programs and must be able to decode them properly, so it must know how they are encoded. In other words, you must set your terminal to UTF-8 as well. Most terminals, including PuTTY and gnome-terminal, are by default set to UTF-8, but you can change that in their preferences.</p><p><em>This post is largely taken from the first chapter of </em><a href="https://djangodeployment.com/"><em>my book</em></a><em>.</em></p><p><em>This is a republication of an old article </em><a href="https://djangodeployment.com/2018/04/14/encodings-part-3/"><em>first published</em></a><em> in my </em><a href="https://djangodeployment.com/"><em>Django Deployment site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470ca70f79f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-deployment/demystifying-encodings-part-3-470ca70f79f5">Demystifying encodings — part 3</a> was originally published in <a href="https://medium.com/django-deployment">Django Deployment</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying encodings — part 2]]></title>
            <link>https://medium.com/django-deployment/demystifying-encodings-part-2-104c1595ce73?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/104c1595ce73</guid>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[unicode]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 06:20:42 GMT</pubDate>
            <atom:updated>2021-01-11T06:21:45.042Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demystifying encodings — part 2</h3><p>As we saw in <a href="https://djangodeployment.com/2017/06/19/encodings-part-1/">part 1 of this series</a>, each program reads stuff from input and writes stuff to output. Whenever it reads strings of characters in the input, these strings are encoded in a certain encoding such as UTF-8. The program must decode these strings into an internal representation. When writing to the output, the program encodes strings from its internal representation to an encoding such as UTF-8.</p><p>What this internal representation is is usually not our concern. For example, in Python versions earlier than 3.3, the internal representation is either UCS-2 or UCS-4, depending on how Python was compiled. In Python 3.3 or later, the internal representation is more complicated and described in PEP 393. But these details are rarely of interest; what matters is that a program must be able to communicate with other programs via its input/output, and for this to work properly the programs must agree on an external representation. Whenever you see “appétit” rendered as “appÃ©tit” it usually means that two programs did not agree on the encoding of the external representation; for example, that one program sent UTF-8 to its output, and another program read this output as its input, thinking it was ISO-8859–1.</p><p>So, you have a Django application that displays images, and the browser shows an image, and under the image it renders the caption of the image, which is “Bon appétit!”. This caption is stored in a CharField or TextField in a model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xp0XYfL1v-tlHZzg.jpg" /><figcaption>Bon appétit!</figcaption></figure><p>The string is stored in a file from where it is retrieved by the RDBMS, travelling through Django, the web server, and the web browser, to be finally painted on the screen by the operating system. On this way, it is encoded and decoded several times. The following figure shows more details of this travel of the string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*-Ys0K4RV_xks0g-R.png" /></figure><p>In the end what you must remember is that programs store strings in internal representations and encode/decode them when they communicate with other programs. In the next post we will see what you can do to lessen the probability of some error happening along the way.</p><p><em>This is a republication of an old article </em><a href="https://djangodeployment.com/2017/08/16/encodings-part-2/"><em>first published</em></a><em> in my </em><a href="https://djangodeployment.com/"><em>Django Deployment site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=104c1595ce73" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-deployment/demystifying-encodings-part-2-104c1595ce73">Demystifying encodings — part 2</a> was originally published in <a href="https://medium.com/django-deployment">Django Deployment</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying encodings — part 1]]></title>
            <link>https://medium.com/django-deployment/demystifying-encodings-part-1-719f381338df?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/719f381338df</guid>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[unicode]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 06:56:45 GMT</pubDate>
            <atom:updated>2021-01-08T06:56:45.652Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demystifying encodings — part 1</h3><p>Has a UnicodeEncodeError ever got on your nerves? I think it has happened to pretty much everyone. I thought it’s a good time to start demystifying this mystery, and to have fun while doing it.</p><p>You are probably familiar with the famous hello program, which does nothing but print “Hello, world!” Now we are going to create the bon program, which prints “Bon appétit!” Here it is, but <strong>don’t type it in or copy/paste it</strong>:</p><pre><strong>import</strong> sys<br> <br>sys.stdout.write(&quot;Bon appétit!<strong>\n</strong>&quot;)</pre><p>We could have written it with a single print statement, but for several reasons I prefer this version.</p><p>Now, I told you to not type in this program or copy/paste it. Instead, we are going to create it by writing down the bytes that comprise it. The file bon.py, like any file, is a series of bytes. These bytes represent the characters in the file. The first character is “i”, which is represented by the byte 105; the second one is “m”, represented by 109; and so on. You can find the table for all characters (except é) <a href="https://en.wikipedia.org/wiki/ASCII#Printable_characters">at Wikipedia</a>.</p><p>In order to create the file, we will use another Python program. Here it is. You can copy and paste that one; name it createbon.py:</p><pre>byte_values = [<br>    <em># i   m    p    o    r    t        s    y    s</em><br>    105, 109, 112, 111, 114, 116, 32, 115, 121, 115, 13, 10,<br> <br>    13, 10,<br> <br>    <em># s   y    s   .    s    t    d    o    u    t   .</em><br>    115, 121, 115, 46, 115, 116, 100, 111, 117, 116, 46,<br> <br>    <em># w   r    i    t    e   (   &quot;   B    o    n</em><br>    119, 114, 105, 116, 101, 40, 34, 66, 111, 110, 32,<br> <br>    <em># a  p    p   +------+   t    i    t    !  \    n   &quot;   )</em><br>    97, 112, 112, 195, 169, 116, 105, 116, 33, 92, 110, 34, 41, 13, 10,<br>]<br> <br><strong>with</strong> open(&#39;bon.py&#39;, &#39;wb&#39;) <strong>as</strong> f:<br>    f.write(bytearray(byte_values))</pre><p>Type python createbon.py and it will create bon.py. Don’t try to run it yet; instead, open bon.py in a UTF-8 editor to see it. By default, on GNU/Linux systems any editor should work properly. On Windows I experimented with Notepad and it worked, but you might need to tell it it’s UTF-8.</p><p>You may have noticed that 32 is the space, and that I’m using the sequence 13 10 for a new line. 13 stands for “carriage return”, and 10 for “line feed”. On Windows both characters are needed to change line, whereas in Unixes only line feed is used. Here I used the Windows version. Python programs in GNU/Linux will rarely use 13 10 as the newline, they will normally use only 10, but if it happens that a file uses 13 10 it will work without problem.</p><p>Running bon.py is a different story. First of all, you can only run it in Python 3. Python 3 assumes that the encoding of the input file is UTF-8, which it is.</p><p>If you try to run bon.py with Python 3 on GNU/Linux, most likely it will work; however, on several environments, it might not work and instead give you a UnicodeEncodeError:</p><pre>UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode character &#39;\xe9&#39; in position 7: ordinal not in range(128)</pre><p>Whether it succeeds or not, here is what happens: Python reads bon.py. When it reaches the “Bon appétit!\n” part, it reads the bytes and decodes them into a string of characters. Python assumes these bytes are the string encoded in UTF-8, which it is, so it is able to decode these bytes into an internal representation of the string.</p><p>When the time comes to print the string to the standard output, Python must convert the string from the internal representation to an encoding that will be understood by the terminal inside which Python is being run. The way Python determines that encoding depends on the system on which it is running.</p><p>Let’s see some examples only for the word “appétit”. If the terminal uses UTF-8, the bytes produced by the encoding will be 97, 112, 112, <strong>195, 169</strong>, 116, 105, 116 (I’ve bolded é just to make it easier for you to read the whole sequence). If it uses ISO-8859–1, the bytes will be 97, 112, 112, <strong>233,</strong> 116, 105, 116. If it uses UTF-16, the bytes will be 97, 0, 112, 0, 112, 0, <strong>233, 0,</strong> 116, 0, 105, 0, 116, 0. In all cases, Python will throw these bytes to the terminal, and the terminal will decode them into its internal representation, and in co-operation with the operating system and the windowing system it will paint the corresponding glyphs on the screen.</p><p>If the terminal uses ASCII, Python will attempt to encode the string into ASCII. In addition, if the encoding used by the terminal is unknown to Python, Python will also use ASCII. But é cannot be encoded into ASCII, because the ASCII character set does not contain that character, so Python will throw the UnicodeEncodeError.</p><h3>Python 2</h3><p>Python 3 is much better than Python 2 when it comes to all this stuff. In Python 2 there are two complications.</p><p>First, Python 2 assumes that the encoding of the input file is ASCII, and in ASCII all bytes are a number between 0 and 127, and here we have two bytes that are more than 127 — it’s the two bytes that represent é, 195 and 169. So Python 2 will stop and complain (“SyntaxError: Non-ASCII character ‘\xc3’ in file /tmp/bon.py on line 3, but no encoding declared”). You can solve this problem by adding a comment on top of the file that tells Python that the encoding of the file is UTF-8, but we will not bother with that here; read <a href="https://www.python.org/dev/peps/pep-0263/">PEP 263</a> if you are interested in that. (Python 3 always works with UTF-8, whereas Python 2 needs a PEP 263 comment, and if you use one it should always be UTF-8; don’t use anything else, otherwise you will be in trouble when porting your code to Python 3).</p><p>Second, in Python 2 the literal &quot;Bon appétit!\n&quot; is (speaking in the much cleaner Python 3 terminology) a sequence of bytes, not characters. While the program will work as it is, Python 2 treats the string as a sequence of bytes and just throws these bytes to the terminal. It will not attempt to translate them to the terminal’s character set, as they’re just bytes. So it might work in this case but the program is actually buggy, and it will fail in different circumstances, such as when you try to run it on a UTF-16 terminal. To make Python 2 treat this as a string of characters, you’d need to prefix the string with a u and make it u&quot;Bon appétit!\n&quot;; or, better, to use from __future__ import unicode_literals. This talking about “unicode” is quite confusing and the reason for it is Python 2’s history and backwards compatibility. Your best bet is to forget about it and think in terms of Python 3’s strings and bytes. So the u prefix tells Python 2 that what follows is a sequence of characters, not a sequence of bytes. In other words, Python 2 (if you use the u prefix) will internally know that é is the character é, whereas, if you don’t use the u prefix, Python 2 will understand it as the otherwise meaningless sequence of numbers (195, 169). In Python 2, len(u&quot;Bon appétit!\n&quot;)is 13 whereas len(&quot;Bon appétit!\n&quot;) is 14.</p><p><em>This is a republication of an old article </em><a href="https://djangodeployment.com/2017/06/19/encodings-part-1/"><em>first published</em></a><em> in my </em><a href="https://djangodeployment.com/"><em>Django Deployment site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=719f381338df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-deployment/demystifying-encodings-part-1-719f381338df">Demystifying encodings — part 1</a> was originally published in <a href="https://medium.com/django-deployment">Django Deployment</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview with Rivo Laks about Docker]]></title>
            <link>https://medium.com/django-deployment/interview-with-rivo-laks-about-docker-8654b788a811?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8654b788a811</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 07:01:54 GMT</pubDate>
            <atom:updated>2021-01-07T07:01:54.700Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z4ZATuSCsOQ8LG9d.jpg" /></figure><p>This is an interview I took from Estonian Django developer Rivo Laks about Docker. Recorded in <a href="https://2017.djangocon.eu/">DjangoCon EU 2017</a>, Florence, Italy.</p><p><em>A: Hello everyone, this is Antonis from djangodeployment.com. The date is 7 April 2017 and I am in Florence, Italy, at the European Django conference. I’m sitting with Rivo Laks, who is a developer from Estonia. He has a company called Thorgate, and we are going to be talking about Docker and similar things, mostly about deployment. Hello Rivo, how do you like the conference?</em></p><p>R: Hello Antonis. I like it a lot and I think it’s my fifth DjangoCon now, so it’s been a pleasant experience throught the years.</p><p><em>A: That’s very interesting because it’s actually my first Django conference. So what do you think it is that brings you here?</em></p><p>R: I guess it’s the people, most importantly; and also the fact that this is a good place to keep you up to date with everything that is going on in the Django world.</p><p><em>A: Would you like to tell me some examples of Django applications that your company makes?</em></p><p>R: Well, it usually begins with some sort of business problem. One recent example is a company that manufactures pipes, and they needed a better way of getting an overview and keeping an overview of their production process and production queues, so we helped them with that by creating a Django application that basically contains the schedule for the production, so that they can add new pipes there from their existing bookkeeping software, then do quality assurance as well as use it in the future for actual monitoring of the production.</p><p><em>A: You made an interesting presentation a few days ago about how you use Docker to deploy your Django apps. So the question, first of all, is if this is something you have been doing for a long time, and I would especially like to know what problem Docker is solving for you.</em></p><p>R: We started looking into Docker because we had some dependency isolation issues, because for more recent projects we wanted to use more recent versions of Python and PostgreSQL, and at the same time we had, in the same server, older projects, running on older versions of Python, which we didn’t feel like upgrading at that time. We hoped Docker would help us keep these requirements and different versions of Python separate for each project. I think it succeeded in that, because we are now able to accomplish that and we have been using Docker in test and production servers for something like six months now, perhaps slightly less. It’s a quite recent development, but all the projects we are starting today are based on Docker.</p><p><em>A: I understand that you mostly deploy on single server. So you may have a virtual server and you deploy some Django applications in there. When this problem arose, and you had made some applications that use newer versions of PostgreSQL and Python, why didn’t you just create another virtual server perhaps, and you needed to use Docker to isolate things on the same virtual server?</em></p><p>R: We do use quite a low number of servers and put multiple projects on a single server because the projects themselves are often quite small and they don’t require a full server and so on one hand it is financially more efficient to keep multiple projects on a single server, and on the other hand it’s also more efficient for us to not have to maintain multiple servers, because we only have to monitor, configure backups and everything else for a low number of machines.</p><p><em>A: There is a lot of hype about Docker; we were discussing this yesterday. It’s a relatively new technology, it’s changing a lot, and it seems like it’s the new fashion that is going to solve, somehow, magically, all your problems, like XML was 20 years ago — I can’t remember any more recent example though I’m certain there is. When would you advise someone NOT to use Docker?</em></p><p>R: I definitely agree with you about the hype, there’s lots of hype going around, and it makes it a bit difficult to find good and objective information. When would I advise to not use Docker? I think that if you have a project that’s already running, that’s perhaps a bit on the bigger side, and that you’re not that actively developing any more, then there’s probably no point in moving to Docker. Perhaps you don’t need Docker in some cases. For us there was a very clear need or desire of what we wanted to accomplish with Docker, so if you don’t have that need, if you are looking at the advantages Docker might give you, and decide that these advantages are not really something that are a problem for you, then I guess you can just skip on it.</p><p><em>A: Thank you very much Rivo, and I hope to see you again next year.</em></p><p>R: Thank you for having me, and likewise.</p><p>Related information:</p><ul><li><a href="https://rivolaks.com/">Rivo Laks</a></li><li><a href="https://thorgate.eu/">Thorgate</a></li><li><a href="https://speakerdeck.com/rivolaks/docker-lessons-from-real-world-projects">Slides from Rivo’s presentation</a></li></ul><p><em>This is a republication of an old article </em><a href="https://djangodeployment.com/2017/06/01/interview-with-rivo-laks-about-docker/"><em>first published</em></a><em> in my </em><a href="https://djangodeployment.com/"><em>Django Deployment site</em></a><em>.</em></p><p><em>Interview<br> © 2017 Antonis Christofides and Rivo Laks.<br> The interview is licensed under the </em><a href="https://creativecommons.org/licenses/by-sa/4.0/"><em>Creative Commons Attribution-ShareAlike 4.0 International License</em></a><em>.</em></p><p><em>Photo by Bartek Pawlik<br> © 2017 </em><a href="https://2017.djangocon.eu/"><em>DjangoCon Europe 2017</em></a><em><br> </em><a href="https://www.flickr.com/photos/140681500@N07/34042459511/"><em>Original photo</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8654b788a811" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-deployment/interview-with-rivo-laks-about-docker-8654b788a811">Interview with Rivo Laks about Docker</a> was originally published in <a href="https://medium.com/django-deployment">Django Deployment</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview with Andrew Godwin about deployment]]></title>
            <link>https://medium.com/django-deployment/interview-with-andrew-godwin-about-deployment-d2471a72c673?source=rss-55580151393d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2471a72c673</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Antonis Christofides]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 07:30:44 GMT</pubDate>
            <atom:updated>2021-01-05T07:30:44.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KfZy3a5wCfWi6pGX.jpg" /></figure><p>This is an interview I took from Django core developer Andrew Godwin about deployment. Recorded in <a href="https://2017.djangocon.eu/">DjangoCon EU 2017</a>, Florence, Italy.</p><p><em>ANT: Hello everyone! This is Antonis from djangodeployment.com. It’s 5 April 2017 and I am at the European Django Conference in Florence. I am sitting with Andrew Godwin, who is a Django core developer mostly known as the creator of migrations and now Django Channels, and we are going to have a little chat about deployment. Hello Andrew!</em></p><p>AND: Hello! It’s lovely to talk to you!</p><p><em>ANT: Thanks! Some years ago you tried to create a deployment service which was called ep.io. So, could you tell me a little bit more about that?</em></p><p>AND: Of course! As a bit of background history, we’re talking quite a few years now when Heroku was just for Ruby at the time, and so I was sitting in DjangoCon US and me and a friend had the idea to, why not do Heroku for Python?, which of course was an idea common to several startups at that time. We took on the challenge of making a platform-as-a-service, which is what Heroku of course is. I think it was two or three years from start to end of that project. It was quite difficult, and eventually we sort of shut down gradually, the company itself moved to a project then called Orchard, which then later got sold on to Docker, Inc, so it still had a history through that time, but I left it around four years ago.</p><p><em>ANT: One question that I’ve been having about deployment, because I started a blog and a book about deployment and I see that people are really interested: So I asked my readers, why do you care when you can just press a button in Heroku and have your application deployed? I got a number of answers but I’d like to have your viewpoint.</em></p><p>AND: So that’s a very interesting and common question of course, and I have a number of different viewpoints. The first one for me is cost, ultimately. Heroku is very expensive for what they give you in terms of resources. Obviously the value out there is in terms of management and time saving and wages, but in general I would say that, as someone who’s experienced in deployment, I can do that. If that is in my range, I don’t need to spend too much for it. And the other part is customization. Heroku, I would say, is very good for a small or medium sized web site where you fit into the common pattern, but as you grow you inevitably become more specialized. You require different kinds of routing or network or storage and that’s the point where I think that something like Heroku restrains to make everything work, you can’t have one pattern that works for every big site. Now, would I recommend it? For a small site, absolutely. Would I run it? No. But that’s two very different things.</p><p><em>ANT: I think that services like Heroku, or, maybe, the Divio cloud, they treat deployment as a black box. That is essentially their purpose, to make deployment simpler for you, so you are not supposed to know anything about it. But do things eventually go wrong? And when things go wrong, is it useful to have knowledge of the mechanics of deployment in order to fix things? Or is it maturing now? Is it a matter of maturity?</em></p><p>AND: So it’s not just maturity, it’s also about how well you are equipped to deal with these problems. Having full knowledge of the system is not useful if you don’t have the resources to fix that system. You just know about your failure rather than not knowing about your failure. So I think it is in some cases better to know of a failure and be able to fix it, but doing that requires a lot of expertise that is hard to find, like good operations people are very very thin on the ground in almost every part of the world. So it really depends, is it worth for you to know how to fix the black box or can you take the failure? One good example that isn’t about deployment is a database. If MySQL or PostgreSQL fails, it’s technically open source, you can, in theory, go and fix it, but in all likelihood you don’t have the knowledge or the ability to fix the problem in PostgreSQL, and so, it’s not about if it’s technically close, it’s also if it’s by the nature of its complexity close to you. If I made you a system that is fully open, and gave you that system with the ssh keys and everything, but you didn’t know how it worked, it would still be effectively a black box, but now it’s a black box with no support contract. In a lot of cases it’s best to have a black box with a support contract than something you half-know yourself.</p><p><em>ANT: People compare Django deployment to PHP deployment, because PHP has a fame for easy deployment — you just throw your files in a directory and it just works. Is there any fundamental reason why Django has to be harder? And a related question is, is PHP deployment really simpler, or is it deceptive to think that you can just throw your files in a directory and that’s it?</em></p><p>AND: There’s two parts to that question. The first one that I will address is, is it really simpler? The answer is, for a small project yes. PHP has the unenviable ability to just take a directory, put a file in there, and you’re off. And for that reason I came into web development from PHP. I had my problems with it as a language but I still respect the ease of use of it. The problem is that simplicity quickly becomes irrelevant as you get bigger and bigger, and one of the downsides of PHP can often be, yes it is a directory, and so you have to have an htaccess file in the old days, there’s a few more security issues. In Python and Django it’s just having standards. Before the advent of WSGI — when I started doing Django WSGI was there but very new — it was much harder, you had to sort of find a custom web server, wrangle with it, and it wasn’t particularly right. So we have come a long way in having a standard where you can pick anyone of uWSGI, mod_wsgi, Gunicorn, a number of other servers, plug any Python application into them, and there you go. It is more difficult, but it’s only very marginally more difficult. And ultimately I think, what I see the difference is with PHP you can drag-and-drop files in an interface, with Django you need to have some command line access. I think for some people just the presence of a command line makes it seem more difficult — it may not <em>be</em> more difficult but it makes it seem more difficult. That’s ultimately the sticking point some people have.</p><p><em>ANT: One example I have been thinking about that, a very simple one, is that when you deploy you also need to setup the email settings so that it can email you in case of an error, and for people who have no experience in deployment this is also something that they have to learn. You have to do this also in PHP I guess.</em></p><p>AND: Of course, you do, the difference there being that PHP is not setup to email you errors by default. If you configure it you can make it show a 500 page; if you do it incorrectly, as if you leave DEBUG on Django, it will show you a full traceback and all these wonderful variables and things exposed in there. So it’s more the case that out of the box Django is looking for an email address to send errors to. In a way that might be outdated by itself, for example I use something like Sentry more often than emails, my mailbox is already full enough. It’s just the defaults, the way it arrives, like, you install Django, you open that settings file, and there’s like 40 different things that you’re like “Oh! Do I need this? Do I fill it in?” and one of those is the email address.</p><p><em>ANT: OK. This is everything, so thank you Andrew and thanks everyone for listening.</em></p><p><em>This is a republication of an old article </em><a href="https://djangodeployment.com/2017/05/23/interview-andrew-godwin-deployment/"><em>first published</em></a><em> in my </em><a href="https://djangodeployment.com/"><em>Django Deployment site</em></a><em>.</em></p><p><em>Interview<br> © 2017 Antonis Christofides and Andrew Godwin.<br> The interview is licensed under the </em><a href="https://creativecommons.org/licenses/by-sa/4.0/"><em>Creative Commons Attribution-ShareAlike 4.0 International License</em></a><em>.</em></p><p><em>Photo by Bartek Pawlik<br> © 2017 </em><a href="https://2017.djangocon.eu/"><em>DjangoCon Europe 2017</em></a><em><br> </em><a href="https://www.flickr.com/photos/140681500@N07/33362229853/"><em>Original photo</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2471a72c673" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-deployment/interview-with-andrew-godwin-about-deployment-d2471a72c673">Interview with Andrew Godwin about deployment</a> was originally published in <a href="https://medium.com/django-deployment">Django Deployment</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>