Sunday, January 27, 2008

A LINQ query to generate names for test data

I needed to generate a large test file of names to test a HR function but for privacy reasons did not want to use the actual names in the HR system. My solution was to grab a web page of names from Wikipedia, save it as a text file, and use LINQ to filter out just the names. Worked like a charm and the LINQ portion was essentially a single line of code. The VB.Net source code snippet is shown below:

Dim Lines As String() = System.IO.File.ReadAllLines(strFileName)
Dim names = From line In Lines _
Select line _
Where (line.Contains(","))
And (Not line.Contains(" to "))
And (Not line.Contains(" of "))
And (line.IndexOfAny(":$""()") = -1)
And (line.Length < 30)

Hope that helps.

Joe Kunk
Okemos, MI USA

Speaking at Flint Michigan on February 14th 2008

I will be speaking at the GLUGnet Flint meeting on February 14th 2008. It will be held at the New Horizons offices off Bristol Road. Hope to see you there.

Speeding up .Net application development with Framework tools
The .Net frameworks distributed by Microsoft as part of a .Net language release have significantly shortened application development time by providing advanced functionality to developers "out of the box". This presentation looks at putting application development into overdrive by using framework products that generate much of the remaining code for you. They claim to boost developer productivity by taking care of the "plumbing" and allowing the developer the focus on business logic. These frameworks can be used to quickly generate proof-of-concept applications or even final-quality applications.

Sunday, January 06, 2008

Software Architect - A study plan

I have designed and implemented many successful software systems in my career. One system processed more than $65 million dollars in its first year. Another implemented system was presented by the customer at a national conference as a best practices approach to solving a common but vexing problem. The point is that I have no problem conceptualizing successful software solutions to complex business needs. Does that make me a Software Architect? Unfortunately the answer is No.

In order to be a successful Software Architect in today's business environment, you must be able to employ generally accepted best practices to complete an efficient, flexible, and appropriate object-oriented design and then communicate that design to developers in a way that ensures the product can be built and delivered in stages and ultimately meets the customer needs. You must fully understand the business environment that has given rise to the need to the software system and how your design will satisfy that need, both now and in the future. Communication, project management, and general people skills are very important characteristics of a successful Software Architect.

Assuming you enjoy working with others and have the soft-skills, what materials can be studied to gain the hard-skills that are needed? Once I master the materials listed below and get a chance to fine-tune their use, then maybe I will be comfortable calling myself a Software Architect.

I mentioned my study plans at a recent meeting of other developers and I was surprised by how eager the other developers were to know exactly what I was studying. So here it is:

  • Enterprise Architect 7.0 Professional as a high-quality affordable tool for preparing UML 2.1 diagrams with a familiar Visual Studio interface. Great tutorial materials on the web site.

  • Design Pattern Framework 2.0 as an excellent resource to understanding and implementing design patterns in terms of C# and VB.Net code. As a bonus, it includes the .Net code for the Head First Design Patterns book above since that book shows the examples only in the Java language. Great tutorial materials on the web site.
  • Microsoft Enterprise Library as a collection of pre-written libraries that are easily incorporated into your system. Completed and full-tested code is even better than design patterns and can eliminate coding for one or more modules of your system. Enterprise Library includes application blocks for caching, cryptography, data access, exception handling, logging, policy injection, security, and validation.
  • .Net Rocks as a view of what is hot and happening in the .Net developer world.

  • ARCast as a great overview of the concepts, trends, and people involved in .Net architecture.
So there you have it.

Disclaimer: I gathered input from some very smart people including experienced Software Architects when preparing this list. That said, this list is of my own making and does not guarantee results of any kind and comes with no warranty.

Hope that helps!

Joe Kunk
Okemos, MI USA

Saturday, January 05, 2008

Create a Date only property (C# example)

One of the minor frustrations in the .Net framework is that there is a datetime type but note a date-only type. There are many times when I want to represent a date but carrying along a time value seems extraneous and sometimes can cause issues in comparisons, etc.

One simple solution (I'm sure there are others and I'd love to hear how you handle it) is to create date-only properties in your objects. It is simple enough to do, a C# example follows:

private DateTime _Date01;
public DateTime Date01

get { return _Date01.Date; }
set { _Date01 = value.Date; }

Hope that helps.

Joe Kunk
Okemos,MI USA

Tuesday, January 01, 2008

Get all subdirectories in a single line of C# code

One of the necessary evils of programming has been the need to write recursive routines in order to discover all the sub-folders and files on a file system based on a specified parent folder. Recursion is the practice of writing a routine that calls itself. In the case of "walking" a directory tree, a method can look at a folder, list all the files and folders in that folder, process each file, and then call itself for each of the folders. Recursion is not hard, it is just something that make you go "hmmmm" each time you do it.

My latest discovery is that I can now get all the subfolders of a parent folder with a single line of .Net code, returned as a string array. Then simply write a foreach loop that processes all files found in each of the fully-specified folders. No more recursion and it works like a charm. Can't stand the suspense? Here is the line of C# code that does it:

string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);


I would say that you can now forget recursion, but it is still a popular question in programming job interviews and certification tests, so you still need to get comfortable with it.

Hope that helps.

Joe Kunk
Okemos, MI USA