Saturday, February 25, 2012

Starting LINQPad 4 from Visual Studio Express

As I am writing this year’s Code Camp presentation about Entity Framework, I’ve come across a problem: I want to use Visual Studio Express 2010 AND I want to demonstrate Linq to Entities using LINQPad 4. If I were using a commercial version of Visual Studio, I could use Start Action = Start external program. I can’t just launch LINQPad and edit my project because LINQPad would lock my assembly and Visual Studio would refuse to build a new one.

So, to work around this limitation, I added a console project that would launch LINQPad and wait for it to return.

C#:

using System.Diagnostics; namespace LaunchLinqPad { class Program { private const string LINQPAD_EXE = @"C:\Program Files (x86)\LINQPad4\LINQPad.exe"; static void Main(string[] args) { var process = new Process(); process.StartInfo = new ProcessStartInfo(LINQPAD_EXE);> process.Start(); // Without this, the program will exit immediately process.WaitForExit(); } } }

VB:
Module Module1
    Const LINQPAD_EXE = "C:\Program Files (x86)\LINQPad4\LINQPad.exe"
    Sub Main()
        Dim process As New Process()
        process.StartInfo = New ProcessStartInfo(LINQPAD_EXE)
        process.Start()
        ' Without this, the program will exit immediately
        process.WaitForExit()
    End Sub
End Module

A couple of issues:

  • This doesn’t work with LINQPad 4 (and newer)
  • I can’t step into my code.

Even with these limitations, I find this helpful because doing this endures that LINQPad is closed before I recompile, therefore preventing me from locking up the file that I am building.

Thursday, February 02, 2012

Happy Groundhog Day!

Punxsutawney Phil, some rodent 2,000 miles from me sees his shadow so we get 6 more weeks of winter. Had he not seen it, winter would only 42 days left. I will have my traditional Groundhog Day dinner of pork sausage.

Wednesday, January 11, 2012

Less Than Simple Group By LINQ Queries

Lately I have been going through LINQ. Most of it has been review, however I ran across something that I really didn’t understand. That area: Grouping.

Suppose I wanted to write a LINQ query which would do the following:

SELECT a.city, COUNT(*) AS Count
FROM authors a
GROUP BY a.city
I can easily render this into LINQ as follows (LINQPad C# Expression):
from a in Authors 
group a by a.City into c
select new
{
City = c.Key,
Count = c.Count()
}

When things got just a little bit more complicated, I got lost. Suppose that I wanted to render this query:

SELECT a.au_lname, a.au_fname, a.phone, COUNT(*) AS Count
FROM authors AS a
GROUP BY a.au_lname, a.au_fname, a.phone

I figured out that the Key didn’t need to be a simple type. The type of the Key is determined by the type between by and into in the group clause. So here I create an anonymous type for the key and refer to the properties of Key in the select clause. So I can render it as follows (LINQPad C# Expression):

from a in Authors 
group a by new
{
a.Au_lname,
a.Au_fname,
a.Phone
}
into c
select new
{
Au_lname = c.Key.Au_lname,
Au_fname = c.Key.Au_fname,
Phone = c.Key.Phone,
Count = c.Count()
}

GroupBy() (the extension method that group .. by is translated into) returns an IQueryable of IGrouping(s), a IGrouping is an IEnumerable with a generic Key property tacked on. Since Key is generic, I can pass in a complex type.

NOTE: I haven’t been able to get it to work with a non-anonymous type In LINQ to SQL.

I didn’t use LINQ grouping in my production code. I don’t know if it is because I didn’t understand it or just didn’t need it. If I really needed it I would think I would have pushed harder and learned it earlier…

Saturday, December 31, 2011

Example of Repetitive Comments

Looking through some old code for a project I’m working on I saw a block of code similar to this:

/// <summary>
///
This is MY method
/// </summary>
/// <param name="intValue">
Some Number</param>
/// <param name="stringValue">
Some String</param>
/// <returns>
An empty string</returns>
public string MyMethod( // Returns An empty string
int intValue, // Some Number
string stringValue) // Some String
{
return string.Empty;
}
This code annoys me. Yet I see the problem: the XML comments are just a little too far away from the actual data. I think it would be cool to have tool tips for the parameters described in XML comments. It would have also helped name the parameters better.

Friday, December 16, 2011

Two devices to read a tech book

Last week I bought some technical books from the internet; they were stolen from my front door and I needed them immediately, so I ordered the e-book version. I like e-readers for pure text that is meant to be read in order (novels, histories, etc.), but technical books have diagrams, tables and code samples (“figures”) that may be referenced several pages later. So I decided to try using two devices …

two_dev_code

I use the reader for the text and the tablet for the figures. I don’t like to read lots of text on a tablet because it is backlit. I really like reading plain text on a reader; I bought mine this spring and read the Lord of the Rings (+ the Hobbit) on it. I like reading on it better than reading books.

Since the reader doesn’t support zoom, I like to use the tablet to zoom the figures; actually, the image support on the reader is so bad that it would be difficult to read my current book without viewing images on the tablet.

This is not a supported way to read an e-book and will probably never be. Even with the hassle of juggling two devices it is better than the supported way. It would be nice if I could move between figures without shuffling through the text. Some UX designer better than me needs to do something to improve the tech book reading experience.

Thursday, November 17, 2011

My Play

In this week’s This Developers Life, they discussed Play. Not to be out done, I thought I would write about my own play patterns. It was fun to hear about the race car driver and the home manufacturer, I want to hear more. To promote dialog, I am presenting my story.

Improv

Almost 2 years ago, I started taking Improv classes at the Blue Door Theatre in Spokane because I heard about some consultancy in New York City that provided Improv classes to all their consultants. The local NPR station announced the class on their arts calendar and I just said what the F# and I took the class. At that point I had never even seen live Improv.

Like many programmers, I have an Aspergers personality. This serves me well when I am actually doing my core job; for the rest of my life, not so much. Improv gives me a chance to play at being in the world where everyone else lives. It gives me the opportunity to playing at being an extrovert.

Through something we call “Yes, And”, I am learning to accepting the current situation and adapting to the current situation. And I am learning to do it quickly. As a programmer, I like to work carefully and look for the perfect solution; in Improv I just don’t have the time. (The programmer in me is telling me that this blog post isn’t good enough; if it wins, no one else will ever read this.)

Am I taking Improv to become a great actor and become famous? No. My chances of ever performing Improv in public: about 50/50 (based on the fact that most of us underestimate our own talents). Do I really care? Do you take Kung Fu to fight? If memory serves me right, Cane was able to avoid fighting as much as he fought. I have presented at Code Camps 5 times since I started Improv.

Technology

My work project is frozen to the technology that existed when it was started. I like to play with the new stuff. I have Windows 8 installed on my laptop. I am slowing working my way through WPF 4 Unleashed. I am looking into writing for the Android Tablet. No, this is an extension of work.

Music

I have a guitar, a bass and a keyboard that I attempt to use to make sounds with. In the past I found that the guitar to be a great stress reliever. On second thought I haven’t really even touched these things since I started Improv. Since classes don’t start up again until next year, I would take out an instrument and …

Christine

I have a 1982 Supra that I have tried to keep alive for the last dozen or so years. Due to some poor financial decisions on my part, I haven’t done much with her for the past couple of years. My dream is to restore her on YouTube. Yes, her name is a reference to the Stephen King book.

Wednesday, November 09, 2011

Tablets and Open Source Voting Software

Yesterday on NPR, they had a short piece on iPad Voting. I don't like modern voting machines because of the closed nature of their software; very few people know what is going on inside those things.

If I had my way, the voting software would be written as an open source project. The voting machines would be common hardware that could be used in schools after election season. On Election Day morning, representatives from all interested parties would download the source from the project's site, build, run unit tests, install the software and generally verify that the software is correct.

The hardware would probably be tablet computers. Right now the market would be iPad, Android and, coming soon, Windows Metro. I would imagine that each vendor would sponsor voting machine projects that use their hardware. When the local community center would buy tablet computers of some after school program, the quality of its open source voting software may affect the buying decision. You wouldn’t need to buy new hardware every election cycle, schools could go without the iPad for the first week of November (“Hey kids, this is a ‘yellow pad’, we used these in the 20th century”).