Phil posted on January 18, 2010 15:22

Bugs vs. Defects

I really don’t like the word ‘bug’ when describing a piece of (missing) functionality that doesn’t work correctly or has unintended consequences. I much prefer the more accurate word: defects. If you use ‘bugs’, you’re doing yourself, your projects, and your customers a disservice.

It’s a Mindset

The word ‘bug’ brings a cutesy picture of a ladybug or maybe a little grasshopper, or maybe an uglier thing like a house fly or cockroach. Get real and be professional: these are defects. Don’t trivialize your work and its consequences. Call it what it is.

Imagine you buy a car or a house (here we go with the metaphors) – how would you feel if the driver’s door had a flaw whereby the handle or lever would open the trunk on each odd turn, and open the driver’s door on each even turn? What about a defect where your GPS took you to the wrong destination? How frustrating or expensive would it be, for you as the customer, to work around that?

If your software doesn’t do what you intended/written, then you haven’t tested enough. Shipping that product is, by and large, up to you. If your product contains untested/unpredictable behaviour, that’s all on you!

Not Helping

Yes, it’s a nice story about Grace Hopper and the moth at Harvard. Of course, it’s an easy feel-better-about-yourself term that’s used. However, it becomes an uphill battle for those professionals who care about terminology when there are products called Bugzilla and FogBugz in the bug-tracking line of programs. I use both, and both are great at what they do.

Of course, the term ‘bug’ is well engrained into our minds and language, and has even crept into the language of the non-programmer.

Personal Software Process

Personal-Software-Process-Watts-S-Humphrey This reminds me of one of the textbooks at BCIT’s CST program. It’s the Personal Software Process by Watts S. Humphrey. Watts is crazy-focused on software quality. One distinct lesson I got from that particular course was the concept of constantly recording and measuring. Defects per 1000 lines of code (KLOC). The other theme, perhaps in the book, or with that particular instructor, was this idea of ‘defects’, and not ‘bugs’.

Own Your Defects

I’ve come to this conclusion for myself when thinking about flaws in software:

Don’t trivialize those flaws with your words, own them. Call them what they are – flaws and defects!


Posted in: development , punditry  Tags:
Actions: E-mail | Permalink | Comments (0) |

Consider your behaviour and desires as a customer when you visit:

a) your favourite local coffee shop - you specify what you'd like, rather than how it's made. You care about the outcome, but rarely care about the process/sequences/steps that are followed as it's being constructed.
b) a Subway/Quiznos shop - you care equally about the outcome and the construction. Meats, veggies, bread type, order of placement of each, precise amount of mustard, pickles, etc.

baristaThe difference here is: you aren't instructing the coffee barista on how to steam the milk, or when to start brewing the espresso. You don't remind them that their level of ground beans is getting low, or where to store the milk. You are happy to assume they know their job best, and order of operations is properly under their control. They have their efficiencies to care about, and you're happy to let them manage that.

Consider now your desires as a programmer when your task is to find customers with a condition. Let's say we want to use this contrived example:

    Find the customers whose account balance owing is over $5,000. Find the youngest customer in that set. 
 

The Sandwich Model of Algorithms

//find all customers with the appropriate account balance
var owingOver5000 = new List<Customer>();
foreach (Customer c in myCustomers)
{
if (c.TotalAmountOwing > 5000)
{
owingOver5000.Add(c);
}
}

var youngestCust;
DateTime youngestBirthdate=null;

foreach(Customer c in owingOver5000)
{
//initialize on the first go-round; many ways to do this.
if (youngestBirthdate==null)
{
youngestBirthdate=c.BirthDate;
}

//find the youngest by their age
if (c.Birthdate < youngestBirthdate) //pretend nobody has the same birthdate ;)
{
youngestCust = c;
}
}
//you now have youngestCust populated (in most cases)


Very fine-grain operations are explicitly laid out by the developer, and execution path follows exactly what the developer wrote. Defects and all! The number of defects is up to you!

The Coffee Shop Model of Algorithms

Consider now the Coffee Shop model of this algorithm. We'll use LINQ.

var youngestCust = myCustomers
.Where(c=>c.TotalAmountOwing > 5000)
.OrderBy(c=>c.BirthDate)
.SingleOrDefault();

It should be obvious to you now, if it wasn't at the start: the LINQ extension methods are doing all the looping for you, and taking care of all the small bits and housekeeping. You, as the customer, don't want to care about how it's found, but rather, you declare what you want.

Outsource Your Loops

I hate to steal Eric Lippert's thought on this, but it's worth saying once more in a different way:

Avoid loops. They’re becoming a code smell. Let built-in methods and functionality do the boring non-value added logic for you.

You should be focused on YOUR business logic or end-goals (i.e. eating your sandwich and drinking your coffee), and less on syntax + language constructs. Take advantage of more declarative constructs provided in your language/framework. LINQ is a perfect example of this.

*this post is a mashup of Luca Bolognese's PDC 2008 F# metaphor and Eric Lippert's post on loops. Apologies to both!


Posted in: development , best practices , linq  Tags:
Actions: E-mail | Permalink | Comments (0) |
Phil posted on January 8, 2010 09:52

2009 was a great year for me professionally. I've focused on continually learning new things and patterns in software development. There was a fair amount of professional growth, learning, and the realization that there is so much more to learn.

One benefit of taking a new job/position is that it helps you realize how much you don't know. I've taken on a few new skills/technologies, sharpened a few existing skills, and challenged myself to re-evaluate some beliefs or patterns I've held for a while. One exciting event was a presentation to the British Columbia Health CIO Council. The topic was our adoption of the Enterprise Master Patient Index project as part of the Electronic Health Record initiative.

Tech Learnings


ASP.NET MVC

My opinion of ASP.NET MVC went from 'terrible idea' in 2007 to 'awesome' today. At first I just did not get ASP.NET MVC; I thought it was classic ASP all over again, and I totally balked. I was looking for asp:GridViews and trying to output server controls. Then I got it. What really nailed it for me was Dino Esposito's talk at DevConnections in Fall 2008 where he made clear the distinction of ASP.NET (the HTTP runtime) and WebForms (the abstraction of state and page lifecycle). I’ll frequently use Hanselman’s Motorcycle vs Car analogy.

Not to knock on WebForms, because it’s provided a lot of benefit to me, my projects,  and my customers for years. WebForms provides so much abstraction with its incredible productivity gains, but feels a bit dirty when it comes to control-over-HTML.

I dove into ASP.NET MVC, and the NerdDinner sample app was a huge help in many respects. I followed up by purchasing the Hanselman/Haack/Guthrie/Conery MVC book, which is a great resource.

I was lucky enough to develop and implement 3 MVC apps, and have 2 personal projects using ASP.NET MVC. I am excited to use ASP.NET MVC for projects where I care about markup and testability. More from Dino on ASP.NET MVC.

LINQ

linq A major tool to discover and learn more about in 2009. Upcoming investment in the dead-tree edition of LINQ In Action http://www.manning.com/marguerie/. I am finding it fun to have a list of objects and write a LINQ query. It makes coding that much easier! I started with the 'query' syntax, but much rather prefer the 'dot notation' syntax. The 'query' syntax for joins, however is much easier to read and write

jQuery

No question JavaScript has been a help in my web projects, but a pain to work with in the browser at development-time. Most of my logic has been server-side, but I know I can do better to give the user a better experience in using my apps. jQuery has been fun to start learning, and it's satisfying to be able to use a few lines of code with terse syntax to have your form elements behave as you want. The usability of the jQuery libraries is stunning. Truly this is a 'for-developers, by-developers' library, like they've anticipated your needs. I have yet to have a need and not have jQuery have a solution. I am looking forward to more jQuery in 2010.

Systems Integration & Health Care Messaging

A major learning for me was around integrating different existing systems. I had gotten used to creating greenfield solutions or solutions where both/all ends were totally under my control. I had smaller integration subprojects where, for example, I was taking waterslide orders from an Excel document, and creating new records in my app. In that case, my solution was the consumer of that data.

In my recent integration projects, the source and end consumer is a downstream system that I don't have control of. Actually my project is the broker/intermediaries between the source and destination. Further complicating things, there are 3 systems within this intermediary, each on different technology stacks. So the learning for me was to be the middle-man, and to work with constraints on both side of that data transfer.

Unit Testing

In my projects previous, I'd tried to create unit testing projects to help keep my code meet its requirements, and to keep code changes from deviating away from those requirements. Only recently have I begun to rely on unit tests to ensure my changes don't break.

osherove_cover150With VS 2005, I was using NUnit to test my business logic in .dll assemblies. At the time I had lots of code in code-behind, and of course, that's difficult to put under test. Fast forward to today with Visual Studio's Test Project, I've abandoned NUnit. After writing a (large ? 70+ tests) set of unit tests for this particular set of web service logic have I finally proved to myself the value of unit tests. The payoff moments came when my implementations had to change (LINQifying some algorithm), and when new requirements/feature were added.

From here on out, any important logic will be under test. I feel a book purchase upcomingThe Art of Unit Testing by Roy Osherove

Large Scale Applications

I've had the pleasure of taking on two large scale health care applications this year. One had its technical requirements well laid out (mostly), and the other was a collaborative effort with my counterparts 500km away. Some lessons learned around large projects: 

  • large numbers/skills/discipline/remoteness of team members make for interesting and different challenges on each of those attributes
  • scalability will come back to bite you if you haven't prepared!

Project Successes


Deployment - I was lucky enough to have been a part of a successful software project this year. I developed and deployed a large scale enterprise app that brokers 6000+ messages per day. The important attribute is that humans are directly waiting for these messages to cross & acknowledge back to them. It would be nice to be able to be able to publish a high level systems diagram here instead. In this case, success is measured in user acceptance, on-time delivery, and stability.

Managing Changes - A few times I've gotten the call/email or attended a meeting where a *breaking change* was discussed/agreed on. Not to get into a performance review here, but I found myself reacting quickly to those changes, and have breathed a sigh of relief when my implementation handled those changes well. Is it luck?

Looking Toward 2010

2010_inukshuk My answer to New Years resolutions is: why wait until the turn of the year to set goals for self-improvement? What were you doing throughout the year?! In any case, my list of professional goals this year are:

  • Learn A New Language! I have been listening to the endless talk of Ruby and Python. I fully value the concept of 'knowing more than one and many languages', both in software and in life. So this year, I'll be taking on (one of) Ruby, Python or F#. The great thing about these languages is that they're dynamically typed. F# is a first-class .NET language, but it's not clear whether IronRuby and IronPython will be first class languages in Visual Studio 2010. I am looking forward to F# in that it's a functional programming language. I will be learning WHEN to use a functional language, and I will be posting my findings. My first intro is Luca Bolognese's PDC 2008 video presentation: "An Introduction to Microsoft F#".  'let' doesn't mean assign a value to a variable, but bind a value to a symbol!
  • Deploy More Personal Projects! There's nothing worse for a developer with ideas than to NOT convert on them. Smaller designs, shorter iterations, deploy more. Cost isn't an issue, really!
  • Find A Good Webhost. I think I've already done this with SoftSys. Their .NET 3.5 hosting packages include SQL Server, which is my #1 requirement for hosting. Goodbye DiscountASP!
  • Move This Blog to SubText! I feel that BlogEngine.NET was an upgrade over DasBlog. Both aren't being actively developed and maintained. After having used SubText for my internal blog, I feel comfortable enough with SubText and *its continued development*! It requires SQL Server 2005 / Express.
  • Do These Things Better: Document changes. Make more graphs.

How Are You Improving ?

What professional challenges and successes did you have? How are you striving to be better in what you do? Are you ‘sharpening the saw’ in regards to your professional skills?


Posted in: development , unit testing , improvement  Tags:
Actions: E-mail | Permalink | Comments (0) |

sqlmag

I’ve had a subscription myself for 2 years now to SqlMag. They’re one of many of Penton Media’s magazines, along with the Windows IT Pro site. I like paper mags for portability’s sake – the beach, roadtrips, etc. The same goes for Code Magazine and MSDN Magazine.

Dead Tree Edition?

I’ve often asked myself if a paper-magazine-delivered-to-your-door makes any sense these days. Rather, does it make sense to me? Obviously the magazine industry has been in trouble, along with every other industry, since the internet moved their cheese. Along with that analysis is the subscription cost of the magazine, and its (perceived) benefits.

  • Can I get this content, or similar, or better in other places?
  • Why do I need the paper version?
  • Yes, they let you into their walled garden of SQL Server content when you’re a subscriber, but…
  • Is the content actually useful to me?

Yays

Nays

  • they’ve got Itzik Ben-Gan
  • a perception of trust
  • content is NOT automatically out-of-date on arrival
  • too many ads & ads are not relevant to me
  • yes, ads are their business!
  • content not always suited to me
  • far too many other free resources on the internet

 

SqlMag’s Top 10 IT Websites – December 2009 edition

Flipping through the Dec. 2009 copy, I saw something that had me questioning SqlMag’s quality and relevance. The headline was straightforward – Your Top 10 Favourite IT Websites. The “Your” bit seems to indicate that the readers had a vote in it, or… something. The list of sites, though, got me a bit suspicious. More than a few questionable choices here, and it was just too much to not say something. Let’s take a look:

sql-server-magazine-top-10-december-2009 10. Google – this was waaay to obvious to be on anyone’s serious list of IT websites. Can you even call this an IT website?! It’s certainly got lots of content indexed, but questionable whether it’s an actual IT website. If they’d mentioned Google Code, then I could see where they were headed.

9. Major Geeks – this stood out like a sore thumb. Isn’t this a shareware/utilities download site? I can’t remember the last time I specifically visited the site on my own desire, but it was probably for a copy of WinZip 5.0 in 1998.

8. TechNet – sure.  A solid and stable resource put out by a major 1st party vendor. Lots and lots of technical info on anything Microsoft that you’re administering.

7. The Register – whaaa? This site is an anti-Microsoft FUD machine. Take the worst of Britain’s tabloid industry, combine with dash of tech news, and you’ve got “the Reg”. A terrible pick!

6. ServerFault – now you’re talking. A Q&A site for system administrators and IT professionals that's free. Perfect, a well deserved site.

5. Slashdot – hardly a tech resource, in my opinion. Call it Tech News 1.0, run by editors with their ‘base’. It’s full of anti-Microsoft FUD, this time with their Borg.gif adorning any Microsoft story. That, to me, shows exactly the level of professionalism the site operates with. A terrible pick for your Top 10. I’m debating whether it’s Slashdot or The Register who use the term ‘M$’ more often than the other. Another sore thumb of a pick. Aside – who really thinks that term is funny?

4. Windows IT Pro – the readers submitted the parent company’s flagship website as a Favourite IT Website? Something doesn’t smell right here.

3. GPAnswers – admittedly I do NOT or haven’t visited this site. Certainly Group Policy is a major set of tools to help set rules around A.D and the computers and users within. GPAnswers’ forums are running on vBulletin, and is run by a Group Policy MVP.

2. CodeProject – a clearinghouse for articles and how-to projects. A worthwhile consideration, but certainly not #2 on my list.

1. Experts Exchange – ARE YOU FREAKING KIDDING ME?! You’ve lost your mind, SqlMag! This site is the absolute scummiest Q&A site on the planet. Their entire business model is built around CLOAKING their site, and TRICKING THEIR VISITORS into paying. (Yes, you can see the full set of user answers when you scroll 8 pages down!)

SqlMag, bad choice for your #1. Even if this list WAS user-generated, which I doubt, any list that includes Experts Exchange loses credibility, in my eyes. When I’ve asked any developer about their experience in finding good answers from that site, roundly I’ve heard nothing but bad things. I’ve even thought this piece was done by an intern, or some writer’s little cousin’s brother.

My Own Top 10 Tech Sites

I can’t sit and cast my personal judgement on their picks for Top 10. Let’s see how hard it will be for me, maybe it’s tough!

  1. StackOverflow & ServerFault
  2. Channel 9
  3. CodePlex
  4. Your RSS reader + your fav blogs. Take it to 10+, or as far as you like.  Mine include developers and leaders in the community – Phil Haack, Jon Skeet, Scott Hanselman, Scott Gu, Brent Ozar, and more.

You don’t need 10 to get a good list. StackOverflow is full of excellent questions and answers on EVERYTHING a developer needs. The amount of quality answers and quality answerers are enough for a top 50 list.

Online Really Has Moved Their Cheese

I can’t bring myself to pay any more money for the mag. That really sucks for the people who work on the mag, and that industry in general but they’ve got incredible opportunities to redirect their efforts on the web. The shift in the print industry has been obvious for years, hopefully they can improve their website to keep users/readers coming back. I believe that established industries need to be more agile or nimble in their ability to change with technology.

If their strategy is to continue to grab technical readers, and SQL Server being one of those topics/content areas, then they really should ask themselves: “What do database professionals need/want?” Is it education, how-to, one-way articles, Q&A, user-created content, interaction with your authors… there are lots of ideas out there.


Posted in: learning , punditry  Tags:
Actions: E-mail | Permalink | Comments (1) |
Phil posted on December 12, 2009 07:08

Recently I found myself with the desire to start a new site. Rather than jumping into Visual Studio headfirst, I sat down and thought about how to start.

  • What technology am I going to use? I always jump to this in the Top 5 Things I Consider, and I know it’s not terribly important, and I know I should be thinking of other things. I always know the answer to this question, though.
  • What features should be on this site? Getting warmer. I typically write down the main features of the site goals of the user in point form. I am trying to train myself with this way of thinking: The site doesn’t matter without the users wanting it to. Don’t think about features, think about the user’s goals.
  • Monetize? Sure, in some small way, but that’s not the main point of this new site, though.
  • How will the user see and contribute to the site? Most important and relevant question. Piss off your users, or make it too complicated, or too lame, and you’ll lose visitors.

The typical process I go through when faced with a new idea and a fresh start is to pull out the pad of paper and a pen. I am not a design genius, like most software developers, but try my best to grok user experience. Sometimes I fall flat, sometimes I look back at previous work and throw up a little, and sometimes I am happy. Most of the time, I think I’m just lucky that I don’t have too much scrutiny on my layouts and flow in my corporate line of business web apps.

mockingbird

I found this site recommended a few times on StackOverflow. It’s almost self explanatory to how the site works.

mockingbird mockup of youtube

Draggy, Droppy, Stretchy, Copy

There’s a palette on the left, and a design surface on the right. Make a page for each of the user-goals. This isn’t going to be set in stone, and things will change. Arrange the page elements on the design surface as you like.

Some neat features or user experiences I noticed:

  • Labels/text scale nicely as you grab the corner and stretch. It (smartly) figures out when to bold and/or increase the size of your label. Other elements scale beautifully, especially those that are icons – calendar, pie chart, Twitter logo, etc.
  • Double click any element to modify its text or contents – just as you’d expect.
  • Configuring a Linkbar was easy. Mockingbird really nailed this element.
  • You’re able to associate links with pages that you’ve already defined. Just drag the Page on the left onto a form element.
  • Elements are very generic – no Windows or Mac bias. It’s just a rounded rectangle representing a button.
  • There are lots of great elements that trigger new ideas. Seeing the Map and the Banner ad were great. Aside - tag clouds – meh… does anyone really like and use the tag cloud in the real world? I know StackOverflow has one, but I have never used it.
  • The overall feel or experience is very much like a sketch. Positioning elements is made easier thanks to the horizontal and vertical alignment bars. Nice touch!

mockingbird thumbnail grid

Go Try It

Just jump into mockingbird. You don’t need to create a mockingbird account to try; only to save and retrieve your designs. It’s free!

I wonder what platform mockingbird is running? Oh wait, it’s called Cappuccino  (learn more) and it’s

implemented using a new programming language called Objective-J, which is modelled after Objective-C and built entirely on top of JavaScript

Very cool user experience! Kudos to the mockingbird developers Saikat and Sheena.


Posted in: development , design  Tags:
Actions: E-mail | Permalink | Comments (0) |
Phil posted on December 11, 2009 03:06

Here’s a class that’ll make your life easier when you want to deal with saving information in cookies on your user’s browser. Everyone needs a wrapper class for all those external data-stores – session, cookies, file system, web.config and app.config, registry, log files, etc. Here’s a class usable in ASP.NET Web Forms and ASP.NET MVC.

Wrapper Class

Here’s a static class that you can simply include in your web project, and refer to its static properties to get to your cookies. Any and all simple datatypes can be used, and heck, even serialized versions of your POCO objects can be saved/retrieved here. Image if you wanted to save those shopping cart items, a collection of user prefs, or whatever, you could simply override the .toString() method in your custom class.

Just Make Properties

The key pattern here is that you purposefully create new properties for each piece of data that you want to save/retrieve. This solves the problem of:

  • having to remember strings all over your project.
  • ensuring no duplicates exist – imagine if multiple developers created a defect by using the same string indexer for their cookie, and ended up stomping each other’s value?
  • typos in cookie names.

Instead, the data access cookie-retrieval is done through named properties. This solution solves all those potential problems. Here’s a peek at one of these properties.

public static string UserFullName
{
get { return GetCookieVal(CookieItem.UserFullName); }
set { UpdateCookieVal(CookieItem.UserFullName, value, 365); }
}

Enums Help

With the aforementioned ‘remembering strings’ problem, the pattern that this class uses relies internally on an enum to handle the naming of the value in the cookie. The enum will boil down to an integer, but really we don’t care what the key’s is actually stored as in the cookie. We really only care to access/read/save the values constantly and easily from our calling code.

Download

Download the cookie class, or copy/paste from below. You can see that I pre-loaded it with some amusing properties for your entertainment!

Be sure to change the ApplicationName const at the top.

Special thanks to Special-K!

using System;
using System.Web;

namespace MyNamespace
{
public class Cookies
{
private const string ApplicationName = "MyCoolApplication";

private enum CookieItem
{
UserGuid,
UserFullName,
UserLoginExpiry,
UserHadForBreakfast,
UserTimezone
}
/**************
All cookie values are accessible by public static methods.
No typos/duplicates are possible from calling code!
**************/

public static string UserFullName
{
get { return GetCookieVal(CookieItem.UserFullName); }
set { UpdateCookieVal(CookieItem.UserFullName, value, 365); }
}

public static Guid UserGuid
{
get { return new Guid(GetCookieVal(CookieItem.UserGuid)); }
set { UpdateCookieVal(CookieItem.UserGuid, value.ToString(), 365); }
}

public static DateTime UserLoginExpiry
{
get { return DateTime.Parse(GetCookieVal(CookieItem.UserLoginExpiry)); }
set { UpdateCookieVal(CookieItem.UserLoginExpiry, value.ToString(), 365); }
}

public static string UserHadForBreakfast
{
get { return GetCookieVal(CookieItem.UserHadForBreakfast); }
set { UpdateCookieVal(CookieItem.UserHadForBreakfast, value, 1); }
}

private static string GetCookieVal(CookieItem item)
{
HttpCookie cookie = GetAppCookie(false); //get the existing cookie
return (cookie != null && (cookie.Values[item.ToString()] != null)) //value or empty if doesn't exist
? cookie.Values[item.ToString()]
: string.Empty;
}

private static void UpdateCookieVal(CookieItem item, string val, int expireDays)
{
//get the existing cookie (or new if not exists)
HttpCookie cookie = GetAppCookie(true);

//modify its contents & meta.
cookie.Expires = DateTime.Now.AddDays(expireDays);
cookie.Values[item.ToString()] = val;

//add back to the http response to send back to the browser
HttpContext.Current.Response.Cookies.Add(cookie);
}

private static HttpCookie GetAppCookie(bool createIfDoesntExist)
{
//get the cookie or a new one if indicated
return HttpContext.Current.Request.Cookies[ApplicationName] ?? ((createIfDoesntExist) ? new HttpCookie(ApplicationName) : null);
}

}
}


Posted in: c# , asp.net , best practices , code blowout , development  Tags:
Actions: E-mail | Permalink | Comments (0) |
Phil posted on November 28, 2009 20:32

Just a quick recent thought. As I am watching the PDC09 videos made available free online by Microsoft, I got me thinking more about the recent changes/improvements in VB. A new feature for VB 9 in 2008 was XML Literals. You know, writing/pasting plain old XML into your source code.  Like this simple example:

dim myXML =  <custs>
<cust ID="5" Name="Oscar" />
<cust ID="9" Name="Ernie" />
</custs>

My thoughts went like this:

  • hey, cool! you don’t have to wrap it in strings, thank goodness.
  • hmm, why would you be hardcoding XML anyway?
  • that belongs in a resource file somewhere, really.

I basically have written off this feature as demoware, really, until I saw the video of Lucian Wischik’s session “Code Like the Wind with Microsoft Visual Basic 2010”. There was one really intriguing feature in his demo of a VB Silverlight component.

The key task that lured me in was a fairly simple demo dealing with HTML replacement. Great application of the technology! If you’re being careful to write your HTML as XHTML, then this is a great way to use VB’s XML Literals feature. Here’s the simple use case from the demo:

  • clicking an input button
  • replacing the innerHTML of a div

 Lucian-InnerHTML

The great thing I like about this that you don’t necessarily have to mess around with string.Format() or string.Concat() and all those other small speedbumps. i.e.

myDiv.innerHTML = string.Format("<p><i>Hello {0}</i><hr/><b>Hello everyone, welcome to VB XML Literals</b></p>",customerName)

Perhaps take it a step further and externalize those snippets if you like. My first thought on that snippet was: “document.getElement? WHAT? Get some jQuery in there! Doh - it’s code-behind!” Interesting how it’s declared as an Object while being assigned Browser.HtmlPage.Document. Likely it’s a quick/dirty demo artifact.

Useful in the Real World?

There’s always the balance of demoware vs. actual best practices vs. your development standards. I am leery of hardcoding markup in your compiled app. It’ll take an application redeploy to change that markup to something different.

Of course, in the real world, you’d probably be loading something user-specific here, like a customer’s name, shopping cart, etc. where you’d be wanting to string.Format() all those details anyway. Heck, you’d even want to iterate through your invoices, tweets, or whatever collection you’d want to start building a simple <ul> with your collection of business data in <li>.

Even if it was a simple replacement of XML, with some business logic around which snippet to insert, consider if you'd had externalized those snippet into an XML resource file(s), you could refer to them easily, although not as simple as strongly typed XML literals compiled in a resource file. There’s that balance again – ease of coding vs. maintainability in production.

I always like discovering new personalities at Microsoft. I’ll be RSS’ing Lucian’s blog, looking forward to seeing any great content he might share.

Real World Production Examples?

Do you know of any examples in the real world of VB and XML Literals in a production app? If/when I find some, I’ll post a link here!


Posted in: visual basic  Tags:
Actions: E-mail | Permalink | Comments (0) |

cruft_folder_2Usually when jumping into a new OS, I largely disregard the built in programs. My typical thought is that they’re for newbies, grandmas, and otherwise lack the features that other 3rd party programs offer. (think MSPaint, Getting Started, Fax/Scanner Wizard, Welcome to XP videos, etc). It got so annoying that I actually go out of my way on new installs to make a new folder on the Start Menu to bury those shortcuts.

Windows 7 Snipping Tool Special-K  brought the new Windows 7 Snipping Tool to my attention, and it’s most definitely a productivity enhancer. My snap judgement was “really, a built-in Windows tool?”, but after 10 seconds of using this tool, I knew I’d be using it immediately in place of my current screenshotting process.

Screenshotting

Here’s my typical OLD style of creating a screenshot. Typical use case here is to send a cropped & marked-up screenshot by email, or perhaps for insert into Windows Live Writer.

paint_net Total Clicks/Buttons = up to 15

  • Alt-PrtScn
  • Open Paint.NET
  • Ctrl-V
  • Start cropping
  • Change the color selector to red or yellow or something to make your selection stand out
  • Select the Oval or Rectangle tool to highlight what you need. When Oval doesn’t line up the way you want, Ctrl-Z, and try again x3.
  • Either: a) Select All –> Ctrl V into a new email or b) Save As –> enter a filename, save to desktop. Open email client (Gmail or Outlook), and attach to email as attachment.

Stop the Insanity with Win7’s Snipping Tool

 

Windows 7 Snipping Tool Total Clicks = max 5

  • Keyboard Start key
  • Type sn as if you were typing snipping tool. Hit Enter.
  • Start cropping
  • Highlight, markup, erase, recrop to your heart’s content.
  • Click the Email button to generate a new email message with the image embedded. Launches the default mail client. Works well with Outlook and Gmail.
snip_types

Being the artsy type, you’ll probably want to screenshot in different ways. I think the typical use-case would be the rectangle, whereby you click-drag a rectangle to highlight the parts of your screen that you want. Otherwise, you have the ability to screenshot:

  • a window you choose (it outlines the window when you hover over it, Win7 style)
  • free-form, lasso-style!
  • the entire screen

 

Caveats (or not!)

  • doesn’t work well when you’re trying to capture something from your Start menu!
  • not a caveat – it’s super easy to snip/screenshot your entire toolbar. Select Window Snip, and click your toolbar. The tool captures just your toolbar, from Start button to minimize button. Awesome!
  • not a caveat – saves as .png by default. Yes, Paint.NET does this as well.
  • not a caveat – turns out the .exe isn’t named winsnip.exe (which I would have loved), but rather c:\Windows\System32\SnippingTool.exe

snipping_tool_windows_7_markup_msdn


Posted in: windows 7 , shortcuts , microsoft  Tags:
Actions: E-mail | Permalink | Comments (0) |