Non (Coding Standards)

 

What do you say when you see this code?

 
Console.WriteLine(((ThirdEnum)(new Task<string>(() => 
{ 
    return ((FirstEnum)((Func<string>)(() => 
    { 
        return "Hello World"; 
    })).Invoke().Invoke()).Invoke(); 
})).Await().ContinueWith((@string) => 
{ 
    return ((SecondEnum)(@string.ContinueWith((@return) => 
    { 
        return ((FirstEnum)(@return.Result.Invoke() + 3)).Invoke(); 
    }).Result.Invoke())).Invoke(); 
}).GetAwaiter().GetResult().Invoke()));

Console.ReadKey();
 
namespace ConfusingCode
{
    public static class Things
    {
        public static int Invoke(this string invokedItem)
        {
            lock (Program.key)
            {
                Console.Write(invokedItem.Length == 1 ? invokedItem + (invokedItem == ((SecondEnum)invokedItem.Length - 1).Invoke() ? invokedItem : "") : "");
            }
            return invokedItem.Length > 0 ? 0 : 0;
        }
        public static Task<string> Await(this Task<string> taskToAwait)
        {
            taskToAwait.Start();
            return taskToAwait;
        }
        public static string Invoke(this FirstEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this SecondEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this ThirdEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this Enum @enum)
        {
            return @enum.ToString();
        }
    }
    public enum FirstEnum
    {
        P = 0,
        I = 3,
    }
    public enum SecondEnum
    {
        Z = 0,
    }
    public enum ThirdEnum
    {
        A = 0
    }
}

And what should be added to the coding standards in order to not permit this … code ?
( Credits to Stefan Petrini for the code )


Posted

in

by

Tags:

Comments

3 responses to “Non (Coding Standards)”

  1. Tudor Avatar
    Tudor

    One question: the names for the various enums, classes and methods are the real ones, or they were ‘anonymized’? 🙂
    Other than that, what can you add to coding standards?
    ‘don’t go drunk to the office’
    or ‘the code should be understandable by humans too’
    🙂

    1. Andrei Ignat Avatar
      Andrei Ignat

      This was an example from the most twisted programmer that I know: Stefan Petrini .

      1. Tudor Avatar
        Tudor

        Never heard of him.. And if the code really was the one above, I wouldn’t call this “twisted”, but just plain bad/obfuscated on purpose programming.

Leave a Reply

Your email address will not be published. Required fields are marked *