Wednesday, June 28, 2006

Is it wrong? Is it right? I don't know..

...but it sure is funny. Anyone want a wooden Commodore 64 keyboard?

Things to consider when using SQL 2005 Query Notifications

When looking into why I was getting immediate notifications of a SQLDependancy being changed, I discovered a really nice MSDN2 page that documents the things to watch out for, Special Considerations When Using Query Notifications

Major things to note:

  • If you use a query that doesn't comply, you'll get notified it is out-of-date immediately, so make sure you save the query results somewhere other than Cache[] when you do have to go to SQL Server.
  • You must use two-part table names like dbo.Address, but you should be doing that anyway or you don't get pre-parsed queries. This means that you are obviously? only allowed to talk to one database.
  • Don't use any SQL that requires aggregations or row-counting. This means aggregates like AVG, MIN, MAX, DISTINCT, COUNT(*). You can use SUM on non-nullable columns in the presence of a GROUP BY, but no ROLLUP or CUBE.

For full details, consult the article.

Friday, June 23, 2006

More about exception handling and new coolness from Joshua Flanagan

Regular readers of my blog (all 14 of you), will know that I'm a stickler for handling exceptions correctly in applications. I strongly believe that you should only catch exceptions you can handle, never catch something you can't correct for, unless you have signficant contextual information you can add, then use the InnerException property, yada, yada...zzzzzzz...


Sorry about that, you were dozing off.

Anyway, as I was typing... always log exceptions in detail using a top level handler, and only stay running if it makes sense; like in ASP.Net applications.

Most of that is easy, but what about when you have a background thread in an ASP.Net application? In CLR 1.1, an unhandled exception in a background thread just killed the thread, which is bad because you don't know that it is safe for other threads to continue, and a deadlock or static-data corruption is a very real possibility. Of course, you always wrapped your outer-most function for that background thread in a try {} catch (Exception ex) { /* log it */ throw; } block, so you at least logged it. In CLR 2.0, your (proper and correct) re-throw of the Exception will result in the Application being terminated. Bummer, but we'll come back to that.

Joshua Flanagan has put together a nice WaitCallback derived class that does all the by-rote work of wrapping a thread-top-level try {} catch (Exception ex) { /* log it */ throw; } block. If that was all it did, I wouldn't be wasting your time, nice as it is to StayDRY™.

Remember what I said about CLR 2.0 dumping your Application if the background thread had an unhandled exception? Remember the pattern of rethrowing at the top-level-catch? What if we could somehow marshal that thread's exception details over to the foreground thread(s) of the ASP.Net Application where it could be handled by the handy-dandy infrastructure setup in Global.asax's HttpApplication.Error or Application_Error.

That's where Joshua's cleverness shows. He has done just that, building a nice generic framework for turning the thread-top-level exception into an inline request to an HttpHandler, passing the serialized Exception details along. Once in the handler, it's simply deserialized and thrown anew, whereupon it is caught and logged as a foreground-thread exception.

Head over to Safely running background threads in ASP.NET 2.0 and get the goods!

Monday, June 19, 2006

IIS Compression the easy way.

With server-based IIS 7.0 you get easy compression of outgoing content, but for earlier versions compression is unavailable (workstation IIS doesn't even support it). For IIS versions above 5.0 you can get very good compression support from Ripcord Software. They've just released IISxpress 2.0, and it's really slick. The configuration is well integrated into the IIS pipeline and works in an opt-out paradigm so you can easily configure specific things not to compress (sub-sites, directories, file extensions, content-type, URI, client IP, etc.) You also can watch live statistics of the files and compression ratios as they are served.

The best part? It's free for non-commercial use and only $50 for commercial use (per server). That's almost as good a deal as Paul Wilson's Wilson O/R Mapper.

Download (or buy) IISxpress here.

No remuneration was or will be paid for this recommendation, I just like this stuff

An open reply to Congressman William Lacy Clay

My vote was cast with the majority. "Net neutrality", as defined by the FCC, requires consumers' free access to any legal content, applications and devices of their choice. It also reduces the threat of gatekeepers over new content and services. In order to safeguard net neutrality, the bill contains language giving the FCC authority to intervene on a case-by-case basis, if such violations are alleged. These components and more eliminate the need for restrictive or premature "net neutrality" provision.

I personally disagree with your assessment of the protection provided by the base COPE Act. While I understand that you may disagree with the current language of the "Net neutrality" amendment, passage of the COPE Act without SPECIFIC language PREVENTING scaled-fee/rate-based-charge by the telecommunications provider levied on content providers will effectively allow discrimination of the right-to-publish based on economic means of the provider. In addition, such scaled-fee/rate-based-charges allow a second charge above and beyond what said providers are already paying for the bandwidth they use.

The language does protect the cosumer's right to recieve information, but does NOT sufficiently protect the right of publishers of that information. What good does it do for me to freely access information at a (intolerably) slower rate, merely because the publisher doesn't have deep enough pockets to pay MORE for services they've already paid for in terms of the datarate agreements and connection sizes thier provider is already contractually obligated to provide? Moreover, can you not see the danger of each level of provider layering more and more charges to those under, ending when the two or three providers at the top of the Internet peering hierarchy collecting money from everyone and benefitting no one.

The stated reason for a scaled-fee/rate-based-charge is to "make the publisher responsible for the largest bandwidth use pay for the privilege of higher-rate delivery". This is completely against what the Internet was, and continues to be, about... free access to information and the right to publish content that the CONSUMER pays to access, and the PUBLISHER pays to provide, through line connection fees and bandwidth-related charges. A delivery-rate-based charge is just another way to extract money from the publisher, and will erect barriers to publishers that cannot afford a higher quality of service. This discrimination will prevent publishers (and even individuals) from being able to publish merely based on financial means.

The aforementioned components and initiatives of the COPE Act-economic growth, universal access, anti-redlining, and "net neutrality" safeguarding-are key to allowing Internet access to grow and remain unimpeded.

The key to the growth of access to the Internet is NOT to allow the carriers one more loophole by which they can charge the publishers to provide the delivery of data that BOTH the publisher and consumer have ALREADY paid for in terms of the connection and data rates purchased.

Experience tells us that if you do NOT prevent this extortionary charge, the bandwidth providers will charge the publishers, and that this kind of charge (for services already provided) will be levied at every level, ultimately eliminating the free and open access to information that makes the Internet such a powerful source of information and innovation.

Please reconsider the importance of this CRITICAL amendment to an otherwise good legislation. Your failure to add SPECIFIC language to prevent this pay-by-rate charges will be considered a failure of you to represent me in an area near and dear to my heart. I would be hard-pressed to support you in further elections.

Sincerely, Marc C. Brooks

I don't think Microsoft really gets the web (or what's wrong with this picture?)

Go to this page... and wait... and wait... okay, now right-click and select View Source... and wait... and wait... okay, now check out the file size and line count. You should see (assuming you are using Notepad2 or some such editor) this:

In what reality is rendering a 1.02 megabyte, 3120 line page reasonable? Certainly not over the web! No wonder all these MSDN2 pages take forever to render.

Friday, June 16, 2006

I haven't got time for the rants...

Jason Bock is right. For the first time in my blog reading history, I'm dropping a blog. The irony is that I'm dropping Jason's blog. I just don't want to read another rant about how there is no god, or how fundamentalists are stupid, or how wonderful it is to be able to explain everything through the wonders of science.

Don't get me wrong, I love the scientific method and the gains in understanding it enables. I'm just not cocky enough to believe than our (humankind's) cumulative knowlege is every going to be sufficient to fully explain the universe that contains us. What there is outside of what we can understand is open to debate and faith. That is, unless you want to deny it exists simply because you can't apply science to discover it completely.


Wednesday, June 14, 2006

DotNetSlackers... (sounds like me)

There is a nice new site to head to that aggregates many .Net relate blogs and also has a forum area for Atlas-related things. Garbin has already posted a couple controls there. Head over and see how it looks.

My must-read book list (part 2, SQL)

Continuing the recommended book list from part one, here's my short list of SQL books:


  • Joel Celko's SQL For Smarties is a fine distillation of SQL syntax and strategies. He covers all of SQL in a detailed way, including views, partitioning, grouping, aggregates. From there he builts difficult queries advanced statistics, regions, runs, gaps, sequences and series. Next he takes on emulating array, sets (working on all relevant rows at once), subsetting, trees, hierarchies. Next he dives into a topic near and dear to me--temporal (time-based) queries, graphs, and OLAP. Wrapping it up, he talks about transactions, concurrency and optimizing. Simply put, it's like have a SQL ninja in your cube.
  • Joel Celko's Trees and Hierarchies in SQL for Smarties splits out the trees and hierarchies chapter from SQL for Smarties and expounds on it in a much more detailed treatment. Simply amazing detail on the issues and strategies that work.
  • Richard T. Snodgrass's Developing Time-Oriented Database Applications in SQL takes on a very difficult subject, temporal (time-based) data and explains the issues in creating efficient designs for SQL databases. It addresses the concepts of effective-time, as-entered time, bitemporal data and issues that arise when you start giving data a "when valid" or "when entered" dimension. Coverage is for several databases so you can see a solution expressed in multiple ways. Unfortunately, the book is out of print, but it is well worth the search. If nothing else, the example code for triggers that handles set-logic correctly is 100% gold.
  • Ales Spetic and Jonathan Gennick's Transact-SQL Cookbook gives great sample solutions specific to SQL Server. Some overlap with Joel's books, but a nice T-SQL perspective. He also covers audit logging and importing data, topics which are lacking in the other books given here.

That's about it for this cut, I'll update when I think of others. Stay tuned for posts about language-specific and platform-specific books. Don't miss my first part with the basics.

My must-read book list (part 1, the basics)

I have been asked so many times, so I'm putting the list here. I'll updated it from time to time, but this is my list:

Analysis and Design

  • Martin Fowler's Analysis Patterns : Reusable Object Models approaches the recurring patterns that appear in the analysis of systems (not the design/coding as Design Patterns does). He covers Accountability (organizational), Observations and Measurements (ratios, units, etc.), Corporate Finance, Inventory and Accounting, Planning, Trading, Declarative Contracts, and Trading Packages. He then talks about support patterns for the analysis of the system like, Layering, Application Facades, Type Modelling, and Association Patterns. Martin understands the concepts of modeling better than any person I've every encountered and this book does for analysis what the gang-of-four's Design Patterns does for design.
  • Martin Fowler's Patterns of Enterprise Application Architecture does for the architecture design phase of systems (especially enterprise/company-wide systems) what Analysis Patterns does for the analysis phase. This book is a reference volume filled with solutions for common architectural issues that arise when building big systems. The contexts are clearly defined and then the book dives into a problem/solution format. Each pattern clearly solves a recurring issue in systems architecture, with clear explanation of the reasoning behind the pattern.
  • Gang of Four's Design Patterns: Elements of Reusable Object-Oriented Software is the seminal work on the recurring patterns that appear in the design phase of an application. The patterns revolve around the issues that crop in the "how do we implement that" part of a project. Each one is explained in general terms based on a real-world example.

Development Process

  • Martin Fowler's Refactoring: Improving the Design of Existing Code dives into the process behind improving code quality and reuse through the process of refactoring the code. The process of refactoring is integral to modern agile development and this book tells you the patterns to apply, how to apply them in a safe way, and what the benefits and risks of each pattern are. By capturing the process as a set of patterns, Fowler reduces the risks associated with refactoring while improving the chances that you will recognise what refactorings could be applied to improve the code-base.
  • Scott Ambler's Refactoring Databases : Evolutionary Database Design does for databases what Fowler's Refactoring did for code. Scott approaches the concepts of evolving a database over time and explains testing, the patterns use when making changes, and the process of improving the quality of both the data and the structure of a database. He clearly explains the processes needed to evolve a database over time as the applications needs change and as the requirements of the database improvements trickle back up to the application code.
  • Kent Beck's Test Driven Development: By Example clearly explains what the modern movement of TDD is all about. Using clear examples Kent walks you through to process of writing the tests first, making them pass and then refactoring (red, green, refactor). This process leads to code that is provably correct, safe to evolve, and more likely to do what the requirements specify. Kent shows each step, clearly explaining the reasons and methods to apply. This process can also be applied to the database world as Ambler clearly shows in Refactoring Databases.
  • Joel Spolsky's Joel on Software: And on Diverse and Occasionally Related Matters That Will Prove of Interest to Software Developers, Designers, and Managers, and to Those Who, Whether by Good Fortune or Ill Luck, Work with Them in Some Capacity (winner for longest title this post!) is a collection of Joel's writings over the years on software design, customer focus and company management. This book is for everyone (can't you tell from the title) because he addresses things that affect everyone involved with software development. Each chapter is an essay, and each is a gem filled with ideas written in a very approachable style. Ideal "waiting for the meeting to start" reading.
  • Steve Maguire's Debugging the Development Process: Practical Strategies for Staying Focused, Hitting Ship Dates, and Building Solid Teams talks about how to organize teams to work effectively and how to avoid common snares and impediments to high productivity. It's not a modern "agile" process, but the concepts given are applicable in any environment where there is a team of developers. This book is written for the manager of developers, but even a line-programmer can benefit by learning how to teach their manager to be better.
  • Steve McConnell's Code Complete dicusses the strategies to follow to get solid, working, well designed and executed systems. Strategies from the simplest of variable naming to the complexity of code performance tuning to the shipping an actual product. This book is written for the line-programmer and even gives good advice on managing your manger. The second edition really builds on the first edition while pulling in more of the modern agile strategies that have evolved.


  • Henry Petroski's To Engineer Is Human : The Role of Failure in Successful Design discusses actual examples of how engineering designs can (and do) fail. By careful examination of past mistakes you can get a new understanding into how to prevent those kinds of failures in systems you design. The book is a delightful read, and the selected examples are familiar and clearly explained. Simply put, if you know how things have broken in the past, you are more likely to recognize the parallels in your own designs.
  • Charles Petzold's Code: The Hidden Language of Computer Hardware and Software shows how modern computer programs are really not that different than the signal flags of long ago. Building from the need to communicate over long distances, Petzold shows the evolution of coding systems into telegraphs, ticker tapes all the way to the beginning of the PC era (and frankly he should have stopped there). This book will teach a new perspective to those that have always viewed computers through high-level languages. It is very entertaining and an easy read.

That's about it for this cut, I'll update when I think of others. Stay tuned for posts about SQL, language-specific and platform-specific books.

Thursday, June 01, 2006

JavaScript SVG-emulation

If you've ever wished you had cross-browser support for SVG-type graphics everywhere, check out the cool DIV-based work of Walter Zorn. DHTML: Draw Line, Ellipse, Oval, Circle, Polyline, Polygon, Triangle with JavaScript