Salvaging the Anti-Pattern: Smart UI

I've been reading the first couple of chapters of Steve Sanderson's MVC 2 book. I haven't learned much about MVC from it that I didn't know from Rails, yet. It does have a decent discussion of XSS and the .NET 4 features to make it less common.

What really caught my interest is the discussion of the Smart UI anti-pattern. This is something I definitely feel I've been guilty of. Using this anti-pattern stems from two beliefs of mine:

One, both client and server side validation should be present. The server has to have it because the client may be malicious. The client should have it because it shouldn't have to do a network round trip to find out fields were required or formatted incorrectly. If I don't need to go the database to validate, I probably don't need to go to the server (but afterwards I will make sure you played fair).

Two, clients should display an elegant and concise UI. Often this mean hiding inputs and information until it is needed. Inserting the necessary logic to do so however creates quite a mess of event handling code. It also makes my code more fragile, since changes in the domain logic now require changes in the event logic as well.

I'm sure there is a clean way to import validation and input relationship logic into the UI without using clipboard inheritance from the domain, but I haven't found it yet.

Busy Week

I've been busy this week.
  • Got my feet wet with ASP.NET MVC.
  • Took a more official role in my local Java Users Group.
  • Bought my first house. //Here's the problem.
I hope to put a more sturdy line up of posts next week.

On a more relevant note, I've added my Stack Overflow profile in the sidebar. If you haven't heard about Stack Overflow, or just haven't used it, make sure to take the time to check it out. It takes some of the best aspects of slashdot.org style community based moderation and applies it with full force to the technical FAQ genre website. Even the creation of new FAQ sites under their umbrella company, Stack Exchange, is handled via a community moderated technique. Very cool use of crowdsourcing. I'll see you there!




Code Puzzler: T-SQL

Problem:

Common Table Expressions (CTE) are a really cool recent addition to my vocabulary. Operating a lot like a temporary table, they only last for the duration of the query and clean up after themselves.

Another cool idea is string concatenation within a SELECT statement. Together they make some interesting code.

So we had some code that looked something like this:

;WITH Person as ( --This is where we kick off the CTE
SELECT @STR = @STR +
CASE E.FirstName WHEN ''
C.FirstName --Remember this line.
ELSE
E.FirstName
AS 'FristName'
FROM Employees E
JOIN Contacts C ON E.Email = C.Email
ORDER BY
FirstName
)


An elegant solution for a more civilized age. The string concatenates the correct field while the CTE loops over the tables all without the use of a cursor.

Puzzle:

This code would work, except we care about order. And order and string concatenation don't mix, at least according to the following knowledge base article.

What's interesting is that the query doesn't blow up, it just acts...weird. Like returning on the last thing to be concatenated. Or not causing any problem at all. Remember the line I marked above? If I set it to a string literal, the code operates normally. Otherwise, weirdness.

Solution:

Dump it all into a temp table to order it. Of course you lose your nice tidy code that way, but it works. At least you can say you tried to use a CTE.

If you have a more elegant solution, please post it below in the comments. I'd love to hear it.

Ongoing Mystery:

So what actually is happening with those queries where the undefined behavior hasn't bitten me, yet? Do tests for multi row result concatenation conclusively tell me whether I've missed the error. Or is the weird undefined behavior dependent not only on query structure but also table contents?

Display Fusion

I get plenty of stuff done at home on a 17" monitor. It meets all my needs, services all of my requests. It has done so now for many years. I've got a 22" monitor in a box waiting for a desk that can hold it. That's a bit sad but I'm in no hurry to put down the cash for the furniture.

Imagine how I feel every day coming into work to two 22" monitors. Pure bliss, that's how. Display Fusion is a utility that takes that bliss and smooths out any wrinkles from the lack of advanced Windows support for multi monitor setups. I'm just using it for a seamless desktop background across two monitors right now, but additional options abound.



A great deal of those options, such as hot keys to send a window to another monitor, are available in the free version. A trial of the paid version is available and it only cost $25 to purchase. That's a lifetime license, so there's no additional cost for new versions. If you go multi monitor, check out Display Fusion.

LinkedIn

I'm throughly perplexed about the machinations that allow one social network to dominate another. The question of how to obtain and maintain a user base of millions of customers is one I don't think a good answer exists for.

LinkedIn is one of the few I think actually has a chance at answering the question. It answers the initial questions of delineating access level and social graph noise by focusing on professional relationships. You don't wonder if your boss is looking at your LinkedIn profile, you want them to. You can request recommendations, list qualifications and professional associations, and network with potential partners.

This strong sense of purpose I think will make LinkedIn a contender for survival in the social networking sphere. You can catch my profile there, drop me a line, or check out my professional history.

Review: 1 Month

While the real 1 month anniversary of the creation of this blog isn't for a couple of weeks, the event that spawned its creation has passed that milestone. Namely, my first day of work at my current job.