﻿<?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>Binoj Antony commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>bool isJohnGalt = this.WhoIsJohnGalt();
  
if (isJohnGalt.Equals(true))
  
  //do something
  
  
//better still
  
 if(isJohnGalt = true)
  
  //do something more
  
  
//yet another one
  
Customer item = new Customer();
  
while (reader.Read())
  
{
  
  item.IsJohnGalt = reader.GetBoolean(0);
  
  item.CustomerCode = reader.GetInt32(1);
  
  item.Name = reader.GetString(2);
  
 }
  
return item;
  
  
//Most common one -  same as vjd pointed out earlier doing a ToString to something that is already a string
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment65</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment65</guid><pubDate>Mon, 02 May 2011 07:07:50 GMT</pubDate></item><item><title>Gavin commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>public void DoStuff()
  
{
  
   // ... 
  
   return; // &lt;- Really?
  
}
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment64</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment64</guid><pubDate>Thu, 21 Apr 2011 08:37:56 GMT</pubDate></item><item><title>Winston commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>I like a lot this boolean redundancy like:
  
  
if (!confirm('A senha será cancelada, confirma?')) {return false;};
  
  
Or
  
  
bool validUser = Service.ValidateUser(Username, Password);
  
if (!validUser)
  
{
  
    return false;
  
}
  
return true;
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment63</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment63</guid><pubDate>Tue, 19 Apr 2011 15:32:45 GMT</pubDate></item><item><title>James_2JS commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>This little golden nugget was written by a contract developer earning a fairly decent daily rate. Needless to say he has gone!!
  
  
Private Function DoesFileNameStartWithATimeStampValue(ByVal FName As String) As Boolean
  
  
        Try
  
  
            'this function returns true if the first 4 characters of fname are a valid year (from 1900 to 100 years from the current year)
  
  
            'and if the next 2 characters are between 1 and 12 (month) and if the next 2 characters are between 1 and 31 (days of month)
  
  
  
  
            Dim result As Boolean = False
  
  
  
  
            If FName.Length &gt; 14 Then
  
  
                'these checks are to make sure that the leftmost characters are a timestamp value. eg "20110222152115" 
  
  
                If Microsoft.VisualBasic.IsNumeric(FName.Substring(0, 14)) Then
  
  
  
  
                    Dim YearValue As Integer = CInt(FName.Substring(0, 4))
  
  
                    Dim YearNumber As Integer = 1990  'start from 1990 years back
  
  
  
  
                    Do Until YearNumber &gt; System.DateTime.Now.Year + 100
  
  
  
  
                        If YearValue = YearNumber Then
  
  
  
  
                            Dim MonthsValue As String = FName.Substring(4, 2)
  
  
                            Dim Months As Integer = 1
  
  
  
  
                            Do Until Months &gt; 12
  
  
  
  
                                ' (Months).ToString("00")  eg 0 = 01
  
  
  
  
                                If (Months).ToString("00") = MonthsValue Then
  
  
  
  
                                    Dim DaysValue As String = FName.Substring(6, 2)
  
  
                                    Dim Days As Integer = 1
  
  
  
  
                                    Do Until Days &gt; 31
  
  
  
  
                                        If (Days).ToString("00") = DaysValue Then
  
  
  
  
                                            result = True
  
  
                                            Exit Do
  
  
  
  
                                        End If
  
  
  
  
                                        Days += 1
  
  
                                    Loop
  
  
  
  
                                    If result Then Exit Do
  
  
  
  
                                End If
  
  
  
  
                                Months += 1
  
  
                            Loop
  
  
  
  
                            If result Then Exit Do
  
  
  
  
                        End If
  
  
  
  
                        YearNumber += 1
  
  
  
  
                    Loop
  
  
  
  
  
  
                End If
  
  
  
  
            End If
  
  
  
  
            Return result
  
  
  
  
  
  
        Catch ex As Exception
  
  
            Return False
  
  
        End Try
  
  
  
  
    End Function
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment62</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment62</guid><pubDate>Tue, 19 Apr 2011 11:04:09 GMT</pubDate></item><item><title>Matt Freeman commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Seen a few good ones. 
  
  
// we need to wait for middleware server for 5 seconds
  
DateTime currentTime = DateTime.Now
  
while((DateTime.Now - currentTime).TotalSeconds &lt; 5) {
  
  
}
  
  
(or something to that effect, not tested). This made it to production server on one of most popular price comparison sites a few years ago, debugging 100% cpu kept the team going for while. One of the guys found it so funny he printed and framed it, but he was on the other side of the office so the victim was none the wiser. 
  
  
Also someone decided to reinvent HtmlEncode and UrlEncode, inlined in same class doing the web scraping of course. 
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment61</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment61</guid><pubDate>Sun, 17 Apr 2011 11:45:07 GMT</pubDate></item><item><title>Chen Kinnrot commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>I got a good one
  
  
If(UserID == 123)
  
{
  
  UserID = 321;
  
}
  
//... continue login process with a different user. I wonder what will happen on prod...
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment60</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment60</guid><pubDate>Sat, 16 Apr 2011 15:44:12 GMT</pubDate></item><item><title>Arturo Molina commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>This was actually in production for several years:
  
  
if(status == "Continue")
  
{
  
   if(status == "Cancel")
  
   {
  
      return;
  
   }
  
   //some logic
  
}
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment59</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment59</guid><pubDate>Sat, 16 Apr 2011 04:00:39 GMT</pubDate></item><item><title>Jorge Alves commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>@Steve py
  
  
I've seen your minor wtf a lot. People like to put a breakpoint in the throw; so that it stops there instead of crashing.
  
  
And yes, no one listens when I say there's an option to do that automatically.
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment58</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment58</guid><pubDate>Fri, 15 Apr 2011 22:37:28 GMT</pubDate></item><item><title>dave commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Several days ago I stumbled on this in our Silverlight application:
  
  
public SomeUserControl() {
  
try {
  
    InitializeComponent();
  
} 
  
catch(Exception) {
  
    InitializeComponent();
  
}
  
}
  
  
i found it so funny so I didn't touch this :)
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment57</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment57</guid><pubDate>Fri, 15 Apr 2011 19:49:30 GMT</pubDate></item><item><title>Mike Scott commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>I've seen this a lot in the last couple of years, often in Microsoft sample code and conference sessions!
  
  
  var a = b as C;
  
  a.SomeMethod();
  
  
It seems that this viral confusion started somehow. Someone in a trusted position probably wrote some code or issued some best practice advice that since  "as" is a "safe" cast which won't throw if it fails, it should be used instead of a regular typecast.
  
  
Then the likes of Scott Hanselman and Rob Conery started doing it.
  
  
NB: I can't be remember for sure that I saw this in either of these guys code, so I'm saying the *likes* of these guys ;)
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment56</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment56</guid><pubDate>Fri, 15 Apr 2011 16:48:20 GMT</pubDate></item><item><title>Steve G commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>bool isValid = false;
  
....
  
if (isValid == null)
  
{
  
    ...
  
}
  
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment55</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment55</guid><pubDate>Fri, 15 Apr 2011 10:41:24 GMT</pubDate></item><item><title>Jorgen commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>// Todo: Must fix
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment54</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment54</guid><pubDate>Fri, 15 Apr 2011 00:46:45 GMT</pubDate></item><item><title>Steve Wagner commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Another good one:
  
  
try{
  
  ....
  
}catch{
  
   MessageBox.Show("An error occured");
  
}
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment53</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment53</guid><pubDate>Thu, 14 Apr 2011 14:44:48 GMT</pubDate></item><item><title>Thomas Christensen commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Maybe this is more in the 'clearly the programmer does not understand pass by reference", but anyways:
  
  
public void ClearToken(Token token)
  
{
  
if (token != null) token = null;
  
}
  
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment52</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment52</guid><pubDate>Thu, 14 Apr 2011 14:33:12 GMT</pubDate></item><item><title>Chris Fisher commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>We had this lovely piece that made it into prod, for a short while until it was asked why it wasn't working. Of course it worked in dev/test where debug was enabled for logging and failed in prod where it was obviously set at error.
  
  
public void someMethod() {
  
  
....
  
....
  
    if (logger.debug.enabled == true {
  
  
       Logger.debug("some log message");
  
  
        Important business code here!!
  
  
     }
  
  
  
}
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment51</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment51</guid><pubDate>Thu, 14 Apr 2011 13:37:54 GMT</pubDate></item><item><title>Mark Porter commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Read this post and comments as I was reviewing some legacy code for a customer - not necessarily worthy of deadly sin status, but certainly worth a giggle.
  
  
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification =
  
      "'It can not be converted into a property as it needs an open connection and the one of the constructors" +
  
      " does not take connection as a parameter")]
  
public decimal GetSomeValueOrOther()
  
{//literally loads of code...}
  
  
Excuses, excuses excuses - just fix it already!
  
  
and of course within this very same method:
  
  
catch (Exception ex)
  
{
  
    Logger.Log("a looked up exception message");
  
     throw new UtterlyMeaninglessException(ex.Message);
  
}
  
  
names changed to protect the guilty of course.
  
  
Thanks for a good laugh!
  
  
  
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment50</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment50</guid><pubDate>Thu, 14 Apr 2011 11:54:58 GMT</pubDate></item><item><title>Reza commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>I saw this in a locked down TFS branch (accessible only by the architect)
  
  
public int GenericAddRecordToTableMethod(string SQL)
  
{
  
  // instantiate connection objects etc
  
  object result = SqlCommand.ExecuteNonQuery();
  
  
   return Convert.ToInt32(result.ToString());
  
}
  
  
The rest of the site had similar issues with boxing/unboxing and casting down to object
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment49</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment49</guid><pubDate>Thu, 14 Apr 2011 10:59:39 GMT</pubDate></item><item><title>Dominic Pettifer commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Fun with singletons:
  
  
public class MySingleton
  
{
  
    private static MySingleton _instance = null;
  
  
    private MySingleton() { }
  
  
    public static MySingleton GetInstance()
  
    {
  
        if(_instance == null)
  
        {
  
            // expensive initialisation logic that should only get called once here
  
        }
  
  
        return _instance;
  
    }
  
}
  
  
And this is in a heavily traffic'd web app :-)
  
  
PS: Ayende, formatting code in these comments is such a pain
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment48</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment48</guid><pubDate>Thu, 14 Apr 2011 09:13:22 GMT</pubDate></item><item><title>Fredrik M&amp;#246;rk commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>@Simon (4/13/2011 2:39 PM): so true: the class itself was not static, of course, but almost its members and state were static, so it effectively became a "use-once-per-process" type.
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment47</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment47</guid><pubDate>Thu, 14 Apr 2011 08:59:09 GMT</pubDate></item><item><title>Gian Maria Ricci commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>SomeClass instance = new SomeClass();
  
instance = FunctionThatReturnSomeClass(); 
  
  
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment46</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment46</guid><pubDate>Thu, 14 Apr 2011 08:15:01 GMT</pubDate></item><item><title>Steve Wagner commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>+1 for:
  
  
if ( sthThatEvaluatesToBool( args) ) {
  
return true;
  
} else {
  
return false;
  
} 
  
  
and saw:
  
  
class FooViewModel
  
{
  
  public void Show(ViewModelBase viewModel)
  
  {
  
     if(viewModel.GetType().Name == "OrderViewModel")
  
       do something;
  
     if(viewModel.GetType().Name == "InvoiceViewModel")
  
       do something;
  
  }
  
}
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment45</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment45</guid><pubDate>Thu, 14 Apr 2011 07:36:00 GMT</pubDate></item><item><title>Me commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>@Fredrik
  
  
How is it possible you've seen this in production c ode?
  
  
public static class WhatEver : IDisposable
  
{
  
// code
  
}
  
  
This would be a compile time error... static classes cant implement interfaces... 
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment44</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment44</guid><pubDate>Thu, 14 Apr 2011 02:51:06 GMT</pubDate></item><item><title>fschwiet commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>@Tony
  
  
Of the original 7 deadly sins, from the Bible, I don't think any of them were actually deadly in an immediate sense.  In fact, a few of them are quite enjoyable.  Likewise, so are the deadly sins I've listed for programmers.
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment43</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment43</guid><pubDate>Thu, 14 Apr 2011 00:11:05 GMT</pubDate></item><item><title>Adam Langley commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>// C# .net code
  
Application.DoEvents();
  
  
  
  
NOOOOOOOOOOOO!!!! THE MOST EVIL METHOD EVER WHEN USED ON A PLATFORM THAT FULLY SUPPORTS ADVANCED THREADING!!!
  
  
Debugging re-entrancy issues due to this old chestnut has consumed much of my life I will never get back.
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment42</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment42</guid><pubDate>Thu, 14 Apr 2011 00:04:43 GMT</pubDate></item><item><title>Adam Langley commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>public class SomeWrapper : IDisposable
  
{
  
  private AnotherDisposableResource _resource = null;
  
  public SomeWrapper(AnotherDisposableResource resource)
  
  {
  
    this._resource = resource;
  
  }
  
  
  public void Dispose()
  
  {
  
    // does nothing!! ARGH!
  
  }
  
}
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment41</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment41</guid><pubDate>Thu, 14 Apr 2011 00:02:07 GMT</pubDate></item><item><title>Russell Wilson commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>Just lazy... only writing 3 out of 7.
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment40</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment40</guid><pubDate>Wed, 13 Apr 2011 23:25:22 GMT</pubDate></item><item><title>Steve Py commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>- Any time I see commented out code checked in.
  
- 95% of times I see a Singleton or static class added.
  
- Most times I see a class "newed" in-line.
  
- Just about any comment generated by GhostDoc. (As being either completely pointless, or completely missing the point.)
  
I.e:
  
       /// 
&lt;summary  
        /// Gets the name of the unique.
  
        /// 
&gt;  
        /// 
&lt;typeparam&gt;  
        /// 
&lt;paramThe list.
  
        /// 
&lt;paramThe propname.
  
        /// 
&lt;paramThe name.
  
        /// 
&lt;paramThe prefix.
  
        /// 
&lt;returnsthe unique name
&gt;  
        public string GetUniqueName
&lt;t(IEnumerable
&lt;t list, string propname, string name, string prefix = "")
  
  
  
  
A minor "wtf":
  
try
  
{
  
  // Do stuff
  
}
  
catch
  
{
  
  throw;
  
}
  
 literally around every block of code. (Some kind of weird template.)
  
  
&gt;</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment39</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment39</guid><pubDate>Wed, 13 Apr 2011 22:57:29 GMT</pubDate></item><item><title>Tony commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>@frank
  
  
Why is deadly? It's just unnecessary code which runs fine without possible errors?
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment38</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment38</guid><pubDate>Wed, 13 Apr 2011 20:36:44 GMT</pubDate></item><item><title>Pedro J. Molina commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>I swear I saw this in an application having multi-language as one of the main requirements:
  
  
if (language="en")  { return "Hello"; }
  
else if (language="es")  { return "Hola"; }
  
//and so on... for each string literal. 
  
  
Now, try to add a new language... and search for this code in all of your application. My eyes are still crying after seeing this. =8-O
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment37</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment37</guid><pubDate>Wed, 13 Apr 2011 20:14:23 GMT</pubDate></item><item><title>Nadav commented on The seven deadly sins for the developer (* some restrictions apply)</title><description>foreach (x in collection1) // ~ 3000 instances
  
   foreach (y in collection2) ~ 7 instances
  
      foreach(z in collection3) ~ 3 instances
  
            var results = do query by y and z
  
  
talk about N^3+1 :)
  
notice that the query doesn't depend on x
</description><link>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment36</link><guid>http://ayende.com/4810/the-seven-deadly-sins-for-the-developer-some-restrictions-apply#comment36</guid><pubDate>Wed, 13 Apr 2011 20:09:50 GMT</pubDate></item></channel></rss>