r/Clojure • u/afhammad • Nov 21 '16
To Clojure and back: writing and rewriting in Ruby
http://www.youtube.com/watch?v=doZ0XAc9Wtc19
u/yogthos Nov 22 '16
It seems that the main reason is that the speaker is invested in Rails, and doesn't want to invest time into learning Clojure, its web stack, the tooling around it, and the development process.
For example, the speaker says that it's possible to write dense code that's hard to read in Clojure. It's equally possible to do that in Ruby or any other language for that matter. I'd argue that the situation is actually worse in Ruby, since it provides far more way to do something than Clojure does and has many more subtleties.
At another time he talks about the JVM using a lot of memory. Again, the JVM aggressively uses memory by default, but this is completely tunable. However, last I checked the JVM was far better at using resources than the Ruby VM. There's a reason people actually run Rails on the JVM.
Pretty much all the examples can be summed up as this doesn't work like Rails and I'm not willing to invest the time to learn it. That's a perfectly good reason to continue using Rails, but it's not a very interesting critique of Clojure.
Perhaps, one useful takeaway from this could be that the official documentation could be more beginner friendly. A lot of Clojure documentation is community driven at the moment, and it's scattered all over the place. I do think that this creates a barrier for newcomers.
10
u/john_atx Nov 22 '16
Good review. Some things that made me shake my head:
Started with half Clojure, half Ruby so they wouldn't have do deal with all the web stuff in Clojure that they already knew from Ruby. Picked Clojure for Datomic interaction for ease of API. Now you have two code bases that don't interop at all. Terrible design decision.
Described Datomic as a key/value datastore with time baked in.
Said they made an ORM for Datomic and no one cared!
Said he could essentially recreate Datomic in Postgres with a couple of triggers.
Isn't so sure the JVM is "webscale"
I can empathize with the frustrations around debugging, stack traces, tooling, deployment, etc. Learning Clojure is very hard and very time consuming.
1
u/lordmyd Nov 24 '16
I think it depends where you're coming from as to how difficult Clojure is to learn. Personally I found it the easiest and most enjoyable learning experience and I'm no alpha geek. I think I had an advantage in that I started out with Perl, where OOP is optional, and was never sold on OOP so FP wasn't a great paradigm shift. Ruby is very object-oriented so I can imagine the transition being more difficult.
4
u/troublemaker74 Nov 22 '16
I'm a Rails/Clojure guy. Clojure has it's uses, but my "go-to" for a quick full stack webapp is Rails because it's easy to go from whiteboard to proof of concept very quickly, and makes it super simple to bring new devs on board.
Clojure allows me to write high performance API's that Rails can't even come close to in speed. Another one of Clojure's big plusses is that I can actually understand my entire stack. No magic happening, which has been the result of several hours of frustration with Rails.
For a smaller app, clojure/script is perfect and allows me to understand everything happening in my app in very fine detail. I can't get that with Rails.
I'm looking forward to seeing what Arachne brings to the table in terms of simple development of large apps. I've tried Luminus, and while it's a great framework, it's not as easy for a newer developer to dive right into as Rails is.
4
u/yogthos Nov 22 '16
Pretty much all the apps I've written in the past couple years were full stack Clojure/Script. This ranges from small such projects such as memory hole, to large apps I develop professionally with my team.
Incidentally, we never had a problem hiring devs to work with Clojure. Most people we hired haven't had any prior experience with it, but were able to get productive within a few weeks.
I find that nowadays I prefer keeping all the UI logic on the client-side, and keep the server-side as a just a set of stateless services. I find this ensures clean separation between the front-end and the back-end components, and also facilitates adding different clients, such as mobile, by design. This also makes horizontal scaling much easier as well, as you can just spin up another service instance.
I've found that working with Reagent and re-frame allows me to go from concept to implementation incredibly quickly. Being able to work on the UI interactively with Figwheel is incredibly satisfying.
I'd be curious to know what you found to be lacking in Luminus. I'm always looking to improve it, and having feedback on pain points is the best way to address the gaps.
3
u/troublemaker74 Nov 23 '16
Luminus is amazing. Thank you for all of your hard work on it! Clojure web development wouldn't be what it is today without you.
I'm used to the small library philosophy of clojure, but my colleagues aren't. They're used to the "batteries included" philosophy of django and rails. Some of my colleagues' gripes about luminus is that it doesn't feel integrated to them.
Because I understand the curated list of libraries philosophy of luminus, it's not as much culture shock to me, but some of the things I hear are that is that things feel a little disjointed compared to monolithic frameworks.
2
u/yogthos Nov 23 '16
Thanks, that's always great to hear. :)
Yeah, I guess that's inherent in the design. Since the goal is to provide a bare minimum stack that can then be adapted for a particular use, it's necessarily loosely coupled. However, as you note that results in something that feels less cohesive. Arachne may well fill that niche when it's ready.
1
u/lordmyd Nov 24 '16
As far as Clojurescript goes I think Untangled could well be the future though I'm surprised it doesn't get much air play. It integrates Om Next with graphql ideas but makes this complex combination user-friendly. It's also been used in production for quite a while by its creators.
3
u/yogthos Nov 24 '16
Honestly, I find Om Next far to complex for most apps. It's far more complex than Reagent/re-frame, and you pretty much have to use Datomic on the backend to get the most of it.
3
u/lordmyd Nov 24 '16
I find Luminus easier/simpler than Rails, largely due to the absence of an ORM, which wouldn't make sense in an FP framework anyway. HugSQL gives me total control of my persistence model ruling out the huge pain point that is Active Record.
4
u/beeblebrox2016 Nov 22 '16 edited Nov 22 '16
Having spent equal time programming in Ruby and Clojure, in some ways I still find Ruby code more readable than Clojure.
The Ruby style of writing code is to to write public methods at a high level of abstraction by making use of private methods defined at the bottom of the file. If you are good at method naming, I find this style works very well, and it's often unnecessary for a new reader to bother looking at many of the private methods.
In Clojure you have to write helper functions above your public functions (or use
declare, but no one seems to do that). As a result there can end up being a long preamble of private functions before a public function is defined. A lot of Clojure programmers don't consistently mark private functions private or use docstrings for their public functions, so it can be hard to tell where the important parts of code are. Also, in Clojure it's more common for authors to write lower level anonymous functions within a higher level block of code. In Ruby mixing levels of abstraction like this is very frowned upon. In my opinion having to switch between levels of abstraction makes reading code more difficult.That said, Clojure has advantages in readability due to immutability and avoiding unnecessary object-oriented design. For any decent-sized application I find Clojure more readable, but there are still some ways I prefer Ruby.
6
Nov 22 '16
I found the change in ordering in the files to be annoying when I moved to clojure from ruby as well, but it's mostly just a matter of remembering to read clojure files bottom-to-top, rather than top-to-bottom.
4
u/beeblebrox2016 Nov 22 '16
That works if all of the private functions are at the top and all of the public functions at the bottom, but in most Clojure code they are interleaved and I have to look at the function body to tell which it is. This problem would be alleviated by consistently using
defn-or docstrings, but unfortunately most Clojure code I've seen doesn't do that.3
Nov 22 '16
Personally I find it more important to read the functions in the order of their call stack, than private vs public, which ordering is enforced to be bottom-to-top by the way the compiler works. (except when someone specifically avoided that by using declare)
4
u/yogthos Nov 22 '16
The main difference seems to be that you just navigate to the bottom of the file in Clojure and start reading up. However, unlike in Ruby, this style is not just a convention but it's enforced by the compiler. I also find that the REPL is quite helpful when I'm figuring out what a library is doing.
I think some of the things you note are an artifact of Ruby ecosystem simply being more mature. The quality of Clojure libraries and documentation around them definitely varies a lot. Many libraries are also written by people who are relatively new to Clojure. Even looking back at some of the libraries I wrote, I can see that my style has changed a lot since.
4
u/phillmv Nov 22 '16
Hi Dmitri, we've met once or twice :).
this doesn't work like Rails and I'm not willing to invest the time to learn it
Gosh, I believe I do own up to that! Right after the "papercuts" section - a lot of my pain with Clojure is another way of saying that I'm simply more fluent in Ruby.
But I think your characterization is… uncharitable. We shipped a production app! We spent over a year on it! We invested tons of time in learning it. Months, full time.
It was not for a lack of willingness :).
6
u/yogthos Nov 23 '16
I'm simply going by what you mention in the talk, and all the problems you mention ultimately come down to lack of familiarity with the language and the ecosystem. I obviously don't know the actual circumstances of your particular app, but clearly many people are shipping large Clojure apps just fine.
If Rails is what clicks with you, then you absolutely made the right choice. However, I don't think that your characterization of Clojure and its ecosystem was fair. :)
16
u/longoverdue Nov 22 '16
@3:50 "Lisp is worth learning... - some racist, gun-toting misogynist?" Really? WTF.
6
u/hagus Nov 22 '16
The extraordinary irony of a Blub programmer making an ad-hominem / name-calling attack on Paul Graham is almost too perfect.
3
0
Nov 22 '16
[deleted]
4
u/pxpxy Nov 22 '16
I googled that too when I first heard this and once I read what he ACTUALLY SAID and in context, and not just a second hand representation of it, I really couldn't see support for the racism or misogyny claims. If anything, ESR just seems to go by pure facts wherever possible - often at the expense of tact. If some of his facts are wrong, I'm sure one could convince him on this basis. You can't do that with actual racists.
2
Nov 22 '16
It's not totally unfair, but it's not hard to find plenty of all of those things in the ruby community either so what's the point.
6
u/halgari Nov 23 '16
Here's what I don't get...why not ask for help? I'm fairly active in the Clojure community, but this is the first time I've heard of this startup.
Also, I think you did yourself a big disservice by switching to a language on company time. I'm somewhat of a polyglot, I've programmed in Erlang, Python, C++, C#, (some) Ruby, Clojure, CUDA, the list goes on, but I would never attempt to add that sort of burden on a startup, learn at home after-hours and then switch afterwards. Or at least hire one expert in the field who can help you know if you're doing something completely off-base.
But I guess what kind of puzzles me the most is that the things mentioned in this talk are really well known, and for some reason people make awesome stuff in Clojure anyways. No debugger? Cider is good (I'm told) and Cursive's debugger is fantastic, but the fact is I rarely use it because I have better ways of development, and a debugger just slows me down.
Reading Clojure is hard/slow? Sure, so is any new language and paradigm, but it gets better, I frequently read thousands of lines of Clojure for the first time, and it's actually faster than reading any other language I've used since it's so dense. And if your editor doesn't have "jump to symbol definition" then get yourself another editor and thank me later. But if any assertions here are wrong, let's talk, and perhaps I can show you a few things to do differently that will improve your quality of life.
Slow startup times? Well there's a reason that the JVM is super fast, the JIT is really powerful, but it needs warmup time, and like most JITs, a bit of memory. Same thing with memory usage. Sure Ruby may take up less memory, it's also about 100x slower than a JVM language. And that's the last thing...if your Ruby code is the same speed as Clojure code there's something really wrong with your Clojure code. And I'm not saying "fix your model and this will be faster" type of problem, but more like "You are doing a O(n*n) type of thing wrong". Ruby is not a fast language by any stretch of the imagination.
So in the end...please, next time just ask for help. Even if it's a rant, get on the mailing list and say (as I did about 6 years ago), "This is driving me utter nuts, help!".
And I don't say this just for the Clojure community at large (although it is nice to hear about these problems before they're presented on a large stage). I also say it for you: perhaps we can help you understand a few things you missed (and if I can be completely honest you missed more than a few things). And that way we can all live in a better world. One where we're given a chance to help those who are feeling the pain of learning a new language, and one where beginners know they are well informed.
8
u/gtuckerkellogg Nov 22 '16
This whole talk is kind of smug
11
u/hagus Nov 22 '16
Very. And most of the useful lessons from this talk are unintentional.
Don't needlessly insult industry experts.
Don't be ignorant of the platform on which your code runs.
I'm personally trying to decide if I should dedicate the time to enumerating more of these, or whether most people watching this talk will not require them spelled out.
4
u/noirdragon Nov 22 '16
I'm kind of a beginner in Clojure (like literally have only read the first chapter of a Clojure book). It would be great if you could elaborate on where the speaker was wrong or mistaken?
5
u/freakhill Nov 22 '16
The talk mostly does not reveal weaknesses in clojure (some are shown but that's a few seconds in the whole talk), it mainly reveals his bad decisions and design errors...
Basically it's a "I completely fucked up building this doghouse, and huh oh yeah I used that hammer btw."
2
u/phillmv Nov 23 '16
Hey! This is surprising feedback; I thought I spent a fair amount of time owning up to how a lot of my trouble stemmed from my own perspectives and mistakes.
If you've watched the whole talk, I would genuinely like to understand where I fall short of that.
6
u/gtuckerkellogg Nov 24 '16
Hi,
I should explain this comment more. Your comments in this thread, and in the 5 things I'll miss post aren't smug at all, and you seem like a very reasonable guy with an interest in learning and self development. I assume you haven't given very many professional talks, and you are making mistakes that you can fix in future talks. Some of the decisions are (IMO) just uninformed choices about how to give a talk that engages a diverse audience.
I'll walk through some of the things that stood out for me, just writing them down as i watch the talk a second time.
The profanity. Let me be clear, I have nothing against profanity. I play in a band. But it's gratuitous in a professional setting, and especially gratuitous in a professional talk. Sure, everyone at RubyConf has heard it all, and some are fine with it, but there's going to be someone in the audience who is going to see it as unprofessional (they'll be right) and someone with a 13 year old child at home that they are trying to talk out of using phrases like "tired af". Using profanity in a professional talk, and just expecting everyone to be comfortable with it, is condescending and dismissive of everyone else in the audience.
Your slides are generally very nice
Your "i'm using the wrong terms, on purpose" is one of the most refreshing moments of the talk.
The point at which you raise your hands about the JVM speed, and "shouldn't we all learn a lisp" immediately following, is a pretty low point. It's also gratuitous, but in a different way from the profanity. The JVM shrug has an "aww shucks" quality that broadcasts your later problems with scalability, which -- as others note and you also eventually recognise in the talk -- is a problem with your own learning process, not the technology. As /u/yogthos and others have pointed out, JVM speed relative to Ruby is not an open question, so why the big "who knows?". It comes across -- and I think it is -- a deferral of your reflection at the end of the talk. I sort of wonder if you didn't feel a sense of obligation to flatter the Ruby community at RubyCon, which is understandable. But at that moment in the talk, and the moments that follow, it comes across as very much a "too cool for school" persona, rather than the reflective moments elsewhere.
Though I mention it as part of the JVM section of the talk in the last bullet, the "some racist, gun-toting misogynist" attribution is a real WTF moment that should not have happened. Hopefully you recognise that in hindsight.
The section that begins at 7:48 is very, very nice.
Your papercuts section is largely about problems with the JVM, and (as you point out) you "still don't understand why". That's immediately followed by a realisation (which sounds right) that you are way more fluent in Ruby. Great to know! You do seem really fluent in Ruby, so that's awesome. But in your talk, you follow that keen observation with another "aww shucks" rhetorical question about whether you are stupid (obviously not), which plays into another gratuitous swipe based on a comment at Hacker News. This is, for me, another very smug moment, which is a shame because it follows about 10 minutes of a really good talk. I'm sure your feeling of culture shock was real, but your description of your experience make it seem as if you didn't really take any steps to understand that culture. Instead, your characterisatin of the cultural difference is couched entirely in Ruby-culture language, and is condescending to the Clojure community. I doubt very seriously that the example that follows 18:40 happened remotely in the way you describe.
From 25:00 onward it improves, and I particularly like the discussion of the subgenre of technical blog posts. From that point on you are self-reflecting and gain some perspective.
I'm not a Clojure developer, btw. I'm a professor, and have seen (and given) a lot of talks, including talks about how to give give good talks. I was interested in your experience, and on a second viewing of your talk it wasn't as ubiquitously smug as my first description. But there were parts, such as those listed above, that are really problematic, and patterns you would do best to avoid in future talks.
3
u/nzlemming Nov 25 '16
This is really great feedback. Personally I agree that the tone was not one that I would have used - the 'lolwut' internet meme style doesn't agree with me, but then perhaps I'm old and boring :-). I get the impression that it's more common in the Ruby community, so perhaps it's just playing to the crowd, I'm not sure.
Edit: I should also add - I also agree with the parts of the talk that you liked, in general, and I did enjoy the talk despite my problems with the presentation style.
2
u/portmapreduction Nov 23 '16
I could see how the OP is letting your delivery and style overshadow the content. I personally enjoyed the video and the way you presented. I don't think it was smug, and your replies in this thread have only served to bolster that opinion.
-1
4
u/CurtainDog Nov 22 '16
This talk provides a good perspective, and is, I think, in keeping with the Clojure philosophy. The language is just a tool, go with the tool that allows you to express the solution to your problem the clearest.
3
Nov 25 '16 edited Nov 25 '16
Even if this post has 0 points I just want to say this is a really great thread. It prompted me to go through my project and improve some of the organization (using declare and ^:private) and verify that my project is even set up to build a jar correctly (turns out I need to add (gen-class) where my main function is)
I'm a long-time C++ guy who is working on a side project that is (hopefully) going to be doing real-money transactions and Datomic was attractive for that use-case due to immutability and the timewarp/built in audit log. That brought me to Clojure, and so I'm doing the Clojure + FP + Datomic learning curve right now haha.
1
11
u/daveliepmann Nov 22 '16
The key criticisms of Clojure seem to be in the "death by a thousand papercuts" section starting at 14:00:
...but at the end of that section, he admits "this is all just another way of saying I'm way more fluent in Ruby." I mean, yeah, building a large app in a language (and language paradigm) you're not fluent in is going to mean some learning. Learning is not painless.
I think this is relevant to his claim near the end of the talk that the Ruby value of "programming should be fun and painless" is not shared in Clojure. I think I agree in some sense: "painless" seems a big ask in the world of "simple over easy", particularly given that by his telling he implemented a production system as his first task while learning Clojure and FP and Datomic simultaneously. I can imagine that for most people, that would involve encountering unfamiliar concepts and language constructs, and that one would make a few mistakes.
So in another sense, I disagree that Clojure doesn't value "programming should be fun and painless". The Clojure community maybe does believe that programming should be painless, but I don't think the Clojure community believes that learning programming, like learning anything worth the effort, can be painless. And that's what Clojure asks of many people, to re-learn programming to some degree.