Fork me on GitHub
#other-languages
<
2022-04-21
>
Cora (she/her)23:04:38

immutable persistent data in js

Cora (she/her)23:04:58

structural sharing and everything

dgb2323:04:15

It’s a very clever library, but to me personally it feels incredibly clunky in comparison to a more expression based style. Also the performance improvements over just writing vanilla functional JS are flaky at best.

Cora (she/her)23:04:27

I don't think performance improvements are a goal?

Cora (she/her)23:04:38

I'd expect it to be slower, even

dgb2323:04:59

slower than copy on write with object/array spreading?

dgb2323:04:09

would expect it to be faster

Cora (she/her)23:04:05

I'm comparing it to plain mutation

dgb2323:04:24

but my bigger problem is it feels clunky to me and it breaks my flow and both reading and writing. when I see imperative code I expect it to be imperative

dgb2323:04:48

> I’m comparing it to plain mutation ah that’s for sure

Cora (she/her)23:04:52

I do wish there were things like assoc-in and friends

Cora (she/her)23:04:33

but as a selling point for integrating into current code that relies on mutation this setup is probably nice

dgb2323:04:37

ah yes, spreading is also not nearly as ergonomic as that

Cora (she/her)23:04:10

and also modifying deep structures in clojure suuuuuucks where something like this would probably do a lot better job

Cora (she/her)23:04:51

it's all trade-offs. this seems like a step in a good direction for comprehensible apps, to me

dgb2323:04:42

you still write out the whole path and have to query with loops etc with this

Cora (she/her)23:04:51

sure, but you can operate on things directly. for clojure you have to chain update-ins

dgb2323:04:15

in some cases normalizing is the way to go

Cora (she/her)23:04:16

I love clojure but this is definitely one of the weaker parts

seancorfield23:04:24

We've been using https://immutable-js.com/ at work for a while. I wonder how this compares?

Cora (she/her)23:04:06

I'll bet there's some similarity

dgb2323:04:13

this is “just” JS syntax and you don’t need to translate between normal objects/arrays

dgb2323:04:02

immutable is faster and IMO more ergonomic if you stay in immutable world. immer can be used more in an ad-hoc fashion

seancorfield23:04:37

Ah, good to know. Our front end team is big on immutability.

dgb2323:04:12

but I tend to use neither now and just use the spreading operator all over the place. looks kind of ugly but it’s one less dependency and “weirdness”

Cora (she/her)23:04:42

we just use good ol discipline to keep from mutation

Cora (she/her)23:04:08

occasionally i get bit. like when I forget that sort mutates

😭 1
dgb2323:04:10

and when there is mutation it is meant as such

dgb2323:04:17

i hate that 😄

Cora (she/her)23:04:30

it takes a lot of discipline for sure

Cora (she/her)23:04:38

you get used to it

Cora (she/her)23:04:54

but I'm sure sisyphus said the same

seancorfield23:04:56

I'm fairly certain my life is happier for not having JS in it...

dgb2323:04:58

did you know you can sort nodelists and the dom updates accordingly? it’s kind of wierd

👀 1
Cora (she/her)23:04:35

neat! (and terrible)

Cora (she/her)23:04:01

that's the whole js story I think

seancorfield23:04:55

My partner has a T shirt that says "That's a terrible idea! What time?"

😄 3
Cora (she/her)23:04:47

I like using a variety of languages and platforms and tooling and such. so many things I want to learn even after 15 years as a pro

dgb2323:04:51

I think that’s great! This is such a fun profession 🙂

1
Cora (she/her)23:04:06

some day i'll have my own programming language, i'm sure of it

Cora (she/her)23:04:50

it'll be terrible and full of hacks and dubious features and I'll love it

dgb2323:04:57

make a lisp!

dgb2323:04:17

there’s not enough of those

😅 1
Cora (she/her)23:04:05

I mean that was the idea

Cora (she/her)23:04:13

another hosted language, probably

Cora (she/her)23:04:20

maybe something akin to hy

dgb2323:04:10

WASM is a cool target, it’s pretty small and easy to learn

Cora (she/her)23:04:33

and it's already all sexps!

dgb2323:04:36

you’ll have to write some kind of GC though

dgb2323:04:47

it even supports hot reloading apparently: https://epiccastle.io/blog/hot-loading-wasm/

seancorfield23:04:04

I try to learn a new language every year or two (per Pragmatic Programmer) and I'm still enjoying learning new stuff after doing this professionally since the early '80s 🙂

Cora (she/her)23:04:16

why not write threading, too!

Cora (she/her)23:04:16

marks &amp; sweeps &amp; marks &amp; sweeps

seancorfield23:04:39

Writing new languages used to be so much easier when we had fewer expectations of them. When I was at uni, lots of postgrad students were writing their own languages, mostly FP, mostly in the mold of SML in some sense. GC was still somewhat in its infancy back then so folks were experimenting with that too.

Cora (she/her)00:04:55

that's the big win in a hosted language that does straight compilation to the host language like hy or fennel, you don't have to meet the expectations yourself they're already there

seancorfield00:04:56

(like everyone else at the time, I designed and implemented SURE -- Surrey University Recursive Evaluator -- and it had an interruptible GC intended for better interactivity... because we only had single-threaded systems back then!)

🆒 1
dgb2300:04:58

I never made it to a full language. that’s still on my bucket list. but it sounds very fun

Cora (she/her)00:04:36

SURE you did, Sean. SURE

1
seancorfield00:04:22

My first job out of uni was essentially a compiler company. That was fun. We got to play with prerelease silicon which often had missing instructions (an early version of what became Motorola's 88000 RISC chip had no divide instruction).

seancorfield00:04:48

TIL from that job: the Microfocus COBOL compiler was written mostly in COBOL at the time.

Cora (she/her)00:04:11

I mean they warned you, it's just an extra-reduced instruction set

Cora (she/her)00:04:54

COBOL in COBOL? in the spirit of pypy I'm going to call that COBCOB

😄 1
dgb2300:04:07

This would be a fun language to learn next: https://en.wikipedia.org/wiki/INTERCAL

Cora (she/her)00:04:28

seems appropriate it has more than one version

mauricio.szabo13:04:37

Not gonna lie, looking at documentation Immer sounds amazing. I think it's probably one of those things that I would think "wow, this is incredible", then when I start to use it I'll think "oh gosh, this is so bad it hurts" or something 😄

dgb2313:04:38

That’s what happened to me to some degree. When I see mutation I expect mutation, not structural sharing. It would be somewhat equivalent to seeing set! or swap! in a function, but instead those are macros that turn imperative code into functional code. Just think about how a program flows and composes much better if it is expression based, has functional HoCs etc. versus a bunch of imperative loops, statements and mutations.

dgb2313:04:31

on top of that inside of React/JSX for example you write functional expressions anyways. This basically only makes sense in reducer code (Redux or useReducer hook) if we’re in React world.

Cora (she/her)14:04:07

I often do multiple transforms on data into different structures that are handy for different interfaces where something like this would be really helpful

Cora (she/her)14:04:39

but yeah, it might irk me that it's so magic, I'm not sure

mauricio.szabo19:04:08

@U02N27RK69K did you think about creating a function where you pass the original data, a map with keys/vals and transformations, and apply then all to produce a result? Something like (transform-all <my-data> {:person {:name str/upper-case :age inc}}), for example?

mauricio.szabo19:04:55

That could be a good experiment to check how well this would make transformations work, and how easy (or hard, or horrible 😄) it would be to use something like this 😄

Cora (she/her)20:04:04

have you seen specter and meander?

Cora (she/her)20:04:25

they're there for this purpose but it's hard to justify bringing them into a project in my experience