OpenSource at Clojure

    In Run Loop invite those who make great products with their own hands. Nikita Prokopov ( tonsky ) - a man and a steamer, managed to do several OpenSource projects that other people enjoy using.

    First of all, let's talk about the FiraCode font, Clojure, and completely different projects, for example, ClojureScript wrapper for React. And then we move on to more general considerations about good interfaces, common sense, and learning models for programmers.



    About guest: Nikita Prokopov is notable because he created FiraCode, made a significant contribution to the development of the Clojure community and published projects such as Datascript and Rum in OpenSource. In addition, he writes on Objective-C under macOS: AnyBar program will tell you about the occurrence of any event in the statusbar, oh, menubar of your computer.

    Presenters : Roman Busygin (developer of Yandex.Music for iOS) and Alexey Mileev (App in the Air).

    Nikita : I am a programmer from Novosibirsk, but now I live in Moscow. I was engaged in web projects mainly fond of interfaces. Last time I program on Clojure.

    Roman : I propose to build today's conversation around your open source and public projects. I want to start with the first and most interesting for me - this is the FiraCode font . It is used by many of my colleagues and myself. I was always interested in how to make my own font, how it happens, if there is a special program, what knowledge you need to have to make your own font. Please tell about it.

    FiraCode


    Nikita : It's not entirely correct to say that this is my font. I took a ready monospaced font and finished drawing ligatures, I did not draw the letters myself. To make the letters themselves, you need a great experience and perseverance. It is very difficult, there are a million unobtrusive subtleties. There are amateur fonts and it is always clear that they are clumsy, but it is not always clear what this sloppy is.

    I took a good FiraMono font from Mozilla and finished drawing ligatures there, for this there are several programs. I used the fairly popular program Glyphs. In font design, I am not an expert, so I looked at what others use, and I also used it. It may be a surprise that it is quite expensive, but they gave me a license to develop FiraCode. Glyphs is like a vector graphics editor. You open, there are letters, you find the cells and draw pictures. Plus, any subtleties associated with fonts, for example, that letters have size, anchor points, transitions from bold to non-bold. Everything is quite simple.

    It is interesting that inside the OpenType font there is a programming language on the basis of which this replacement of ligatures was made. Initially, it was created as a means to implement all sorts of tricky things in fonts. For example, ligatures, when fi, ffi and the like in ordinary fonts are replaced with ligatures. Plus, there are variability, terminal traces in letters: if a letter stands at the beginning and end of a word, some tail is drawn to it. All this can be programmed with the help of cunning patterns, and also ligatures that are made.

    Roman : How much time did it take to refine FiraMono to the kind of FiraCode that everyone now uses?

    Nikita: It will be difficult to calculate. The first version was not very complicated. As always, it all started pretty quickly, but it took some time to figure out what was going on, how to do it: there weren’t much examples.

    Roman : That is, there were also several versions. How were they different?

    Nikita: Yes, and versions are updated. Firstly, I finish new ligatures, remove old ones sometimes, if they conflict in some way. At some point, the mechanism for drawing ligatures has changed. There is a very interesting algorithmic problem inside: there is a long sequence of characters, from it it is necessary to isolate those combinations of which ligatures consist, but if they intersect, then there must be another substitution. I even have a Clojure program that generates a set of rules that are then inserted into the font — quite difficult. This thing has changed, the way of rendering ligatures has changed. Previously, they were replaced by one character, now they are replaced by three. In fact, for the user, it becomes better, fewer bugs, more ligatures.

    Novel: Interesting. I never thought that there could be bugs in fonts. The rules by which the renderer decides when to insert ligatures, and when not, are described in a special programming language or just declarative?

    Nikita : Declarative, and then translated inside quite effectively into the replacement table.

    Set for the first version of ligatures


    Roman : Tell me, when you invented a set of ligatures, did you look at any specific programming languages ​​or is there a more or less general list of what people need in everyday life?

    Nikita : I didn’t come up with this idea myself. I saw that there is a Hasklig font made specifically for Haskell. But I didn’t need Haskell, so I thought I should make the same font, but, first, based on the font I like, and second, for any language. Then I just took everything that occurred to me . First, the obvious things: <=,> =, ->, <-. You write as in C, and it is replaced by an arrow. In my opinion, it all started.

    Clojure


    Alexey : At the very beginning you mentioned that you are writing to Clojure. Tell me how you came to Clojure, how it all began, how you came to this language?

    Nikita : I watched several lectures by Rich Hickey (I recommend, for example, this and  this ). They are cool and universal on the topic of how the programmer’s head works, roughly speaking, how to design systems. Lectures opened for me a huge amount of new important concentrated information, and I am a fan of Rich Hickey. Then he became interested in what he did. It turned out that he made Clojure. Went to read, figured out and everything started away.

    Novel: I, too, can be enrolled in Rich Hickey's fans. I saw his speeches: they are long, and most importantly, interesting. That is, he manages to keep the attention of listeners for a long time.

    Alexey : What exactly do you like about Clojure?

    Nikita : At the last conference, Rich Hickey made the following remark:

    Clojure is a language for old, tired programmers.

    They do not come to him at the beginning of his career, and he becomes interesting after 10-15 years. First, you have absolute freedom. Everything you need, you do it yourself or take it from libraries. The language itself is sewn with a minimum of things . Everything else you construct, you do exactly as you need. Everything is homemade and can be changed. This is dangerous when you are a beginner, but it is useful if you are already an expert and know what you need.

    In this language the thought is most clearly and compactly expressed. That is, the minimal gap between the complexity of what you are trying to express and the complexity of how it is recorded. In Java, for example, you can do some completely trivial thing, but it will stretch over 10 lines and you will get tired. In Clojure, if a thing is trivial, then it is written, most likely trivially, in one or two lines.

    Roman : I understood that you answered my question. When I heard that Clojure does not impose any restrictions on you, for some reason I immediately remembered C, who also stood on his ears somehow. But then I heard the answer that after all it is not just syntactic sugar, but also a convenient, compact language that allows you to express your thoughts with less code.

    Nikita : Yes, he is very high-level, and C is low-level.

    Alexey : I wonder if this freedom of language doesn’t interfere with working in large projects with a lot of people. Or in OpenSource, where you need to carefully track every change? As far as I heard, Clojure allows things to  change the syntax of the language . Does it not interfere?

    It reminds me of the situation with Scala, when the language can do a lot of things, and in every big project everyone is surrounded by some kind of rake. As a result, they come to some common practice that we use it, but not this. As a result, Scala in one project and Scala in another is two different Scala . Is there such a problem in Clojure?

    Nikita: I didn’t work in especially large projects. In those in which he worked, there were slight variations. In fact, for some reason, there is no such confusion. It seems to me that this is because in Scala, for example, there are lovers of theory and speculation about how to do something most correctly. As you said, there are a lot of things - you can choose the wrong thing. In Clojure, on the contrary, there is not enough of everything - you cannot choose the wrong thing. This is a very practical language. On Clojure they do not like to fence abstractions for the sake of something for the future. If you need, for example, to print something, then you simply print as practical as possible and you don’t worry about where the printer came from, what interface, protocol you implement. Do specifically what you need. Therefore, this practicality is probably the common denominator.

    Clojure Projects


    Roman : As far as I can see, you have several projects on Clojure on GitHub. Tell me more about them.

    Datascript


    Nikita : My first relatively successful OpenSource project is Datascript . This is client storage for the browser. For the site, this is probably not very useful, and if you write some interactive application in the browser, then you need to store somewhere in the state. Datascript is just a store for states. His chips:

    • It is immunable . That is, it does not destroy the previous versions, it simply creates a fairly new copy of storage.
    • He sorted . It automatically maintains indexes on attributes, on any entity_id, and so on. It allows you to quickly find everything you need. all you need
    • He is flat . If you haven't really thought about how to implement storage on the client, then the first thing you do is the structure of nested JSON. In Datascript storage is flat, at any time you can go to any place and find what you need.

    In general, this is a relatively convenient access to data, and two-way: you can go from parent to child, or you can also from child to parent.

    For the Clojure community, it has another advantage: it is made with the same API as Datomic. Datomic is a Clojure database. Since they have the same interface, then, if you know Datomic, —- you know Datascript. There are also requests, you can write requests to data in the Datalog language. I did not find this feature particularly useful for the interface, but there are people who find it useful in this. This is SQL-like, you can pile up conditions and get results from the client repository.

    Novel: Tell me, please, what Datascript is unique about. The task of storing state on the client in an interactive application is quite common. It seems that it should already be somewhere embedded either in the language itself, or in some kind of framework. However, you decided to make your decision. What prompted you?

    Nikita : I was wondering if I could make Datomic small means. It was an interest to replicate an already existing system. Then it turned out that this is actually a good idea, and it is very convenient to organize and access the state in this way. In the world of JavaScript, there are probably similar solutions. There is such a thing as Relay. She, as I recall, solves the problem and synchronize and store data. It is somewhat similar, but, in my opinion, later appeared.

    Rum


    Alexey : There is one more your library Rum . Tell me about her, please.

    Nikita : Rum is just a React wrapper for ClojureScript. React is cool, great, and everyone likes. I want to use it in ClojureScript b. It is a Java script, and I want to use it in Clojurescript. There were several solutions in the ClojureScript world, but they were all too conceptual. They offered their model, which inside used React. That is, not pure, but its own concept, which uses React.

    The idea of ​​Rum arose from the fact that with these previous binders it was impossible to use Datascript, but I wanted to use it. As a result, I came to a construction in which Rum is the most transparent and trivial binding to React. We offer the same things that are in React, just wrapped in a convenient interface for using ClojureScript. It does not hide anything, you can get to the native components of React. He is agnostic, as you wish, and organize the application and architecture.

    Roman : According to the stories of familiar layout designers, and in general, glancing in the direction of React and React Native, I see how wildly popular your project is gaining. You said it was a wrapper around React. But React is a huge project, and you managed to make Rum very small without learning tons of React sources. How did you manage it?

    Nikita : React is not such a huge project. All the essential things in React are in the Preact library, which takes only 3 KB. React has a rather small API, plus a bunch of hacks for new browsers, there’s no special point in learning hacks, they are all inside React.

    Roman : Is G6 a part of React or not?

    Nikita : Officially, no, this is a separate component.

    Roman : Did you port it or leave it aside?

    Nikita: No, I haven’t ported it, you don’t use it in ClojureScript. In ClojureScript, the code is data and all that, you don’t even need something like G6, you already have your own vector-based syntax that is accepted in the Clojure community. With the help of data, we present the same thing that in G6 is done by macro and source preprocessing.

    Roman : Great! Now I propose to switch to the next project. I was very surprised and delighted when I saw that you, Nikita, wrote the AnyBar project  - a menubar application that shows different indicators near the clock. It's amazing that my first project for MacOS was also a menubar application that showed notifications about new letters from Yandex.Mail. I looked at the source and went straight back 8 years ago.

    The project is very simple and popular. Surely, they use it for some applied tasks. Please tell me how the project appeared, how you use it yourself, or perhaps you know how someone uses it?

    Anybar


    Nikita : The project appeared quite by chance. You know, programmers like scripting something, so here. Clojure code does not need to be compiled, ClojureScript code is needed. Every time you change the source, it is recompiled. It takes some time: a cold start takes 30-40 seconds, for example, and an incremental build from one second to ten seconds. You changed the source, switched to the browser, and you still don’t know if you can already watch or still have to wait, because the source has not compiled. To know this, I came up with an indicator.

    They all mostly work on laptops, there is not much room for where to put it. You have to switch to the terminal and wait until everything is compiled in the terminal, and then switch to the browser. In order not to go to the terminal again, I made myself an indicator in menubar, which showed the build status: compiled, compiled, compiled with an error. If an error occurred, then you do not need to refresh the page a hundred times, it still does not apply.

    I did not do it in a particularly specific way, but I did it as universally as possible. To change the color of the indicator in AnyBar, you just need to send a UDP packet, this is the easiest way to cross-communicate. It turns out that this is a super flexible thing that is trivially scripted. I used mostly for build status only.

    Someone, for example, recently tweeted that he made an indicator of the status of empty seats in the embassy. So you can make an appointment immediately when there is free space. He was also displayed in AnyBar.

    Roman : Nikita, this thing only works on Localhost or can my virtual machine in Holland ping my laptop and something will show up in menubar?

    Nikita : If you can send a UDP packet from your virtual machine for a laptop, then yes.

    Alexey : Hearing about the cold build time of 30-40 seconds and then the hot reload for a second or two, of course, I can only envy from the Android world. But I have the following question: hasn’t all this business overgrown with a set of ready-made shell scripts, ready-made plug-ins, which you can not even write, but simply connect so that it all works right away?

    Nikita : Not overgrown, because I didn’t really do that. I'm even surprised that someone else is interested. There's a lot of everything: a lot of ideas, a bunch of clones even. People want to display text or several indicators and so on. I was going to do all this, but my hands did not reach.

    grumpy.website


    Alexey : Let's move on to your next project. Tell me what grumpy.website is.

    Nikita : grumpy.website  is such a blog about bad interface examples. We collect any shoals in computer and non-computer interfaces, discuss, complain about them.

    Alexey : How long has this site appeared?

    Nikita : About a year ago.

    Alexey : How many people there post something?

    Nikita : This is an author's project, we now have four authors. Mostly we post, but five more people periodically send their suggestions. This is a completely custom engine, written on Clojure live on my YouTube channel. It took on air 13-14 releases, full descriptions of which are in the Gist . If you are interested in how to create a Clojure web application from scratch, you can see.

    Roman : This course has already been completed or the project is still being finalized and you, as it is being finalized, are you posting records?

    Nikita: It's more like a video blog. It ended to the state in which grumpy.website  is now located - it is in real time. What is now on the site is in the blog.

    Design and usability


    Roman : You, like the person who raised the project about the nonsense of interface design, probably understand design and usability. How did you get into this area? How are you interested in this?

    Nikita : It happened quite early, at the beginning of a career. I was engaged in web projects, and it seemed to me that in order to do interfaces well, you need to understand what we are doing. There was a feeling that not everything was in order with computer interfaces.

    I read some famous books and it all sounded very reasonable. On the one hand, to create good interfaces you need to have an eye. On the other hand, common sense. To read grumpy.website , you do not need to be an expert on the interface, common sense is enough to understand that this is horror-horror.

    Roman : I remember that after reading the book "Design of familiar things" by Donald Norman, I really began to see more. But before that, I used these nonsense, these flaws and the look did not cling.

    Report on AppsConf


    Alexey : Nikita will speak at AppsConf with the report “ Gaining Skills ”. Nikita, tell me how this report appeared.

    Nikita: I looked at the report on the model of the drift. This is a model of acquiring skills, in which each person, learning a new area, goes through different stages: beginner, competent, specialist, expert, master. I went to read, figured out what these levels are, how different they are, I figured how it falls on programming and on everything I see around programming: courses, books, discussions on the Internet, device programming languages. That is precisely regarding different levels of the programmer or programming. It turned out that this is an interesting model that explains a lot of things. It has become much clearer and clearer that people often cannot come to a common opinion, because they are simply at different levels now and cannot hear each other.

    An example to not quite abstract: the dispute about whether the programmer needs to know the algorithms or not. Some say it is necessary, others do not. Why they can not agree. It has become much clearer, including how the career is arranged, how to move up the career ladder.

    Roman : Nikita, thank you very much for agreeing to come to us today, it was very nice to talk with you, learn and get answers to questions that personally interested me. For example, how to make or modify your font. It turns out that it is quite real.
    The most useful conference for mobile developers AppsConf in a month - October 8 and 9. We have already selected all the reports and now we conjure over the schedule. Subscribe here or in the  newsletter (there are only important materials: reports, transcripts and videos) to get the information before anyone else.

    Look at the  YouTube channel , where we diversified the video presentations with cool invitations from future speakers and the Program Committee.

    Also popular now: