Sunday, June 18, 2006

LINQ, deeper

{

My Tuesday morning session was with Luca Bolognese, lead program manager on LINQ, covering a slightly different flavor than what Pablo Castro was demonstrating with ADO.NET vNext on Monday morning. Luca’s Italian accent was charming, but it was even more exciting to see what LINQ does on a deeper level.

He started by showing a classical problem that LINQ solves. Imagine a collection of integers which you need to filter out based on a certain criteria, something like:

int[] nums = {2,3,5,7,11};

It’s usually done with some kind of iteration in the form of:

int[] nums = { 2,3,5,7,11};

List<int> selected = new List<int>();

for (int i = 0; i <>

if (nums[i] > 4) {

selected.Add(nums[i]);

}

}

// selected represents my values

I write code like that on a daily basis, it seems. In LINQ, queries become a “first class” member of the language and operate on anything that implements the IEnumerable interface. A problem like the above can be solved without line noise and iteration:

int[] nums = {2,3,5,7,11};

var selected = from i in nums

where i > 4

select i;

From the perspective of someone who writes the iteration + selection stuff every day, I think that LINQ is going to have a big impact on my code. But this is just the beginning. Luca then showed how LINQ is split out to target several different forms of data structures:

  1. LINQ to Objects (Anything implementing IEnumerable, collections etc… )
  2. LINQ enabled ADO.NET (mapping database structures to objects and then querying off of them)
  3. LINQ to XML

The first example above is a typical LINQ to Objects scenario where filtering, querying, or manipulation can be applied to a collection that supports IEnumerable. Being able to do this sort of manipulation on HashTables, DictionaryEntries, and so on is the type of power that I demonstrated above.

In a LINQ enabled ADO.NET scenario, you can take an object that is mapped to some entity in your database and query off of it. I don’t recall the exact demonstration, but an example would be querying a collection of “customer” objects based on some filter:

var topcustomers = from customer in customers

where customer.orderCount > 10

select {customer.id, customer.fullName};

I’ve heard a lot about ORM ever since my friend Aaron started talking about Hibernate (some time ago) but what catapults this over the typical ORM scenario is that the functionality is built into language and not abstracted through method calls. I’ve been a bit lukewarm to the notion since it seemed like a lot of work up front and because this type of abstraction where objects can represent data and provide some manipulative capacity is already built in the DataSet/DataTable model. However two things make LINQ enabled ADO.NET a little different: first, the IDE facilitates the mappings that are made through an “EDM” diagram and mapping providers that give a lot of flexibility in connecting to the datastore, secondly the developer wields a lot of control over how the mapping works and how things are updated – the queries, the stored procedures, all data access still belongs to you and not to some “tool.”

Finally the LINQ enabled XML is powerful – it exposes XML data to yet another format of “query” besides XQuery and XPath. There is also the ability to work with the hierarchical structure that XML documents sometimes expose as collections within collections. The LINQ processing, with a bit of instruction, can also be instructed how to retrieve content (depth first traversal, and so on).

Luca’s blog seems to have died, but for some interesting tidbits, it’s here. Maybe with a few hits it can start up again?

}

Wednesday, June 14, 2006

Python and Ruby with .NET

{

An amazing session with Mahesh Prakriya and John Lam came on Monday night. Mahesh was covering the IronPython efforts for .NET and John came to talk about Ruby. It was refreshing to see the smaller number of developers practically using .NET but for whom language mattered.

Mahesh gave a history of Python support in the CLR and made a case for dynamic languages within .NET. His examples were pretty cool, especially when he started with a few examples of Python:

2 + 2 (room is quiet)
22**64 (room is quiet - David is amazed at the response in milliseconds)

He also showed a powerful implementation of a Matlab / Mathematica type tool written in Python for .NET.

John's part of the talk was also very good - he has written a bridge between Ruby and the CLR. John was fairly funny and expressive and his demos of Ruby and the CLR were fairly good in giving a picture of what he was tring to do.

John's blog is here, Mahesh doesn't blog but a search on Google shows him in a few places. I'm going to be downloading Iron Python and RubyCLR in the next month or so. Not completely sure, but it seems that here is where one can find RubyCLR.

}

ADO.NET vNext at TechEd

{

One of the best talks of this week was Pablo Castro's Monday session covering some of the new features of ADO.NET. Having used some form of data access library from Microsoft for a while, the changes he showed were fairly dramatic, and they will really impact on a fundamental level how programmers think about data access when it becomes widely available.

The general direction from Microsoft seems to be giving more modelling capabilities to developers to manage in an application space. The original step in this direction was ADO.NET from which we can model on the application level using a DataSet and it's associated classes. But the features in ADO.NET vNext - and I hesitate on superlatives - are an unparalleled shift (in my short life as a developer) in what we do for data access.

The rational behind my claim of this being as big a change is that it is no longer limited to the object model or some IDE-fu that Microsoft implements in Visual Studio. This change is a part of the language with which we express ourselves when talking to the database. My rational is LINQ.

LINQ is simply understood by unpacking the acronym: language integrated query. From a syntactical point of view in ADO.NET we can obtain a reference to the database and retrieve a collection of objects that represent what's inside.

I think this is a huge revelation - something that goes well beyond even the Object Relational stuff I hear about from time to time simply because it's not just objects, it's syntax.

Around LINQ as a syntactical approach to getting data from the database is the ability to create what is now called an EDM diagram which is essentially a mapping of the database to the class types that will be used to represent the internals. The EDM diagram can be manipulated so that you can do trivial things such as changing a column name reference in the object versus what's in the database, to complex things such as consolidating content from tables in order to avoid SQL JOIN expressions.

On keynote night the topic of Microsoft "innovation" came up and based on what was delivered, it didn't seem as though there was much in the way of newness to Microsoft's portfolio. But LINQ in all it's forms - for xml, for databases, and for that which implements IEnumerable, this is an innovation indeed.

I'm definitely staying tuned to the LINQ project and the Microsoft Data Access blog.

}

Tuesday, June 13, 2006

Rob Relyea on WPF

{

The timelag on posts is due to several 4 hour nights in succession while partaking in the festivities at TechEd. Here is a quick recap of Monday.

First session was WPF presented by Rob Reylea. WPF seems to be coming together more and more; Rob demonstrated new controls and old controls with new features: the listbox is quite a standout – textboxes that support spellchecking, controls having the ability to embed any other controls (button in a button). Another new feature is in the ability to do screen layout: flow layout, grid layout, and others besides the traditional absolute layout most WinForms developers are used to. Databinding in WPF is also quite improved, and learned from the web world: there is a repeater type approach to it now possible as well as functionality in the new listbox control. Vectors, fonts – there was a lot to the presentation. Rob has a blog, so it’s something to watch as the WPF things consolidate more.

After the session was finished I asked Rob whether they were watching other projects like Mozilla’s XUL/XPFE stuff since, in my own thinking, they were similar in approach. He was a bit dismissive here in the sense that he didn’t see why WPF and XPFE should be compared. Since we didn’t have the same assumptions, I withdrew the question although here is my own thinking:

  1. XAML is like XUL, both are a special markup for describing presentation.
  2. XPCOM provides hooks into the operating system functionality, making the client thick just the way that Windows Vista is going to have a special understanding and capability with XAML and the code associated with WPF applications.

There are some big differences for sure: XPFE uses javascript and CSS, WPF does not. XPFE relies on RDF, and I’m not sure that they’ll be any configuration involved in WPF applications since the runtime should handle much of that for the developer. I am not sure about this. Another set of differences are the vectors and rendering of WPF - XPFE does not, to my knowledge, have an equivalent. However, the basis for my assumption was that they both attempt at solving similar problems - extend the web aware application to the desktop to give it a more "client app" functionality and feel. Leverage better controls and have more flexibility than HTML/DHTML and so on. And yes, this is from the perspective of WPF/e - the use in web based applications.

There is much to learn, and much to be seen of WPF, I’ll stay tuned to Rob’s and other blogs that follow the development.

}

TechEd Keynote

{

I’d been looking forward to the keynote for a while since I found out that Ray Ozzie was going to be speaking. Unfortunately his piece of things was quite small – I imagine I wasn’t the only person disappointed by this. The meaning of the keynote was the general direction and strategy of Microsoft and how we “IT people” fit into that.

It made me think a lot of Macintosh ads and how differentiated the corporate strategies of Microsoft and Apple differ. Microsoft has taken the rather difficult (and not necessarily sexy (in a geek sense)) undertaking of “people-centric” software for business. The idea is to make people more productive in an organizational setting with software.

This reminds me of Paul Graham’s evocation of young people to pick hard problems to work on. The word “hard” is subject to semantic lashing but in this case, the idea of making people work better together is a very difficult problem, especially because it’s difficult to do without reinventing the wheel and causing new problems with current fixes.

Although it’s not explicitly stated, it seems that Microsoft’s approach here is not to “innovate” necessarily, but to commoditize new technologies that are proving themselves and package them for masses at all levels: masses in systems administration, masses in development, and, of course, the “mass” of society.

One other thing about Ozzie’s keynote: there is now a conversation about “smart client” applications which represent something that I began to suspect when I first installed Google Earth: the possibility of leveraging a thick client that was intensely web aware. Of course this notion has been around for a long time – yes, I do play MMOs on occasion – but now a technology like that could possibly be commoditized by Microsoft moving developers away from the traditional web based application to a more controlled, powerful “experience” the developer can produce. Web applications still have their place but essentially the XAML WPF/e notion. Kind of cool in the sense that fewer “fix the back button” types of issues in an internal web based application are possible but also a bit sinister since this is a big move away from “standards” to the proprietary, Windows choke-hold environment.

Lots of other thoughts, and some larger context as TechEd gets underway.

}

Thursday, June 08, 2006

Thinking Atlas

{

One thing I'm very interested in hearing about at TechEd is going to be the Microsoft Atlas framework. Ajax is haute couture and Atlas seems to be at the center of Microsoft's strategy. On my current project I took a look at using Atlas but never really "got" the benefits of the technology. The declarative side of things seems to be designed for the IDE, and without the IDE here it's a bit of a non-intuitive hassle to hand code things out. The second thing that made me leary was the direction Atlas took towards web services. The tasks I needed to perform were very simple and I shuddered when I thought about how much overhead there would be, say, for a webservice whose only job was to send me a filtered list of things for a dropdown. In the end I used my own XmlHttp and a bit of POX (I love that acronym, "Plain Old XML") to send things back and forth. Also courtesy of the O'Reilly Ajax Hacks book I got a handle on JSON and how awesome it is when it comes to sending things from the server and handling it with client side javascript.

Today I listened to Ken Alstad interviewed on .NET Rocks concerning Atlas and it confirmed my suspicions on Atlas leveraging web services and how easy it was to "bind" data from the server using javascript.

It's interesting that there seem to be two directions here - looking on the open source side of things, Prototype seems to be generating quite a buzz. I ran into Prototype in December courtesy of 24 ways and it took about 35 minutes to really "get" it. Prototype is getting mixed in with a lot of JSON and other javascript libraries and techniques for some pretty cool stuff like script.aculo.us.

On the Microsoft side we're waiting for Atlas to become standardized, complete, (marketable?). It's declarative, more IDE friendly it seems, and at least for me, less intuitive.

Anyway, part of the problem might be my ability to understand it and see where I can leverage it so I'm going to be in Jeff Prosise's session on Atlas at TechEd. A few questions I'm thinking of are as follows:

1. How to control when data is bound, doing filtering and other operations using javsacript.
2. Will Atlas play well with JSON? Not JSON being shoehorned into some Atlas app, but more like the ability to return JSON style strings from the server.
3. What sort of IDE interface can we expect with Atlas's release? Can we expect any improvements to javascript editing in Visual Studio as a result?

... I'm sure there are more, and I'm sure that after the session I'll have a much clearer picture of Atlas and it's future in web apps for Microsoft developers. I am pretty sure we made the right choice on the current project, but a year from now I could be singing praises for Atlas.

}

Tuesday, June 06, 2006

Code as Design: Implications for Architects

{

I've just got to Jack W. Reeves thoughts on Code as Design in his seminal article originally in the now defunct C++ Journal, and now republished on developer.*. I really liked his thoughts and although I can't necessarily say it's been something intuitively sitting in the back of my mind, its implications are definitely something I've thought for a very long time.

The basic premise of his article is stated early: final source code is the real software design. From the source code design specification, a compiler and linker do the manufacturing work to implement the software from what one could term the design document of source code. He continues to discuss some implications of this that are well thought out and, from my experience, very true.

A great thing about the article is the return to the notion of engineering and software development being treated together. These days I see a lot of writing about how the words software and engineering could never go together, but as Reeves shows, there is a very real relationship between disciplines especially if we think of our code as a design document.

But the real implication for me, beyond the ones stated by Reeves, has to do with the title "Software Architect" - which I happen to hold (not overly meaningful, by the way - everyone at my company is a "Software Architect"). People with the title, who wield Visio, Use Cases, and management-speak exclusively, aren't the real architects of the system. Of course these tools are very useful, and of course general direction is always necessary for a project, but for the notion of a real "Software Architect" one has to stay close to the code - close to the actual design document - to really shape the manufacturing process. Although staying close doesn't mean, to me, writing every line of code oneself, it means understanding and being a part of the process of making it.

}

Monday, June 05, 2006

TechEd 2006

{

I'm very, very excited to be going to Microsoft's TechEd conference this year with my boss. Now I'm counting down the days - we leave for Boston on June 10, and the conference runs from June 11 - 16. The first conference I was able to talk my way into going to was VBITS 2000, and as I think back upon my years training and consulting for my previous employer, that was among the best.

I got to rub shoulders with some pretty amazing people, and learned many valuable lessons. I'll never forget sheepishly asking Aaron Skonnard what he thought of XML Data Islands in IE 5, or Bill Vaughn's theatrics (and knowledge) of data access.

I think my approach and goals at the conference may be a little different from some people who are looking forward to a week off to fraternize and network. I'm hoping to learn as much as possible since I'm not sure when next I'll get the opportunity to go to a conference on my employer's expense.

The biggest trick is going to be separating the Fire & Motion from the sessions that will give me knowledge and direction for the work I do on a daily basis. Of course it's good to be aware of what's upcoming, but I've always been really reluctant to spend much of an investment in something that is subject to change. Beyond that I usually prefer to wait when adopting something for a little while (let others be the bug testers) so that also pits me against things that are a bit too futuristic.

With that said, here is my schedule for the week. There are a few things I'd like to see this year (list is totally subject to change, like, on a minute by minute basis):

1. More ASP.NET 2.0
Deeper on the new features, Personalization API, Web Parts, Internals

2. XML / XQuery / LINQ
Some ideas on where these are in the pipeline so I can start using them on projects

3. Workflow
I have DVDs of the last TechEd, and this came up a bit. I'm interested again on seeing an angle to take on this tool.

4. Sharepoint and Biztalk
I signed up for a few sessions but this is the part where I get leary; I'm not sure when the 2007 versions will be out and about. I know there are many, many opportunities to use the current versions of these products and would probably benefit from seeing that kind of stuff right away. But I'm hoping to glean and perhaps get a few tidbits to stay ahead of the curve when the new versions are released.

5. Team System
We are using it in house, so I need to understand it - I also want to get an accurate picture of how Team System can be leveraged by small teams. Most descriptions (and the pricing!) seems to put it in the "enterprise" category but most of what I've worked on in the past, and probably for the forseeable future will be software projects with less than 20 people involved.

6. IIS 7
I use IIS every day, and it's been like an old friend since the early versions. I'd like to see where the product is headed, and how its path meets with ASP.NET 2.0 and all the other pieces of web application development.

7. Architecture Talks
I signed up for a few that will hopefully be interesting and useful. I'd also like to get a better handle on SOA, "contracts," and the like. Distributed architecture makes a lot of sense to me, but I'm a bit wary of the architecture astronauts when it comes to enterprise application architectures - I try to translate that stuff into what I do on a daily basis (enterprise app for a publicly traded company of 5000+ employees) and still sometimes miss the mark. Perhaps I'll get a chance to meet some people in this environment as well who I can maintain contact with.

I'm hoping that I'll be able to change sessions as well during the conference. I'm fairly pleased with what I have, but the flexibility would be nice.

As the week progresses I'll hopefully write down some things I'll be hoping to answer, as well as some pre-conference reading.

TechEd 2006, here I come!

}

Dino says...

{

I think it was a bit of a rub off from me liking Francesco Balena after being very impressed with him at my first tech conference, VBITS 2000 in San Francisco, but Dino Esposito is another of those intensly smart Italian programmers living right on the edge of that Microsoft technology curve.

Anyhow, Dino, in response to lots of developers like myself, wanting to get better wrote the following:

"Some people here at the conference asked what I feel to recommend to do NOW. Pretty easy job.

I do recommend to learn as much as possible about ASP.NET 2.0 internals. For example: handlers, modules, providers, lifecycle, script-oriented API around the Page class. To learn as much as possible about best practices for control development.

In this regard, I wrote quite a few articles for the ASP.NET DevCenter in the past months to form a sort of crashcourse on control development. "
That's some great advice and it exposes a few personal areas that could see growth.

}

Friday, June 02, 2006

How good are you?

{

In my teaching years I'd often run into people who thought they understood things that they really didn't. Today, spreading like a fire I found a series of "do you know" posts that measured levels of understanding in three technologies most people think they understand: HTML, Javascript, and CSS.

Of course a personal evaluation leaves one open to questions but I think I'm doing okay level-wise. I wasn't at the top in any of the posts, but just a notch below.

When it comes to technologies, even those that I use on a daily basis (like the above) I'm always loathe to say I have a maximum level of knowledge because I am well aware of those who sit on the top of the food chain in whatever areas of knowlege it might be: I'm no Eric Meyer when it comes to CSS, I'm no Thomas Fuchs when it comes to javascript, and although I know much of what there is to know about HTML, I haven't spent (what I consider to be a waste of) time navigating differences in rendering on different browsers and standards support unless it's been a big problem on a project.

Well, here's to all of us who are still learning...

}

Friday, May 26, 2006

RadioButtonList Javascript Accessible

{

I recently was trying to write some javascript that interacted with the ASP.NET 2.0 RadioButtonList. My first attempts at obtaining a handle to the control via document.getElementById were successful but unsuccessful. Successful in that they weren't giving me a "null" reference back, but unsuccessful in that I was not getting the selected value of the radio buttons.

It turns out the RadioButtonList is rendered as an HTML Table element, with the table getting the corresponding id of the server control and the radio buttons getting id values that had an increment on the end. Their name attribute, which groups them, was the same as the RadioButtonList id.

Simple example: you have a RadioButtonList you give an id of myList. ASP.NET 2.0 renders a table with the id attribute of "myList." You'll have your radio buttons inside, named myList_0, myList_1, and so on. These radio buttons, rendered as getElementsByTagName("input") to get your radio buttons. Test to see which is selected and you're all done. The following function encapsulates that logic, and we've begun reusing it all over the place. The radioList argument should just be the ClientId of your RadioButtonList:

function getRadioSelectedValue(radioList){
var options = radioList.getElementsByTagName('input');
for(i=0;i<options.length;i++){
var opt = options[i];
if(opt.checked){
return opt.value;
}
}
}

}

Tuesday, May 23, 2006

Crypto with Schneier II: One Way Hash

{

My reading of Schneier has continued. He still proves to be a very accomodating writer; consider the following on the "One-Time Pad," a encryption scheme that can be literally unbreakable:

"Many Soviet spy messages to agents were encrypted using one-time pads. These messages are still secure today and will remain that way forever. It doesn't matter how long the supercomputers work on the problem. Even after the aliens from Andromeda land with their massive spaceships and undreamed-of computing power, they will not be able to read the Soviet spy messages encrypted with one-time pads (unless they can also go back in time and get the one-time pads)."
In the second chapter he is discussing the basics of protocols and describes the one-way hash: "a function, mathematical or otherwise, that takes a variable-length input string (pre-image) and converts it to a fixed-length output string. Essentially, a computed hash represents a fixed length byte array that is unique for whatever its input stream was. This is interesting and useful beyond cryptography.

Here's a simple idea from Steve Oualline's book "Wicked Cool Perl Scripts," but implemented in C#: you can compute a hash to check to see if two files are different or the same.

The following code uses the System.IO and System.Security.Cryptography namespaces:

private static bool CompareFiles(string path1, string path2) {
byte[] hash1 = GetMD5Hash(path1);
byte[] hash2 = GetMD5Hash(path2);
for (int i = 0; i < hash1.Length; i++)
{
if (hash1[i] != hash2[i])
{
return false;
}
}
return true;
}

private static byte[] GetMD5Hash(string pth)
{
MD5 hasher = MD5.Create();
byte[] fileBytes = File.ReadAllBytes(pth);
byte[] hash = hasher.ComputeHash(fileBytes);
return hash;
}

I was curious about the performance of this technique - I was originally testing it on 40MB files. I extracted some old database backup files - about 200MB a piece and the comparison took somewhere on the order of 20 seconds. My laptop has a P4 3Ghz with 1GB of RAM. Nice, but not out of the ordinary (especially these days). I've also got suspicions that the speed was not necessarily on the hash computation, but rather on reading out the byte array in the file. I'll test sometime to see...

}

Saturday, May 20, 2006

Personal Projects

{

One of my jedi masters, Darren Neimke, posted the following about having personal projects:

"One of the questions that I always ask is for the applicant to tell me about their favorite personal project that they have going right now. It's a bit of a loaded question I suppose because of how it assumes that they do have a personal project - but that's almost my point. Having a personal project (or more than one) is a trait that is shared by every developer that I respect and so I rate it rather highly."
Interesting, because my latest "personal" project is a tool I called Palantir which let's the developers browse around the database getting schema information much more quickly and effeciently than writing queries like:

select * from information_schema.columns where table_name = 'foo'
or
select * from information_schema.columns where column_name like '%foo%'
It pleasures me to no end when I walk through our work area and see it running on everyone's machines. Usually in the evening I add features that are in response to feedback and what I think will make it more effective of a tool. For example, one screen, devoted to exposing stored procedures, displayed TSQL without syntax highlighting and it became a request. That evening I spent some time with regular expressions and search/replace to get a "pretty" version of procedure definitions into the software.

Invariably the question of why I wrote Palantir comes up, and my response usually a bit of surprise; I thought everyone had little pet projects of software they worked on at home. In fact, most don't. In fact, as I ask around, I find that I'm quite unique in that environment for working on my own stuff at home.

I don't think it necessarily defines me as a better programmer but I know that it's when I write my own stuff that I get that free reign to improve my skills instead of working against a spec and a deadline. My projects give me a chance to do things with regular expressions, backreferences, web services, RSS, XML, and a ton of other things that don't come up in the regular work day.

I'm still considering what to do with Palantir; I want to keep it personal for now so that I can work in some more features and leave it with my personal vision at its core. Then I may work up the courage to put it up on CodePlex or SourceForge.

}

Redirect to Self (ASP.NET)

{

It's easy to reset a page to it's initial state in ASP.NET by redirecting to itself. Here are 3 ways you can do it:

1. Response.Redirect(Request.Path);

In which the path to the request is presented in the following form: /MyApp/MyFile.aspx

2. Response.Redirect(Request.RawUrl);

In which not only is the path exposed, but also any querystring parameters like:
/MyApp/MyFile.aspx?foo=bar

3. Response.Redirect(Request.Url.ToString());

In which not only is the path and querystring parameters exposed, but made available as an absolute reference in the form:
http://MyServer/MyApp/MyFile.aspx?foo=bar

Interestingly enough, if you have a named anchor in the form of <a name=#test, this is not exposed by any of these methods! (You'll see how I know a post or so from now, but suffices to say that you can still get this information from the client side by parsing the window.location object:

alert(window.location);

}

Sunday, May 14, 2006

Crypto with Schneier

{

A coworker loaned me Bruce Schneier's Applied Cryptography. So far it's a very interesting book, and surprisingly readable. I may see if I can work my way through various forms of encryption but translate his samples to C#. Here's a version of a substitution cipher that uses XOR operations in C# (make sure you're using System.Text):

private static string Cipher(byte key, string plainText)
{
byte[] plain = ASCIIEncoding.ASCII.GetBytes(plainText);
byte[] ciph = new byte[plain.Length];
for (int i = 0; i < plain.Length; i++)
{
ciph[i] = (byte)(++key ^ plain[i]);
}

string cipherText = ASCIIEncoding.ASCII.GetString(ciph);
return cipherText;
}

To decrypt, if you have the key:

private static string Decipher(byte key, string cipherText)
{
byte[] ciph = ASCIIEncoding.ASCII.GetBytes(cipherText);
byte[] plain = new byte[ciph.Length];
for (int i = 0; i < ciph.Length; i++)
{
plain[i] = (byte)(++key ^ ciph[i]);
}

string plainText = ASCIIEncoding.ASCII.GetString(plain);
return plainText;
}

Back to my earlier comment on Schneier being readable, his comments on this approach are as follows:

"... the list of software vendors that tout this toy algorithm as being "almost as secure as DES" is staggering... An XOR might keep your kid sister from reading your files, but it won't stop a cryptanalyst for more than a few minutes."


}

Tuesday, May 09, 2006

AAARGH!!!

{

Can you spot the mistake?

string where = PathContext.Value += "\\" + subfolder;

Another night of programming my little mistakes away...

}

Sunday, May 07, 2006

Mac Adverts

{

The most recent Mac advertisements have two guys, side by side: a chubby guy that looks like a dishevled Bill Gates and a young hipster. You can guess who represents the PC and who represents the Mac.

But truth is a little bit more boring than fiction: Macs are vulnerable too. They are expensive too - I was salivating over a MacBook until I priced one out.

Luckily I have an iBook courtesy of the company that I can use. I love it, but I don't have that kind of money - or rather, I'd drop it on a nice Thinkpad or Alienware and keep that extra money I had left over.

I always liked Mac ads (Remember the "switch" campaign?). Who else would get folks like De La Soul and Liza Richardson for an endorsement?

But alas, here I sit in the coffeehouse: a monstrosity of a HP laptop in front of me, upon which I write code in javascript, perl, C#, VB.NET, and C++, running my RSS aggregator, messenger, and of course, of course Firefox amongst other things in the toolbox. And I'm not in a bad suit either.

}

Thursday, April 27, 2006

C# Dynamic Instantiation with Reflection

{

In our case it was a control that needed to be placed in a GridView column, but this could be used anywhere:

System.Type t = AnyControl.GetType(); // the control or class of your choice
object o = System.Activator.CreateInstance(t);
System.Web.UI.Control newControlOfType = o as System.Web.UI.Control;

}

Sunday, April 23, 2006

Development Abstraction Layer

{

Joel is at it again. In his most recent essay, The Development Abstraction Layer, he asserts that management at a software company should build an "abstraction layer" that eliminates all distractions from the programmers except programming. Programmers are to be cushioned in the best environment possible to think:

A programmer is most productive with a quiet private office, a great computer, unlimited beverages, an ambient temperature between 68 and 72 degrees (F), no glare on the screen, a chair that's so comfortable you don't feel it, an administrator that...

Okay stop Joel! That is the perfection that I dream of but have yet to really be placed into. In a different thread, however, I get my answer as to why:

But of course, it really depends on where you are in the foodchain. For Developers, I've always considered it to be:

Bottom - Coroporate IT Department Developers. Developers are a cost center

Middle - Internet Company. Developers are part of the core business strategy.

Top - Shrinkwrap Vendors. Developers are the profit center.
Generally speaking this seems to be true. Because my experience has primarily to do with corporate environments, there is a vast difference between that programmer experience and that of, say, your average programmer at Google.

My current employer is good to us, however - most of that seems to come from the fact that the principal is himself a programmer. As a result we have excellent hardware, software, beverages, chairs, and reading material.

}

Saturday, April 22, 2006

Motives

{

Toby Segaran, of Lazybase and tasktoy fame, recently emitted the following on motivation:
"The truth is that I don't make any money from these applications. They were never intended to be a business. I wrote them because I wanted them, it was an opportunity to learn something new, and like most people I love creating things. I determined that for less than I spend on coffee, I could put them online and share them with everyone."
In a recent conversation with a person from work I spoke about an idea for RSS aggregation I had that would be different from current tools but make for better use. As cool as it was, I said, I doubted I could build a business model around it. When it was suggested I came up with the thought as a way of making money, it gave me pause -

Not really, not at all, in fact. Things I write like iTunesBuilder, antiPod, Hobbitwerk:::pwd, Hobbitwerk::PIdigit, phoDak all had some personal problem or interest that prompted me to make them.

Pekka Himanen's book, The Hacker Ethic, does well on this note by giving "Hacker" culture three main attributes (from Wikipedia, I'd suggest you actually read the book):
1. enthusiasm, passion about work that is enjoyed

2. creativity, wish to realize oneself and one's ability, often in teams that are formed spontaneously (project orientation)

3. wish to share one's skills with a community having common goals, along with the need to acquire recognition from one's "tribe"; one is motivated by inner zeal rather than external awards: the fruits of one's work are donated to everybody for their advances and further developments
I would scarcely deign to mention myself in the same sentence as guys like Linus Torvalds or Toby Segaran, I understand this a lot from the stuff that I am trying to do. I'm hoping one of these days to have a good enough idea to make a contribution to programmers and people who use software.

}

Thursday, April 06, 2006

Northwind, Pubs on SQL 2005

{

It's a strange thought but these databases are like old friends. If you, like me, are disappointed not finding them with SQL Server 2005, and you have Visual Studio 2005 installed, navigate to:

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Samples\Setup\

You'll find scripts to generate your old friends for another round of programming.

}

Friday, March 31, 2006

Thursday, March 30, 2006

Remove Carriage Return, Line Feed, Tab in TSQL

{

-- remove carriage return, line feed, and tab from a field in tsql
REPLACE(REPLACE(REPLACE(MyField, CHAR(10), ''), CHAR(13), ''), CHAR(9), '')

}

Saturday, February 25, 2006

Simple is the new robust

{

I first got this vibe from Jason Freid of 37 Signals while listening to a podcast from Venture Voice (I'm not that into VV; it's a bit too "MBA" for my more technical tastes - I found msyelf there only because Joel Spolsky was interviewed).

This is by recollection but he spoke of simple tools designed to do a single thing well. Now, a few months out from that I see the following on Noise Between Stations:

Robust tools are seductive, but their complexity quickly results in diminishing returns. Adopt tools with as many features as you need, and no more. Usually a few essential features will enable you to do many things well.
Interesting and thought provoking. One thing I'd add is to have tools that let you do things fast and terse. What about a class designer for Visual Studio that let you design a class skeleton with as little as the following:

class Person:
p string FirstName
p string LastName
p int ID
m DoSomething(int paramA, string paramB)
m DoSomethingElse(string[] p, ArrayList p2)
language C#

would emit:

public class Person{
private string m_FirstName;
private string m_LastName;
private int m_ID;
public string FirstName{
get{
return m_FirstName;
}
set{
m_FirstName = value;
}
}
// and so on
}


The challenge of something like that would be leveraging plain text without becoming too esoteric. I would have assumed a lot of tools that would automate things like this but Visual Studio 2005's "class diagram" tool seems to disprove that.

}

Saturday, February 04, 2006

What's in a name?

{

Apparently there is an RFC on naming conventions! Here is the thread is on JoS. Gadgetopia also had a thread concerning the naming of things.

I've always liked more creative naming conventions, even though an argument can be made for the sensible but boring "Computer01"... type approach.

My machines were named after places in Middle Earth, like Minas Tirith and Isengard. Pretty soon I'm going to have to clean things up and the new names will probably have some vague reference to Neal Stephenson (Raven, Hiro, Ng, ...). But that's probably something hard to explain to the Judy in accounting types.

I'm glad scientists and discoverers are creative with their names. The solar system, our human anatomy, different species, all are named well, and not "XXX01", "XXX02", "XXX03."

}

Friday, February 03, 2006

MeWare

{

Eric Sink of SourceGear has an article, Yours, Mine, and Ours, about writing software that other people use. Over the years I've noticed that massive chasm in the "personal" software developers write for themselves and the software that people actually find useful.

I've written lots of simple utilities for myself but it's been ever so rare that I've made something that other people find useful. Perhaps my biggest flop in this was an online link database that I had hoped my friends would jump in on and use to spread and keep those funny, cool, and useful snippets of the web that we are constantly emailing and instant messaging to each other.

I still use the utility (it's proven quite useful to me), but after a few logins from friends it died as a "public" tool. I haven't talked much to people about it but here's a few reasons I think they didn't like it:

>> It required login/registration.
Even though they were my friends, no one seems to be looking for Yet Another Password Website. Worse yet, I required an email address thinking in future I'd createa mail list with all the links that had been recently submitted.

>> It was buggy.
There were a few things I knew it had problems with. It's embarrassing to say but there was one area where I did a database insert by manually constructing the "INSERT... " and therefore if any content had an apostrophe, it would break. As non-developers they all didn't have time to hear the reason why it broke, I think most, after one error just never came back.

>> It didn't organize well.
I figured out a way to organize things that worked for me personally but never got outside input for how things worked.

>> I wasn't the best evangelist
I did fix some of the bugs, and even though it got a bit better I didn't really know who to tell. So apart from some close friends who tried it and left, it lived in isolation.

>> The URL sucked
It was an offshoot of my main site, easy for me to remember, but a big pain for other people.

So anyhow, Eric's essay resonated with me. I've got some "new" personal projects that I am really hopeful will become Usware. The thing that I find encouragement in is that with each new piece of software I write in my spare time, things get a little better and a little smoother when I show them to other people. Oh, and I'm better at keeping my mouth shut until it's actually working.

My big questions for public consumption are what other deliberate steps one can take away from Meware to Usware, especially with the limited resources of an individual? Or are there any good stories of strategies used to transport Meware to Usware?

}

Monday, January 30, 2006

Throwaway Design

{

Joel Spolsky, software pundit of Joel On Software is writing a series of articles on "Great Design." In his most recent article draft he talks about "star" products - his examples include Brad Pitt, the iPod, and the Herman Miller Aeron.

Here is my short rebuttle, not because I think he's wrong, but because I think sometimes good design is boring as ever:

>> It's interesting how iPods and Aerons always come up when it comes to "good design" but no one is crazy enough to talk about Wal Mart and design.

Joel asserted as much himself in his previous article describing design that as a discipline it's focuses on a lot more than the aesthetic.

But one of the things that is impressive to me about good design is invisibility.

Wal-Mart is a perfect, but scandalous example of this. No one wants to bring them up because it's not as chic as, say, an iPod, but when we are honest with ourselves it seems as though this "proletariet" design seems to contact us more than something like an Aeron chair.

How fashionable is it to talk about the design of throw aways, or the design of "just good enough?" I think Visual Basic and Wal-Mart have a lot in common: they touch *everyone* (have a look at the POS (no pun intended) system at the next store you visit and chances are it was written in VB), but they don't jump to the front of one's mind when they think of (capital D) Design.

Is the Wal Mart throwaway an excellent example of design?

Okay, how about this for a change of direction. What car do people pick out of a crowd for "great (capital D) Design?" Audi? BMW? But what car silently makes the profits of these vehicles like chump change (some boring car that *everyone's* got, like a Honda Civic). By design? <<

What is to be said of throwaways and invisible design?

I'm sure people are going to respond to my post here.

}

Sunday, January 29, 2006

Good Design is Hard

{

Joel Spolsky has begun a new series on design. I'm looking forward to it because I find myself having to refocus on the discipline of good design quite often.

The one thing I have begun to understand about design is that in order to do a good job you've got to be absolutely tenacious. If it means *exactly* 172 pixels, you use every means necessary to use 172 pixels. Not 171, nor 175, exactly 172.

His first article, "What is Design?", does a good job of dispelling the myth that design is something mystically done by "artsy" people. It will be interesting to see where he goes from there.

I managed to get the company where I did my last project to use Fogbugz, Joel's bug tracking software. At the time it seemed like simplistic software - I had a hard time believing that this "guru" of software development only had Fogbugz to show for himself. However, I've been able to understand more of the design behind Fogbugz now; we use Serena Teamtrack and although it *seems* like it has more functionality, it's missing a lot of the ease, flexibility, and philosophy of Fogbugz. The best designs are like the best special effects in a film; they are so good you don't realize they are there.

}

Wednesday, January 18, 2006

10 years, not 10 hours

{

Most programmers hope they are smart, myself included. Especially at the chastisement of Joel, or some other pundit, we bristle defensively or let it go to our heads whether we meet the criteria of "smart" for the day.

What's even more taboo is to say "I don't know" or "I don't understand." To avoid this many people broaden their exposure so that they can claim they know something of HTML because they've written a tag in notepad, or they claim they "know" C++ because they've written a Hello World.

Out of this a whole cottage industry of 24 hour / 21 day books have flourished to mock what it really means to know something technical. I'm sure the authors of such books aren't claiming to transmit a full understanding of thier topic but that's irrelevent here; it's how books like this are used.

I read an excellent essay by Peter Norvig which confirms an intuition that I had: it takes many years to really know a programming language. For the last five or so years I don't think I've gone more than a week without writing something in C# and I still learn knew things all the time about the language. If someone asked me if I "knew" C#, it would be awkward; I know the answer they'd be looking for is the simple yes or no, but I wish I could stop them and say, "hey, I've been programming the .NET Framework for a while and I feel like I'm getting there with C#."

Norvig's challenge to "know" a dozen programming languages is a formidable one.

"Learn at least a half dozen programming languages. Include one language that
supports class abstractions (like Java or C++), one that supports functional
abstraction (like Lisp or ML), one that supports syntactic abstraction (like
Lisp), one that supports declarative specifications (like Prolog or C++
templates), one that supports coroutines (like Icon or Scheme), and one that
supports parallelism (like Sisal)."

I'm a few languages short but that's where I'm headed.

}

Painful Growth

{

Raganwald has an excellent essay on failure in software development. In a world where everyone seems to be talking about how programmers ought to be smart, this is a dose of reality in which we realize that the line between success and failure depends on so much more.

I've been on two failed projects. Each time there's a bit of painful growing. I know I'm not alone; there's that statistic of the majority of software projects failing; but I like honesty and candor with the attempt to become better.

}

Monday, January 02, 2006

Rumble in the Jungle with Joel

{

In his latest essay, Joel Spolsky has taken the gloves off for a rant against what he calls "Java Schools"; schools that use Java as the implementation language for various Computer Science courses.

Joel's always been a point of love/hate for me: I love his writing style, his lack of fear in pointing out what's wrong, and how he's been a good model of the loud programmer that pisses people off, but who is, more often than not, right. I've taken a bit of pleasure exposing his venture capital articles to business types around me.

It's a bit different when you're at the end things. I lack a formal computer science degree from even the likes of a "Java School" and he seems to sneer at those of us who weren't part of the brotherhood at Yale or MIT. He didn't even spare Penn, which in it's own right is a pretty good school.

It's been interesting to see the responses come, some which look past the vitriol and point out the truth of what he's saying, as well as others I've enjoyed which involve people as educated and smart as Joel putting many of his comments in their place. My favorite thus far has been one from a UPenn professor delivering a bit of a lashing in Joel's direction.

The real question is what I do with what Joel says, which in essence is that good programmers understand recursion, algorithms, and pointers extremely well, and that the best languages to cultivate that understanding are C++ and LISP.

On the first point I agree. I use recursion on a regular basis (lots of XML and heirarchies with my work), but instead of pointers I've been the user of references since I've been using C# and Java. Although I've implemented lots of my own data structures and applied a few well known algorithms, they've been within the safety (and usefullness) of my non-C++ language pool (C#/Java/Javascript/Visual Basic/SQL/Perl etc... ). Maybe there is some reason for me to revisit some of these concepts in the "harder" language of C++ with the use of pointers. And perhaps it's time for me to pick up that dusty copy of LISP, by Patrick Henry Winston, with a compiler and a notebook. I'll never be able to claim that I went to MIT, or Yale, or even a Java School. But I'll be a better programmer for it.

However, there's another thing that all the good programmers I know of seem to understand well and that is regular expressions. And, another thing that intuition tells me is that to learn them well I need a language in which using a regular expression is as easy as a breath of air.

}

Sunday, January 01, 2006

New Year's Day for my night language

{

Each year, as many people gear up for their New Year's resolution that they will ultimately fail, I make my own doomed promise that this will be the year that I become proficient in perl. As the year wears on I get more engrossed in project work and "lose" time. Or I work on my own pet projects which I can prototype and finish so much more quickly in C#, or whatever else I know well.

But my encouragement for the upcoming year's attempt is coming from all directions.

One is YAPC, which will be in Chicago this year. That's within reach, and it's not so expensive that I can't afford to be there.

Another has been Josh McAdam's perlcasts. While I'm at work moving pixels or writing C# I've been listening to quite a few prime hackers in the background.

The second encouragement came from a post on Joel On Software about having a "night time" language:
"For the purposes of this argument I am assuming the programmer uses the language he likes best at night, and maybe not his favorite during the day. If you wish to debate this, start another thread and I will. Why does the programmer like the language that he likes at home so much? I would argue that it is largely about efficiency in the language. If you can do something quickly in a language you get that feeling of control that I think most programmers enjoy. " - threaded here
It's nice to know that other people out there feel as I do, and have their own "night" languages.

Long live the night language.

}

Thursday, December 01, 2005

24.

{

24 ways is a new way to countdown to Christmas: web development tricks to impress your friends. This is worth a little application. Now the trick is just to apply some of these techniques instead of just linking to it.

The gnome behind it all is Drew McLellan. His blog is phat too.


}

Monday, November 28, 2005

Centered DIV

{

I'm used to the align attribute, but my recent CSS conversion has me doing things a bit different. Instead of table align="center" I've discovered the same affect with:

margin-left: auto;
margin-right: auto;


}

Tuesday, November 22, 2005

WinFX horizon

{

What does WinFX bode for smallfolk like me? At this point I'm given to think of Visual Studio 2005 and what sort of placement it will have in the product. I haven't done deep digging, but something tells me a WinFX designer is not going to be a part of Visual Studio 2005.

It goes back to my wariness of the concept of a "release cycle." Microsoft will reap another set of good earnings from a forthcoming release of a Visual Studio 2006 (or whatever) that has a WinFX designer for Vista's windowing system.

If you're designing a desktop application on .NET 2.0, what does this bode? Think hard about your strategy, and look over your shoulder at those slick COM applications.

I've posted on Joel on Software, hopefully someone will have a good response.

}

Get Executable Directory with .NET

{

What directory am I in again?

string dir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

}

Strip Time Off SQL Server Date Variable

{

DECLARE @DOUT DATETIME
SET @DOUT = CONVERT(DATETIME, CONVERT(CHAR(10), GETDATE(), 101))
PRINT CONVERT(DATETIME, @DOUT)

}

Wednesday, November 09, 2005

Technology or Tools, Visual Studio 2005

{

The big release is upon us. But it begs a question that I think those of us who use commercial development tools have to ask ourselves, something our Open Source brothers and sisters do not to the same degree. The question is whether we are driven by technology first, or whether we are led by tools.

Microsoft is driven to release products on a cycle that will earn them a consistent amount of revenue; sometimes the "new" product is hardly new at all.

Visual Studio 2005 looks good from my very preliminary browsing about, but I'm still approaching it with some caution. It's really cool to do "push button" refactoring, but is refactoring something we need to really think deeply about? A part of an underlying structure that must be designed carefully? Something that can't fix code that is already structurally defunct?

The class designer and snippets are cool too, but when I see the IDE eating up 800MB of memory on "Hello World" type projects, it makes me nervous.

My first stop is going to be new language features. After that I'm going to delve a little bit more heavily into the IDE. The ASP.NET features look good and somewhat different. But I'm a skeptic until I see the power for myself.

It's such a contrast to other worlds - to return to the idea of Open Source - technology there is more likely to evolve because of a need that must be met or a new idea. It is independent of the goons in sales & marketing.


}

Thursday, November 03, 2005

ASP.NET Control Trees

{

Debugging a problem today I wrote this, which may be useful to someone. It displays all the controls on an ASP.NET Page in a tree structure. You can actually call it from any control, it will recursively traverse the heirarchy below it. I tested it on ASP.NET 2.0, and it works fine:

Call it with the following:

DisplayControlTree(this.Controls, 1, 30);

Incidentally, the problem I had (and still have) comes from dynamically loading User Controls. Once they've been loaded using LoadControl("... path") they don't seem to persist themselves in the ViewState. I think my best hope for now is to save entries made to the User Controls by parsing the Querystring or Form collection manually.


}

Wednesday, November 02, 2005

Buzz Watch: Ruby on Rails

{

Ruby on Rails is getting more and more buzz each time I open my browser. This time it was Bruce Tate claiming that Java is dead ("like COBOL, not Elvis") and that he was turning to Ruby on Rails as his framework for application development.

A few days ago I also noticed a define/tutorial on Ruby on Rails over at O'Reilly. More and more of these seem to be popping up of late.

The most interesting thing about this buzz, however, seems to be the shift in the pendulum swing to a language that is light and airy, one which isn't belabored by the stiffness of strong types.

I remember the process of learning Java - there seemed to be a lot of people coming from a C/C++ background who perpetually scowled at the VB/Microsoft/Webby/Scripter types like me. Now many of this camp are turning away from that rigidity and heading back to the land of "dynamic" typing.

Pendulum swing... a few days ago I met with a prospective client and they showed me an app they were using that was written in PowerBuilder. I don't know much about PowerBuilder but the app seemed quick, flexible, and tightly coupled with the database. What's most ironic is that the reason I was there was to help with stored procedures and triggers that would let them add business logic to the otherwise light and airy environment in which their application came into being.

Deja vu, all over again.

I've got Ruby on Rails on my watch list. Go to the official website and there's even a movie amongst the tutorials.

}

Tuesday, November 01, 2005

Remedial CSS

{

I've been doing web development for a long time. Long enough to have developed lots of patterns and habits for how I'd approach putting together a website. Because most of my work is done with server side code, I've also yielded most layout thinking to the Panels, Grids, and User Controls I create in ASP.NET.

So it's a bit of a surprise now that I find that my habits are wrong, horrid even when it comes to web development. My effortlessly thinking in tables goes against the grain of any CSS ideologies out there. Having just redesigned my personal site, this is a bit of a drag.

As I read up on layouts with CSS, it's funny to see things turned back on themselves:
  • Absolute Positioning - I used to tell everyone to avoid this because of different screen resolutions
  • ul/li tags - Which were so passe, and used as an example of the obscure tags one didn't need anymore.
  • Tables - frown upon for anything other than displaying tabular data. Read: no layouts, thank you.
So I'm beefing up again. I need to learn the particular advantages of these newer layout strategies - after messing around today a bit I don't seem to gain anything over my older methods. I'm sure this will change.

I did some surfing and checked out various sites... most of them are using DIVs and CSS for layout, not tables. Curiously, Yahoo! Picks is one site that seems to have kept things the way they were.

}

Monday, October 31, 2005

Hunting for the elusive column, table, proc, ...

{

One of our clients has a Microsoft SQL Server table with 284 fields. So when I'm given a spec that references the "OrigLoanAmount" field, it's sometimes difficult to ascertain where that field lives. On some systems, especially if you've got familiarity where data are likely to be stored, you can make an educated guess. But if you're interested in some quick digging, try these queries from the Information Schema views:

-- find that elusive column
SELECT * FROM Information_Schema.Columns WHERE Column_Name LIKE '%MyColumn%'

-- list out the tables
SELECT * FROM Information_Schema.Tables

For procedures, views, and functions, I've just queried sysobjects. I learned this from a guy who was in my class once; I used to be one of the hapless Enterprise Manager users until I saw him digging effortlessly with queries like:

-- show me all stored procedures
SELECT * FROM syobjects WHERE type = 'p' AND name NOT LIKE 'dt%'

-- show me all views
SELECT * FROM sysobjects WHERE type='v'

-- show me all user defined functions
SELECT * FROM sysobjects WHERE type='FN'

... and so on.

}

Web Developer Tools

{

Glad I found about Chris Pederick's Web Developer Extension. It's a set of tools that will run inside Firefox or Mozilla revealing the underlying structure of any site you pull up in your browser.

Some of my favorite things:
  • Displaying borders on table structure
  • Displaying borders on frame and iframe elements
  • Showing dimmensions of images on screen
  • Adding your own user stylesheet
  • Displaying stylesheets for a site within your browser

Now to find an IE version...


}

Sunday, October 30, 2005

Office Interop with .NET

{

Are you still doing VBA with Office even though you know you should be doing your coding with the .NET Framework? Probably like many I did things the old way rather than dealing with COM Interop, especially since this was particularly daunting with Office.

It isn't as of a while ago, but you, like me, may have been a bit too busy to notice.

First, you must download the Office Interop Libraries from here. The instructions are clear; run the register.bat from the VS.NET command prompt. After that you can make a reference to the application interop assembly of your choice, such as Microsoft.Office.Interop.Excel.dll.

Reference the namespace in your app:
using Excel = Microsoft.Office.Interop.Excel;


Code away:

Excel.Application app = new Excel.Application();
Excel.Workbook book = app.Workbooks.Open(@"c:\data\Daita.xls",Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1];
for(int i=1;i<10;i++) j="1;j<7;j++)" rg =" (Excel.Range)sheet.Cells[i,j];">

A few interesting things:
  • The Type.Missing passed for all those COM-esque optional parameters. Ugh.
  • Casting the cell you are on into a Excel.Range when you need to access its contents.

Finally:
Many more articles can be found
here, on MSDN.

}

Saturday, October 29, 2005

Try. Fail. Try again. Fail better...

{

After months of neglect, I'm going to try this again. No more epics, just short snippets of developer talk.

}

Thursday, June 16, 2005

XML .NET (the custom samples)

{

Here are the examples from the last piece of the course when we explored the .NET Framework's implementation of XML related parsers and techniques.

You can download the sample in this zip file which you can extract to its project form to look at the code. Most examples are "methods" implemented off of Module1.vb1.

Read and Write

The BasicReader() method shows an example of parsing an XML document with a XmlReader. Pay attention to the Select… Case expression to see how to filter nodes based on their types.

The ValidReader() method shows an example of a validating parser (XmlValidatingReader). Although this method does the legwork, our ValidationEventHandler, the method ValidError() is responsible for responding to any "events" related to the validation. I stressed the importance of understanding Delegates here, and did a quick example of what I meant which you can download in a different project, vbDel. If you don't mind looking at C#, you can look at some earlier entries I made about how delegates work. One of the best uses of delegates is to make an asynchronous call to any method you've written. Asynchronous delegates are how asynchronous web service calls are implemented.

The fake SAX Parser we wrote is also in the project, in its own file called SAXP.vb. It is not very complete but should give you an idea of how to get the SAX functionality out of the .NET Framework. If you'd ever want to – that's probably a remote possibility.

The WriteXML() method is a very basic example of how you can use the XmlTextWriter to create XML documents. This isn't too interesting, but if you start to combine the XmlTextReader and the XmlTextWriter, you can start to see the power and ease of the .NET APIs. In the second group, we wrote some code that would convert an attribute based document into an element based one. You will find this in a method called AttToElement().

Transforming

The SimpleTransform() method is an example of the simplest form of XSLT Transformations that can be done with the .NET Framework. Another method, called MemoryTransform(), is an example of how transformation can be done and processed in memory to return results in a string format. You will notice the use of the MemoryStream class in this example.

Serialization

We took two different looks at serialization. In the first we looked at how a built in class, the DataSet, has the ability to persist itself in XML format. Our method PersistDataSet() shows an example of this. In order to demonstrate the retrieval of a persisted DataSet, we wrote another method called ReadPersistedDataSet(). Along the way we talked about the Schema options of the WriteXml method of the DataSet. Although it was a barely noticeable blurb, make sure you investigate the XmlDataDocument class. It's a quick way to go from a DataSet to an XML Dom-like object and back again.

Once we'd seen that type of persistence, we looked at conventional serialization, or being able to take any old class and serialize it into some output stream. We wrote the PersistConventional() method to display this functionality with a class called Person, and then we depersisted in a method called DepersistConventional().

This was a good way to start working at understanding web services. I'll make another entry with the web services demos, but really quickly, the last few examples related to XML and .NET:

XML and SQL Server 2000

We looked at ways to retrieve XML data from the database, and I demonstrated the FOR XML clause of an sql statement. After we looked at a few examples, we wrote the GetXMLFromDB() method that would issue a FOR XML query and return results using the XmlReader. Which left us with one other thing on our "to do" list: inserting XML data into SQL Server directly.

In the project you will find a file called OPENXML.sql. This file contains a series of scripts to work through to understand how one can use the OPENXML function in SQL Server 2000 to build a "rowset" view on an XML document. Once this rowset functionality is understood, it's easy to see how it can be combined with Insert/Select statements to insert data. This is demonstrated in the InsertXMLContent() method.

So that was the tour de force. You can download it all in this zipped project. If you have questions, don't hesitate to email me.


}

Wednesday, June 15, 2005

Java Samples

{

Generated during class with South Dakota State employees but hopefully useful to anyone who wanders this way.

[NOTE: My web host doesn't serve the *.java files, so download the zipfile at the end of this post instead. I'll rename with *.txt later.]

We began things with a Hello World program in Hello.java. Soon after we talked about defining classes, the basic building block of any java program. Clerk.java shows an example of a class with fields, methods, getters and setters (accessor methods), and a constructor. Along the way we also learned about overloading, as seen in Calculator.java.

We learned more details about class definitions: Clock.java (check with TestClock.java) and Employee.java are examples of how you can chain constructors. BankAccount.java was used to show the difference between static and instance methods and fields. You can see the BankAccount class tested in Thursday.java. Once we were comfortable with the static keyword, we talked about defining constants, using Constants.java as our example.

We had a chapter that covered arrays, in which we looked at UsingArrays.java. I added an aside about Collection classes in java, which are a more robust alternative to arrays in most cases, and we looked at Swapmeet.java. Even though I got the bubble sort wrong in class, it's fixed in this example with some helper methods, sortMyArray and printArray. We looked at working with Calendars and dates in TestBed.java. I also included a DateDiff.java that shows how to get the functionality of a basic DateDiff command. Like other things, it's ugly in java.

You saw one class from the swing library, the JOptionPane, which was used to talk about getting user input. I also showed you the BufferedReader along with it in Dialoging.java. I would recommend the BufferedReader approach if your application runs from the command line, personally. For most other examples in class, we used EasyConsole.java, which abstracted reading and writing from the console with a few simple methods.

At this point we began to cover inheritance. We looked at a basic inheritance heirarchy in Person.java, InhEmployee.java, and Executive.java. We looked at abstract classes in Shape.java and we briefly looked at interfaces in IPrintable.java.

We closed out with the basics of exception handlers and subclassing exception. The try{..}catch{...}finally{...} is probably best introduced by your material.

Our final two topics were File I/O and parsing XML documents. On the File I/O side, I had two classes: DavidFileReader.java to demonstrate methods of reading from a file stream, and DavidFileWriter.java, to demonstrate writing to a file stream. In terms of XML, I have a class called Xreader.java which should help you get started parsing XML files.

Wow, that was a lot for three days. Even typing it out makes me tired. In regards to the samples, you can download them individually, or you can download a zip archive of the entire set. If you have questions or comments, don't hesitate to email me.


}

Friday, May 13, 2005

iTunes Hacking

{

So I am still coming to terms with how iTunes works, and trying to get the "philosophy" behind its organization system. My understanding is this: iTunes can scour the hard drive, if you allow it, and maintain a nice library of tracks, no matter where on your physical disk they are located. You can then sift through by artist, etc...

In my case I have ~30 GB of music and much of it isn't in mp3 files with ID3 tags - I've got a pot pourri of mixes and a ton of podcasts I've been listening to while I work. It's too much of a pain to manually create a playlist for all the folders or try to find unlabeled music in the library. Maybe it's because of winamp but I'm used to organizing my music physically, and then grabbing tracks out of a directory that I want to play, rather than by "artist" or "genre." For example, I've got the following:

-/Mp3
----/PodCast
--------/ITConversations
--------/KCRW
--------... and so on
----/Albums
--------/Interpol
-------- /Massive Attack
-------- ... and so on
----/Mixes
-------- /Jan2005
--------/Feb2005
-------- /Mar2005
--------... and so on

This scheme works well, but it doesn't seem to mesh with iTunes. So I wrote a little program using the iTunes COM SDK that takes a directory as a parameter and automatically creates a playlist for each folder that contains mp3 or other music files. In my case it worked perfectly (took seconds!) in creating playlists for all my folders and the files they contained. I put in a "Sync" button too, so it can synchronize with changes you make to file structure.




I've uploaded a *.zip along with source (it's written in VB6). I tested it with iTunes 4.7 and it works fine. I'm not sure whether this was unnecessary; perhaps iTunes has an option for doing just this, I don't know. But more deeply, I think, is an attitude, an approach of giving the user an interaction with a piece of software. In the PC world, one spends a lot more time "organizing" things than does on one on a Mac. I've heard and read often that systems should be able to manage themselves but find myself balking at the notion that the system can do as good of a job as I can. I download faster than I listen, so things must be organized, but the content of the audio is the archival attribute, not the date, artist, or genre. How this can be known outside of the user, I'm not sure.

If you do make a modification, or an improvement (many probably could be made), let me know. I'm also unaware of any plug-in architecture for iTunes, otherwise I'd try to just make it a couple of buttons or menu items in the program itself.

}

Wednesday, May 11, 2005

Supporting Each Other, VB6 in Longhorn

{

I posted a bit ago about Microsoft's MVP revolt with regards to supporting VB6. They've responded in kind with VBrun, "Visual Basic 6.0 Resource Center."

The product manager for Visual Basic, Jay Roxe, responded to the petition on his blog and, most importantly, has acknowledged support for VB6 in Longhorn:
"However, I want to highlight to you that Microsoft is still supporting Visual Basic 6 and will continue to for quite some time. In fact, the Visual Basic 6 runtime is slated to ship as a part of Windows Longhorn, which means that it will be covered under Longhorn’s support lifecycle."
I'm an unapologetic lover of VB6, and find myself still using it all the time for helpful utilities. Most recently I wrote a tool using the Apple iTunes COM SDK to sync my physical arrangements of mp3s and folders with the playlists that it created. It's a nifty tool, and I'll post about it soon along with source code.

}

Vasters on SOA

{

A small time ago I admitted that SOA is still a bit elusive to me as this ubiquitous need we were all unaware of having. Multiple marketing machines are in full swing with it, however, and it's hard to separate useful and useless facts, much less fact and fiction.

I found a lengthy article on java.sun.com which should prove to be more technical (and therefore more useful) but meanwhile I'm also beginning to find some other questions similar to my own.

Clemens Vasters writes in his blog:

" When you look at what’s being advertised as “serviced oriented architecture”, you see either the marketing-glorified repackaging of Ethernet, TCP/IP, and LDAP (“Enterprise Service Bus”), or architectural blueprints that looks strikingly similar to things that people have been doing for a long time with DCE, CORBA, J2EE, COM, or mainframe technologies. What’s different now is that it is easier, cheaper and likely more productive to create bridges between systems. "


A Bill Simser responds:

"Indeed at the lower levels of the architecture stack the base concepts of SO have been around as good practices for years. However, we as an industry haven't been applying these base concepts consistently or properly across solutions so it's somewhat academic. If calling them SOA means that people now pay attention to them and somehow feel better about using them, then that's reason enough for me to accept that SOA exists. "


And finally, visiting his blog, I read something that gels the concept a bit more clearly as he speculates on how SAP might have been implemented in a SOA world:

"But what if the architects for SAP had applied SOA from the get-go? The actual architecture would have been defined as several aggregations of financial capabilities (like accounts, money movements, and so on) with appropriate service contracts. It would have also included a collection of capability that would be needed by the finance functions of a typical organization, again with appropriate service contracts. It would have have included some UI capabilities (Web Parts if they were really on the ball) that could consume these services (and indeed other services from different providers) and have the "appearance" of a traditional "application". However, as architects we would recognize that what the user thinks is the "application" is really just a thin facade to the orchestrations of functions they need. An important additional capability is to easily orchestrate other services that are not part of SAP (for example, a service with AMEX to get your credit card statements that can augment expense reports)."


Definitely food for thought, with my own response as follows:

Relating to your speculating about SAP, however, a few things come to mind. First, a different way of thinking when it comes to enterprise applications. You are right when you say that "traditional" thinking lies around task automation rather than loosely coupled "services" that are stitched together by consuming applications (or environments).

But how much of development revolves around loosely coupled services versus automation? Has the nature of the application changed to justify all the force behind service orientation? In one sense I can see it: the elegance of separate, contractual, modular partners, on the other I see architecture astronauts [http://www.joelonsoftware.com/articles/fog0000000018.html] building a massive framework that ultimately doesn't propel us.

All this talk of "contracts" and "services" and so on, and I contrast this with Amazon ECS - making requests for XML formatted data over HTTP: simple, elegant, and effecient.
The journey continues, but it's midnight and tomorrow's coming fast.

}