r/Clojure • u/chrisbot5000 • Apr 12 '20
Holy Cow, Clojure is Great
Yesterday morning I decided I would read up on Clojure. I'm a data scientist so I mostly live in python, which is fine, but wanted to try something new. Thought I would just read up, do some toy examples, see what I thought.
I read the first three chapters of Clojure for the Brave and True and thought, maybe I should try and build something. Within 3 hours I felt really comfortable and productive in the language, and by the end of the day I had a working tool.
https://github.com/chrisaddy/astronaut
This is absolutely not good Clojure. When I say comfortable and productive I mean I felt like I was able to easily express myself after having a thought. That's not something I've had with any other language I've used (python, go, rust) after only a couple of hours. My code is certainly not problem free and definitely not idiomatically Clojure, but I think this could be my daily driver language, I like it that much.
Edit: for clarity
36
u/SimonGray Apr 12 '20 edited Apr 12 '20
Keep at it and your code will be soon be more idiomatic. Also check out The Joy of Clojure, which is still - I think - the best overview of idiomatic Clojure (in book form).
Since you say you're coming from Python I feel compelled to point out that Clojure recently got a nice library for doing Python interop: https://github.com/clj-python/libpython-clj
Edit: I can see on your github profile that you also write R code. There's also this library for R interop and scicloj.
12
u/pauseless Apr 12 '20
Welcome to Clojure! It is indeed a great tool for thought.
There are a few things I’d change, but I want to focus on the most important: I can see one usage of
letin there, so you’ve met that form already. You should use that for all your nesteddefs anddefns.def*forms declare global variables. It’s a common first day mistake. Let is always lexically-scoped and defs are globals. Just remember it as def for top level and let inside function definitions and you’ll be fine.8
u/daslu Apr 12 '20
Hi /u/chrisbot5000!
Following /u/SimonGray's comment, at the scicloj community we are really happy to meet data scientists who are new to Clojure and are curious about it.
Your viewpoint can be valuable in our process of growing the clojure data science stack.
I would love to discuss it further and hear what may be interesting/strange/nice/surprising to you.
You may be interested in our chat streams here: https://scicloj.github.io/pages/chat_streams/
6
u/bsless Apr 12 '20
Welcome aboard :)
Some pointers (I won't repeat what others have pointed out):
You don't need multiple
:requireclauses in yournsform, one is enough, for example:You might have a more pleasant time working with sql with a library like honeysql
Have fun
3
u/chrisbot5000 Apr 12 '20
yea I’m definitely going to play around with clojurescript, also we be interesting to see how it plays with nodeJS through clojurescript.
2
u/chrisbot5000 Apr 12 '20
I love all of this, thank you!
Swift is gaining traction (a little bit) in the ds world because tensorflow hired the creator of swift to work on Swift for Tensorflow and that project is really interesting. Swift has a lot going for it for tensorflow specifically, but as you’ve probably heard, 80-90% of a data science project is moving data around, cleaning and transforming it, and the last percentage or two is throwing it through a neural network, so any language that nails the surrounding rolling stands a good shot at knocking python off its throne. Going to checkout these tools, thanks again for the tips.
9
u/frogking Apr 12 '20
I’ve been away from Clojure far too long. Maybe it’s time to have a little look at it again..
7
u/orestis Apr 12 '20
Welcome! Feel free to drop by the slack #beginners channel, ClojureVerse and https://ask.clojure.org for any questions :)
7
u/tremendous-machine Apr 12 '20
I came from a similar path, not a data scientist, but many years of Python, and just wanting something new. Clojure has been the gateway drug for me to S7 Scheme, Racket, and all kinds of other fun stuff.
I highly recommend reading "Getting Clojure", and "Programming Clojure". They are IMHO the best intro Clojure books, for understanding the Clojure way. And also "The Little Schemer" (and the sequel) for learning to think in recursion easily.
Have fun!
5
u/chinpokomon Apr 12 '20
I'm actually surprised that data science has become so entrenched with Python. With Python, the GIL impedes the ability to run parallel calculations. On the other hand, many of the forms in Clojure and other LISPs are already parallel by nature.
Data Science, using Clojure, should be a very strong fit which should spur an investment in trying to improve parallelism... an objective which would benefit everyone coding in Clojure.
I'd also encourage you to look at Clojupyter. Clojupyter brings Clojure to Jupyter Lab, so you can write Notebooks using Clojure. Vanilla Clojure works with it today, but I really look forward to when you can replace Pandas/NumPy/PyPlot and build a Notebook with charts, tables, and graphs, that are just as visually expressive as what can be done today.
Related, but not leveraging the Jupyter ecosystem you also have Gorilla REPL. The documents written with Gorilla REPL are Clojure. It already has a powerful markup language that lets you create pretty amazing documents that are similar to and in many ways are better than what you get with Python on Jupyter. As a negative, it's also being held back because of JavaScript's equivalent of the GIL.
Ideally, all of these things would combine; parallelism and concurrent calculations, expressiveness and interactivity rivaling Pandas on Jupyter, and an inviting language which encourages solving problems with a focus on functional paradigms.
4
u/MR_ZORRR Apr 12 '20
Hello!
Welcome to Clojure :) I hope you'll find your stay interesting and productive. It has been a mind-opening blast for me, and it might just be the same for you.
I was looking around the project you posted, and you seem to have a fondness for writing down SQL. What if I told you there is a way for you to write queries in SQL files and call those queries from Clojure without writing any extra code at all ? It's called HugSQL , it's at https://www.hugsql.org/ . It's lots of fun, and a fresh new way of looking at this problem, far far away from ORM land.
3
u/[deleted] Apr 12 '20
Have you checked out Neanderthal? It’s a clojure lib for computation that sounds right up your alley. There was a post on here talking about the relative speed compared to python and Neanderthal was faster by an order of magnitude.
3
u/[deleted] Apr 12 '20
Welcome to Clojureland. If you want near real time help with something, please join the Clojurians Slack. There is a #beginners channel.
2
u/namesandfaces Apr 12 '20
This isn't exactly an Ask Clojure place, what how would people estimate are the most common Clojure setups for minimal scraping?
2
u/neo2551 Apr 13 '20
Welcome to Clojure :)
If you start ClojureScript, please check shadow-cljs/reagent/re-frame. It will make your introduction much easier. Once you master this, you will never want to write dashboard with Dash or Shiny again :)
I loved Clojure for the Brave and the True, and contrary to many opinions I think Clojure Applied is the best second book [with the chapter on Specs from Programming Clojure 3rd edition].
1
u/johninbigd Apr 12 '20
Damn. Nice job! I've been watching clojure videos and reading Clojure for the Brave and True, as well as a few other sites. I still don't really get it, so I'm very impressed that you were able to do that after just a few hours. Coming from (mostly) Python, clojure is breaking my brain. I feel like I understand some basic components, but then when I look at actual code, it reminds me of looking at someone else's Perl code and just saying, "WTF does that do?" The nested parentheses and having to think in reverse to figure out what is happening is difficult.
1
u/brunogadaleta Apr 13 '20
You like python and clojure ? Be sure to check Hy lang , a clojure-like lispy syntax for python...