Archive for October 5th, 2009

Kirstin Juhl

I am a former engineer who writes code. I did Toyota Operating System, Kanban, and Lean in my factories a decade ago, and am fascinated by its use in software development today. You can take the girl out of the factory, but you cannot take the engineer out of the girl, and so I approach everything in life as a problem to solved or optimized. Including software development. I strive to be a craftsman.

I am a mom, and I take lessons from parenthood into my work everyday.


Private Extension Methods

I spent a few hours on a failed experiment recently, but one concept that outlived the spike was how to make use of private extension methods. By private I mean the extension methods have a private access modifier and are only visible inside of a single class.

Sounds pointless, right?

Consider the code in the following class that is attempting to build multiple script tags out of the names of JavaScript files embedded as resources in an assembly.

public static class ScriptHelper
{
    public static string AsyncUploadScripts(this HtmlHelper helper)
    {
        var scriptNames = new string[] 
        {
            "Baz.Biz.js",
            "Bar.Foo.js",
            "Foo.Bar.js"
        };

        return scriptNames
            .Select(name =>
                _manager.GetWebResourceUrl(typeof(ScriptHelper), name))
            .Select(url => String.Format("... src='{0}' ...", url))
            .Aggregate(new StringBuilder(),
                       (sb, tag) => sb.Append(tag),
                        sb => sb.ToString());                          
    }

    // ...
}

That LINQ query is not pretty. Something with ON ERROR GOTO statements would be easier on the eyes.

I thought it would be nice if I could have descriptive names for the operations being performed. But, I didn’t want to create new extension methods for use outside the query.

Fortunately, extension methods as static private members work well inside the same class.

public static class ScriptHelper
{
    public static string AsyncUploadScripts(this HtmlHelper helper)
    {            
        var scriptTags = GetScriptResourceNames()
                            .MapNamesToResourceUrls()
                            .MapUrlsToScriptTags()
                            .CombineScriptTags();
        return scriptTags;                                              
    }

    static string CombineScriptTags(this IEnumerable<string> tags)
    {
        return tags.Aggregate(new StringBuilder(),
                    (sb, tag) => sb.Append(tag),
                    sb => sb.ToString());  
    }

    static IEnumerable<string> MapUrlsToScriptTags(
                                    this IEnumerable<string> urls)
    {
        return urls.Select(url =>
            String.Format("... src='{0}' ...", url));
    }

    static IEnumerable<string> MapNamesToResourceUrls(
                                    this IEnumerable<string> names)
    {
        return names.Select(name =>
                _manager.GetWebResourceUrl(typeof(ScriptHelper), name));
    }

    static IEnumerable<string> GetScriptResourceNames()
    {
        return new string[]
        {               
            "Baz.Bif.js",
            "Foo.Bar.js",
            "Zak.Wak.js",
        };            
    }

    // ...

The code is now in the junk pile, but the idea will stick with me forever … or at least until I switch to something else.


Flash on Devices

Flash on Iphone: Flash Professional CS5 will enable you to build applications for iPhone and iPod touch using ActionScript 3. These applications can be delivered to iPhone and iPod touch users through the Apple App Store.* http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/ http://www.youtube.com/watch?v=kusXgPAmMLw Flash10 on...

Video: New CodeRush Plugin To Collapse Long Methods

Check out this short seven minute CodeRush plugin screencast with Rory Becker. The screencast explains:

  • What is DX_CollapseFromEnd?
  • How do you use it?
  • How was it built?

Rory is not just an avid fan of CodeRush but he’s an extraordinary plugin developer too. Not only has he developed several plugins but also goes the extra mile to help others learn about CodeRush and refactoring.

Click the image below and watch the full screencast. Then drop me and Rory a line below with your thoughts.

Video: CodeRush Plugin - Collapse From End


Flash Catalyst Beta 2: New Features

With the release of the Flash Catalyst Beta 2, the public gets its next look at Adobe’s rapid prototyping tool. The application has continued to mature since the last release. Here is a brief rundown of some of the features...

  • Sponsored Links

  •  

  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress