4 ms·
If your team and you can read it later or when it goes wrong, then it's fine. I don't want to need to think hard about what code does, it should be clear. Or j
by samsquire 4y ago
If your team and you can read it later or when it goes wrong, then it's fine.
I don't want to need to think hard about what code does, it should be clear. Or jump through 100 files to find a simple algorithm that has been divided into 100 pieces.
I think people refactor to their own understanding or mental model or refactor-to-understand.
I think there are cases where imperative code is intuitive and others where functional code is intuitive.
I've worked on two professional projects in Clojure at a surface level but I still find Python easier to read, but that's my experience YMMV.
There's a point in my programming projects when my own understandability is weakened and I this week I've been trying to think of a mindset that simplifies the problem. I am experimenting with multithreaded code in Java that implements left-right concurrency control. The idea is readers don't block writers and writers don't block readers and writers don't block writers. Give each thread a shard and rely on commutative property of your tree data structure and have a coordinator thread handle merging. The benefit: each thread can operate at single core speeds without any synchronization for reading OR writing. Buffer flipping is handled by the coordinator thread.
Each thread has its own copy of state which is merged by the coordinating thread. So it's an eventually consistent system. The result: each thread can modify its own copy of the data as much as it wants and it can see its own snapshot of global state at the last snapshot point. Cross thread writes always happen on the inactive buffer.
How do you think about data transformation pipelines? If only there was an IDE for kafka or clojure transformation pipelines.
- janetacarr 4y agoAgreed, cyclomatic complexity is definitely something to be aware of when designing functional programming systems. Although, I disagree about Clojure's readability, but that's probably because I've been doing it for so long. Interesting Java project you've got there. Reminds me of Clojure's core.async library and software transaction memory ;) (though, I know it's not exactly the same thing). If I was transforming large streaming input from Kafka or Kinesis, I would probably reach for Cortex (a map-reduce style lib for Clojure), or I might rig up some strange, stream-to-lazy-seq adapter and reach for transducers as they have much better performance when dealing with larger input.
- samsquire 4y agoI am really interested by Software transactional memory and enjoyed reading the Joe Duffy's blog posts about Midori and adventures with STM. https://github.com/joeduffy/joeduffy.github.io/blob/master/_posts/2015-11-03-blogging-about-midori.md https://github.com/joeduffy/joeduffy.github.io/blob/master/_... I like left-right concurrency control because it sidesteps a number of thread safety problems by ensuring that a thread can always safely read or write to its own buffer.
- KingMob 4y agoFair warning, STM has largely not panned out in industry, and is no longer in common use. Clojure was built when it was still fashionable, but even having the advantage of immutable-by-default data structures, 99% of modern Clojure doesn't use complicated STM, and instead relies on the humble atom, which is updated with a glorified CAS.