2 ms·
Java has a little const. Strings are immutable. You can make objects with no mutations, so you can make read only collections fairly easily which is usually whe
by hinkley 1y ago
Java has a little const. Strings are immutable. You can make objects with no mutations, so you can make read only collections fairly easily which is usually where const becomes a problem.
But then you have for instance Elixir, where all functions are pure, so mutating inputs to outputs takes a ton of copying, and any data structure that is not a DAG is a gigantic pain in the ass to modify. I lost count of how many tries it took me to implement Norvig’s sudoku solver. I kept having to go back and redesign my data structures every time I added more of the logic.
[edit to add]: DTOs exist in Java because some jackass used the term “Value Object” to include mutation despite large swaths of the CS world considering VOs to be intrinsically const. So then they had to make up a new term that meant Value Object without using the concept they already broke.
- throwawaymaths 1y agoThere are so many purity escape hatches in elixir!!
- hinkley 1y agoThe only ones I know about are the ones in functions and closures, where SSA basically just creates a new variable that hides the original (until the end of the block at which point you discover the reassignment didn't stick). What did you have in mind?
- throwawaymaths 1y agoets tables are the goto for data structures (for example the :digraph module that ships with elixir is built on an ets table, presumably because A* needs a mutable datatype) Process dictionary is also an option. Can always use a genserver as a data store (but only do that if lifetime shenanigans make it make sense) Postgres is also an option. Sqlite if you don't want to stand up a service.
- hinkley 1y agoAh yes. I’m using a genserver to persist a countdown clock across page loads. ETS gives me a memory leak vibe but I need to bite the bullet and learn to use it properly.
- throwawaymaths 1y agoThink of ets as an arena. You can clear the whole table by yanking its owning process. This could even be made automatic by linking it to whatever process needs the ets table.
- hinkley 1y agoHmmm. Maybe I’m misremembering some Erlang release notes then.