zlacker

[parent] [thread] 23 comments
1. XorNot+(OP)[view] [source] 2024-01-19 23:42:57
I'm not clear what your last sentence has to do with anything else? What does immutability have to do with Async/sync conversions?
replies(2): >>polyga+n3 >>throwa+D3
2. polyga+n3[view] [source] 2024-01-20 00:11:51
>>XorNot+(OP)
Immutability is great for multithreaded/async programs because every thread can rest assured knowing no other thread can sneakily modify objects that they are operating on currently.
replies(3): >>candid+w3 >>IlliOn+Be >>wredue+Yk
◧◩
3. candid+w3[view] [source] [discussion] 2024-01-20 00:12:57
>>polyga+n3
Go can prevent this with the race detector among other things
replies(3): >>stouse+L3 >>binary+d9 >>omgint+4l
4. throwa+D3[view] [source] 2024-01-20 00:13:36
>>XorNot+(OP)
you can fearlessly run code on another thread if you're not worried it's going to cause a data race or mutate anything
replies(1): >>XorNot+s4
◧◩◪
5. stouse+L3[view] [source] [discussion] 2024-01-20 00:14:54
>>candid+w3
Sometimes.
◧◩
6. XorNot+s4[view] [source] [discussion] 2024-01-20 00:19:44
>>throwa+D3
This is very much not free though. Predicting memory usage in Haskell programs is notoriously tricky (and all the memory copies aren't free either).
replies(3): >>c-cube+Q5 >>bippih+ob >>whatev+t22
◧◩◪
7. c-cube+Q5[view] [source] [discussion] 2024-01-20 00:33:03
>>XorNot+s4
It's also the case with OCaml, Elixir, clojure, etc. Non lazy languages can also have a rich collection of immutable data structures and have more predictable memory usage than Haskell. On the other hand, Go doesn't have a culture or features that encourage immutability.
◧◩◪
8. binary+d9[view] [source] [discussion] 2024-01-20 01:06:25
>>candid+w3
The race detector needs to actually encounter a race in order to detect it, it's not a complete static analysis.
◧◩◪
9. bippih+ob[view] [source] [discussion] 2024-01-20 01:25:55
>>XorNot+s4
it's not free, but it is explicit. it's nice for the code to explicitly define how the memory is being modified. there are copies in java too, you just have to know how the runtime works to know what each line does.
replies(1): >>ric2b+Vd
◧◩◪◨
10. ric2b+Vd[view] [source] [discussion] 2024-01-20 01:51:12
>>bippih+ob
Copies in haskell are not explicit at all, though?
◧◩
11. IlliOn+Be[view] [source] [discussion] 2024-01-20 01:56:59
>>polyga+n3
How Haskell deals with access to shared resources which are mutable by their nature, like file system, or the outside world?

(A honest question, I start to think that I'd like to learn more on this language)

replies(2): >>andyfe+Tg >>whatev+J12
◧◩◪
12. andyfe+Tg[view] [source] [discussion] 2024-01-20 02:22:19
>>IlliOn+Be
AFAIK they tend to operate through the IO monad, which serves to order read/write events and mark parts of your code as interacting with the global mutable state that lives outside your program.

So the mutable (or is it “volatile”?) environment is there, but you explicitly know when and where you interact with it.

◧◩
13. wredue+Yk[view] [source] [discussion] 2024-01-20 03:10:20
>>polyga+n3
Immutability is, quite possibly, the dumbest “silver bullet” solution ever to be praised as a solution to anything.

Congratulations, nobody is going to sneakily update an object on you, but also, nobody knows about your updates either.

It’s not a worthwhile trade off given the massive extra work it causes.

replies(3): >>throwa+8v >>Fire-D+Dx >>whatev+522
◧◩◪
14. omgint+4l[view] [source] [discussion] 2024-01-20 03:10:56
>>candid+w3
Detectors detect, they don’t prevent. All detectors suffer misses.
◧◩◪
15. throwa+8v[view] [source] [discussion] 2024-01-20 05:14:26
>>wredue+Yk
Completely uninformed take. Some of the most impressive update notification systems are built off of pass-as-immutable runtimes (for example: phoenix live view + phoenix pubsub). Try implementing that in just about a y other language. You will trip over yourself eight ways to hell

The whole idea of CQRS is to build separate (segregated) pathways for updates. Immutable passing plays extremely well with CQRS. The alternative is the complete clusterfuck that is two way data bindings (e.g. out of the box angularjs)

replies(1): >>tgv+5F
◧◩◪
16. Fire-D+Dx[view] [source] [discussion] 2024-01-20 05:48:22
>>wredue+Yk
Immutability frees the mind from so much baggage when developing that i'm always shocked it didn't become mainstream
◧◩◪◨
17. tgv+5F[view] [source] [discussion] 2024-01-20 07:47:10
>>throwa+8v
I think you both are referring to the same point: you can't update an immutable object, so you have to set up some mechanism to keep changes in sync.
replies(1): >>throwa+JH
◧◩◪◨⬒
18. throwa+JH[view] [source] [discussion] 2024-01-20 08:27:26
>>tgv+5F
Yeah, and update mechanisms are not created equal. two way data bindings suck because they elide the challenges of distributed consistency.

When you're immutable, you can still delete or replace data.

replies(1): >>wredue+1G1
◧◩◪◨⬒⬓
19. wredue+1G1[view] [source] [discussion] 2024-01-20 16:44:03
>>throwa+JH
Immutability “maybe” (and that’s a massive grain a salt, because this is not a specific thing I’ve ever worked on to say any different) having certain use cases where it works well is not the same thing as making literally every single object in your entire application immutable.

I agree that immutability is a tool. My issue with it is when you treat it as a rule.

◧◩◪
20. whatev+J12[view] [source] [discussion] 2024-01-20 18:35:10
>>IlliOn+Be
Haskell has full support for IO and mutability. It even has software transactional memory in its standard library.
◧◩◪
21. whatev+522[view] [source] [discussion] 2024-01-20 18:37:14
>>wredue+Yk
> Congratulations, nobody is going to sneakily update an object on you

I've seen Heisenbugs where some random code calls a setter on an object in a shared memory cache. The setter call was for local logic - so immutable update would've saved the day. It had real world impact too: We ordered a rack with a European plug to an American data center (I think a human in the loop caught it thankfully).

Also, how often do you even use mutability really? Like .. for what? Logic is easier to express with expressions than a Rube Goldberg loop mutating state imo.

replies(1): >>wredue+r54
◧◩◪
22. whatev+t22[view] [source] [discussion] 2024-01-20 18:40:02
>>XorNot+s4
Predicting memory usage in Haskell programs isn't actually tricky. At least, I stopped thinking so once I became an intermediate Haskeller. It's not that hard to have a mental model of the Haskell RTS the same as you'd have the JVM.

Having the ability to do so generally is tablestakes for being an intermediate professional programmer imo. In university, I had to draw diagrams explaining the state of the C stack and heap after each line of code. That's the same thing. And I was 19 lmao. It's not hard.

Maybe you're referring to space leaks? I've run into like 2 in my ten year Haskell career, and neither hit prod

I've actually seem more Go and Java space leaks/OoM bugs hit prod than Haskell - despite having fewer total years using those languages than Haskell! Nobody blamed the language for those though :/

◧◩◪◨
23. wredue+r54[view] [source] [discussion] 2024-01-21 14:26:22
>>whatev+522
>how many Heisenbugs

I suspect, given the real, actual measurements, the number of difficult to deal with bugs is pretty consistent between immutability and mutability. Actual measurements does not support claims of “easier to reason about”, or “reduced bugs”.

>how often do you use mutability

Whenever something should change and I don’t specifically need functionality that immutability might provide (literally 99.99999999% of every state change).

replies(1): >>whatev+eb4
◧◩◪◨⬒
24. whatev+eb4[view] [source] [discussion] 2024-01-21 15:05:12
>>wredue+r54
I'm just confused as to what you need mutability for exactly? I get needing it for communicating between processes (STM has you covered there). But for "normal" code that is doing pure logic, what is the benefit of using mutability?

Immutability has some big advantages for pure logic, such as allowing containers to be treated as values the same as numbers. And efficient immutable data structures of all kinds are commonplace now.

[go to top]