﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Tom Janssens commented on Memorable code</title><description>I was checking whether someone provided an answer on this one yet...
Looking back, please forget my previous incredibly stupid comment; I was talking rubbish;allowing an app to set up a multitude of concurrent connections would hog your DB connection pool, leaving no connections for your app, in other words this would be a recipe for disaster.
Rather odd that I missed it the first time, as did everyone else... 
So, next to the missing "else throw" in the first exception handler, just ditch the paralleled approach all together, as it would probably hog up all connections on your database !</description><link>http://ayende.com/131073/memorable-code#comment54</link><guid>http://ayende.com/131073/memorable-code#comment54</guid><pubDate>Tue, 22 Nov 2011 12:18:32 GMT</pubDate></item><item><title>Tom Janssens commented on Memorable code</title><description>I think that for db connections async dev might be beneficial, although I have not tried it. However, I would just opt for a backgroundworker instead.
IMO the biggest problem with this code is in the exception handling: it lacks an "else throw;" in case the exception isn't the one expected...</description><link>http://ayende.com/131073/memorable-code#comment53</link><guid>http://ayende.com/131073/memorable-code#comment53</guid><pubDate>Thu, 10 Nov 2011 20:02:39 GMT</pubDate></item><item><title>Ayende Rahien commented on Memorable code</title><description>Duplicated,
Yes, fix now, a post with an explanation coming up shortly</description><link>http://ayende.com/131073/memorable-code#comment52</link><guid>http://ayende.com/131073/memorable-code#comment52</guid><pubDate>Thu, 10 Nov 2011 08:47:18 GMT</pubDate></item><item><title>duplicated commented on Memorable code</title><description>It's your RavenDB database corrupted? Post and comments seems like duplicated (or triplicated... or more) :)</description><link>http://ayende.com/131073/memorable-code#comment51</link><guid>http://ayende.com/131073/memorable-code#comment51</guid><pubDate>Thu, 10 Nov 2011 07:46:39 GMT</pubDate></item><item><title>Ryan commented on Memorable code</title><description>@dead-detector He has been teaching classes in NYC. See the top of the sidebar.</description><link>http://ayende.com/131073/memorable-code#comment50</link><guid>http://ayende.com/131073/memorable-code#comment50</guid><pubDate>Mon, 07 Nov 2011 05:26:53 GMT</pubDate></item><item><title>dead-detector commented on Memorable code</title><description>What happend to Oren? Is hope he is alive.</description><link>http://ayende.com/131073/memorable-code#comment49</link><guid>http://ayende.com/131073/memorable-code#comment49</guid><pubDate>Sun, 06 Nov 2011 10:38:46 GMT</pubDate></item><item><title>Clay commented on Memorable code</title><description>@Christopher

Thanks for bringing that to my attention.  I apologize as I should have been more clear.  A slobbering cloud of sycophants. </description><link>http://ayende.com/131073/memorable-code#comment48</link><guid>http://ayende.com/131073/memorable-code#comment48</guid><pubDate>Sun, 06 Nov 2011 03:40:16 GMT</pubDate></item><item><title>Christopher Wright commented on Memorable code</title><description>@Clay: you failed to honor Ayende properly in that post. Please enter additional grovel, else you will be reported to the authorities.</description><link>http://ayende.com/131073/memorable-code#comment47</link><guid>http://ayende.com/131073/memorable-code#comment47</guid><pubDate>Sat, 05 Nov 2011 13:55:16 GMT</pubDate></item><item><title>Clay commented on Memorable code</title><description>A cloud of sycophants.</description><link>http://ayende.com/131073/memorable-code#comment46</link><guid>http://ayende.com/131073/memorable-code#comment46</guid><pubDate>Thu, 03 Nov 2011 19:25:42 GMT</pubDate></item><item><title>ThomasX commented on Memorable code</title><description>A "great" example of cloud computing. A cloud of threads...</description><link>http://ayende.com/131073/memorable-code#comment45</link><guid>http://ayende.com/131073/memorable-code#comment45</guid><pubDate>Tue, 01 Nov 2011 09:59:11 GMT</pubDate></item><item><title>Dathan commented on Memorable code</title><description>@Chris Taveres Not necessarily.  Any blocking calls should make the thread sleep, at which point the other threads will have an opportunity to run.  Which, of course, makes setting ThreadPriority.Highest kind of pointless, but it shouldn't starve out the other worker threads, since most of the time spent here will either be in establishing the connection or executing the command - both of which I would expect to cause the thread to sleep.  Unless I'm missing something - I have to admit I'm a bit of a multithreading neophyte.</description><link>http://ayende.com/131073/memorable-code#comment44</link><guid>http://ayende.com/131073/memorable-code#comment44</guid><pubDate>Tue, 01 Nov 2011 08:16:11 GMT</pubDate></item><item><title>Dathan commented on Memorable code</title><description>@Harry Agreed.  And frequently even when Ayende does provide feedback on the code samples he presents, the comments include lots of additional feedback that he doesn't mention.  In the case of code whose shortcomings actually *require* significant expertise to really appreciate, then it makes sense for Ayende to chime in.  In the case of a code sample like this that's just egregiously broken, it makes perfect sense to just let the commenters evaluate it.  It's like crowdsourcing source code review.</description><link>http://ayende.com/131073/memorable-code#comment43</link><guid>http://ayende.com/131073/memorable-code#comment43</guid><pubDate>Tue, 01 Nov 2011 07:58:02 GMT</pubDate></item><item><title>Joe Marquardt commented on Memorable code</title><description>At least an invalid server name in the connection string will timeout in parallel! meh.</description><link>http://ayende.com/131073/memorable-code#comment42</link><guid>http://ayende.com/131073/memorable-code#comment42</guid><pubDate>Mon, 31 Oct 2011 20:48:34 GMT</pubDate></item><item><title>Nadav Sofy commented on Memorable code</title><description>Not opening the connection is a legitimate bug that you find out about after the first run. Not using a transaction is a huge bug that is not as easy to find. And no way someone wrote this code during a 30 minutes interview and knew the codes of specific sql exceptions</description><link>http://ayende.com/131073/memorable-code#comment41</link><guid>http://ayende.com/131073/memorable-code#comment41</guid><pubDate>Sun, 30 Oct 2011 23:45:17 GMT</pubDate></item><item><title>firefly commented on Memorable code</title><description>If somebody can code this in 30 minutes then either he is really good or really bad; generally it is the later because it include premature optimization code that is obscure.</description><link>http://ayende.com/131073/memorable-code#comment40</link><guid>http://ayende.com/131073/memorable-code#comment40</guid><pubDate>Sun, 30 Oct 2011 10:01:01 GMT</pubDate></item><item><title>Nick commented on Memorable code</title><description>If the insert throws an exception then it must be an update haha. Love it</description><link>http://ayende.com/131073/memorable-code#comment39</link><guid>http://ayende.com/131073/memorable-code#comment39</guid><pubDate>Sat, 29 Oct 2011 19:56:44 GMT</pubDate></item><item><title>Fishy commented on Memorable code</title><description>A piece of code and everyone starts laughing. But what is the context of this code? If it is a test for an interview without any VS at hand and just 30 minutes time for it? In this case it isn't that bad. And it would excuse that there is no con.Open...btw most of the commenters above did not realise this.  </description><link>http://ayende.com/131073/memorable-code#comment38</link><guid>http://ayende.com/131073/memorable-code#comment38</guid><pubDate>Sat, 29 Oct 2011 11:54:40 GMT</pubDate></item><item><title>TJ commented on Memorable code</title><description>This code is basically doing nothing but spin a thread for each line within the text file that it is reading. It never open the connection to sql in the first place therefore none of the catches will be executed after it fails on executeNonQuery.</description><link>http://ayende.com/131073/memorable-code#comment37</link><guid>http://ayende.com/131073/memorable-code#comment37</guid><pubDate>Fri, 28 Oct 2011 19:30:10 GMT</pubDate></item><item><title>Darren Cauthon commented on Memorable code</title><description>I think the biggest problem with this code is that it expresses no intent.  I read the code yet I don't have any idea what it does.

Yeah, there might be issues with the implementation, but even without ToString() or the threading or whatever this would still be bad code.  Good code can be understood.</description><link>http://ayende.com/131073/memorable-code#comment36</link><guid>http://ayende.com/131073/memorable-code#comment36</guid><pubDate>Fri, 28 Oct 2011 19:09:51 GMT</pubDate></item><item><title>Nadav Sofy commented on Memorable code</title><description>to those who suggested select and then insert/update, it's more efficient to do update, check the return value to see if any row was updated, if it's 0 then do an insert. 

@Paulo Abom Pinto - in 99% of the times, there's no justification for using a stored procedure to do anything.</description><link>http://ayende.com/131073/memorable-code#comment35</link><guid>http://ayende.com/131073/memorable-code#comment35</guid><pubDate>Fri, 28 Oct 2011 16:12:57 GMT</pubDate></item><item><title>Paulo Abom Pinto commented on Memorable code</title><description>@EDev of course the SELECT before it's not he perfect way, but he could ensure that on SELECT the record is locked or try a dabase trasaction and try to ensure the flow.

In my opinion some of this code should be in a Store Procedure and the thread flow in the C#.</description><link>http://ayende.com/131073/memorable-code#comment34</link><guid>http://ayende.com/131073/memorable-code#comment34</guid><pubDate>Fri, 28 Oct 2011 15:04:06 GMT</pubDate></item><item><title>Jimmy commented on Memorable code</title><description>A very nice new API - upsert.</description><link>http://ayende.com/131073/memorable-code#comment33</link><guid>http://ayende.com/131073/memorable-code#comment33</guid><pubDate>Fri, 28 Oct 2011 14:52:11 GMT</pubDate></item><item><title>Bob2 commented on Memorable code</title><description>@Dan Bailiff and @Bob

Eventually you'll figure out only the k00l kidz hang out here and they all try to out do each other to impress the guy who runs the blog.

You'll need to pass your Ayende blog readers certification test before you'll be accepted as a k00l kid.

Fear not, most of them don't understand either - they're just trying to impress each other.

Yawn, how boring.  It's like living high school over and over.  Occasionally there is a nice post, but each time you see code dumps, skip the post, the only responses are from kidz trying to impress each other.</description><link>http://ayende.com/131073/memorable-code#comment32</link><guid>http://ayende.com/131073/memorable-code#comment32</guid><pubDate>Fri, 28 Oct 2011 14:33:10 GMT</pubDate></item><item><title>Max commented on Memorable code</title><description>Not so memorable ;)
For example, if you start the thread in the second loop you can have a really memorable code !!!  ;)
no limit to the worst!</description><link>http://ayende.com/131073/memorable-code#comment31</link><guid>http://ayende.com/131073/memorable-code#comment31</guid><pubDate>Fri, 28 Oct 2011 10:09:24 GMT</pubDate></item><item><title>Ori commented on Memorable code</title><description>nice :)

This is obviously production code for bank accounts and may be the reason for the worlds economic woes..

When all you have is a hammer, everything looks like a nail.
</description><link>http://ayende.com/131073/memorable-code#comment30</link><guid>http://ayende.com/131073/memorable-code#comment30</guid><pubDate>Fri, 28 Oct 2011 07:50:23 GMT</pubDate></item><item><title>Chris Tavares commented on Memorable code</title><description>Heh... all that effort to get parallelism and he shot it in the foot. Using ThreadPriority.Highest means that the worker thread will take higher priority than any other thread in the process... including the process that's running Main and scheduling the other threads. Once the thread quantum expires, no more iterations on the loop until the scheduled (and probably small number of) worker threads all finish.
</description><link>http://ayende.com/131073/memorable-code#comment29</link><guid>http://ayende.com/131073/memorable-code#comment29</guid><pubDate>Fri, 28 Oct 2011 04:15:56 GMT</pubDate></item><item><title>oh my commented on Memorable code</title><description>No more posts in queue!</description><link>http://ayende.com/131073/memorable-code#comment28</link><guid>http://ayende.com/131073/memorable-code#comment28</guid><pubDate>Fri, 28 Oct 2011 03:56:31 GMT</pubDate></item><item><title>Nadav Sofy commented on Memorable code</title><description>Bob - if he had tried to explain everything that is wrong with this code it would have been a very long post.

and may be i'm way off, but i think that even the newest programmer should know the basics of exception handling, magic numbers transactions, threading and the rest. those who don't notice the problems with this code should read some more basic programming articles.</description><link>http://ayende.com/131073/memorable-code#comment27</link><guid>http://ayende.com/131073/memorable-code#comment27</guid><pubDate>Thu, 27 Oct 2011 23:20:28 GMT</pubDate></item><item><title>Harry Steinhilber commented on Memorable code</title><description>@Dan Bailiff &amp; Bob, 
Keep in mind, this is *Oren's* blog. He can help or not as he sees fit. Personally, just sifting through the comments has helped me pick out several issues I missed on my first read. That lead me to thinking about how I would re-architect to fix those problems in addition to the ones I spotted instantly. That alone is useful.</description><link>http://ayende.com/131073/memorable-code#comment26</link><guid>http://ayende.com/131073/memorable-code#comment26</guid><pubDate>Thu, 27 Oct 2011 22:23:35 GMT</pubDate></item><item><title>Jason Pettys commented on Memorable code</title><description>Bob: come on, man! He never promised to be didactic in every post!
Ayende: thanks - that was awesome.

</description><link>http://ayende.com/131073/memorable-code#comment25</link><guid>http://ayende.com/131073/memorable-code#comment25</guid><pubDate>Thu, 27 Oct 2011 22:09:49 GMT</pubDate></item></channel></rss>