182 points · by tosh · 9y ago · 246 comments
Parentheses? You don't even see them after a short while--as a beginner, you use something like parinfer, you are good to go. That, and like all lisps, you begin to appreciate programming directly in the abstract syntax tree: the language you type and the way it is interpreted aren't disjoint things.
Dynamic typing? Being functional, immutable by default, and data orientated steal the vast majority of the sting from that in my opinion--and leave you with often downplayed advantages. On the last point, "data oriented", to put it succinctly, data itself is first class or the prominent currency among Clojurists, rather than a zoo of abstractions that never quite fit and and all have to be reconciled and made to play with one another (and often the reason you need types everywhere to keep it all straight).
But where types--or validation--are more crucial near the boundaries of the API, there are outside the box solutions like Spec that don't rely on a baked in type system.
The recent keynote by Rich Hickey covers a lot of these points (and far better than me):
In nitty gritty terms, programming in Clojure actually feels a lot like programming in Haskell to me, without the heavy type system. Lazy infinite lists, all your FP classics like map, reduce, filter, etc. work exactly like you would expect. But I don't miss having to create a stack of monad transformers in an area of code where I need to mix IO and state or something...and using type synonyms to mask the monstrous Turing-complete type signatures I had to make to describe it... In Clojure, you just put the "dirty" work in its own function, clearly separated from the pure functions (which are the de facto default), and you push them to the boundaries of the system while passing extracted data into pure functions (just like Haskell). If you did anything different, you'd get the stink eye from even the least principled Clojurists. It's just not done. A ball and chain type system is unnecessary.
The lack of (explicit) types has been at the very most a minor nuisance. Occasionally I mistype something or miss a parameter, you're going to see the error pretty quickly in the REPL. If you run or test your code at all, the pedestrian type errors (oh, that was a string not an int) will be wrung out immediately. That benefit of type systems (preventing typos, essentially) has been much, much overstated IMO. Given you're going to be in the REPL a lot with Clojure, you'll be iteratatively developing and running your code constantly, so it's really not an issue. As far as refactoring, I think that's where there is more meaningful benefit. I use Intellij/Cursive IDE, and the refactoring capabilities are good--much like if it were a Java project (and there are hints and such for the typos I mentioned earlier, autocomplete, etc). So, while it is more of a challenge for IDEs, there are some excellent ones that do a pretty bang up job of inferring types for you.
I haven't used Clojure on the job (Java dev by day), but I would have no problem using it for something "real", whereas I never felt anywhere near confident in using Haskell for something outside my own fiddling.
I've programmed in dynamic languages for most of my career (about a decade now), and have always missed types. I picked up OCaml (Reason flavoured) recently, and I've been able to enjoy the Hindley-Milner typesystem without worrying about side-effects with complex types, since OCaml is a fine mix of imperative and functional programming.
Language preferences are usually framed as an objective measurement, but I've always found it to be based on our personal experiences. Since you've been doing a lot of Java, I'd surmise that the clean, functional yet dynamic nature of Clojure with Java interop is appealing to you. Me on the other hand has been burnt enough times with dynamic systems that keep shifting from under your foot (Ruby metaprogramming), test suites that makes refactoring more difficult (it provides safety, but the manual labour is unforgiving), and a general sense of dread everytime I put systems into production. But more than anything else, the biggest pain has been the sheer difficulty to refactor growing codebases.
Large dynamic systems, if they manage to not crumble from the inside, usually gets hammered by a sweeping change in external reality (terminology changes, shifting of levels in domain hierarchy etc.). When there is a pressure to ship we add a new mapping without touching existing naming, and slowly the domain names in the system exhibits a tangled relation with the actual domain.
That's just been my experience, and so I'm here learning me some good old OCaml and being very happy with what I'm getting out of it.
Then you can assert that `user` is a User, with type hints, preconditions, 'spec' (a Clojure library), tests, docstrings, or some ad-hoc convention ("this kind of namespace does this kind of data transformation").
Then again, some Clojure users might prefer to use plain hashmaps (Rich tends to encourage this; or at least that's the common interpretation from his talks), and none of the mentioned mechanisms.
The mechanisms are there. Up to each to use them or not, depending on your scenario (and sincerely on one's competence too)
Because these are not actual static types, you can get a lot of control and say things like "this function accepts three arguments, all integers between 5 and 50, but in increasing order, and the output must be a float between 0 and 1", and then have that checked on the function before the program ever runs. At run time, you can then verify that you are passing in valid arguments.
Spec is relatively new, and there are experiments in the community to do things more like traditional static type checking also. The future is an interesting place.
I think dynamic typing is a lot more problematic in imperative/OO languages. One problem is that the data is mutable, and you pass things around by reference. Even if you knew the shape of the data originally, there's no way to tell whether it's been changed elsewhere via side effects. The other problem is that OO encourages proliferation of types in your code. Keeping track of that quickly gets out of hand.
Clojure embraces immutability, and any changes to the data happen explicitly in a known context. This makes it much easier to know exactly what the shape of the data is at any one place in your application.
Meanwhile, all the data is structured using a set of common data structures. Any iterator function such as `map`, `filter`, or `reduce` can iterate any data structure, and it's completely agnostic regarding the concrete types. The code that cares about the types is passed in as a parameter. Pretty much any data transformations in Clojure are accomplished by chaining functions from the standard library together, with domain specific code bubbling up to a shallow layer at the top.
There's also the culture of using Spec and Schema in Clojure, so you often have assertions at the interface level. For example, there's ring-spec https://github.com/ring-clojure/ring-spec/blob/master/src/ri... providing the specification for Ring.
Well, javascript does not have some of the features that other dynamic programming languages have, that help you manage complexity and create successful projects of large size.
I also feel that Clojure's tooling is a lot nicer than most languages, and especially Haskell; Leiningen is very easy to use and Fireplace is a really simple and nice plugin for Vim.
I'm willing to bet that any dev who has learned Clojure does the same thing. If I'm right, that's a huge indictment of what we've been doing for the last 60 years in programming.
It's quite probable that this language changes from dev to dev, depending of habits, type of problems and skills with said language. However I suspect some languages are just better at it by nature as well.
It seems to me you're conflating "how to solve this problem" with "how to use a particular tool to implement a particular solution to a given problem."
Clojure growth is just fine. If average devs have to add something there is Java. In our experience maintenance of Clojure code is orders of magnitude better than average languages (Python, Java, etc). Yes, object orientation in large organizations leads to the most unimaginable mess. People mostly get paid for unproductive behaviour. Clojure is great for startups where you can do things right.
For decades, there have been rumors about the death of dynamic languages in general. And yet the decades pass and not only do those languages continue to flourish, but others come along and get popular too.
Clojure just turned 10 years old and I see no signs of it slowing down. They did consolidate their 2 major conferences in the States into just one annual conference, so there's that (which may not mean anything). But I am in a large city and companies keep appearing and starting up with Clojure as their key language.
With Clojure, it's an oddball because it is very simple and very powerful. Oftentimes, simple languages are not so powerful, and powerful languages are not so simple. But with Clojure, you can very easily get yourself into the situation of having extremely dense logic in just a few lines, where another language might easily take 10x (or more) lines to accomplish the same. This leads to code that can indeed be difficult to read later, especially if you are on a team and others must help maintain it. The Clojure community has come up with some excellent solutions to this problem, most recently the Clojure.spec library which is gaining wide adoption, which not only makes such "cleverness" easier to understand when reading it, but also makes a codebase automatically testable with property generators, which is a major feature. But your point about readability is always going to exist with a language like Clojure if it isn't written with a team in mind. That doesn't take away from its power though, in my opinion.
However, there is one particularly indispensable tool that Clojure offers that I have not seen anything to meaningfully compete with for productivity, and that's ClojureScript. Writing a front end with Reagent or even the alternative libraries is such a major win over everything else I've tried. I've worked a bit with Elm, Typescript, Reason, Bucklescript -- I am so spoiled by the extremely fast turnaround and easy interaction with very powerful features like React in Clojurescript that I don't see anything on the horizon that will come close to replacing that workflow for now. Perhaps some day something will come along to shine an even brighter light on how front ends can be developed, but for now, ClojureScript remains one of the most significant contributions to the software industry in many, many years.
Clojure never had much usage on real world projects. It cannot be extinguishes as it never took of.
I'm not sure what you mean by "never took off" but thousands of developers around the world, myself included, have made their living just writing Clojure code for many years. So, it has certainly taken off for them. And there are many, many companies using it all over the world. I live in a town of about half a million people, so not super big, and there are about 12 companies primarily operating on a Clojure codebase.
Who is making these decisions to rewrite?
It would be great if we can see a before and after comparison.
Clojure is a pretty simple language. Ive taught it to junior devs with only Java experience and they learn it within a few weeks without any major problems.
So every hire will be a cost to cross train through language as well as get used to the codebase. And a lot of more seasoned devs are very binary about lisps. I personally wouldn't work at a place that wanted me to do Clojure over Scala/Java/Kotlin.
I worked at a globally known media company that were primarily a Scala company and they had made a handful of applications from people with Scala experience a year at best. The churn of every skilled dev leaving being replaced by someone very green is a horrible opportunity cost even for a large business.
Even training devs isn't an issue. C#, Java, Python, PHP, C, JavaScript, and Ruby developers have had an easy time being productive on the first day because of how high level the language is. Projects tend to be very domain-driven, and a decent editor config let's people get started right away. Within a week of reading code and a tutorial on syntax, I have a perfectly reasonable dev on my team making meaningful contributions to maintenance and feature development. Locality, immutability, and brevity make for an exceptionally fast on boarding experience even when the dev had never used clojure or a lisp before.
(I remember my boss at one of my previous jobs literally saying to me "you know, we could let you write that in something more advanced, like Ruby or Python, but then when I'll be hiring, I'll have to pay 2x to a Ruby programmer than I have for a PHP programmer, so PHP it is".)
Leaving this comment so people who may read this and get scared off understand that it's definitely not the case.
My company has both a) hired a number of Clojure developers, and b) a number of developers who were good programmers, so switching to Clojure was not a problem.
In general, I noticed that you either hire average programmers (in which case Clojure/ClojureScript could be a problem), or good programmers. Good programmers have no problem with Clojure, regardless whether they know it or not.
Leaving this here because people might think the above comment is universally true. It isn't.
Meanwhile, Scala is a much more complex language, and training somebody on it will be a lot more challenging.
How big of a problem this is depends on the team and the company.
I've worked on plenty of medium (30+ dev) projects with <10% yearly turnover and for these teams learning Clojure is practically no cost.
I've also worked on teams with 70%+ yearly turnover and teaching anyone anything was a waste of time.
Media companies tend to be on the higher turnover side and I wouldn't recommend Scala or Clojure.
Anecdotal evidence incoming: For any rewrite it's always the developer. Every time. It might sometimes be the manager's decision to do it, but it's always instigated by a developer.
It's similar to training someone to use Vim in that it's quite a different tooling set and workflow they're probably used to. I think that's the main barrier.
The language itself is pleasantly simple. And tools like Paredit make it one of the most pleasant languages to write. It's just hard for someone to appreciate Clojure until they put in the work to credentialize in its tooling.
When you rewrite a project it's always going to be a lot better, because you have a much better understanding of the problem being solved having done that once already.
There are many ways to use Clojure, the laziest one of course being the least maintainable. No language can subsitute engineering principles, years of experience, empathy etc.
I wrote a few hints of what I consider maintainable here -> https://blog.vemv.net/maintainable-clojure-beyond-aesthetics...
This is probably true if your building a very very generic small webapp. In which case, maybe use rails if it's the stack your good at.
However, as the complexity of the system grows, the less will easily fit in mvc. When that happens, pushing all the complexity into mvc will make it harder to understand, not easier.
Why would an average dev not be able to maintain a clojure code base? I'm going to guess what you really mean is a average dev that doesn't know clojure. In which case the argument your really making is that its hard to find "clojure devs". Which I think runs contrary to the numbers which suggest many more people wanting to work in clojure then can find jobs. This piece seems to echo that sentiment: https://juxt.pro/blog/posts/clojure-job-market.html
I think by and large companies probably struggle to find clojure devs in there immediate area. Which is why i see all the clojure jobs either
A) remote B) in big cities
So its possible that companies could get great devs for less if they just allowed for remote.
Nothing backed up here by hard evidence, but worth considering that the language might not really be the only factor here.
I also agree that it's sometimes easier for novices to pick up the language. I've seen students become productive faster than people with a lot of background in imperative style.
Programming language flamewars (one of the hotter circles of hell) are off topic here, as are all flamewars.
Entities:Person, Insurance, Car
Relationships:
Insurance--hasHolder-->Person(m:1)
Insurance--insures-->Car(1:m)
Car--hasPrimaryDriver-->Person(1:1)
Person--drives-->Car(m:n).
Additional constraint: hasPrimaryDriver(C,P) => drives(P,C).
The domain has cyclic relationships, hence I cannot model it as a tree. If everything is immutable, I have to update all entities that reference each other when replacing one?! What's the standard clojure way to implement it?The answer is straight forward: you use unique identifiers instead of references. A lot of your code would become similar to how you write SQL queries. You always use `id` to cross-reference entities. You can use whatever enumerable functions are in the language - List.find, Map.find etc.
Now if you want to mutate a leaf node inside a tree, well that question is itself invalid. You can't "mutate" a "value". Can you say mutate the number 12? Or the letter 'B'? Imagine every complex data-structure was atomic like this: the array [1,2,3] always remain [1,2,3]. You can't mutate it because it is one single value; you can get information from inside it, but that doesn't mean you can go and change it. If you do want to change it, then you "transform" it into a new value. So instead of using `array.push` in Javascript, you'd use `array.concat` which provides a new value. Or even better you always use the rest operator `{...oldHash, someKey: newValue}`.
This also means your complex, large tree structure is a "value". You can't mutate it. You can however transform it into a new value. So if your leaf node has to change, then it means what you now have is an entirely new value. The old value still exist; any variables that pointed to the old value still point to that, because, duh, values don't change. Rich Hickey has articulated all this really well in his talk "The Value of Values" (https://github.com/matthiasn/talk-transcripts/blob/master/Hi...)
You'd now be rightly vary of the space-time implications of copying over large sets of data everytime you want it changed a tiny bit. This is solved in functional languages by using structural sharing. When you get a new tree value with just one node changed, the runtime would actually share most of the tree structure, and newly create just the one we want changed. It'll update the reference pointer of the root node, and the entire path that goes from the root till the leaf that changed. This means if you do a shallow comparison between the new tree value and the old tree value, you'll immediately know they're different. You can also safely assume that the entire path till the changed leaf has a new reference and you can do quick shallow comparisons.
This is however an optimization and implementation detail. We're able to do this because structural sharing still allows us to keep the semantic model of everything is value for all practical purposes yet have the benefits of immutability.
OCaml lets you do both though - it supports the imperative place-oriented way of programming and value-oriented programming. It encourages value-oriented programming through its syntax and runtime library, but when you need it (for performance reasons), it is there for you.
I do wish people would give clojure a real go, not just running a toy program, but taking the time to setup a REPL in clojure and clojurescript, learn about sending commands from the editor directly into the REPL, etc.
The reasons for choosing clojure are un-obvious at first glance. Moving from Java -> Ruby for example is something that you feel immediately. People understand in < 5 mins why ruby might be a better fit for a number of solutions then Java.
I don't dig clojure because it's a LISP, or it's homoiconic, or because of most of the academic ideas here in this thread. I picked clojure because with it, I get clojure and clojurescript.
With clojure I get to target all java libraries, great concurrency primitives, the ability to live code a running system, the ability to experiment extremely quickly due to the REPL based workflow, now with spec/generative testing, I get better testing then I had before, with writing fewer tests. I get systems are often easier to reason about or debug. There's rarely a ton of libraries to do a single thing. Existing libraries don't change much. We launched our first service in clojure 1.6, we've never had to do anything but bump the version number. No breakage.
With clojurescript we get just as many benefits. CLJS gives us access to all javascript libraries that have been written, Re-Frame/Om Next are incredible frameworks on top of react, figwheel allows us to never (rarely actually) have to refresh a page when doing layout / css things. Because we have access to a running REPL we can change the state of the app via function, allowing for way rigamarole when trying to test out inputs, etc. devcards lets you look at all the state of your widgets on the page + figwheel means you can see how CSS changes will affect all the states of your widget at once.
Synchronicity between the two languages allows us to write .cljc files where share functions and schemas can exist, so your backend and front end are pointing to the same place for critical things that should be shared.
It's really really different, but it's really really great. If you're a professional in the field, you owe it to yourself to just try it out and see if it helps you save time and be more productive.
I discovered clojure about 25 years into my programming career, and while it introduced new "annoying things", it resolved most of the annoying things I had dealt with over the past 25 years in most other languages.
Discussion from a couple of years ago (97 comments):
> In my experience, if you can't get something interesting working in a few days the likelihood of actually finishing the project starts rapidly approaching zero.
> With Clojure you can get things done fast, fast enough that you get something working while the initial spark of excitement is still present. I would hazard to guess that this is the reason why Clojure has so many great libraries despite being a young language.
Even with JVM based solutions, such as Stanford CoreNLP Python has more support/interest than Clojure.
I am not here to pump up Python and knock Clojure, just to illustrate there are areas that Clojure has a ton more wood to chop. And I do understand there have been significant efforts made in this arena lately. e.g. Neanderthal
There's a recent presentation that makes a good case for using Clojure over Python for ML https://www.youtube.com/watch?v=0m6wz2vClQI
There are also some lisps that target the Python VM, so you could consider using one of those.
If you are talking about ML, then basically every language has "wood to chop" when compared to python.
This argument I usually dismiss by suggesting moving to INTERCAL or Brainfuck. Even syntax matters a lot more than people care to admit. The best language is the one with which you can frictionlessly reason about and express a problem without impediment from syntax, paradigms, concepts and boilerplate. Computer languages just as much as natural ones are deeply tied to the way we think[0].
[0]: https://en.wikipedia.org/wiki/Linguistic_relativity#Programm...
Go down to the "From the Publisher" section and you'll see:
> "But the practical question is how well the language maps to the problem to be solved. Does the language let you think in terms of your problem domain, or do you have to keep translating domain concepts in the constructs of the language? The best case is when you can use the language without thinking about it."
One also can help creating job market by
- starting up
- introducing Clojure at work
- evangelizing it at local meetups (e.g. hijack a JS meetup, explaining cljs goodness)
I've been thinking about the latter, as a consultant creating a 'need' for your services would be quite an accomplishment.
Tip #1 - spend more time in the repl than in the editor. The repl lets you figure out and grok the small things.
Tip #2 - compose the small things into bigger things. (And if you find yourself composing too many semi-complex expressions into on big expression, feel free to take any smaller grouping of expressions and turn them into a function.
You may start out very disoriented; but if you keep trying, at some point after trying (perhaps for a few evenings, consistently) it will just suddenly click. It's a wonderful feeling to suddenly get it.
One last tip - Everything is really just this pattern: open paren, operator, some number of parameters/data, close paren. I'm not a Lisp teacher, so I may be stating this inaccurately, but it's just that simple. The pieces may look like more than what I just described, but they are really that simple.
And on the topic of "too many parens", compared to Javascript, C/C++, Java and many other languages, you'll find about the same number of them. They're just arranged differently (and more uniformly in Lisp). Better yet, because they're so uniform, you can completely ignore/forget about the end of big expressions with their )))). Ignore it. Use an editor that matches braces, (I like rainbow color matching).
And now, a warning. If you take the time to really learn Clojure, there's a good chance you'll love it. Then you will find that in most companies, you won't be able to use it unless you sneak it in. Then you'll end up in Elixir because it "looks like" Ruby, and because everyone bought into Rails. But you'll still wish you were using Clojure.
Exactly. Even more, if you start counting {}, <> and []...
Also, before someone says "but prefix notation!", all mainstream languages are prefix too everywhere except math. That is,
frob(barify(foo, bar))
is prefix notation, and equivalent Lisp is achieved by just shifting the opening paren to the left of the operator name (and dropping commas, thanks to the uniform syntax): (frob (barify foo bar))I feel your pain here and just wanted to let you know how common this is for programmers who initially try out Lisp for the first time. As others have alluded to, I promise this initial "parenthesis shock" goes away rather quickly as you read and write Lisp code. In my direct experience, I have hired junior developers straight out of a coding bootcamp who were able to pick up ClojureScript in their first week using Sublime Text with no editor extensions. In other words: you can definitely do this; it's not magic.
I would strongly encourage you to check out Parinfer [1]. Parinfer makes indentation "significant" so you never have to worry about "closing the parens". Basically, if you can handle Python or CoffeeScript indentation, you can handle Lisp. There are no hotkeys to learn and it is available in most common editors today.
For a first project I would recommend rewriting something you have already written and are familiar with. That way you can focus on just the language and not worry about the problem domain or "how to solve it". Just do a 1-to-1 port of something you've already done and compare how the two solutions are the same or different.
I'm sorry you are being downvoted and being told to "just use emacs" or "use the REPL more". IMO, these are not helpful suggestions for someone new to the language.
Good luck. You won't regret learning Clojure. One of the best things I have ever done for my career.
If you need the visual differences between those various kind of parentheses, many lisps and schemes allows to use and mix any of those.
If you are confused because the parentheses are not in the usual place, then I think you are trying to solve problems that are too trivial if such a tiny bit of syntax get all the attention. Or, that you are trying Lisp on problems that are not a good fit. Obviously, lisp (or ML, for that matter) shines at manipulating symbols, not bytes.
I do not personally believe that lisp is, in general, "the most powerful language", but there is a problem where it can be said that it is the most powerful language: it's to write a Lisp interpreter.
Maybe that's the good starting project you are looking for? If so, I can't recommend enough the book "lisp in small pieces".
This is true a lot of the time. Also, commas don't exist in Clojure.
So you might have this in a C-like language:
if ((foo > bar) && (bar > boo)) {
doSomething(a,b,c);
} else {
doSomethingElse(d,e,f);
}
And in Clojure: (if (> foo bar boo)
(doSomething a b c)
(doSomethingElse d e f))
Another interesting side effect is that in C-like lang, one my say that due to precedence rules, (foo > bar) does not need the parenthesis since && is lower precedence. Yet, if you weren't sure, you'd have to take a short break and go look that up to be certain. Most devs will just keep the parenthesis instead of take that little break, or they will write them in anyway for readability. In Lisp, precedence rules are never an issue because all operators and functions are applied the same way. So the parenthesis might seem cumbersome at first, but they quickly make syntax quite a lot simpler. if(foo > bar && bar > boo) doSomething(a, b, c)
else doSomethingElse(d, e, f)
> Yet, if you weren't sure, you'd have to take a short break and go look that up to be certain.If you don't know how logic works then why programming? Also, this is not a "complex rule", this is just BASIC LOGIC. As obvious as it can be: read it aloud and you have it.
Also, what would this even mean:
(> foo bar boo)
THIS is what we need to check out because it's everything but obvious.> So the parenthesis might seem cumbersome at first, but they quickly make syntax quite a lot simpler.
It won't, it'll just make the code monoton and harder to look at.
You never "use your mind" to keep track of parentheses in any language - you use the editor's features for this, and read code structure by indentation like any sane human being does (also, it helps that I touch mostly Python ;) ...but for other languages you just configure your editor to reformat you code on every save or on linting). Everyone can get over "parenthesis madness" after configuring their editor properly and a few days of habit. Also, once you learn about "paredit mode" editing, if you like it, parens become a superpower, because you're not "typing code" anymore, you're just using your editor's shortcuts to edit the abstract syntax tree as a tree object that it rightfully is, not an ugly bucket of "code text"...
If you're sincerely not trolling, then Lispers will be glad you don't join in and come and soil their codebases with miss-indented or unnecessarily over-nested because of bad structure code...
Clojure improves on this compared to other lisps because it uses brackets and squiggly braces instead of parenthesis for a lot of its syntax, making that aspect much easier to read.
Just stick with it, you will see it is a non-issue after you get started in earnest.
Break big functions with deep nesting into smaller functions. (Like in any language). If you have to page up and down several screenfuls to check whether multiple blocks are at the same indentation level and under the same parent, maybe the function is too big.
I'm linking it because it has a couple of screenshots, which I think works better than just reading a description of how it should look like.
There's a standard way to indent lisp (the emacs way, which everybody copies) and as long as it's indented properly you read it like a whitespace significant language (Python, F#, etc).
Clojure is a bit easier to read than other lisps because it uses [] for vectors, arguments, and assignment blocks and {} for maps and sets. Gives the code a bit more texture.
People writing lisp day to day use an editor feature to automatically keep parens balanced (Paredit, Parinfer). Not required since there's a learning curve but it makes editing smoother if you're going to write lisp full time. A text editor that highlights the opening paren when the cursor is on the closing one (pretty common feature) is all you really need.
So in addition to additional symbols for notating vectors, map, etc, it uses fewer parens in general.
try using Atom with Parinfer plugin. i vehemently disagree with people trying to push emacs on Clojure/LISP newcomers. having to learn a possibly completely alien editor to be effective programming LISP is another big thing that pushes people away.
Firstly, you have an editor that matches them up for you.
Secondly, you read via indentation and whitespace. And since just about the only thing defining the syntax of lisps is the list structure, the editor also parses and can take care of that relatively automatically too.
I found it took about 6-12 months of exposure, and then your brain just tweaks/snaps/breaks magically one day, they all disappear, and then you no longer see them :P
>The only difference in readability is that the Java version has a lot more parentheses.
Clojure has a rich set of functions for manipulating data such as map, filter, reduce, and so on. There are also libraries such as Specter https://github.com/nathanmarz/specter that allow you to declaratively transform complex data. I highly recommend watching this https://youtu.be/rh5J4vacG98 short video to see how it works.
(function x y z)
let a = 123, b = 456, c = 789;
# more code
vs: (let ((a 123)
(b 456)
(c 789))
; more code
)
In many cases outside of function calls, there are more parens. {
let a = 123, b = 456, c = 789;
# more code
}
Because Lisp let explicitly defines its scope, while the first example inherits the scope from whatever it is embedded in. (let [a 123
b 456
c 789]
...)
Clojure syntax was designed with a clear and deliberate attempt to remove many of the parenthesis from lisp syntax. This is just a part of the greater design goal of offering very concise and elegant syntax in general, which is one of the reasons I keep coming back to it.The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of programmers who can follow recursion naturally.
(loop exists in lisp but recursion seems to be the common idiom)
All examples of recursion I've ever seen in Lisp follow a similar structure...
* First section checks if recursion is finished. If so, return final result (or final element of full result if returning a list).
* Second section performs an action or two on the inputs.
* Third section calls the function again with revised inputs.
In many ways it's just a do while loop with different syntax.
I know C is not a good example, bit at least in C projects, I was always wary of "smart" developers inventing their own "smart" conventions and syntaxes
"What matters to me in a language is whether I can use it without thinking about it."