Article :: Programming the Windows Script Host

Paul McFedries shows how to execute scripts and runs through the various elements in the Windows Script Host object model.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Article :: More Effective C#: Item 36: Understand How Query Expressions Map to Method Calls

Learn to understand this mapping from two different perspectives: From the perspective of a class user and as a class designer.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Article :: LINQ Query Expressions

Learn seven different types of query expression clauses and explains the four ways in which they introduce range variables.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Common Interfaces for Tool Families

There are a load of different tool "families" in use in the .NET ecosystem which I'm sure LosTechies readers will take advantage of pretty much every day. IoC containers. Logging infrastructures. URL routing mechanisms. Each of these families operate on broadly similar principals - taking the container example, we know that we need to add types to the container and resolve types which are already in there. For logging, we'd generally have the ability to log to different levels of severity. So you can see that while the implementations and underlying behaviour may be significantly different, there is a layer of abstraction which highlights commonality.

Castle Project has a Castle.Core.Logging.ILogger class which supports the use of a variety of different logging systems within your applications. It is a facade behind which log4net or NLog does the magic while your application happily logs information while not worrying about what is actually taking care of the logging. To me, this is a very interesting method of supporting a tool family - expose the most common methods which a tool supports and let the tool get on with its own business.

What I'd like to see is a community effort to publish an ILogger interface to which various logging libraries can adhere, and an IContainer interface for IoC libraries, and other interfaces for various tool families which have enough common features. In this way, we can enable a new level of code sharing and integration between projects.

(Also published on my personal blog)



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
HR-XML Integration in Human Resources Software

Most of the programming and architecture work I do is in the human resources space. I write software for paperless onboarding and acculturation, personell change management, background checks and verification services, new employee requisitioning, and the like. As you can imagine, I spend a great deal of time and effort integrating with human [...]

Categories: Agile Programming | Computer Humor | Computers | CSharp | Dot Net | Emerald Software Group | Humor | Onboarding | Patrick Caldwells Blog | PHP | Programming | Project Management | Service Oriented Architecture | SOA | SQL Server | Technology | Web Development | Web Services | Windows Programming
Article :: Delegates and Lambda Expressions in C# 3.0

Mark Michaelis discusses the use of methods as a data type and their support for publish-subscribe patterns in this chapter.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Adventures In Lean

In the last six months, my team has undergone some very radical changes and has turned into a full blown Agile team. I'm very happy with our success and I consider this team to be the shining example in our company, at the moment.

Now, in keeping with the tradition of this team in changing at least one thing every few weeks, we are about to embark on a new journey in our project management processes: Lean Software Development.

Starting at 1pm, Central Time, today, my team will be kicking off the following processes:

I am going to be posting a series of entries on each of these specific items over the next few weeks, and will most likely keep this post updated as the index of entries for a while. So stay tuned for a whirlwind of opinionated posts on our next great experiment!

Table Of Contents For Adventures In Lean

Here are the articles that I have written or am writing for my Adventures In Lean series:

  1. Kanban - Pulling Value From The Supplier - In this post, I am laying the foundation of what Kanban is along with a couple of other important terms that I will be using throughout the series
  2. We're Going Kanban - Learning To Pull Value Through Our Development Process
  3. Release Per Feature - Delivering Value As Soon As Possible
  4. Just In Time Retrospectives - Fixing Problems As Problems Occur

There are likely to be other articles added to this list as well. Please check back now and then to see what has been added!



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Functionally dynamic?

I was just playing with this tonight, but I don't know it's worth anything.  I thought of it after some conversations with Matt Podwysocki back at KaizenConf on how do apply some functional ideas in C#.  First, I started with a simple class:

public class OriginalProduct
{
    public decimal Price { get; set; }
    public decimal Cost { get; set; }

    public decimal CalculateProfit()
    {
        return Price - Cost;
    }
}

To do anything interesting, functional-wise, like swapping implementations or doing things like decorators is annoying or impossible.  But if I went this (albeit weird) direction:

public class Product
{
    public decimal Price { get; set; }
    public decimal Cost { get; set; }

    public Product()
    {
        CalculateProfit = calculateProfit;
    }

    public Func<decimal> CalculateProfit { get; set; }

    private decimal calculateProfit()
    {
        Console.WriteLine("Calculating profit");
        return Cost == 0 ? 0m : Price - Cost;
    }
}

Yes, weird.  But tests look rather normal, except a function is a property:

[Test]
public void No_change()
{
    var product = new Product {Price = 11, Cost = 10};

    product.CalculateProfit().ShouldEqual(1m);
}

Because you can invoke delegate instances directly, it looks like I'm calling a function on the type.  I can do some interesting things with some simple decorator extensions:

public static class DelegateExtensions
{
    public static Func<T> Before<T>(this Func<T> func, Action before)
    {
        return () =>
                   {
                       before();
                       return func();
                   };
    }
    public static Func<T> After<T>(this Func<T> func, Action after)
    {
        return () =>
                   {
                       T value = func();
                       after();
                       return value;
                   };
    }
}

And now I can decorate my the functions at will:

[Test]
public void Decorator_fun()
{
    var product = new Product { Price = 11, Cost = 10 };

    product.CalculateProfit =
        product.CalculateProfit
                .Before(() => Console.WriteLine("Before"))
                .After(() => Console.Write("After"));

    product.CalculateProfit().ShouldEqual(1m);
}

This outputs:

Before
Calculating profit
After
1 passed, 0 failed, 0 skipped, took 1.05 seconds.

That's just some simple decorator implementation.  Finally, I can swap out implementations at runtime:

[Test]
public void Straight_up_replacement()
{
    var product = new Product { Price = 11, Cost = 10 };

    product.CalculateProfit = () => 1500;

    product.CalculateProfit().ShouldEqual(1500m);
}

It's still not dynamic typing, as I can't add new members at runtime.  I have no idea if this is useful or not, as the structure is rather weird, and you'd need to do some interesting things to get polymorphism in play.  But, it might have some interesting applications in some strange scenario.



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Where TDD fails for me

TDD is by far the sharpest tool in my belt.  The simplicity of client-driven design combined with the safety net of unit tests allow me to build software at a remarkable constant pace.  At the edges of most of the applications I've worked on are areas where TDD has completely fallen flat on its face (for me).  It's a little disheartening when these areas are always around frameworks that I can't change.  These are areas where adding unit tests provides coverage, but completely fails in the "tests as documentation" category.  Or, it's in an area where testing is difficult or impossible, regardless of the available tools at your disposal.

My current TDD failures are around NHibernate and ASP.NET MVC, but they both center around a common theme – I'm deep in the extensibility points of someone else's framework.  These frameworks offer great extensibility points, but often at the cost of the final result making any sense whatsoever.  Perhaps it's how I practice TDD, as I like to start on the outermost visible behavior, and let client-driven code direct the design underneath.  Often the outermost behavior leaves little point to TDD internal implementation details.  Other times, the outermost visible behavior is voodoo to get set up, and verification impossible for the next developer to understand.

Example 1 – Extensibility through inheritance

In NHibernate, mapping from types to the database at the property level is done through a set of IType implementations.  These mappings provide the logic to map from System.Decimal to something out of an IDataReader.  Often, we need to provide custom mapping types to do things like map values from enumerations, custom Value Object types, or dealing with legacy databases.  NHibernate is fantastic in that regard, as there has not been a problem I've thrown at it that I haven't been able to solve with an obvious extensibility point.  Side note – this is common with good OSS frameworks – feedback from the community funnels back in to further refine the design.

The one issue with these extensibility points is that it is completely non-obvious to unit test one of these implementations.  Here's one example of an implementation:

public class DummyCustomType : PrimitiveType
{
    public DummyCustomType()
        : base(new SqlType(DbType.String))
    {
    }

    public override object Get(IDataReader rs, int index)
    {
        var o = rs[index];
        var value = o.ToString();
        return value;
    }

    public override object Get(IDataReader rs, string name)
    {
        int ordinal = rs.GetOrdinal(name);
        return Get(rs, ordinal);
    }

    /* etc etc etc */
}

Blah blah blah.  I can TDD individual pieces, but notice that I'm inheriting from PrimitiveType – an NHibernate extensibility point.  But are unit tests valuable here'?  I think not, as the true test as to whether this custom type works is in the context of where it is used – NHibernate.  Instead of testing the individual class, I'll define the behavior I want against NHibernate, usually by loading up entities that match up to the scenarios I'm interested in.

So it's very rare that I TDD an extensibility point driven through inheritance.  The voodoo going on underneath in the base type would put too much knowledge into the test of an implementation that I can't often see without Reflector, so where is the value?  I don't really see any.  Some of the pieces I have to implement I don't even know why I need, so I leave "throw new NotImplementedException" in, and wait for my application to blow up and tell me why I need that piece.  It's another reason I see 100% coverage as a goal that has to be balanced against other concerns.

In cases of extensibility through inheritance, it's only the macro behavior I care about.  I could care less how the specific extensibility is used – all I care about is that the eventual result of my cog in the giant machine works as specified.

Example 2 – Thorny observations

How do I TDD a custom WebForms control?  Or an ASP.NET MVC ActionFilterAttribute?  I know I can create the crazy dependencies required – such as the ActionExecutingContext – but what exactly is this telling me?  The final result, or verification, is the action filter plugged in to the complete pipeline.  Otherwise, I'm only verifying that it's doing exactly what I told it to do – not what I need it to do.  In domain model specifications, I describe how I want the model to behave under specific conditions.  I could TDD this:

public class AdminRoleFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (filterContext.HttpContext.User.IsInRole("Administrator"))
        {
            filterContext.Result = new RedirectResult("/unauthorized");
        }
    }
}

But honestly, only after a spike.  And if I did spike this, how would I get back here?  TDD would lead to a big disconnect between what I was verifying (that some Result is set under certain conditions) and what I actually want to happen.  TDD'ing this part requires knowledge of how the final result is used, leaving the eventual maintainer of the code to guess that this result hopefully has the desired effect.

What I'd really like to verify is that a user gets redirected when they are not an administrator.  However, I have to poke around a lot of framework pieces to get that.  I understand those actions are part of using a framework, but it's up to the next developer to make the jump that hopefully, I did my homework and that setting that Result to that value will have the desired end behavior.  End behavior I can't test easily, as it's really a browser-level interaction test.

I usually still TDD these scenarios, but only after a spike.  And all I'm really doing is TDD'ing back to the point where I knew things were working in my prototype.  At that point, I still do manual, one-time-only verifications that what I did actually created the behavior I wanted.  Because the unit tests didn't really do that, they just verified I'm using the framework in the way I specified.

Whack-a-mole

In the end, I've noticed my tests around framework interactions have the least amount of value.  They definitely have value, but the act of TDD is severely stunted as I'm playing by someone else's rules.  I can verify my little cog behaves exactly how I specify in isolation, but that's pointless if it fails when inserted back into the big machine.  Sometimes I can verify the output of the big machine, as in NHibernate, and sometimes it's very difficult, or slow, as in ASP.NET MVC's example (and other web frameworks).

Not only do these tests have less value, but they tend to be far more brittle than tests against POCOs, or even services where I have the Dependency Inversion Principle in play.  I create some custom NHibernate type, hooray!  But what about the dozen other scenarios for legacy data I don't know about?  Or, when the only true verification is a manual or slow verification of an ASP.NET MVC implementation detail?

The unit tests themselves still provide value, but even tools like TypeMock wouldn't solve the issue.  The issue isn't that I can't mock the framework, it's that the framework in action is the only true verification of the intended behavior.  I'm not getting nearly as much, if any, client-driven design benefits when TDD'ing framework extensibility points.



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: More Effective C#: Item 29: Enhance Constructed Types with Extension Methods

Bill Wagner shows how you can create a set of extension methods on specific constructed types to implement that functionality in a very low impact way.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Programmers are not typists first

Jeff Atwood had a recent post that coders are typists first, programmers second:

Steve [Yegge] and I believe there is nothing more fundamental in programming than the ability to efficiently express yourself through typing. Note that I said "efficiently" not "perfectly". This is about reasonable competency at a core programming discipline.

I'm in the camp that I believe that anyone that touches a computer more than once a month should take a basic typing course.  But programmers as typists first?  I did some math on a recent 6 month project, and found that we averaged around 50-70 lines of code per developer per day.  Typing is important to me as a developer, but I still type far more during the course of a given week writing these ridiculously boring, narcissistic blog posts, emails, and the book.

What's more, the typing skills I do have don't really help out in the course of the day for those 50-70 lines I do write.  I code in C#, which means at least half the characters I do have to type are:

  • {
  • }
  • <
  • >
  • (
  • )
  • ,

Almost all of which require the shift key and some hand gymnastics to get around.  C# certainly isn't nearly as wrist-friendly as other languages, but it's not the most verbose either.

Still, not even most of my keystrokes in Visual Studio are dedicated to typing code.  I have no data to support this, but it seems like half the keystrokes go to a lot of ReSharper shortcuts and a couple Visual Studio ones.  The ReSharper shortcuts still make exclusive use of the Ctrl, Alt and Shift key in various combinations with other keys.  Again, I'm not typing words, but performing key chord combinations.

While typing is important, I'd still say learning design and OO are far more fundamental than typing.  But being a good typist won't really improve your programming much.  If you're typing so much that your typing skills are holding you back as a developer, I'd say you're creating waaay too much code.  That much code is rife with duplication, and you're not doing enough thinking, designing and analyzing.  With ReSharper, my ability to create code is as optimized as it can be.  There are still improvements to be made, but typing was never what held me back coding.

If you have to touch a computer, yes, learn to type.  But let's not get carried away that we are typists first, programmers second.  We're thinkers first, coders second.



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Please caption this photo

(hat tip: Tim Barcz for the idea of making this Slide #1 on all my slide decks henceforth)

staple



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Who do you wanna Jott? Twitter

So I recently started twittering... or tweeting. I'm not sure what the correct lingo is, so hook me up if you know. It all started a while back when James announced that he was the newest Twit. He mentioned a WPF client called Witty, and I wanted to see what it was all about. So I setup a Twitter account to play with the app. After I had my fun, I never deleted my account. Or at least I never looked into how to delete my account.

About a week ago I received and email that a couple of people were following me on Twitter. Man that's flattering to read:

Hi, mo_khan.
Kyle Baley (kbaley) is now following your updates on Twitter.
Check out Kyle Baley's profile here:
http://twitter.com/kbaley
You may follow Kyle Baley as well by clicking on the "follow" button.
Best,
Twitter

Whaa... a celeb is interested in what I'm up to? *blush* So I jumped in, and so far it's been pretty fun. I found another service called "Jott". Jott's pretty cool, because I can call in to a number and I get an automated message that says:

"Who do you want to jott?"

I say ... "Twitter". Then I record my voice message.

Jott then takes that message transcribes it in to text, pushes it up to my twitter page, and drops a tinyurl to the actual audio. Sweet... that saves me a few pennies worth of text messages. But there's more...

I'm one of the poor saps who pay to much for mobile service up here in Canada, eh! I subscribe to Rogers Wireless, and the plan called "My5". I get to make unlimited phones calls to the 5 numbers that are in My5? So I put Jott on My5, and now I can shoot off messages to everyone for....

Free Ninety Nine.... well almost! If you're young, fabulous and ghetto broke (it aint funny) like myself then you ought to give Jott a try!



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Announcing: ALT.NET Online Open Meeting

For a few months now, Zachariah Young, various other folks, and I have been meeting online via Skype+SharedView or LiveMeeting (depending on the size of the crowd) every Wednesday night to discuss various .NET and general technology-related issues. We met at the Agile Austin Open Spaces 2008 conference where I made the foolish statement, out loud, "If anyone wants to remote pair and learn some of this stuff, I'll pair with you, just name the time and IP address" (or something like that).  Zach took me up on that offer and the rest was history.

Anyhow, it turned into a weekly thing with various other folks joining in or not and so we decided that we should open it up a little more and make it a bigger deal.

Last Week's Meeting

Last Wednesday (12-NOV-2008), I posted on Twitter to see if anyone was interested and we had 15 or 16 people show up (I think at it's height it was bigger, but I can't remember the exact number).  The topics included:

  • Basic Subversion usage (how to arrange repositories, when to branch, how to branch, etc)
  • NHibernate usage (Unit of Work pattern, IRepository<T> vs. IRepository.FindAll<T>(), etc)
  • Managing NHibernate ISession and Unit of Work instances through StructureMap (or any IoC)
  • Oslo, M, DSLs, object models, etc
  • Several others which I can't remember right now

Encouraged by this success, we decided to open it up again, but publicize it more to see if that would be a good thing.

This Week's Meeting

I'm not sure if having a lot more people is a good thing or not, but I figured we won't know until we try it and conclude whether it was a success or failure.

Topics

The best part: There are no set topics!  As you'll see below, this meeting will follow an "open" format (in the spirit of Open Spaces – though not necessarily in form since it's 100% online).  The idea is that YOU (all of us) organize it according to what interests YOU.  We may not get to cover everything everybody wants, but there will likely be another one of these next week or next month.

In order to see the meeting in case no one has anything to talk about, I'm prepared to discuss the following things:

  • StructureMap and IoC in general
  • NHibernate, Fluent NHibernate, and ORM in general
  • Internal DSLs and language-oriented programming with C#

Hopefully others will attend that can speak on subjects that other attendees are interested in. If you have a subject you're particularly jazzed about right now and can update the rest of us on it, please come with some talking points just in case! That'd be awesome!

Logistics

The plan is connect via LiveMeeting (Mac users see note below) at around 9:00PM CST (2100 UTC –0600) for about 2-3 hours on Wednesday, November 19th, 2008.

LiveMeeting URL:

http://snipr.com/5qilf

NOTE: Please hit this URL and make sure you have the LiveMeeting client installed BEFORE the meeting starts. This will help prevent you from missing the first 5-10 minutes.

NOTE: Yes, we will try to record it, but sometimes it doesn't work that great, so not guarantees.

NOTE: Mac Users: LiveMeeting doesn't support Audio on the Mac (for some reason) and I'm told that the audio support in VMWare Fusion doesn't work right through it either. I'm told that booting into Parallels works, however. That's all I know about that, if you need help, please post in the comments and hopefully another Mac user can help (or, you can buy a PC that supports audio without hassle ;))

 

How to Sign Up

Don't!  Just show up. If things get out of hand, we'll figure something else out.  NOTE: No refreshments or meals will be provided, so you're on your own! ;)

Multiple LiveMeetings?

I have no idea whether 5 people will show up or 100.  If you access to a LiveMeeting account and can spare the time, it'd be great maybe to have multiple meetings going so that the "Law of Two Feet" can apply properly (see below).  Please let me know if you're interested in doing this and we can coordinate.  Or, just set one up and announce it during the main meeting. REMEMBER: This is self-organizing, so YOU folks figure it out! I'll help coordinate or arrange where necessary, but ultimately YOU get it going.

Kinda like Open Spaces, but not exactly

We'll try to stay true to the Open Space Technology tenants. OST requires a facilitator and (usually) multiple rooms to break out the sessions, so we won't have that and therefore we won't be technically OST, but we can still try to abide by it's higher points, namely:

    1. Whoever comes is the right people: this alerts the participants that attendees of a session class as "right" simply because they care to attend
    2. Whatever happens is the only thing that could have: this tells the attendees to pay attention to events of the moment, instead of worrying about what could possibly happen
    3. Whenever it starts is the right time: clarifies the lack of any given schedule or structure and emphasizes creativity and innovation
    4. When it's over, it's over: encourages the participants not to waste time, but to move on to something else when the fruitful discussion ends

Also, with OST there is a concept of "The Law of Two Feet Clicks": If at any time during our time together you find yourself in any situation where you are neither learning nor contributing, use your two feet clicks. Go to some other place where you may learn and contribute.

Normally, the Law of Two Feet Clicks works better when you have another room/session to go to. Since we only have ONE LiveMeeting room, I'm not quite sure how that'll work.  As I mentioned above, if you have access to a Live Meeting hosting account, maybe we can get multiple rooms running.



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Internal DSL Workshop Videos Posted

On October 31, 2008 I gave a workshop on building Internal DSLs in C# for KaizenConf.  Fellow Los Techian John Teague was kind enough to record them and fellow Austinite Weston Binford rendered them and posted them up on Viddler. Thanks!

You can watch the videos here:

Part 1:

http://www.viddler.com/explore/Wbinford/videos/2/

Part 2:

http://www.viddler.com/explore/wbinford/videos/3/

FYI, unfortunately the camera battery died at the end and missed the actual "building" part. Basically I went through the "Fairy Tale Builder" example. You can see the code in the code dump linked below.

 

The Slide deck and source code is available via our Google Code project:

http://code.google.com/p/pablo/source/browse/#svn/trunk/presentations/chadmyers/InternalDSLs

 

I'd love to hear your comments and feedback.



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology
Article :: Designing APIs Related to LINQ Support

This excerpt provides a very brief overview of LINQ and list guidelines for designing APIs related to LINQ support, including the so-called Query Pattern.

Categories: Computers | CSharp | Dot Net | InformIT | InformIT Dot Net and Windows Programming | Programming | Technology | Windows Programming
Selenium and Fitnesse (WebTest) with Firefox 3

Just wanted to pass something on... I've been using WebTest on Fitnesse for a while but had issue when trying to use it on my Mac. I found that the problem was with the Selenium server jar. You have to hack the jar to get it up and running, but the hack is pretty simple. Here's a URL detailing what must be done: http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3 For my own benefit, I'll reiterate what the other blog stated. First off, here's the symptom. When you try to...(read more)



Categories: Computers | CSharp | Dot Net | Los Techies | Programming | Technology