Opinion: Why you should learn and use Clojure

    image

    Developers from the American company Gaslight wrote interesting material about why the organization, known for its love of Ruby and Ruby on Rails, decided to invest in the development of new technologies - for example, Clojure. We at Later develop billing for Hydra telecom operators and also work with this programming language, so we decided to highlight the main points of the Gaslight team as a separate material.

    So, why should you study Clojure and use it in real projects?

    Not only Ruby and RoR


    According to Jeff Lane, who wrote a post on the Gaslight blog, with Clojure, his team manages tasks that Ruby cannot handle. He illustrates this thesis with the words of one of the founders of Gaslight, Doug Alcorn:

    “I’m sure that you can’t hold onto one programming language forever. The time will come when Ruby will give way to a new language. Because the environment itself will change. I just hope that the one who takes this throne will be better and more merciful. "

    Lane says the company is still kind to Ruby. Here, Rails is still considered the best solution for writing web applications. But, like any tool, it has its own limitations:

    • Ruby is not the best choice for multi-threaded programming, despite the existence of JRuby and the presence of libraries like Celluloid.
    • Ruby and Rails are almost always fast enough. Almost, but not always.
    • Object Relational Mapping (ORM) may not be suitable for specific tasks.
    • Object-oriented languages ​​are, in principle, not always the best solution.

    Functional programming as an alternative


    Functional programming, in turn, is a completely different way of thinking. Let's look at Wikipedia :

    “Functional programming is a section of discrete mathematics and a programming paradigm in which the calculation process is interpreted as calculating the values ​​of functions in the mathematical understanding of the latter.”

    Functional languages, unlike object-oriented Ruby and JavaScript, offer a completely different approach to solving problems. Studying this approach allows you to acquire new knowledge that will be inaccessible if you are constantly in the comfortable conditions of already familiar programming languages, Lane is convinced.

    Clojure runs on a server.
    Let's take a description of how the language works from Clojure.org :

    “Clojure achieves its goals by clearly following industry standards and using the open JVM platform. This is an upgrade to the familiar Lisp. It provides functional programming with stable and stable data structures. Provides built-in support for multi-threaded programming using transactional memory software and asynchronous agents. Clojure is the fast and reliable solution to your needs. ”

    So, Clojure runs on the Java Virtual Machine (JVM), which means it has the undoubted advantages that this tool offers:

    • high quality garbage collector;
    • high performance embedded threads;
    • portability.

    Clojure can be used wherever modern efficient stable data structures are needed. He also introduces a new multi-threaded programming model with core.async. And then, now many other useful libraries have been developed for logical programming, pattern matching, option types, and much more, which would be useful to practice.

    Clojure works in the browser.
    Another quote. Here's how to describe the benefits of the ClojureScript Wiki :

    “A development platform with good portability, wide reach and multi-vendor support. Well-developed tools for creating better and more reliable applications, compatible with all new devices. ”

    ClojureScript is easy to compile in JavaScript and runs in a browser. All this provides a completely new approach to creating client applications. The JavaScript community has a lot of dislikes for many reasons. Clojure can be called a completely independent offspring of Lisp, a convenient, concise language with excellent asynchronous support, Lane writes. It can interact with other JavaScript libraries. This allows you to use the same language for the client and server parts, avoiding unnecessary sacrifices and wasting time.

    Ensuring the full preservation of current state (statefullness) in applications for clients is not an easy thing. And while JavaScript frameworks (for example, React or Ember) are only approaching this problem, it’s worth asking the question - is it possible to radically change the approach itself? Perhaps there is a language paired with one of these frameworks that can teach us how to better deal with such difficulties.

    Of course, there is no universal tool that would be suitable for solving all types of problems. However, the fact that Clojure can be used "on both sides of the barricades" of client-server interaction is its undoubted advantage.

    Anticipation game


    Lane also quotes the great hockey player Wayne Gretzky:

    “How do I do it? "I just always try to be where the puck is in the next instant, and not where she has already been."

    Clojure allows you to fill in some gaps in the process of creating specific types of applications. Those of them that need high speed processing of large amounts of information. The era of multi-core processors has long begun, but most traditional programming languages ​​are still not adapted to such an architecture, Lane is convinced. Functional programming can solve this problem when writing software. Clojure has all the necessary tools to enable programmers to work effectively with large amounts of data. In fact, you can streamline and transform data in real time.

    Without too much innovation


    In the world of technology, sometimes things are so advanced and new that the benefits of them are not obvious - at least sometime in the future and may be significant - but the application carries great risks. To designate such technologies, they came up with a special term - “bleeding edge”. Working with them is comfortable only for lovers of everything new.

    Clojure cannot be attributed to cutting edge technologies whose stability is in question. The language release took place more than 5 years ago, and the new tool received quite friendly reviews in the developer community. Therefore, it's time to get to know him better, without fear of exposing yourself to the risks of pioneers, says Lane.

    The foundation of Clojure is well-known technologies, for example, the same JVM, which has been working on for more than 15 years. Therefore, working with Clojure, you can use all the high-quality Java libraries that currently exist.

    Curiosity is the engine of progress


    Well, the very last argument for learning Clojure is curiosity and a desire to learn something new. There is always a desire to be at the forefront, to own and be able to handle the best technologies on the market. Clojure is perfect for these purposes. It is always interesting to set new goals. And finding solutions for them is incomparable pleasure.

    Now at Later, we use Clojure to execute equipment management teams. The specificity of the task lies in the requirements for simultaneity in the execution of commands and flexible restrictions. On the one hand, it is impossible to “fill up” one device with commands, on the other hand, to execute all commands is sequentially inefficient, because they can be executed simultaneously on different equipment. This task is easily solved by the core.async library, which adds support for go-blocks and channels familiar from the Go language, where interacting sequential processes (a term better known as CSP ) are implemented using them .

    At the same time, Clojure is a general-purpose language; finding it is not difficult to find. Since it is based on the JVM, there is already a huge selection of libraries for it, so when you use it, you don’t need to write everything again, which greatly reduces the entry threshold.

    Even if you don’t take Lisp to the spirit, you should familiarize yourself with the concepts that are embedded in the language, many of them make you take a fresh look at programming.

    Also popular now: