Elegant code and ever-evolving communities
FEB.03.2022

Clojure vs Python: Differences and Perspectives

Artem Barmin
Co-founder at Freshcode
Python became the third most popular technology by Stack Overflow Global Developers Survey 2021. Clojure was honored as the highest-paid and the most "joyful" programming language some years earlier.

Both languages enable programmers to build increasingly sophisticated systems. Both facilitate the creation of flexible software that's required for rapidly evolving domains. Finally, both Python and Clojure are blessed with a:

- powerful toolbox
- simplicity
- development speed
- concise and clear code
- a strong culture of sharing best practices
- ever-evolving community

What is common between Clojure and Python? What Lisp features did Python acquire in the context of Data Science? If Lisp is so great, why do we keep needing new approaches?

Today I want to share some thoughts regarding the topic.

CLOJURE PHENOMENON: "IS CLOJURE AN ACCEPTABLE LISP"?

Development speed, elegant syntax, Code-as-Data paradigm, access to large existing ecosystems (Java, JS, .NET)... It's all about Clojure. Let's talk a little about how all this was implemented and what preceded it.

Common Lisp and Scheme implementations were very large and complex and were handled by multiple teams. In turn, it took Rich Hickey about 2 years to create Clojure. How is this possible? What are the reasons? What problems have been solved?

  • There were no native (machine) code compilers within previous Lisp implementations
  • Porting a new platform (Linux->Windows, Windows->MacOS, Linux->Embedded) was extremely time-consuming
  • Clojure is hosted on the Java Virtual Machine which reduces a huge part of Lisp complexity. JVM enables:

- cross-platform portability

- system API support (it's completely different for Unix, Linux, and Windows)

- performance optimization (JIT compilation), a particularly difficult task because of requiring optimization for a specific machine/processor architecture besides the OS optimization

- organizing multiple libraries

Data Fabric 2022 Tech Trends
Rich Hickey, judging by his interviews, loves to think and more than act. I think this strong propensity to analyze, explore and systemize was a reason why he didn't follow the path of building a system from scratch. Instead of this, he preferred to combine a bundle of ready-made solutions and add a thin layer of appropriate wrapper for industrial programmers on top (Python went the same way).

So, in a sense, Clojure was designed as a sort of good glue between various ready-made components. But as with every Lisp-family programming language, it is also good for implementing some things from scratch.

DIALECTIC OF PYTHON'S PROS AND CONS

I'll consider Python through the prism of data science because Python for web and Python for DS are two huge differences in kinds of approaches, frameworks, and tools.

During the general push toward DS, Python was much more popular than Lisp. And it's interesting that Python for DS acquired Lisp's features, including interactive REPL-driven development. As an example 一 Google Colab, an interactive Python IDE that allows debugging a piece of code (step through it line by line) and visualizing the results.

Here are some of my findings on Python's pros and cons in terms of data science. Some points may be indicated both as Python's strengths and weaknesses.
    PYTHON PROS
    • its syntax is much more handy for mathematicians and physicists than S-expressions
    • mathematics libraries support (for the above-mentioned reason)
    • mainstream programming approaches
    • Python is a good programming language to learn first
    • Python is unaffected by the so-called Lisp Curse, where many devs create their own methods and solutions diverging from widely-accepted practices. Python programmers tend to use existing libraries
    • lack of fully supported metaprogramming (so there is less temptation to reinvent wheels)

      PYTHON CONS
      • Python has functional capabilities but it doesn't support the FP paradigm fully
      • metaprogramming is not a concept that is typically associated with Python (despite the fact that it provides some advanced features). Although there are good things about it, lack of fully supported metaprogramming can be considered as a disadvantage

        WHAT ARE THE SIMILARITIES BETWEEN PYTHON AND CLOJURE?

        Autonomic systems full trend
        • both are developed by BDFL (benevolent dictators for life). By the way, Python's inventor Guido van Rossum announced in 2018 that he'd be stepping down from the position of BDFL of the Python
        • language design is evolving slowly and predictably
        • relatively speaking, there is only one reference implementation and no competing standards (other implementations are suitable only for specific cases and, for the most part, are experimental)
        • well suited for interactive REPL-driven development (this lowers the learning curve)
        • dynamic typing 一 language is very practical for rapid prototyping & fast iteration
        • both languages actively use existing ecosystems (Clojure shares the JVM type system, while Python is based on C/C++)

        WRAPPING UP, OR SOME REASON FOR REFLECTION

        Although Сlojure is less popular than Python it's no less promising. Data science was an early selling point of Clojure. Already 10 years ago developers explored and used Clojure concepts, which are great for mathematical calculations. According to the Clojure Survey 2011 42% of interviewed persons were using Clojure for 'math and data analysis' that is a really stunning number as for the pre-'the hype around neural nets' times.

        Clojure offers intelligent solutions that are really well-suited for data analytics. Extreme development speed, metaprogramming, macros, DSL, map/filter/reduce – all those Clojure benefits are worth trying.

        But, the questions of convergence and tooling are still on the agenda.

        It's a good tendency. Conclusions 'hammered out on the anvil of discussion, dissent, and debate' lead to wise solutions, aged like fine wine, which in turn lead to improving the language ecosystem.
          How to keep with the times and provide a better total experience with Clojure and Python tools? Freshcode welcomes you to talk about it! Please, fill out the form on our website or contact our representative on Linkedin.
          What happens after you fill this form?
          Our representative will contact you within one business day
          We sign an NDA to keep your ideas confidential
          You share essential requirements with us
          Our analysts and developers estimate the budget and timeline
          Shall we discuss your idea?