by Jon Sagara
July 22, 2009 at 1:53 PM
Man, this is getting bad. See anything wrong with this?
INSERT INTO [dbo].[MyTable]
(
<snip />
[CreatedUtcDate],
[ModifiedUtcDate]
)
VALUES
(
<snip />
GETDATE(),
GETDATE()
)
by Jon Sagara
July 22, 2009 at 12:45 PM
Today's a good day. Check this out:
private static Dictionary<string, string> _dict = new Dictionary<string, string>();
static MyPage()
{
//_dict.Add("item1", "val1");
//_dict.Add("item2", "val2");
//_dict.Add("item3", "val3");
//_dict.Add("item4", "val4");
}
private void InitDictionary()
{
try
{
_dict.Add("item1", "val1");
_dict.Add("item2", "val2");
_dict.Add("item3", "val3");
_dict.Add("item4", "val4");
}//END TRY
catch
{
_dict.Clear();
_dict.Add("item1", "val1");
_dict.Add("item2", "val2");
_dict.Add("item3", "val3");
_dict.Add("item4", "val4");
}//END CATCH
}
So what happened here? The guy decided that initializing the static dictionary variable in the static constructor wasn't good enough, and that he needed to do it on every page request, so he created an instance method to do the initialization. For some reason, though, he kept getting an exception when initializing the dictionary after the first page view. Hmm... bettter just swallow the exception, clear the dictionary, and try again.
*slaps forehead*
by Jon Sagara
July 22, 2009 at 9:54 AM
Just ran across this awesomeness today:
string campaignId = null;
/* ------------------------------------------------------------------------
* see if the campaign id is in the request query params, so that a default
* based on the url can be set.
*/
foreach (object key in Request.Params)
{
string objCampaign = Convert.ToString(key);
if (string.Compare(objCampaign, "campaignid", true) == 0)
{
campaignId = Request[Convert.ToString(objCampaign)];
break;
}//END IF
}//END FOREACH
/* ---------------------------------------------------------------------- */
Huh. Well, that's one way to do a Request.QueryString["campaignid"] lookup.
by Jon Sagara
August 31, 2008 at 8:29 PM
You get sloppy and write something like this:
if (string.IsNullOrEmpty(campaignId))
{
throw new Exception(string.Format("Missing campaign ID in the query string: {0}", campaignId));
}
D'oh.
4044654a-5e20-422f-be35-3dec152c4dfb|0|.0
Tags: wtf
Blog
by Jon Sagara
August 21, 2008 at 10:33 AM
Dear fellow coders,
Please don't ever do this:
private static void SomeFunc()
{
try
{
DoSomething();
DoSomethingElse();
}
catch
{
// eat the exception <-- NO! BAD CODER!
}
}
Love,
Jon
f496fa52-ed83-439a-baf0-a253cc0efab5|1|5.0
Tags: wtf, .net
Blog
by Jon Sagara
March 11, 2008 at 12:45 PM
To their credit, I was actually able to sign back in and complete my registration without a hitch, but, still, I expect much more from a large financial institution that handles my investments.
8668dc7a-0f5a-4af2-a9fd-3159ae638402|0|.0
Tags: wtf
Blog