12 ms·
A Little Clojure
- jp0d 7y agoFound this on the same blog --> http://blog.cleancoder.com/uncle-bob/2019/08/22/WhyClojure.html http://blog.cleancoder.com/uncle-bob/2019/08/22/WhyClojure.h... Thanks for this. :)
- john-shaffer 7y ago> (first 1 2 3) evaluates to 1, (second 1 2 3) evaluates to 2, and (last 1 2 3) evaluates to – you guessed it – 3. This is wrong, unfortunately. He probably meant (first '(1 2 3)), etc.
- dkersten 7y agoSince using lists are not so idiomatic, I suppose a better example would be (first [1 2 3])
- rb808 7y agoThere are a hardcore group of developers that love functional languages. Whenever I look it just looks pointlessly complicated. Maybe its because I'm not smart enough? Given that 99% of software is not written in these languages perhaps you have to have a special gene to figure this stuff out. Or maybe its just people trying to be different or trying out things on the fringe. I'm not sure what the answer is or if I should try harder.
- tmountain 7y agoNot sure what languages you are referring to with the 99% comment, but declarative programming is extremely well established, and it marries well with functional programming. See: SQL, Excel, regular expressions, HTML. Functional programming is a subset of declarative programming, and there are a wealth of useful applications.
- eberfreitas 7y ago> Whenever I look it just looks pointlessly complicated. Quite the opposite on my experience. The fact that something is familiar doesn't mean it is free of complications.
- Scarbutt 7y agoStudy SICP
- 0_gravitas 7y ago> Whenever I look it just looks pointlessly complicated. I would say the exact same thing about the imperative style, and I have lived in both the Imperative/OO world and the Declarative/FP world. > Given that 99% of software is not written in these languages citation/elaboration required, and not just because SQL and similar tools are declarative like another comment mentioned: a great majority of imperative languages have begun to include/adopt functional programming tools and ideas (map, reduce/fold, lambdas)... perhaps it's because they are extremely useful concepts.
- nickbauman 7y agoI find it the opposite. Lisp is much easier to write than, say Go. I think the problem is if you're used to the complexity of writing a Spring Boot app (Java) this simplicity of writing in Clojure will confuse you: you think it can't be that simple when in fact it is. I used to freak out when I'd find the library in Clojure I wanted to use but it had no documentation. Eventually I just started looking at the implementation and I'd see it's like the entire library is 35 lines of code! Or like 102 lines of code! You don't need documentation for something that small. I've never seen this before in other languages. If you think it's too complicated, you might just be overthinking it.
- eweise 7y agoWhy are you comparing a framework to a language? Can I not write a Spring Boot app in Clojure?
- regularfry 7y agoIn this case, I think it's meaningful. If you take https://github.com/scotthaleen/clojure-spring-cloud https://github.com/scotthaleen/clojure-spring-cloud as a reasonable example of what that would look like, it's (subjectively) ugly as sin. Because you're operating outside idiomatic clojure, there's a lot of incidental complexity and "why would you do it that way?" moments that you wouldn't get with any of the clojure-native, idiomatic web libraries. Yes, you could wrap a lot of it behind more idiomatic facades, but that's still added work you just don't want to have to do.
- eweise 7y agoTo be a fair comparison you either need to compare java to clojure or spring boot to whatever the comparable libraries would be in clojure.
- nickbauman 7y agoClojure doesn't really have frameworks, though. Every once in a while a framework-like-thing emerges but it quickly decomposes into a few libraries. The level of composition tends to be functions not objects, so there aren't any "taxonomy traps" associated with monolithic things in the OO world.
- heartofgold 7y agoI went thru a magnetic pole swap, if you will. I went from growing up as a kid toying in C , later professional development in c++ and java. In college, had a small taste of functional style and found it difficult for my brain to grok. Later in life I took up clojure, and things started to click. Despite years and years imperative development, my personal preference is for the functional style. I do find languages like Scala and Haskell slightly appealing, but I find many of the deep concepts and rigid type are orthogonal to the problem I am dealing with at hand. I realize for some working thru the type system helps them solve the problem at hand, but for me, it often seems to get in my way.
- crispinb 7y agoWhenever I look it just looks pointlessly complicated Well naturally if all you do is 'look'. Is that how you learnt whatever programming language or style you use now? You just glanced at some code and the necessary cognitive structures leapt with ease into your mind? perhaps you have to have a special gene to figure this stuff out Well I'm learning Clojure right now. It doesn't seem complicated to me (though it is unfamiliar enough that I have to think quite hard about how to do things, which strikes me as a good thing). And, for reference, I'd generally place myself in the lower 30% or so of developers in terms of natural ability. It sounds to me like you're just not very curious about what functional approaches have to offer. Which should be perfectly fine. But your comment sounds like a complaint.
- yakshaving_jgt 7y ago> Maybe its because I'm not smart enough? I doubt it. It's probably more because you haven't invested the time to actually sit and learn it.
- bcrosby95 7y agoIt took me a long time to get used to functional programming. For me a big problem was how dense the code can be. I was relying on the verbosity of imperative languages to act as a sort of whitespace. Another thing is pattern recognition when reading code. I had been using imperative languages for so long that I could mentally gloss over chunks based upon the shape of the code. But functional languages tend to have different shapes from imperative ones so it all looked unfamiliar to me and I got overwhelmed. Eventually I was able to get passed this stuff and functional languages make a lot more sense to me now. Now I prefer them despite working in Java for my day job.
- smabie 7y agoHere's a good start to functional programming: don't modify any variables. I'm sure you can get the hang of it. It's pretty simple.
- pjmlp 7y agoGiven that C++, Java, C#, VB.NET, JavaScript now have functional programming. features, and Smalltalk always had LINQ like capabilities, there is plenty of software written in functional like languages. And then there is the whole lot of Scala, Kotlin, Swift, TypeScript, before we even delve that Haskell and OCaml are used by Jane Street, Intel, Microsoft and Facebook, just to throw a couple of names around. Don't worry, you can use C and Go instead.
- ithrow 7y agoClojure is the most productive(and beautiful) language in existence(personal preference) as long as you don't have to leave its world. I stop using it because the lack of Clojure libraries pushed me to use Java libraries, and that was a life-sucking experience. Java is fine as language but you cannot say the same about the APIs of many of its libraries. I also started sensing that new open source libraries are not being created in Java which worsens the story for Clojure.
- reitzensteinm 7y agoThe other way you have to leave the Clojure ecosystem is when you have to communicate across the network or persist to disk. Writing everything fits in memory data analysis in Clojure is some of the cleanest and most fun programming I've ever done. But once you want to spread between multiple computers or operate on data larger than what comfortably fits in memory, you end up coding just like you would in C#. I started working on some versions of persistent data structures that serialize to a KV store, which lets you send a hash map to another machine, have save that machine add a key, then send it back. It seemed to work pretty well, but there's a ~10x performance penalty over Clojure's inbuilt data types (which are themselves not lighting the world on fire speed wise). That's a pretty harsh price to pay - you can use 100 machines to simulate single address space Clojure on a 10x machine. Awesome, but likely impractical. If you need the persistence between program runs or would like to run incremental computation on large data I could see it working well, though.
- reitzensteinm 7y agoSo this got 3 downvotes, and I don't care about the karma, but I'd be quite curious to hear about opposing experiences scaling up Clojure programs since there seems to be some disagreement. If you started to struggle with fitting everything in one node due to CPU or memory constraints, but still felt like you were writing Clojure in a half way idiomatic style when moving to a cluster, I'd love to hear from you.
- SaxonRobber 7y ago
- 0_gravitas 7y agoI'm certain most of us know who the author of this article, Robert "Uncle Bob" Martin, is, but for those that don't: Robert Martin is one of the original signers of the Agile Manifesto, which is the outline upon which a great deal of modern software development is founded, and helped set the tone for the Software Craftsmanship movement. Martin has a large amount of talks (that are, admittedly, all quite similar to one another) and blog posts (on the site linked) where he discusses his views as to where the industry should go/should continue to go, with a heavy emphasis on professionalism in programmers and programming teams.
- yakshaving_jgt 7y agoRight. He touts "professionalism" while also suggesting that one "needs big balls to write C++", because it is "a man's language".
- SaxonRobber 7y agoHe’s also rewritten the same book about 5 times and walked on water after a copy of sicp hit him on the head.
- mwkaufma 7y ago"... as a treat!"
- yakshaving_jgt 7y agoI don't see anything profound here, except perhaps that the language will gladly accept the user's blatant type error and just explode at runtime. For the most part this article is fetishising over basic syntax. Surely the compelling parts of Clojure go somewhat deeper than basic syntax. And if this is another tired discussion about legibility of syntax between languages, I have to wonder why people are still so fascinated by this? Between the following two representations of the same function… (defn f [x] (+ (* 3 x) 1)) …and… f x = 3 * x + 1 …I see very little difference in legibility. Sure, one is visually noisier (and incidentally, the noisier, less clean(!!!) notation is Robert C. Martin's favourite) but if you can afford to navel-gaze this much on syntax I'd question why you don't have anything more important to do. Of course I recognise that I must also not have much better to do since I read the article and I'm now commenting on it. It's just weird to me that one would fetishise syntax, and then describe a language sporting a less visually-noisy syntax as "The Dark Path". Edit: Apparently I need to state for the record that I spent a few years writing Clojure professionally. I'm not unfamiliar — I just haven't drowned in kool-aid.
- deleted 7y ago[deleted]
- Scarbutt 7y agoI wouldn't give much importance to his Clojure articles, they are all shallow and superficial. My only conclusion is that he writes them primarily for marketing purposes.
- tincholio 7y agoI'd extend this to all his writings.
- malisper 7y agoI've programmed Lisp code for several years and personally I do find Lisp code harder to read, especially when doing arithmetic. The direct benefit of Lisp syntax is that everything is consistent. Arithmetic operators have the same syntax as regular functions. Because all Lisp code has a consistent structure, that makes it easy to do some really neat things. For example, it isn't hard to write a program that takes Lisp code as input and processes it in some way. This is the reason why you see so many people write a toy Lisp interpreter. It's really easy to write code to evaluate Lisp code because all Lisp code has an identical structure. As a Lisp programmer, this benefit emerges in the form of macros. Macros run at compile time, take some Lisp code as input, and spit out new Lisp code as output. The new lisp code is then substituted for the old one.You can think of macros as a very small user-defined compiler. These let you build all sorts of language constructs that you couldn't build in other programming languages. For example, you can add pattern matching to a Lisp with macros. The macro would take a list of patterns and corresponding expressions as input and spit out some code that checks for the patterns and runs the corresponding expressions if the pattern matches.
- _bxg1 7y agoLittle a Clojure, as a treat
- hota_mazi 7y agoUncle Bob discovers Lisp, 50 years after its creation. Expect a follow up blog post telling us all software should be written in Lisp and he has a Lisp book coming out soon.
- deleted 7y ago[deleted]
- fulafel 7y agoThis guy has been writing about Clojure now and then for many years. More generally.. if we start shaming people who discover Lisp after its creation (1958) it's put in a rather unfair advantage!
- pixelperfect 7y agoHe has a presentation from 6-7 years ago called "Clojure Is New C" I never watched it because the title annoyed me too much
- benas 7y agoI have nothing against Clojure, but I agree with Donald Knuth who said: "Programs are meant to be read by humans and only incidentally for computers to execute." [1]. I could be wrong, but I don't find Clojure to be "simple" for humans to read (or write). Here is an example from the blog post: So let’s write a simple one. Let’s write the factorial function. (defn fac [x] (if (= x 1) 1 (* x (fac (dec x))))) Note the "simple one" here. I don't know for others, but this is not simple for me as a human to read, understand and reason about. For instance: if (= x 1) As a human, I read this like "if equals x one", which does not translate to my natural language where I would say "if x equals one". So I need an additional mental effort to do the translation. This is not the case in other languages where "if x equals one" would be written like "if x = 1" or "if (x == 1)". If the gap between the natural language and programming language is big, it is difficult for a human to use that programming language. And for Clojure, this gap is big IMO. (I (wanted) (to learn ((some)) Clojure in the past) but [quickly] ([(realized it was (not) for me)])) [2]. [1]: https://news.ycombinator.com/item?id=16430751 https://news.ycombinator.com/item?id=16430751 [2]: https://twitter.com/b_e_n_a_s/status/1244417191556063234?s=20 https://twitter.com/b_e_n_a_s/status/1244417191556063234?s=2...
- sooheon 7y agoFormatting helps for presentation, just as it does for human text. (defn fac [x] (if (= x 1) 1 (* x (fac (dec x))))) > (I (wanted) (to learn ((some)) Clojure in the past) but [quickly] ([(realized it was (not) for me)])) This is missing semantics for morphology. Delimiters aren't strewn about randomly, they precisely delineate the AST.
- sooheon 7y agoTotally not serious stab at actual semantic representation of your claim in clojure. (state-claim (but (past-tense (desire (learn me clojure))) (past-tense (realize me (not (good-fit? me clojure))))))
- benas 7y agoYes of course, that's incorrect and provocative in purpose. The point is not about the syntax, but about expressiveness: A programming language should make it easy for a human to express (write) his intentions in code and for other humans to interpret (read) those intensions in a natural way. In other words, the gap between the developer's natural language and his/her programming language should be minimal (and this is regardless of the developer's natural language, be it English or whatever).
- jmiskovic 7y agoMaybe this lisp syntax intro is a good place to ask veterans a related question. I find s-expressions quite beautiful and simplistic way to express both logic and data as a tree. On the other hand, top-level evaluation rules are often glossed over, and seem to mess up this elegance. I feel like there is a set of braces missing at top level, for s-expression concept to be complete. I don't really know enough about specific rules or reasoning why they need to be introduced. My mental model of top-level execution is an implicit `(do ...)` block. In rest of clojure code the `do` is a special form that is frowned upon because it is used only when side-effects are necessary. As it is, the 'module' concept is strictly tied to a file, which feels unnecessary. If top-level was enclosed in braces and evaluated with same rules as the rest of s-expressions, maybe we could move away from concept of files and, for example, store our code in a graph database. This would allow for IDEs that can collapse and expand code tree as needed. Rich Hickey uses expression 'place oriented programming' as derogatory term (PLOP) for relying on exact memory addresses as places for our data. It would seem to me that same term would apply to our coding practices - we tie code implementation to specific locations inside files on disk. This seems like accidental complexity that introduces mental burden. If location of implementation could be divorced from specific location inside specific source file, we could concentrate on implementation that is always in context where code is actually used. Is there any decent discussion of such concepts, or some other language that explores such direction? I'm lacking both terminology and in-depth knowledge of code evaluation to express this in more clear way.
- deckiedan 7y agohttp://lighttable.com/ http://lighttable.com/ might be interesting for you if you've not seen it before... It's looking at some of those concepts. (I've not used it personally, but heard good things)
- bgorman 7y agoDefinitely avoid lighttable. Unfortunately it is in a zombie like state with tons of open bugs, outdated dependencies and creators who abandoned the project. If you want a simple experience in an "electron" editor, I highly recommend VSCode + the Calva plugin.