154 ms·
A Year in Clojure
- brian_herman 8y ago? I am not sure why Moving to X from X is so popular? Maybe someone would some more google fu or simply a way to query news.ycombinator could do a search for the string in the header... a = [C, C++, Closure, Python....] look below for a bigger list {Moving from <a> to <a>} and while you are querying {<a> is considered harmful} It seems like news.ycombinator is littered with posts like these. I don't want them to stop or anything it just would be interesting to see someone with like an sql database of news.ycombinator posts to see how many are posted in the last year or so and look at them all so I can binge read them because quite honestly they are the better posts on this site. Bigger list of A here https://gist.github.com/brianherman/64a2800ebd1907c6bba4f6eb69bc1c05 https://gist.github.com/brianherman/64a2800ebd1907c6bba4f6eb...
- vnorilo 8y agoI think well written posts in this category (I thought OP is an example) explain philosophical differences in an enlightening way, rather than evangelize or advocate that everyone else should also move.
- nerdponx 8y agoThis. I often wonder "Is it worth learning X? Will I enjoy it? Will I feel productive in it?" And reading these kinds of posts can be helpful in making that decision.
- CodeArtisan 8y agothere is such a list for Go here https://github.com/golang/go/wiki/FromXToGo https://github.com/golang/go/wiki/FromXToGo The best article of this kind that i have seen is by far http://roscidus.com/blog/blog/2014/06/06/python-to-ocaml-retrospective/ http://roscidus.com/blog/blog/2014/06/06/python-to-ocaml-ret...
- brian_herman 8y agoThanks man I’ll definitely look at this I’ll probably make a meta post but this is a good start
- brian_herman 8y agoI remember reading that article man.. it takes me back they say nostalgia is a drug
- platz 8y agoFromXToY posts are generally garbage - probably 1 out of 1000 are actually insightful and not simply cheerleading
- sdegutis 8y ago> "With function specs, I could assert the inputs and outputs to specific functions at runtime; not quite as reassuring as compile-time but better than nothing!" For 10 years I've seen many developers who have only really used statically typed languages like C++ and Java, now finding the "joy" of dynamically typed languages and all the "freedom" they give you, only to realize within a year or two that, wait a second, verifying those types at compile-time was actually pretty useful. I've also seen mass migrations away from languages like Ruby, Python and Clojure towards OCaml, Haskell, and F#, because people really enjoyed the functional programming aspects but wanted their static typing back. After writing the 10,000th unit test that only exists to ensure that you spelled some function/method/hash-key correctly, it gets a little tiresome. Personally I've settled on TypeScript, which has nice IDE integration in VS Code so that it validates your types live while you code, while still giving you the flexibility of a dynamically typed language (it's all still JS at the end of the day).
- juskrey 8y agoSpecs in Clojure are not static typing. Satisfying spec does not mean a value contains only items described in spec. It is an implementation of much larger messaging idea - message receiver only takes care about data it needs and nothing else.
- rafd 8y agoYou can use spec to verify that "a value only contains items described in the spec". The core library doesn't make it easy, but spell-spec [1] contains some useful helpers. [1] https://github.com/bhauman/spell-spec https://github.com/bhauman/spell-spec
- specialp 8y agoRich Hickey said himself "If a delivery truck comes to deliver a TV to you, do you care what else is on the truck? No, you are only interested in your TV" so the messaging idea is exactly right, and they weren't looking to implement strict static typing. In Clojure, Rich Hickey and others like Stuart Holloway speak of not "complecting" your code by passing around data structures other than uniquely namespaced maps where functions can take what they need and operate on it without having to mess with anything but data. so instead of data Person = Person String String Int Float String String you have :person/name .... By using simple data structures you can work on it much easier and even interoperate with other services and languages, while still checking to see if the data you are fed conforms to what you need.
- ilteris 8y agoI would love to read more about "code as data" in general. I would appreciate any resources you can provide. Thanks.
- vnorilo 8y agoHomoiconicity is the googlable term. The first Lisp book that blew my mind is SICP, nowadays free: https://sicp.me/sicp.pdf https://sicp.me/sicp.pdf I think you need a big picture to appreciate the depth of homoiconicism and meta-circularity. It's a big one, but well worth it IMO.
- kbp 8y agoI remember finding it pretty revelatory the first time I saw LET defined as a macro like (defmacro let (bindings &body body) `((lambda ,(mapcar #'first bindings) ,@body) ,@(mapcar #'second bindings))) Seeing it use MAPCAR like that just made something click for me for whatever reason.
- disconcision 8y agoTo add on, Racket in particular has some very slick syntax for writing these kinds of things: (define-syntax-rule (let ([id expr] ...) body ...) ((λ (id ...) body ...) expr ...))
- yomly 8y agoI definitely liked this about Racket but I did also find the elipses to be a bit magic to begin with...
- disconcision 8y agoAs with all things, the trick to chase the magic away is to implement them. I recently made a little term rewriting library using racket/match syntax but with the pattern/templates specifiable at runtime. Ellipses were a bit confusing to begin with but when you break list patterns down into cons pairs + a cons-like pattern binary combinator to represent ellipses, it started making sense. The unexpected thing for me was that I thought nested ellipses were going to be the tough part, but it turns out they actually just... work.
- usgroup 8y agoI got the Clojure bug at some point not long ago. Decided I’d write a crawler and some data munging stuff directly in Clojure since it’s all about data processing. Crawlers naturally want to be stacks with pipelines and expressing them as tail recursions over URLs curried into transducers, etc was easy enough conceptually, by difficult in reality because you want crawlers to be stateful. I think in clojure you end up hacking state by just attaching stuff to the outputs of your functions and building of more complicated objects down the line. I discovered that stuff which is cake in SQL or a language with data frame support is often typically hard in Clojure. Eg eg joining data , aggregation, etc. The few clojure libraries for this sort of thing are complicated to use because they have a mechanical sympathy with how clojure executes. Eg https://github.com/nathanmarz/specter/ https://github.com/nathanmarz/specter/ So I wrote some of my own libraries to get over this hurdle. I then realised that there isn’t a single decent statistics library that still maintained, and that the java bindings were far from simple to us. At that point I gave up on clojure for my use case. That’s not to say that there isn’t something for which it’s awesone. But in my opinion it isn’t data processing.
- ken 8y agoI think the Clojure answer to stateful data storage is "use Datomic". There's a big impedance mismatch between the functional world and the stateful (RDBMS) world. Datomic extends the functional world all the way down to data storage. You can certainly use SQL, and it's not any worse than any other language (and in some ways a little better), but IME it's not Clojure-simple, either. It's still the most awkward part of all my Clojure programs. Clojure excels when you can avoid mutating state, and I think that's why people especially love it for web apps. It fits almost perfectly into that model.
- digitaLandscape 8y agoSo clojure the language mainly exists as marketing for Datomic, the slow, expensive, proprietary, locked-in database solution? Eww.
- weavejester 8y agoCan you explain a little more why you think state is hard to manage in Clojure? I've done a fair amount of data processing in Clojure, and I'd consider it one of Clojure's strengths.
- jwr 8y agoAs to namespaced keywords, I was skeptical at first, and all my spec definitions used unqualified keywords. But as usual, if Rich does things a certain way, there are good reasons behind it, even if they don't immediately seem apparent. As my code base has grown, I found that namespaced keywords make a lot of sense, not just because of clojure.spec. They give you a convenient way of naming things uniquely, which lets you have data structures that combine several kinds of data without worrying about naming clashes. You don't notice their utility in code examples, or small projects, but in large projects they are very useful.
- iorekz 8y agoThe only issue I thought about would be when using json as I guess this would lose the namespace infos. Did you have issue with that ?
- lvh 8y agoSorta! Cheshire gives you a key-fn entry point. For small JSON objects you may just want the same namespace and then that is sufficient. Otherwise you can look up the right namespace in that fn or walk that tree (I’ve used specter for this) to correctly annotate.
- escherize 8y agoHere's some valid json that might be useful: {"signup/username": "John", "signup/password": "pg4pres"} Then, because you can pass in a function to get called on the keys, just check for a regex like (.+)/(.+) and turn it into a keyword. Here I'll write a function like that real quick using a repl with a nice ux: https://s3-us-east-2.amazonaws.com/photoblobs/Screen_Recording_2018-10-07_at_1.53.55_PM.mov https://s3-us-east-2.amazonaws.com/photoblobs/Screen_Recordi...
- jwr 8y agoI keep my data in a JSON database (RethinkDB). This is not a problem at all: namespaced keywords are converted to strings and the conversion is well-defined in both directions.
- 8y ago
- Jeaye 8y ago> I wondered why there’s a reduce in clojure.core but no fold? (It’s just a different arity of reduce that’s missing the initial state.) There is literally an arity of reduce which skips the initial state. Check out `(doc reduce)`. > No tuple type? Vectors are tuples. “What if one of the vectors is of a different length?” I gasped as I clutched my pearl monads. `s/tuple` is the answer to that question. > This ties into another concept that was new to me: applying a sequence of arguments to a function. You're not applying the sequence to the fn. This is "function application", so you're applying the fn to the sequence. In Clojure, you have some data, you apply a fn to it, then you have some transformed data. Rinse and repeat. Also, check out `(doc apply)`. > I’ve read/heard the Clojure designers encourage the use of namespaced keywords, but I rarely encounter them outside clojure.spec definitions. As other people have done in the comments here, I make a case for namespace keywords here [1]. > I can’t talk about data in Clojure without talking about clojure.spec! Please be sure to check out Clojure spec's instrumentation, along with Orchestra [2] to further improve the experience. My team uses `defn-spec` for basically every fn in both our front-end and back-end code; all of the data is spec'd, with shared specs between front-end and back-end, and we get full instrumentation during development and testing. Thanks to macros, that can disappear completely in production. 1: https://blog.jeaye.com/2017/10/31/clojure-keywords/ https://blog.jeaye.com/2017/10/31/clojure-keywords/ 2: https://github.com/jeaye/orchestra https://github.com/jeaye/orchestra
- lsh 8y agoOrchestra cannot be overstated. You'll quickly find the holes in clojure.spec, have a wtf? moment, feel intense disappointment then discover Orchestra and never look back.
- ataturk 8y agoI liked Clojure in 2014/2015 but like Scala and Groovy, interest has fallen way off. Seems like the JVM language wars are over. I still think everyone should learn LISP. I just don't think Clojure was that awesome. Java 8 isn't awesome, but it was good enough to kill Scala and Groovy.
- mping 8y ago
- jhabdas 8y agoTitle sounds like you need to get out more.
- temporallobe 8y agoI’ve been about 6 months in Clojure, and I am finally starting to like it. Coming from decidedly non-Lisp languages, it’s been a struggle. For example, immutability is possible, but not natural to most other languages; for Clojure, it’s instrinsic. I also often scratch my head at the way things ate scoped and tbe whole concept of purely functional programming. Clojure is very powerful and terse, but what I dislike the most, just like with Ruby, is the culture that the code should be self-documenting and self-explanatory. In all the code I have been maintaining this whole time, comments are rare, whereas in Java, C/C++, JS, etc., comments are plentiful and encouraged. I feel like with Clojure, I am expected to understand the code just by reading it. What gives?
- yason 8y agoConsider comment inflation. Comments should only be needed when things are especially complex and if they are everywhere their average value goes down. Most codebases of good quality that I've seen have not had particularly detailed comments--except where you really need them. The mere existence of a comment already hints that the code that follows needs to be carefully understood before you can touch it! There might be boilerplate comments before each function to describe the function and explain the parameters but other than that comments are only reserved for the tricky interactions. But in many cases also this information can be embedded in the name of the function and its parameters! Good code reads well because it's built on top of lower level blocks that are simple and well-defined. And those are simple and well-defined probably because they are also built on top of even simpler things. This removes the need for a lot of mundane comments. I don't think Clojure is more exceptional with regard to this than other languages. But I think a higher percentage of Clojure code is of good quality, and that probably is because Clojure attracts good programmers who care about these things.
- yogthos 8y agoI don't really find that the community is against documenting code, and majority of popular libraries have doc strings for the public functions at least. In general, I do find that reading through decently written Clojure code tends to be easier than languages like Java or Js. The code tends to be a lot more declarative, there are a lot less syntax quirks, and functions are typically kept short. Meanwhile, majority of the code is written using pure functions, so you can figure out what they do without needing a lot of context about the rest of the program. I also tend to just run things in the REPL any time I'm not sure what a piece of code might be doing. So, while I'm definitely a proponent of having good documentation, I find that I have a much easier time reading through Clojure code than most languages I've used.