Douglas Adams on teaching programming

What I mean is that if you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your own mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that’s really the essence of programming. By the time you’ve sorted out a complicated idea into little steps that even a stupid machine can deal with, you’ve certainly learned something about it yourself. The teacher usually learns more than the pupil. Isn’t that true?

Douglas Adams in Dirk Gently’s Holistic Detective Agency

Work Ethic

You should plan on working 60 hours per week. The first 40 are for your employer. The remaining 20 are for you. During this remaining 20 hours you should be reading, practicing, learning, and otherwise enhancing your career.

Robert Martin in Clean Code

I’m not a great programmer; I’m just a good programmer with great habits.

Kent Beck

Enum friendly names via DisplayAttribute and DescriptionAttribute – MVC 5 edition

Are you using enums in dropdowns or radiobuttons or something similar? Instead of hard coding display names, a way of reusing these names was coined in the MVC 3 days that involved decorating the enum with the DescriptionAttribute. Judging from posts on stack overflow, this was a very popular method.

When MVC 5 came out, it included new helpers for Enums (which was fantastic). However, MS used the typical DisplayAttribute (the DisplayAttribute.Name property to be exact) instead of the DescriptionAttribute to pull this off.

I wrote an Enum extension method that attempts to grab the name from both of these attributes. This method should work great with legacy and the newer MVC apps.

Keep in mind, that it is probably best to be consistent and use only DisplayAttribute in future projects, as this basically deprecates the DescriptionAttribute method but this could be useful for legacy projects that have been updated to MVC 5.

public static class ExtensionMethods
{
    /// <summary>
    /// Returns friendly name for enum as long as enum is decorated with a Display or Description Attribute, otherwise returns Enum.ToString()
    /// </summary>
    /// <param name="value">Enum</param>
    /// <returns>Friendly name via DescriptionAttribute</returns>
    public static string ToFriendlyName(this Enum value)
    {
        Type type = value.GetType();

        // first, try to get [Display(Name="")] attribute and return it if exists
        string displayName = TryGetDisplayAttribute(value, type);
        if (!String.IsNullOrWhiteSpace(displayName))
        {
            return displayName;
        }

        // next, try to get a [Description("")] attribute
        string description = TryGetDescriptionAttribute(value, type);
        if (!String.IsNullOrWhiteSpace(description))
        {
            return description;
        }

        // no attributes found, just tostring the enum :(
        return value.ToString();
    }

    private static string TryGetDescriptionAttribute(Enum value, Type type)
    {
        if (!type.IsEnum) throw new ArgumentException(String.Format("Type '{0}' is not Enum", type));

        string name = Enum.GetName(type, value);
        if (!String.IsNullOrWhiteSpace(name))
        {
            FieldInfo field = type.GetField(name);
            if (field != null)
            {
                DescriptionAttribute attr = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
                if (attr != null)
                {
                    return attr.Description;
                }
            }
        }

        return null;
    }

    private static string TryGetDisplayAttribute(Enum value, Type type)
    {
        if (!type.IsEnum) throw new ArgumentException(String.Format("Type '{0}' is not Enum", type));

        MemberInfo[] members = type.GetMember(value.ToString());

        if (members.Length > 0)
        {
            MemberInfo member = members[0];
            var attributes = member.GetCustomAttributes(typeof(DisplayAttribute), false);

            if (attributes.Length > 0)
            {
                DisplayAttribute attribute = (DisplayAttribute)attributes[0];
                return attribute.GetName();
            }
        }

        return null;
    }
}

Using SQL Server Reporting Services (SSRS) in an ASP.NET MVC project

There are a handful of examples out on the internet on how to use SSRS from an ASP.NET website but all of the ones I came across seemed like hacks. They range from throwing an ASPX page with a ReportViewer control to complex JavaScript hacks. The following method is the one I have used for many years that adheres to the true MVC manner. This method connects to SSRS through the web service using Microsoft.Reporting.WebForms assembly.

Continue reading

Podcasts you should listen to right now

Programming Related Podcasts

  • This Developer’s Life – Podcast in the style of This American Life dealing with programming related topics. An all time favorite of mine.
  • Hanselminutes – Scott Hanselman talks about web development, usually dealing with C#, javascript, ASP.NET, and other MS technologies.
  • Herding Code – K Scott Allen, John Galloway, and others talk about programming topics.
  • Programming Throwdown – The hosts pick a random technology and give you a broad overview of it followed by its advantages and disadvantages.
  • Floating Point – News, tech, programming, random topics are discussed.
  • Javascript Jabber – The JavaScript frameworks that are released approximately 20 minutes are discussed here.
  • Developer Tea – Podcast covering a diverse amount of topics relating to being a developer.
  • Iterate – UX, design, and related ideas are discussed in this podcast.
  • Debug – Mobile development is discussed in depth, mostly on iPlatforms.
  • /dev/hell – Uncensored ramblings of two insane developers.

Hall of Fame – My favorite non-programming podcasts

  • 99% Invisible – The best podcast ever? Short, well produced episodes dealing with design.
  • TED Radio Hour – TED Talks are a must.
  • Radiolab – The best production of any podcast ever made. Interesting and seemingly random discussions.
  • This American Life – I think this has been cited as the most popular podcast ever until Serial came along… which was also created by them.
  • Reply All – Random things relating to the internet are discussed. Gimlet Media is worth paying attention to as every podcast they release is solid gold.
  • Startup – A podcast documenting company creation from brainstorming, soliciting investors, creating a startup, running it, and more. Interesting look at something not normally public.
  • Freakonomics – Economists can be interesting too.
  • You Are Not So Smart – Self delusion… and cookies?

MSI Web Setup Project Error: Unable to build project output group ‘Content Files from SOMEWEB (Active)’

I stumbled onto this error and thanks to Scott Hanselman’s blog I was able to find a solution to it.

The only problem? My project had a TON of files marked as Content (such as multiple versions of angular) and I didn’t want to spend all morning going through the countless folders to figure out which files were missing in order to resolve the conflict. If only Visual Studio has some way to verify this and let you know which files were missing…

Oh wait, it does! Its just buried and very difficult to find.

You can get visual studio to display all these “yellow icon” missing files by using the Publish Solution option. For those of you unfamiliar with the publish wizard, here is what I did:

  • Right Click your website project and click publish.
  • On the publish wizard that pops up, select Custom and type in any name for the profile.
  • For publish method, I selected File System and chose a directory to publish to.
  • Click the Publish button and it will error and show you exactly which files were missing. You may have to do this multiple times until you get all the missing files resolved.

Savarez Cristal Corum High Tension 500CJ String Review

I recently bought a brand new Cordoba classical guitar. I am extremely happy with my purchase and would recommend this guitar a thousand times over. My only problem with it is the Savarez Cristal Corum High Tension 500CJ strings that came stock on the guitar.

https://www.stringsbymail.com/images/medium/SAVAREZ500CJ_MED.jpg

The good
On the plus side, these strings seem to settle in and stay in tune much faster than other ones I have tried. Perhaps this was done on purpose by Cordoba to ensure that floor models of their guitar would always sound great when picked up and played by a shopper.

The bad
These strings seem to wear down very quickly. They can be hard to press down since they are so stiff. The trebles are very dull and it only becomes more noticeable the more you play on them. Also, the price for these things can be steep compared to popular D’Addario ones.

The ugly
After owning the guitar for a month or so and playing for a few hours each night, the strings seemed to rapidly degrade. They barely respond when I am playing now, especially hammer-ons and pull-offs which are now much harder to get proper timbre from. All in all, I would not recommend these strings.