Why is it so easy to deal with concurrency with Rx? [closed] - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
A few months back, we introduce Rx into our codebase, and since then the codebase is getting more and more "reactive". I feel that it is really easy to introduce concurrency into the codebase with Rx, as not a single line of "locking" was used yet.
However, I do not understand why it is easy with Rx when I can't explain it in words.
Is it related to the "Actor Model" and "Functional Reactive Programming" concept?
Can someone kindly enlighten me on this please?

I think the main reason it's "easy" is because of the blood, sweat and tears poured into the Rx library by the very smart Dev team behind it at MS.
Look at the (open) source code to see just how much careful code goes into enforcing the Rx grammar and the parameterisation of when and where things run using Schedulers. That has plenty of defensive concurrent code in it. I suggest it's the grammar and Schedulers that bring the simplicity.
Using the model is quite easy, but achieving that simplicity was not trivial. You are benefiting from standing on the shoulders of giants that have hidden the complexity behind a neat and tidy API :)
Incidentally, there is still the odd trap for you to fall into... I'm sure you'll find one sooner or later! One example is that Subject<T>.OnNext() is not protected from concurrent access in Rx 2.x for performance reasons.

Related

Correct .NET way to implement a single instance application [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have seen at least three distinct methods on StackOverflow for achieving this.
Using a MUTEX: Accepted answer to this SO question
Using the Microsoft.VisualBasic library's WindowsFormsApplicationBase: Second highest voted answer to this SO question
Using Process.GetProcessNames to check if your application is running: Method here was posted as an answer to this SO question
I'm sure there are more ways to do this as well.
I'm simply wondering if one of these is preferred and what the consequences might be if I pick the "wrong" one.
When in doubt, always prefer an implementation that's included in the .NET framework. You can have high expectations that such an implementation is tested by hundreds of thousands of programmers, has been carefully reviewed for security and usability and will be maintained for years to come.
The mutex approach is an easy one to get going. It however suffers from a pretty severe security problem. A denial of service attack is very simple to get going, you cannot keep the name of your mutex a secret and anybody can trivially create a mutex with the same name and prevent your program from ever starting up.
The process name approach is deeply flawed for the same reason. There is no guarantee that a process name is unique. Not just easy to exploit but easily triggered by accident.
WindowsFormsApplicationBase has an image problem in the eyes of C# programmers. They choke at the namespace name and assume that their program will somehow be infected with vb-isms. That's nonsense, it is just a plain .NET class that's useable in any language.
Why nobody mentioned ticking this checkbox?
It's really a matter of taste, but I favor the Mutex approach, simply due to it not requiring a dependency on the VisualBasic libaries, and using Process.GetProcessNames is a non-ideal solution (as mentioned, process names aren't always going to map to what you think they might)

Which Micro ORM to use? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Trying to decide between Dapper, Massive and PetaPoco. I do like simplicity of Dapper, flexibility of Massive and POCO support in PetaPoco but am currently procrastinating about which one to choose for my next project.
I do realise that, to a large extent, it's the matter of personal taste, but believe it will be valuable to hear some opinions on the subject, especially from people who tried more than one of these, err, libraries (what is the right term: library, file, framework?)
Try to decide which of the features you mention -- simplicity, flexibility, POCO support -- will be most useful to you and your project(s) one year from now. Which is most likely to make your work easier?
Then you'll have your answer. And if you still can't choose, pick Dapper (just a random selection I made :-) As the Cheshire Cat says, if you don't really know where you want to go, it doesn't matter which road you choose.
PetaPoco's documentation seems more mature than others. It seems like it is the safest route.
i havent triend any of those. by default i always base my decision on number of lines of resulting client code and type safety. of course there are number of other metrics you should take into account but if your project is not constrained by any special (exotic) requirements those two are generally appliable.
btw. i am aware about controversy my response may lead to ;)

QuickFix C# or Python [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
We are about to implement a small automated securities trader. The trader will be build on top of the excellent quickfix FIX engine.
After due though, we narrowed our options down to implementing it in C# or in Python. Please specify the pros and cons of each language for this task, in term of:
Performance (The fact that Python uses a GIL troubles me in terms of thread concurrency)
Productivity
Scalability (We may need to scale this trader to a fully-sized platform)
EDIT
I've rephrased the question to make it less "C# vs. Python" (which I find irrelevant - both languages have their merits), but I'm simply trying to draw a comparison table before I make the decision.
I like both languages and a think both would be a good choice. The GIL might really be the most important difference. But I'm not sure if it's a problem in your case. The GIL only affects code running in pure Python. I assume that your tool depends more on I/O than on raw number crunching. If your I/O libraries handle the GIL correctly, they can execute concurrent code without problems. And even for number crunching you still have numpy.
My choice would depend on your existing knowledge. If you have experienced C# developers at hand I would go for C#. If you start absolutly from scratch and it's really 50:50, then I would go for Python. It's easier to learn, free and in many cases more productive.
And just to mention it: You might also have a look at IronPython. ;-)
For points "Performance" and "Scalability" I would suggest C# (although a large part of performance depends on your algorithms). Productivity is much of a subjective thing, but now C# has all cool features like lambda, anonymous method, classes etc which makes it much more productive.

Becoming a thread monkey [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What would you suggest as a road map for becoming very proficient in writing multithreaded applications - beyond "tinkering"?
I am a C# developer - would branching off into some other languages help this endeavor?
Does the parallel addition to .NET 4.0 hide things that you should know in order to make it easier?
Read Joe Duffy's "Concurrent Programming on Windows". Joe is an amazing expert.
Investigate different approaches to concurrency on different platforms; look at Erlang, Scala etc
Likewise read Java concurrency books, which will have some subtly different details, but often tackle the same core issues and have some useful patterns. "Java Concurrency in Practice" is often recommended.
Look at the various options on .NET, including the Coordination and Concurrency Runtime and F# asynchronous computations
Definitely learn Parallel Extensions - it'll help a lot, and from what I've seen, a lot of very careful design work has gone into it. (It's changing somewhat for 4.0b2 though, so you may want to defer this for now.)
Theres a really good PDF about threading in .NET here the MSDN documentation for the Thread class as well as the threading primitives (Mutex, WaitHandle, ReaderWriterLockSlim et al) is also good reading.
The key things to understand are:
When to use a thread
When not to use threads
How to manage sharing state between threads.
I could go on to explain these here, but I feel the threading PDF linked to above does a far better job than I could in that respect, the key point is that threads are a powerful tool and understanding when and how to use them will make you more proficient in their use than simply reading MSDN, although strategies for using threads effectively are covered there also.

Looking for a good book on how to code more efficiently in .net c# [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Most C# developers developers, like me have a good solid grasp on the .net framework and the C# language. But I've yet to come across a book that can take a very good c# developer to the next level of C# mastery.
I am looking for a book that can help me make that transition. Dealing with issues like theory on having more robust C# code when connecting to external systems etc. Error logging techniques, and generally better memory usage, and re factoring.
Anyone know of a good book, that's worth the read?
Jon Skeet's "C# in Depth" is pretty good: http://www.amazon.com/C-Depth-Jon-Skeet/dp/1933988363/ref=sr_1_1?ie=UTF8&s=books&qid=1259183768&sr=8-1
Effective C# and More Effective C# by Bill Wagner come highly recommended
If you're a very good C# dev, you should perhaps look beyond a certain language and technology and try: Domain Driven Design. It's a great book and promotes ideas that help writing great software.
The best book I have found for C# internals is CLR via C# by Jeffrey Richter.
Not a C# book per se, but Design Patterns (Gamma et al) might be a good introduction to more abstract, architectural concepts.

Categories