Blog Home  Home Feed your aggregator (RSS 2.0)  
Code to Live, Live to Code - Saturday, January 12, 2008
Randy Patterson's BLog
 
 Tuesday, December 11, 2007

ThoughtWorks has a new IT Matters Podcast that discusses the business and technology issues facing the IT Industry. The First topic is on Domain Specific Languages Part 1 of 2.  A panel of ThoughtWorks employees including, Martin Fowler, Dr. Rebecca Parsons, Neal Ford and Jay Fields; all participate in a discussion around domain-specific languages (DSLs).

Topics include: 

1. How to build effective DSLs

2. When to use a DSL

3. What pitfalls to avoid

4. Some real-world examples of DSL best practices.

With the release of Visual Studio 2008 SDK that includes tools for Developing Domain Specific languages in Visual Studio 2008, the timing could not be better.  I am looking forward to listening to Part 2.

 

kick it on DotNetKicks.com
Tuesday, December 11, 2007 10:00:26 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]   Podcast  |  Trackback
 Tuesday, December 04, 2007

One of the best ways that I've discovered to keep up to date with the constant change of technology is to listen to podcasts.  I find this a great way to learn during my daily commute and exercise regiment (refilling my coffee AND getting the mail). 

 

One thing I would encourage is to attempt to listen while coding.  If you can listen to music while you code you can probably listen to podcasts with little effort.  Everyone is different but here is what I've discovered about myself.

  • If both ears are listening to a podcast I get too distracted and cannot concentrate enough on coding.
  • If I listen using my right ear, I grok almost nothing of the podcast content.
  • If I listen with my left ear, it seems to be a good balance between listening and doing.

I've heard of some who code while listening to a podcast in double speed to save time.  I can't do that but, apparently, some can. 

 

 

Here are the podcasts I find invaluable as a developer

 

smRSSImage Polymorphic Podcast Craig Shoemaker brings insight into software development in the .NET platform along with interviews with industry luminaries. Good content, good quality but an inconsistent schedule.
smRSSImage ARCast with Ron Jacobs Ron Jacobs is a Microsoft employee and delivers a weekly podcast on Channel 9 that dives into some tough .NET architecture topics. 
smRSSImage Software Engineering Radio Not specifically .NET related but contains a wide spectrum of Software topics from Dynamic Languages to Transactional Memory to Fault Tolerance. 
smRSSImage Software Quality Engineering Conferences Podcast Interviews with speakers from the Agile Development Practices 2007 Conference
smRSSImage OnSoftware Weekly interviews with some of the software industry's leading developers about a wide range of programming and development issues
smRSSImage WebDevRadio Podcast Web Development Discussion
smRSSImage Agile Toolkit Podcast Topics covering all things Agile. 
smRSSImage .NET Rocks! .NET Rocks! is a weekly talk show for anyone interested in programming on the Microsoft .NET platform. The shows range from introductory information to hardcore geekiness
smRSSImage Hanselminutes Scott Hanselman discusses utilities and tools, gives practical how-to advice, and discusses ASP.NET or Windows issues and workarounds.
smRSSImage ASP.NET PodCast The ASP.NET Podcast brings a technology focus to the area of podcasts.  This podcast is geared towards developers with applications that scale to a large amount of data and users.

 

I would like to hear what others are listening to and what software you use to manage your podcasts.  I have a love/hate relationship with ITunes.

UPDATE:

Top Developer Podcasts Part II

 

 kick it on DotNetKicks.com

Tuesday, December 04, 2007 7:23:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments [16]   Podcast  |  Trackback
 Monday, November 26, 2007

Right now Techsmith is offering Camtasia and Snag-It for free.  You download the demo then register for a free license key.  These are previous versions of the software but they are still feature packed and will solve most of your screen capture needs.

download free snagit

Monday, November 26, 2007 8:56:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2]   Deals  |  Trackback
 Saturday, November 24, 2007

If you don't have an MSDN subscription and you can't wait to try out the new Visual Studio 2008 features you can download the express edition and learn the new features while you wait for the professional edition to be available in stores.

http://www.microsoft.com/express/

Saturday, November 24, 2007 9:57:43 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]   C#  |  Trackback
 Monday, November 12, 2007

image

 When: 11/28/2007  6:30 PM - 8:00 PM

Abstract: You can run, you can switch jobs, and you can write unit tests, but invariably at some point you will run into legacy code. Legacy code hides in many forms - sealed classes, spaghetti and big-ball-of-mud code, data in disparate data sources (or incompatible schemas). As an architect, there are steps you can take to get ahead of these issues and begin to make your codebases something you actually want to change. In this talk, we will discuss concepts from Michael Feathers' work on Working Effectively with Legacy Code as well as Scott Ambler's work on refactoring databases. You'll see tips and tricks to model your legacy code and data, and hear about ways to begin to turn your legacy code into a usable base."

 

Speaker: Cory Foy is an agile developer passionate about languages such as C# and Ruby. He currently works for Microsoft as a Premier Field Engineer, has been a developer on the NUnit team, and is known to speak at code camps and user groups across the country. He lives just north of Tampa with his wife and 2 daughters.

Registration: here

Monday, November 12, 2007 6:14:04 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]   Events  |  Trackback
 Tuesday, October 02, 2007

Speaking in Tampa on October 18th - Repository Factory, Enterprise Library, Guidance Bundles

 

David Hayden ( Microsoft MVP C# ) is giving a  presenting to the Tampa .NET Developer Group on Thursday, October 18th at 6:30pm at the Microsoft Tampa Office.

 

The focus is on the new Repository Factory, which is a software factory from Microsoft Patterns & Practices that will generate a data access layer for your winform and web applications in minutes. It generates business entities, stored procedures, and repository classes from an existing database within Visual Studio. In addition he will also be showing off the following:

See you there! You can RSVP here.

 

 

 

I really enjoy David Hayden's Presentations and this topic is of special interest to me. 

Tuesday, October 02, 2007 6:26:40 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [1]   Events  |  Trackback
 Wednesday, September 26, 2007

Martin Fowler coined the term "FluentInterface" to describe objects that expose an interface that flows, and is designed to be readable and concise.  The cost of this fluency is additional effort required to design the interface for your object and the slight increase in complexity.  These types of interfaces are often utilized to create configurations for your objects but can progress into an internal Domain Specific Language or DSL.

Configuration Fluent Interface Example: (sometimes called Method Chaining)

Order    
	.AddFreeShipping()    
	.IncludeItem(10)    
	.SetQuantity(2); 

 

DSL Fluent Interface Example:  (Rhino Mocks)

Expect    
	.Call(entityMock.GetID(12))    
	.IgnoreArguments()    
	.Repeat    
	.Once()    
	.Return(entityDataSet);

 

Show me the Code

Fluent interfaces are best explained by showing some code examples, so I'll take the rather prosaic Person object and create a fluent interface for it.   

Take a common Person object and write some code to instantiate and Initialize the object

       public class Person
        {
            private string _firstName;
            private string _lastName;
            private int _age;
            public bool _isActive;

            public Person(string firstName, string lastName, int age, bool isActive)
            {
                _firstName = firstName;
                _lastName = lastName;
                _age = age;
                _isActive = isActive;
            }

            public string FirstName
            {
                get { return _firstName; }
                set { _firstName = value; }
            }

            public string LastName
            {
                get { return _lastName; }
                set { _lastName = value; }
            }

            public int Age
            {
                get { return _age; }
                set { _age = value; }
            }

            public bool IsActive
            {
                get { return _isActive; }
                set { _isActive = value; }
            }
        }
 
This is a common pattern where the constructor is used to quickly set the properties of the class.  The initialization code would look something like this.

 

Person person = new Person("Frank", "Pat", 30, true);

 

Although this code is concise it is not very readable. Is "Frank" the first name or the last name? What does the value true represent? The readability issue becomes more problematic as the number of construction parameters increase.  One solution, and the point of this post, is to write a Fluent Interface for our Person class.  The idea here is to allow each property to be set through a method call and then have that method return a reference to itself so you can continue on with next method call (often called method chaining). 

person.SetLastName("Frank").SetFirstName("Pat");
 

 

This makes our code concise and far easier to read, we now know that "Frank" is the last name.  However, an obvious issue with this pattern is that we are now cluttering up our class with methods that, when taken out of context, make little sense.  We have a FirstName property and a SetFirstName method defined on our class that obfuscates the intent. A better approach is to create an internal class that is accessed through a Set property and exposes only the Fluent Interface.

public class Person
        {
            public Person()
            {
                _set = new PersonFluentInterface(this);
            }

            private string _firstName;
            private string _LastName;
            private int _age;
            private readonly PersonFluentInterface _set;
            private bool _isActive;

            public PersonFluentInterface Set
            {
                get { return _set; }
            }

            public string FirstName
            {
                get { return _firstName; }
                set { _firstName = value; }
            }

            public string LastName
            {
                get { return _LastName; }
                set { _LastName = value; }
            }

            public int Age
            {
                get { return _age; }
                set { _age = value; }
            }

            public bool IsActive
            {
                get { return _isActive; }
                set { _isActive = value; }
            }

            public class PersonFluentInterface
            {
                private readonly Person _person;

                public PersonFluentInterface(Person person)
                {
                    _person = person;
                }

                public PersonFluentInterface FirstName(string firstName)
                {
                    _person.FirstName = firstName;
                    return this;
                }

                public PersonFluentInterface LastName(string lastName)
                {
                    _person.LastName = lastName;
                    return this;
                }

                public PersonFluentInterface Age(int age)
                {
                    _person.Age = age;
                    return this;
                }

                public PersonFluentInterface IsActive()
                {
                    _person.IsActive = true;
                    return this;
                }

                public PersonFluentInterface IsNotActive()
                {
                    _person.IsActive = false;
                    return this;
                }
            }
        }

 

Now the code is clean, concise and quite readable.

Person person = new Person();
person.Set.FirstName("Pat").LastName("Frank").Age(30).IsActive(); 

Conclusion

This pattern for fluent interfaces is often seen in object configuration and setup.  It's fairly easy to design and the objects configuration options are readily discoverable using intellisense.  As the complexity of an objects setup increased, a fluent interface becomes a more attractive option to ease the initialization burden.

 

 

kick it on DotNetKicks.com
Wednesday, September 26, 2007 1:25:09 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [2]   C# | Patterns  |  Trackback
 Sunday, September 23, 2007

 IASA

This is the inaugural meeting for the Tampa chapter of IASA.  In this meeting we will discuss a number of topics about the group and what to expect going forward.  We are also fortunate to have a Microsoft Architect Evangelist coming into town to speak.

Speaker: Jeff Barnes, Microsoft Architect Evangelist

Topic:
The Role of the Software Architect

Abstract:
This session will explore the role of the Software Architect - from defining what the job role actually entails, what it takes to be successful at it, and what steps you can take to become a software architect (or a better one) today. This session will be highly interactive and should lead to lively group discussions and audience participation.

When:

10/30/2007

6:30 PM - 8:00 PM

Where:

Microsoft Corporation

3000 Bayport Drive

Suite 480

Tampa, FL 33607

USA

Click here to register for the event

Sunday, September 23, 2007 10:52:56 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]   Events  |  Trackback
 Friday, September 21, 2007

This is one of the most useless unit tests I've encountered

/// <summary>
///A test for GetByLegalCaseID (int)
///</summary>
[TestMethod()]
public void GetTicketByLegalCaseID_Test()
{
    TicketEntityModel target = new TicketEntityModel();
    int ID = 1;
    TicketDataSet actual = target.GetByLegalCaseID(ID);
 
    Assert.IsNotNull(actual, "TicketDataSet was not returned.");
    Assert.IsNotNull(actual.Citation, "No Citation table was returned.");
    Assert.IsTrue(actual.Citation.Rows.Count > 0, "No Citation rows were returned.");
    Assert.IsNotNull(actual.Ticket, "No Ticket table was returned.");
    Assert.IsTrue(actual.Ticket.Rows.Count > 0, "No Ticket rows were returned.");
}

 

Unit tests in the Entity Model should concentrate on testing business logic, not Data Access Layer (DAL) logic. Unit tests for DAL objects test data access issues.   Furthermore,  this Unit Test simply checks to see if the current database has a record with an ID of 1 and, therefore, is non-deterministic. It can fail for many reasons that have nothing to do with the business logic. If GetByLegalCaseID has any business logic in it then unit tests should to be written to test that logic and the dependencies on the DAL would be mocked so a previously setup DataSet is returned with known values. This falls under the "What Burns Me" category. 

Friday, September 21, 2007 8:10:15 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [5]   What Burns Me  |  Trackback
 Tuesday, September 18, 2007

The very flexible generic collection List<T> contains several methods that take a predicate as it's parameter.  Coupled with Anonymous Methods this provides powerfully concise code for filtering, searching and sorting your collections.

 

List<Person> People = new List<Person>();
 
People.Add(new Person("Randy", "Patterson", 40));
People.Add(new Person("John", "Smith", 15));
People.Add(new Person("Caity", "Johnson", 13));
People.Add(new Person("Jody", "Patterson", 39));
People.Add(new Person("Chloe", "Dog", 30));
People.Add(new Person("Corey", "Patterson", 18));

 

For Example,  to filter the collection and display only my family members requires a single line of code

IList<Person> family = People.FindAll(delegate(Person person) { return person.LastName == "Patterson"; });
 

And produces the following output

image

To remove the teenagers (not a bad proposition) also requires a single line

People.RemoveAll(delegate(Person person) { return person.Age > 12 && person.Age < 20; });

Sorting

Sorting requires a Comparison<T> delegate instead of Predicate<T> but operates in much the same fashion.

For example, sorting by last name requires this single line of code:

People.Sort(delegate(Person x, Person y) {return x.LastName.CompareTo(y.LastName) ;});

a slight modification will sort the list in descending order:

People.Sort(delegate(Person x, Person y) { return y.LastName.CompareTo(x.LastName); });

To sort by Last Name then First Name would look something like this:

People.Sort(delegate(Person x, Person y)
    {
        if (x.LastName == y.LastName)
            return x.FirstName.CompareTo(y.FirstName);
        else
            return x.LastName.CompareTo(y.LastName);
    });

 

Conclusion

I've just scratched the surface on what the generic List collection is capable of providing. There are several other generic methods that take delegates as parameters, such as ForEach and ConvertAll, that open up interesting possibilities in your code.   Overall I find the Anonymous Method syntax a bit kludgy but C# 3.0 promises to reduce the syntactical noise and give us true (almost) Lambda Expressions

kick it on DotNetKicks.com

Tuesday, September 18, 2007 8:40:57 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [8]   C#  |  Trackback
Copyright © 2008 Randy Patterson. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.