5 ms·
> Did you ever attempt to get to the bottom of an intermittent error that was driving you insane, only to discover much later that a private variable wasn’t syn
by rdtsc 11y ago
> Did you ever attempt to get to the bottom of an intermittent error that was driving you insane, only to discover much later that a private variable wasn’t synchronized properly? Have you ever spent hours stepping through the lifecycle of an object, going through many different components spread out across the codebase and wished that you had spent all that time solving new problems instead?
I see 3 issues here.
1) Most people haven't dealt with those issues enough. There are complex programs but there are also many simple program as well. And unless one deals with hard to debug concurrency / pointer / mutable state errors they will not appreciate immutability. They might pay lip service to it, because it is cool, but they will not appreciate it enough to start rewriting their codebase in it. That is a bit like fault tolerance, unless they have been woken up at 3am because their main larger server process segfaulted and had to debug, they will not think about isolated units of failure, about supervision, durable peristent snapshots/checkpoints, monitoring etc. They of course will say that "fault tollerance is good" but it is good in an abstract, general way.
2) Those that dealt with these issue might accept the state (pun indended) of affairs and never realize there is another way of doing things. I mean they just accept that you have to have locks and mutable state and mutexes and dangling pointers and then spend months debugging hard to track concurrency errors at 3am. That is just how software development works and it is as good as it gets.
3) People realize there is something better, they know about, read about, played with it. But they don't have enough energy, political power, or time do fix it.
- golergka 11y ago> Most people haven't dealt with those issues enough This really surprises me. Surely, most programmers have experience with big and complex codebases with a lot bugs coming from mutable state, no?
- rdtsc 11y agoFor 1) I meant that there are lot of utilities, micrservices, small web backends, scripts, and hopefully, applications that have already been split into isolated components that can fail and restart separately (in other words someone did the work already). So if one starts dealing with those in their careers they just might never have a compeling reason to look at Haskell, F#, Erlang, OCaml and such. Also note that quite often one way to deal with large mutable state is to simply shove it in database. Usually good databases just make it explicit what happens to shared state.
- MichaelGG 11y agoThe most compelling reason is being able to write way less code. When I write in C# I'm constantly annoyed at how pointlessly verbose it is. I feel hampered, like I'm trying to talk to a 5 year old that doesn't really understand English.
- fallat 11y agoI'd like to see Haskell vs C# code that demonstrates this. In my opinion Haskell just fits more code onto a single line and is much less readable.
- MichaelGG 11y agoI've done comparisons where I've written the exact same program in C# and F#. The reduction in unneeded type annotations alone is massive. F# required only 1/20th the number of type annotations.
- jcrites 11y agoType inference can make the code easier to write. But, is the code easier to read, and overall less effort for the business? Code tends to be read significantly more than it's written. This is a simplification but seems to be true enough; modification by subsequent maintainers involves a lot of reading. I worry about features like overuse of type inference when it means the types in question aren't explicit from the code that you're reading (agreed, not all type inference involves overuse). For example, if I write: var x = f(); What's the type of x? What's the return value of f? I can answer those questions, certainly, but I have to go look for the answer. I don't immediately have any mental concept or name to hang the idea off of. Whereas in a language like Java, I'd end up writing: Foo x = f(); Now I know the return value is a "Foo". This may not seem like much, but suddenly if there are many different Foos in the code, I can see the patterns I didn't see before, and I can draw correlations: Foo x = f(); Foo y = g(); h(x,y); Everything can always be understood with a degree of thought, but type annotations seem to, in my experience, make programs a lot easier to read and modify. The original authors typically have the whole thing in their head, so it doesn't make a difference to them, but it can be a huge difference for those who come after. There's a certain simplicity that comes from types that are so concrete, clearly named, and linkable as Java libraries are. You can figure out something about this code without reading the declaration or definition: ListenableFuture<String> emailAddress = user.queryEmailAddress(); You have a pointer for what to search for and an immediate name for the concept. I suppose it's like an index, in a way. An index to make code more readable and referenceable is included throughout. It's hard to explain it, but I find this valuable even when I have support from a sophisticated IDE. (Plus I'm often working outside an IDE.) Including these types is more time consuming up front than languages that support type inference, or are dynamic, but for long-lived applications it seems like the overall tradeoff is usually worth it. To be fair, I haven't maintained any F# applications. If the type inference is purely saving annotations that are completely obvious even to a beginner to the codebase, then I could see that being worth it. (It seems to me that we are all beginners to the codebase in meaningfully large platforms.) The actual act of typing the annotations is also often pretty easy and handled automatically by the IDE, but I suppose you have that experience with C#.
- taeric 11y agoI see another issue. Have I ever gotten to the bottom of an intermittent error only to determine it is a synchronization error? Yes. The problem is I have also gotten down to the bottom of a problem and found it was a stale data problem. In a system that was performing gymnastics to keep things immutable. To the point that fixing it was not a simple matter of just updating the variable. Worst were the Multiversion concurrency control (MCC) systems I have seen rolled to "help keep all facts of the system immutable." Suddenly, we had to have database implementation experts just to run basic software...
- sigmaml 11y agoI have similar experiences too. Trying to keep data immutable introduces scenarios involving stale data, and a new problem to solve. I have seen interesting problems with cache coherence that were quite subtle in their manifestations. Understanding the system-wide implications of immutable-only data is a non-trivial design task.
- rtpg 11y agothe issue I have with this statement is that stale data exists when going full-imperative as well. The solutions might be harder to implement in an immutable environment if your setup isn't right, but not an order of magnitude harder. And you get all the advantages of immutability. People complain about stale data issues in immutable programming styles not because they're more prevalent, but because they can rule out so many other classes of bugs immediately.
- sigmaml 11y ago> People complain about stale data issues in immutable programming styles not because they're more prevalent, but because they can rule out so many other classes of bugs immediately. This generalisation is too broad (as with almost any generalisation). In any case, I want to mention one interesting experience -- a very large financial portfolio management system that I worked on, over a decade-and-a-half ago. The system had multiple in-coming tickers, feeding huge amounts of data. The central data structures of the computational pipeline system were immutable. Initially, there was a very haphazard system for determining when a particular piece of data was to be deemed stale. In time, formal definitions were established. However, the software was not amenable to those definitions, since shared data was not `seen' updating instantaneously. The core was too big to be changed in any non-trivial manner, without risking the entire business. We ended up introducing an explicit notion of time into every pipeline processor to ameliorate (not entirely solve) the situation. Every major design decision has its own trade-offs that are specific to the problem on hand. But, those built into the foundations of the system should be made pragmatically, not by adhering to a philosophy!
- zyxley 11y ago> political power This is the big one for me. I deal with assorted systems that I can't get migrated off ancient shitty middleware platforms because any comprehension of them vanishes into the ether somewhere around the upper management types. "Functional programming" isn't even anywhere on the radar when I currently have no chance of even completely getting rid of PHP.