Is Clojure’s syntax really simpler than Scala’s? [closed]

Argument which is always made in favour of Clojure is that.

The syntax is simpler and there is only one way of expressing code with no complicated rules.

However Scala has loads of different types of syntax and constructs as compared to Clojure.

But from last one week while trying to learn Clojure, I have noticed that the list of inbuilt macros are endless, Even though we write them with the same parenthesis syntax we need to learn how each works.

So in what sense is Clojure’s syntax simpler ?
For LISPers it might be but for people from a different background learning different constructs in Scala seems simpler.

So from a neutral point of view, which syntax is simpler and readable?

1

So from a neutral point of view, which syntax is simpler and readable?

Those are two very different questions.

Simpler means “composed of fewer parts”. Clojure’s syntax has fewer rules, ergo it is objectively simpler than Scala’s.

Readability, however, is subjective. It mainly comes down to familiarity. For example, I find ECMAScript, C#, Java, D, Go, C++ and C to be nearly incomprehensible, but for someone who is used to reading that kind of syntax, they are fairly readable. This part of the question cannot be answered objectively or “from a neutral point of view”.

6

When I work in Scala, there is often a phase of my development (especially with for comprehensions) where I have to make all the types work out correctly which is a big plus for big projects, but a definite negative for small ones. I expected that I could just forget types and focus on “getting the job done” in Clojure the way I vaguely remember doing in Perl or Awk, but so far it hasn’t worked out that way for me. My experience is that instead of “making the types work out” in the code/compile phase, I am getting exceptions when I try to run my code. This is not a simplification; the problem hasn’t gone away, it’s just moved to a more dangerous/expensive part of the development cycle.

There is a delightful simplicity to Lisp-ish syntax. One of the big strengths of Emacs is being able to execute arbitrary lisp code by hitting a special key sequence at the closing paren of a block of code at any time in any buffer. The simple parenthesis-delimited nature of lisp syntax makes this elegant in a way that would be awkward (having to introduce curly braces?) in most other languages. Also, the regularity of (function arg, arg...) and (operator arg, arg...) makes thinking about functions and operators as first-class citizens and thinking about anonymous functions very natural, in a way that the infix operators of other languages like Scala do not.

My limited experience with Scala prevents me from saying that the syntax is simpler or more readable. Sure, there is some non-lispish syntax in Clojure using macros, but my perception is that these macros only open a little window into imperative thinking in a syntax that is otherwise very functional. Imposing a preference for functional or imperative syntax in the language can simplify things. I would have to give a point to Clojure, Java, and Haskell for this.

My concern with Scala is the same concern I had with C++ or Perl (though to a lesser degree); the syntax of the language accommodates several different thinking styles (Haskell and Java). This makes it fun to write, but could be problematic for readability. Even as I write that, I remember that Clojure supports Domain Specific Languages and wonder to what extent that undermines my point.

Your question is a very interesting one. Ultimately, the comparison is a complex one. But based on my current knowledge I would have to agree that the syntax of Clojure is simpler than Scala, but maybe not a whole order of magnitude simpler.

Even though we write them with the same parenthesis syntax

And that’s basically the answer to your question.

we need to learn how each works.

While it is possible to introduce DSLs with a not so lispy syntax like Common Lisps loop using regular macros (I’ll leave reader macros out of this), they are mostly used to control evaluation, and will still use regular s-expression syntax. One important feature is that even the more complex loop-like macros can be read using the same old sexpr reader.

While it’s true that you’ll have to learn about the different macros and the form of input they take, say Common Lisp’s cond with its more nested vs. Clojure’s cond reducing one layer of nesting, that doesn’t only hold for macros, but also for regular functions. Imagine a usual function taking a quoted list of a particular structure as an argument – you’ll still have to conform to the expected input structure, whether the function transforms code, expects some kind of alist, plist, a tree or something entirely different.

Whenever you encounter new functionality, there will be some API you’ll have to learn. That would also hold for a language that only allowed strictly function(arg1, arg2, …, argN) syntax – you’d still have to learn what the expected arguments are, what side effects occur, and what the output of any given function is.

What’s easier about Lisp syntax compared to a language like Scale, is that everything is represented more or less the same, and also that the code itself used these representations and data structures (that would be the homoiconicity everyone is talking about). This difference in syntactic complexity would become pretty clear if you tried to write a Lisp or Clojure parser and then a Scala parser. You’ll have to cope with a much more complicated grammar – more complex rules concerning precedence, whitespace, ambiguities, more exceptions, and so on.

From the wikipedia definition:

In computer science, the syntax of a programming language is the set
of rules that defines the combinations of symbols that are considered
to be correctly structured programs in that language

Since clojure is a lisp, you have s-expressions + the list of reader macros and that’s all.

In scala, you have classes, case classes, implicit lambda with _, implicit keyword, traits, generic annotations, variance annotations, etc

Clojure has a simpler syntax because features can be implement as macros or special forms. This is impossible with scala, in his you have to add syntax in order to support some features.

Macros aren’t syntax.

Arguing ecosystem or basic library complexity is a completely different discussion.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật