Can I use Clojure instead of Scheme when working through SICP?
Try Clojure – An interactive tutorial in the browser
81–90 of 96 posts
Re: Try Clojure – An interactive tutorial in the browser
#82Earlier quoted context omitted.
Like others said, Clojure does not reflect on every call. A good resource if you really want to push the perf limit http://clojure-goes-fast.com
Most data focused microservices for business applications devote most of their code to calling databases. The PoC microservices that I implemented in order to evaluate Clojure use Java libraries to communicate with Cassandra, MySql, Redis, and Elastic Search. Clojure is not currently at a point in adoption where it makes a lot of sense for these database vendors to support native Clojure libraries. While it is true t…
When you're doing things like I/O, an extra 0.04 milliseconds won't matter much, since the operation is already a lot slower then that. So hinting in those case generally isn't really needed, as it won't cause visible performance gains in your application.
Where hinting is worth it, is in tight loops where 0.04 ms will add up. Numeric code that uses arrays especially benefits, since the benefits of the array are lost to the reflection overhead otherwise.
Re: Try Clojure – An interactive tutorial in the browser
#83Earlier quoted context omitted.
I thought you were referring to https://insideclojure.org/2018/05/04/add-lib/ which is an experimental feature of tools.deps.alpha. But sure, there could be an (add-lib ...) function in this environment which loads some external code.
rereading the link I guess there are some implementation specifics that are JVM. I'm not really familiar with CLJS to say how those translate - but in principle is sounds like it could work on both platforms
For JS, it's a bit more complicated for the Clojure side, because the compiler isn't in the runtime, SCI is interpreting the Clojure code, it is not compiling it to JS and loading it, which makes adding a source pure Clojure lib tricky. But it could possibly be done for compiled Clojure libs and JS libs, that said I think you couldn't use any forms of advance compilation, because that messes up the references. So there's a lot of caveat I think to doing it in JS and that's why it's not done.
Re: Try Clojure – An interactive tutorial in the browser
#84How do people who write Clojure deal with lack of type checking? And auto-complete when it comes to Java library interop? I tried Clojure, to build a tool on top of a popular Java library that I was new to. And compared to other JVM languages it was not good because there was no type-checking or intellisense/autocomplete popups for the methods.
If you've worked in Python, Ruby or JS it's pretty similar.
What I do is I use variable names that make it more obvious what type things are. I also make use of destructuring and Clojure Spec to indicate what keys a map has or what values in a tuple are supposed to be.
Also the REPL can help you quickly explore the state and functions which you can use to try and inspect the types, that's useful when trying to understand someone else's code base which might not have had the most readable code.
And since you do REPL driven development, as I code I run the code constantly in the REPL which will throw type errors when I make one. It has the bonus of catching logical errors as well as helps me figure out how to implement what I want more quickly.
> And auto-complete when it comes to Java library interop
You should get some auto-complete here depending on your tooling. It should lost all possible methods of an object, just not constrained to the direct type. For me that's often enough as I know kinda what I'm looking for, so I can find it and auto-complete.
If you want the auto-complete to a specific type, you can type hint the object and then the auto-complete will list only methods of that type.
Finally, I do rely on the Javadoc a lot.
Re: Try Clojure – An interactive tutorial in the browser
#85How do people who write Clojure deal with lack of type checking? And auto-complete when it comes to Java library interop? I tried Clojure, to build a tool on top of a popular Java library that I was new to. And compared to other JVM languages it was not good because there was no type-checking or intellisense/autocomplete popups for the methods.
Runtime asserts, typically.
It ends up being somewhat less of an issue in practice than someone coming from Java or Kotlin would assume, I think, because clojure really only has a single datatype: a sprawling, immutable soup of nested maps and vectors. The design of the standard library is such that your standard data manipulation functions will basically always work on every data structure you get passed, so you end up designing your internal APIs so that they take in a blob of data, perform an operation if the soup has the right components (and probably throw an exception if not), and then spit out that changed blob of data.
Is this better (or at minimum no worse) than having a type system? That's a broader question of philosophy and taste that I'm still undecided myself (for instance, I think the type systems in Haskell and Rust are really quite valuable, but the ones in Java and Go don't really pull their weight), but it's not something I really miss on a day-to-day basis writing clojure code--it's just a different way of doing things.
> And auto-complete when it comes to Java library interop?
My experience as both a professional and hobbyist clojure user is that this is not a huge issue in practice:
- Java interop tends to get wrapped in clojure defns so you can get your auto-complete pop-up off the namespace alias.
- At least with my setup (emacs+cider), adding a (:import (...)) clause to a ns form allows me to autocomplete on all method names of classes in scope (and provides type-annotated signatures), so I can still auto-complete when performing interop. I believe IntelliJ+cursive is even better about that sort of thing, and if I were working directly with Java libraries/APIs a lot I would probably consider switching IDEs for that reason.
Re: Try Clojure – An interactive tutorial in the browser
#86Re: Try Clojure – An interactive tutorial in the browser
#87Re: Try Clojure – An interactive tutorial in the browser
#88Thanks for this! I just finished the tutorial and really enjoyed it! Found myself hoping for more. Maybe a small series that would teach one the necessary basics of Clojure so one could actually do a real project in it afterwards. That would be awesome :)
1. https://yogthos.net/ClojureDistilled.html 2. http://clojurekoans.com/
Re: Try Clojure – An interactive tutorial in the browser
#89Awesome job. I have also made another Clojure interactive tutorial which is more advanced, even showcases how to use React with ClojureScript. It is available in https://orgpad.com/s/clojure-tutorial and I have made a video about it in https://youtu.be/lJxvKNjRdu8 .
Re: Try Clojure – An interactive tutorial in the browser
#90For those interested in Clojure in general, the Clojurians Slack is an amazing resource. Great community, and extremely helpful to folks getting started. https://clojurians.slack.com/