4 ms·
I honestly really hate it when "concurrency is hard" is trotted out as a reason for not using it when using it would very obviously make life better for the end
by jgh 11y ago
I honestly really hate it when "concurrency is hard" is trotted out as a reason for not using it when using it would very obviously make life better for the end-user.
Is it as straightforward as non-concurrent code? No, obviously it isn't. Is it so mind-bendingly difficult that we need to be paralyzed by fear at the mere mention of concurrency? No, it isn't that either.
There are things you can do to make concurrency easier. Dispatch queues for one eliminate a lot of bugs. Being thoughtful about when and how we use concurrency is another. Race condition bugs are sometimes difficult to track down and cure, but if you understand the basic concepts around concurrency and controls around that they're generally fairly easy to avoid.
The biggest problem I've run into with people is they don't even understand what mutexes, semaphores, condition variables, or atomic variables are or when you'd use each. People don't know what joining a thread is. I ran into a bug at a previous job where they were spawning and destroying threads very quickly (which is a problem, but not their main problem) and instead of using a join to block until a thread's completion they were using sleep(1). Switching to a join sped up their code immensely and improved a data processing operation that previously took months to now taking days.
tl;dr people need to a) read up on how to do concurrency and b) be more thoughtful about the code they're writing when doing it. It's not so scary we should just avoid it altogether, especially when the user experience can be greatly improved by using it. Concurrency is another tool in the toolbag, even if it's a chainsaw without a cover.
- krat0sprakhar 11y ago> a) read up on how to do concurrency Can you suggest a few resources to further this cause? I'd love to write more concurrent code but outside of an OS class, I don't have much experience. Thanks!
- optimusclimb 11y agoYou could probably read this decade old book: http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601 http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/... and it'd be a good start. It's in "boring" old Java, but it goes over a lot of the meat and potatoes concepts.
- fapjacks 11y agoI can recommend this book as well. I don't write a lot of Java, but this is great for the general topic.
- frozenport 11y agoGo write a producer-consumer queue Also understand this code: http://en.cppreference.com/w/cpp/thread/condition_variable http://en.cppreference.com/w/cpp/thread/condition_variable
- sorenbs 11y agoIt seems to me you don't have a good understanding of the amount and kind of people doing web development. Either that or your comment is not in regard to web development at all?
- jgh 11y agoI'm not really involved in web development much, my comment was more general though. It's surprising the number of people in an environment where threading is a real option that don't really understand it very well.
- theseatoms 11y agoIs there not a wide range of web developer talent available in the marketplace? Certainly some teams are more sophisticated than others and can achieve a higher level of site design.
- sotojuan 11y agoConcurrency is even easier when you use something like Erlang or Elixir, or apply their principles to other languages.
- PopsiclePete 11y agoThe "web" for a long time was Perl/Python/PHP/Ruby. I had never done real concurrency work until I started doing C#/Java. But most web devs I've worked with, especially the ones with an interpreted language background, have no idea or even interest to do any kind of concurrency. NodeJS isn't making things better either. AFAIK, the only "easy" and pleasant language to do concurrency in is Go and maybe Clojure if you can get past the LISP. C# is nice but is (for now) still too MS-centric, and Java is ...well...Java. Until we move away from the intercepted languages and frameworks of the 1990's, this won't get any better anytime soon.
- sotojuan 11y ago> AFAIK, the only "easy" and pleasant language to do concurrency in is Go and maybe Clojure if you can get past the LISP. Have you looked into Elixir? It's a language that compiles to Erlang's VM and thus has the same concurrency model as Erlang's, which is one of the simplest ones.
- techdragon 11y agoPulsar is also a great Actor Model Concurrency library for Python. It gives you Erlang/Elixir style actor concurrency in Python!