
Rust for Clojurists - lsh
https://gist.github.com/oakes/4af1023b6c5162c6f8f0
======
hacker_9
Good article. He missed out the main pro though (and literally the only reason
I ever use any Lisp): hot swapping. The ability to change code on the fly as
the program is running. For this to actually work you need 2 things:

1\. No explicit types: Everything in Clojure is just a list or hash map, so I
can add extra members to anything at runtime no problem. The amount of static
checks Rust does at compile time makes this non viable.

2\. Fully immutable data structures: If my changes cause exceptions, then the
program can just rewind and throw away the new state it was building, let me
fix the error I made, and then continue on as if I never committed the broken
code. In Rust an exception would mean I've potentially mutated state in a
bunch of places, and now can't get back to the previous working state at all.

~~~
nonsince
You don't need dynamic types to allow hot reloading, as long as a function has
the same absolute path and type signature it can be done. I'm pretty sure
miri[0] plus some compiler hooks would allow this, although it would need to
reach nearly speed-parity with debug code if not release code. Hot reloading
and/or repl-driven development is my number one programming desire right now,
and Rust is my most-used language, so this would be life-changing for me.

Also, Scheme and CL allow free reign on data mutation and RDD/HS work
fantastically in them

[0]: [https://github.com/solson/miri](https://github.com/solson/miri)

~~~
hacker_9
I didn't say it wasn't possible, but I've found that hot-swapping in languages
that use mutable data structures, and have heavy type systems, makes for a
poor experience. If I can constantly cripple the runtime with hot-swapping, or
I can't change any type definitions, then there is little point to it.

~~~
yomly
Typed/racket supports hot swapping to a similar degree as clojure

------
charlieflowers
+1 for this gem right here. Well done!

"Many people try to compare Rust to Go, but this is flawed. Go is an ancient
board game that emphasizes strategy. Rust is more appropriately compared to
Chess, a board game focused on low-level tactics. Clojure, with its high-level
purview, is a better analogy to the enduring game of stones."

~~~
actuallyalys
Yeah, the wry humor throughout is great. Another good bit: "While the Rust
project doesn't start off with any equivalent to Clojure's namespace
declaration, once you move beyond a single source file you'll need to use it.
This isn't C or C++, where you just include files like a caveman. Rust
separates code into modules, and each source file is automatically given one
based on the file name."

------
1_player
> Rust chose to call its [package] format "crates". This reflects the
> language's industrial roots and the humble, blue collar town of its sponsor:
> Mountain View, California.

Nice :)

~~~
kibwen
The terminology there was actually inspired by the fact that Grayson Hoare
would walk to work along the docks in Vancouver, passing the shipping crates
as he went.

~~~
kibwen
s/Grayson/Graydon. I blame autocorrect. :P

------
delegate
Some funny gems:

> You will remain a replaceable silhouette with no discernible identity.

> This isn't C or C++, where you just include files like a caveman.

>The upside is, you will curse it at compile-time instead of at runtime. The
downside is, "exploratory programming" means exploring how to convince the
compiler to let you try an idea.

After that it gets a bit more serious, but still a very good Saturday
afternoon read.

------
zcdziura
> You're in an industry reaping disproportionate benefit from loose money
> policies, leading to a trend-chasing culture of overpaid nerds making web
> apps. You feel guilty about this, but there is nothing you can do about it
> because you have no other talents that a rational person would pay you for.

/r/2meirl4meirl

But in all seriousness, this was a great article and an exceptionally fun
read!

------
StreamBright
Nice. My biggest problem with Rust is the poor performance and lack of
complete & sane libraries, especially for HTTP.

I was running into serious issues with the following code:

[https://gist.github.com/l1x/5678c0fdfc2c1a6034b8bcc3800de93c](https://gist.github.com/l1x/5678c0fdfc2c1a6034b8bcc3800de93c)

Its performance is saturated around 60K req/s on a 32 core box with 10G
networking while wrk was more than happy to do 3M req/s. I was trying to dig
further into why it is slow and it seems that hyper is the culprit. However, I
was not able to come by this issue and just used wrk2 for testing. Let me know
if anybody has insight into how to go beyond this perfroamance or what are the
issues with my code.

~~~
kaoD
I'm not sure about performance vs wrk (don't kwow wrk), but just to give an
idea: I noticed you're not using Tokio Hyper. Try Hyper's master branch, which
fully embraces Tokio's async.

EDIT: From wrk's README:

> wrk is a modern HTTP benchmarking tool capable of generating significant
> load when run on a single multi-core CPU. It combines a multithreaded design
> with scalable event notification systems such as epoll and kqueue.

Your example is multithreaded but IIRC release Hyper isn't using event
notification async, which Tokio Hyper does. It might help.

~~~
StreamBright
Thanks, I will look into this.

------
edem
They are called __clojurians__.

------
coldtea
While I understand this kind of guide (showing how things are done in one
language/ecosystem vs another), is there such a thing as a Clojurist that
would have benefited from it?

I'm not asking whether there are Clojurists. Of course there are.

I'm asking whether there are people that primarily and only know Clojure, and
thus would benefit from a translation guide between Clojure and Rust, instead
of say between C or Java or Python or Ruby etc and Rust.

I'd think that anybody who uses Clojure was already familiar and/or proficient
in some other language before, much more major than Clojure.

~~~
AlexCoventry
I think it's satire?

~~~
coldtea
No, it's written in a funny way, but it's a legit guide.

------
akhilcacharya
Not even a clojurist, but this is the best Rust intro I've seen so far.

