Scott Hanselman

Help your users record and report bugs with the Problem Steps Recorder

October 9, '12 Comments [43] Posted in Bugs | Tools
Sponsored By

A few weeks back I ranted in Everything's broken and nobody's upset and it found its way around the web. Some called it a poorly  organized straw man and others felt it was a decent jumping-off point for a larger discussion about software quality. It was likely both of these and more.

On the subject of bug reporting, there's a wonderful gem of a program that ships with Windows 7 and Windows 8 that you and your users can use to report and record bugs. It's the Problem Steps Recorder and it's like TiVo for bugs.

Hit the Start button and type either "Steps" or even "PSR" or to run the Problem Steps Recorder.

Problem Steps Recorder

Click Start Record and reproduce your bug. You can even click "Add Comment" to highlight an area of the screen as a call-out.

Problem Steps Recorder records your clicks

It's kind of a poor-man's screencasting tool. Rather than a heavy full screen video, the Steps Recorder is taking a screenshot on each click or action.

The user can then save the whole thing as as ZIP or just click "Email." I plan on using this the next time my non-technical parents have an issue they want to report.

Since this little app ships with Windows, why not launch it directly from your product's interface or 'Send Feedback' link? Then you could automate the receipt of these recorded problems and directly inject the resulting files into your bug reporting system.

What do you think?

Related Posts in this Three Part series on Software Quality

  1. Everything's broken and nobody's upset
  2. A Bug Report is a Gift
  3. Help your users record and report bugs with the Problem Steps Recorder

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Amazon Kindle Paperwhite 3G/Wi-Fi Review

October 9, '12 Comments [73] Posted in Reviews
Sponsored By

Kindle PaperwhiteOk, let's just get this out of the way. Of all the gadgets I've purchased, I love my Kindle. I have, in fact, owned every Kindle at every step of the way. I've also owned every iPad, but there's been more Kindles.

Related Reading

It could be said that my love of e-reading started with my ill-fated purchase of an Apple Newton in 1993 and then my even more ill-fated second purchase of an Apple Newton MessagePad 2000 in 2007. Let's just say I'm a sucker for small devices with gray screens.

I've talked about the Sony Reader as well in Sony Reader and Amazon Kindle - Will eBooks happen this time? but ended up going all Kindle and I haven't regretted it yet.

My mom got a Kindle Fire and is generally thrilled with this, although she thinks it's getting slower. I suspect that she's getting faster.

I recently "upgraded" my gray Kindle 3G to the new Kindle Paperwhite.

It's Fine

It's fine. OK, it's "fine." But let's be serious for a second. Every technology site is gushing about this device. They're saying this is the e-reader to end all e-readers. It's glorious, it's perfect. Friends, it's not. And this is from a Kindle Fan. A Kindle Stan, even. But I can't gush about this new device. If you want gushing, go read Gizvergmashgadget.

I regret my purchase of a Kindle Paperwhite and I will mourn the death (when it happens...has it happened?) of the superior Kindle 3G. There, I said it. I'm confused why others haven't said as much.

I miss my Kindle 3G. It's better device. It's larger, it's easier to hold, it has a physical keyboard, it has an audio jack for headphones, it has text-to-speech, it supports MP3s and audiobooks. It has physical buttons for turning pages.

I gave up all these features for a backlit screen. The thing is, there's lights everywhere. I have no problem reading under one. The whole reading-on-a-totally-dark-plane thing just doesn't do it for me. Same with reading in a bed. I have a small lamp and the wife isn't bothered by the nightstand's 7W LED light.

The Good

It's small, it's light, it's pretty, it's sturdy, it's got a good screen. They say that they've increased contrast. I don't really see it but I believe them. It's supposed to be 25% better but that's hard to see. It's a lovely e-ink screen.

The name Paperwhite kind of bothers me. For some reason I assumed (and it's my fault) that the screen was whiter, like paper. I wonder how I got that idea. Turns out, if you're in the dark and the backlight (actually a side-light) is on, then the screen looks whiter. Unfortunately it only looks whiter the darker the room is. In regular light it's the same newsprint gray that we've seen before.

UPDATE - Oct 18th: The Paperwhite Cover

I bought the Kindle Paperwhite Leather Cover in Black and I have to say that it changes my opinion of this whole experience in a significant way. It doesn't fix everything, but I like the Paperwhite a LOT more now and it's specifically the cover that improves it.

First, the grip. The Paperwhite is small and the bezels on the side are thin. The cover adds just the right amount of bulk to the device to make it feel more substantial while still being easy to hold in one hand. More importantly this specific cover adds width to the bezel which gives my thumbs a place to be.

The cover also has a magnet clasp. This is an improvement over the rubber band cover I used with the Kindle 3G. The magnet clasp also turns device on and off which is brilliant. Open it, it turns on and lights up. Close it and it's off. It feels more "book-like" with this small feature.

The Paperwhite has its sides, corners and black completely covered, protected and  snug in this cover. It's not something you'll want to take really becomes part of the device. I highly recommend this cover and if you get a Paperwhite you should absolutely pick up a cover as well.

Kindle Paperwhite Magnetic Cover not assembledKindle Paperwhite Magnetic CoverKindle Paperwhite Magnetic Cover open

The Light

Blame the name, perhaps. When you hear gushing about "Paperwhite" and "our best screen ever" your expectation is high. However, the light is uneven as you can see in the un-doctored photo below. I count four small white LEDs at the very bottom shining light up the face of the screen. You can see the dark shadows between the lights about 20% of the way up the screen. It's distracting, and it's even more distracting the darker the room gets.

Kindle paperwhite with uneven backlight

You can adjust the light but I haven't found any use for this adjustment. I either have it completely on or completely off. Anything in between just makes the splotchy light intolerable.


Screen Speed and Clarity

They say improvements  have been made in the speed of the device and how it refreshes the screen. Early versions of the Kindle would turn the whole screen black as the e-ink balls would flip over to black en masse then flip back individually to display a page. It's unclear to me if these "improvements" are actual hardware improvements or software ones. I suspect a little of both.

By default the Kindle Paperwhite will only do a full refresh of the e-ink every 3 or 4 page turns. You can change this setting if you want to force a full page refresh on each turn. Why would you want to do that? Well, take a look at these two pictures. The first is of a page turned to with the default setting. The second is the same page with a full page refresh. Look closely at the first picture. That's not a camera blur or visual aberration. That's the ghosted letters of the previous three pages. It almost looks like a poorly erased Etch-A-Sketch (which makes sense, since that's what e-ink is at it's most basic.)

Kindle Paperwhite with text ghostingKindle Paperwhite with NO text ghosting

Once you've seen this ghosting you can't easily unsee it. It's pretty disappointing and I've turned this setting off. I encourage you to make your own judgment. It's a tradeoff between fast page turns without the black "flash" and clear text.


I've also found the font choice to be very limited. I wish the Kindle folks had the attention to detail of a Marco Arment when it comes to choosing a typeface. There's only two serifs and a weird hybrid called Caecilia. Only the classic Palatino is even close to readable in my view.


There's a new feature called "X-Ray" that is enabled in some books. I've found it to be a cute gimmick but it's provided zero value in my reading over the last week. I don't see any reason for it so far. Perhaps new visualizations are coming. For now, meh is the unfortunate word.

Kindle Paperwhite with X-RayKindle Paperwhite with X-Ray

One new feature I think I like is the "Time to read" where the Kindle keeps track of your reading speed and optionally estimates the number of hours or minutes until the end of the chapter or book. I've found this useful when deciding when to go to bed. ;) If it's just 15 more minutes to finish the book I'll just finish it!

New Kindle StorefrontOnly 6 minutes left in this chapter

What's missing?

Perhaps I have large hands, but the Kindle Paperwhite is SMALL. It's so small it's little hard to comfortably hold in one had. The bezel on the sides is small enough that I can't easily hold the thing with my thumb pressure as my thumb is wider than the side bezel. I end up holding it at the bottom. Perhaps this is another reason I like the Kindle 3G since it has a large keyboard at the bottom. That's more stuff to hold on to.

I really miss the physical buttons. You HAVE to touch the screen to turn the page on the Paperwhite. They've organized screen regions so you just tap the right 85% of the screen to go to the next page and the left 15% to go to the previous. The top 10% gets you the menu. But you have to touch the SCREEN. It feels papery but it can also get dirty. I never, ever touched the screen of my 3G with keyboard. I never needed to because it had physical buttons for turning the page. They were brilliant because they were just under your thumb and just required a twitch to move forward.

I am also a huge Audible audiobook fan but those days are over. The Kindle Paperwhite has no headphone jack or speaker. This MUST be a cost-cutting decision, likely based on some study or survey that showed a single digit percentage of folks using the Kindle for audiobooks. But I did, and I miss it more now that it's gone.

Kindle Paperwhite with large fontsMy hand compared to the Kindle Paperwhite

There's the same anemic web browser as before. It's enough to get the job done but it's also slow enough to remind you that they'd rather you buy a Kindle Fire HD. It's a book, not a tablet.


As I said, it's fine. It's a lovely miracle, even. I read more now than I did pre-Kindle, truly. I have purchased over a hundred books from Amazon since my first Kindle (139, in fact) and that was the goal. There's a single click between my Wallet and Jeff Bezo's Wallet. However, there's still work to be done on the Kindle. The Kindle Paperwhite isn't the ultimate e-reader. But it's fine.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hacking Diabetes

October 5, '12 Comments [41] Posted in Diabetes
Sponsored By

Photo by cogdogblog used under CCNOTE: The top part of this post is background and basics. If you are a diabetic who wants the advanced techniques, they are further down a bit.

Being a Type 1 diabetic sucks. But, if you know anyone who is diabetic then you likely already know that. Over the last twenty years I've tried  many different drugs, diets, techniques, and hacks all meant to keep me alive as long as possible. Diabetes is the leading cause of blindness, liver failure, kidney failure and a bunch of other stuff that also sucks. It would be really awesome to die of regular old age rather than some complication of diabetes.

Every few months a diabetic should get a blood test call an hA1c that is a measure of long term blood sugar control. A normal person's A1C is between 4% and 6% which roughly corresponds to a 3 month average blood sugar of between 70 and 120mg/dl, which is great. My A1c has been around 6.0 to 6.7 which is under the American Diabetes Association's recommendation for Type 1 diabetics of 7.0, but not as low as I'd like it.

Related Reading

I recently redoubled my efforts and lost about 30lbs, started working out more and removed more carbohydrates by implementing a relaxed paleo diet. This, combined with some medical equipment changes that I discuss below have resulted in my latest A1c - just in last week - of 5.7%. That means for the first time in nearly 20 years I have maintained near-normal blood sugar for at least 3 months.


A Type 1 diabetic doesn't produce any insulin, and insulin is required to process sugar and deliver it to the cells. Without insulin, you'd die rather quickly. There's no diet, no amount of yoga, green tea or black, herbs or spices that will keep a Type 1 diabetic alive and healthy. Type 1 diabetes is NOT Type 2 diabetes, so I'm not interested in your juicers, raw food diets or possible cures. I've been doing this with some success for the last two decades and I plan to continue - also with success - for the next two.

If you blood sugar gets too high you'll die slowly and rather uncomfortably. If your blood sugar gets too low you'll die rather quickly (or at the very least lose consciousness). The number one goal for a Type 1 Diabetic is to effectively manage insulin and blood sugar levels by simulating a working pancreas where there isn't one. You eat food and your blood sugar rises. You take insulin and your blood sugar lowers. You can prick your finger and check your blood sugar directly then perform some calculations and inject yourself with insulin. If everything works out well then your blood sugar is stable just like a "normal" non-diabetic.

Unfortunately it's never that easy, and in the case of Type 1 diabetes there's a number of factors that complicate things. Sometimes blood sugar rises on its own, sometimes due to illness, hormones, or any of a dozen other factors. The most difficult issue to deal with is that of lag time. When you check your blood sugar you're actually looking at the past. You're seeing your blood sugar in the past, sometimes 15-20 minutes ago. When you take insulin it won't start working for at least 30 minutes, often as long as 60 to 90 minutes. I talk about this in my post Diabetes: The Airplane Analogy. Try flying a plane where your altimeter shows you the past and altitude adjustments are all delayed. I would imagine it's not unlike trying to pilot the Mars Lander. Sadly, there is no such thing as "real time" when it comes to diabetes management.

Basic Management

Basic blood sugar management typically comes down to carb counting and insulin dosage. You'll learn from a Diabetes Educator that your body (everyone is different) will react to insulin in a certain way. You'll learn that, for example, your insulin to carbohydrate ratio might be 1U (1 unit of insulin) to 15g (grams) of carbohydrate. You'll read food labels and if there's a cookie with 30g of carbohydrates or sugars that you'll need to "cover" it with 2U of insulin.

That's the basics. Things quickly get complicated because not all sugars are alike. A cookie with 30g of carbs will "hit you" - or cause a blood sugar rise - much faster than an apple with 30g of carbs or mixed nuts with 30g of carbs. The speed at which carbs hit you is known as the glycemic index of the food. Fruit juices, starches, candy, all have high glycemic indexes.

Why should a diabetic care about how fast food raises their blood sugar? Because the faster your blood sugar moves the hard it is it control. If a cookie can raise blood sugar in 15 minutes but insulin won't start lowering it for an hour you can see how a daily rollercoaster of blood sugar spikes can get out of control.

A reasonably low carb diet makes Type 1 diabetes much easier to handle and manage. I avoid bread, sugar and anything "white." That means no white rice, no white bread, no white sugar. If I'm going to have bread, it'll be whole grain or sprouted wheat.

Portion Size and Cutting Carbs

You should rarely be eating a meal that is larger than your own fist. Better you eat 6 fist-sized meals than 3 giant plates a day. Reasonable portions avoid high sugar spikes.

Cutting carbs is surprisingly easy. I've done personal experiments with hamburgers, for example. A hamburger might require me to take 6U of insulin but that same hamburger minus the top bun was only 3U. It was still satisfying and yummy but that top bun was just empty carbs. That leaves more room for salad (with dressing on the side) which is a diabetic's "free food." You can eat raw veggies until you're bloated and in some cases take no insulin at all, while a Small French Fry could literally set you on a miserable rollercoaster of a day.

Fries and starches are simply off limits. If you eat them, you will pay the price. Pizza, potatoes, tubers of any kind are all effectively raw sugar. Same with all fruit juices and any HFCS (High Fructose Corn Syrup.) In fact, any "-ose" is ill-advised, including Fructose, Glucose and Dextrose.

The Poor Man's Pump

Not that many years ago insulin came in many speed variations. Some were long acting and some short. In recent years we've standardized on two kinds, very long acting where one shot lasts for 24 hours, and fast acting where one shot starts in about an hour and is gone in about four.

We need some insulin running in the background all the time just to stay stable. This is all the basal rate or background insulin. Then when we eat we need a bolus of insulin to "cover" a meal. Long acting insulin can act as the basal and short acting as the bolus.

For those that don't have an insulin pump (more on that later) a pump can be simulated by a long acting shot of an insulin like Lantis/Glargene once a day to act as a basal and then short acting insulins like Humalog/Novalog/Apidra for means. You can simulate about 80% of a pump with this "poor man's pump."

Insulin Pumps

Photo by cogdogblog used under CCIf you've got an insulin pump like I have then you actually have no long acting insulin in you. Instead you've literally got a pump and a tube dripping insulin into your body. I've worn one 24 hours a day, while asleep and awake for over a decade.

So where's the basal or background insulin coming from? The pump actually contains only short acting insulin but delivers it in extremely precise and tiny increments all the time. For example, I usually have my pump delivering 0.5U/hr all the time.

Note that none of this is automatic. Pumps are not automatic systems and will only do what you tell them, fortunately or unfortunately. If you're willing to put some thought and effort into it you can do some interesting things with pumps that you simply cannot do with MDI (Multiple Daily Injections.)

Square Wave Basal (Buffet Mode)

One of the things a pump can do that injections simply can't is basal adjustments. Once you've taken a long-acting insulin shot, it's in you and it's going to do its work for 24 hours. The only thing you can do with insulin in you already is add more food or more insulin.

With a pump, though, you can program a either a Square Wave Bolus or a temporary Basal. This can be useful when at an event where you'll be "grazing" and eating little bits over a long period, or in situations where you're eating foods that will take a long time to digest, like pizza.

Temporary basals are also useful for exercise and activity. You can temporarily lower your background insulin for a few hours while you're hiking, for example. Lowering your basal temporarily is your best way to avoid exercise-related lows.

Often Type 1's get into trouble exercising because they'll work out, burn a hundred calories, have a low blood sugar, then eat a few hundred calories thereby negating the original exercise. Lower your basal an hour or so before exercise and set a timer to keep it low for an hour or two. Better an exercise-induced high than an exercised-induced low.

Temporary Basals while crossing Time Zones

I do a lot of international travel and often cross a number of time zones in a single trip as a diabetic. Diabetics on pumps often have multiple basals rates programmed on a schedule and this can cause issues when going overseas.

For example, here's mine:

  • 3am - 0.75U/hr
  • 8am - 0.5U/hr
  • 6pm - 0.6U/hr
  • 12am - 0.5U/hr

The 3am to 8am boost there is to manage the blood sugar rise known as the "dawn phenomenon." It's your body trying to get you ready for the day. It's part of your circadian rhythm and it's great for you. It's lousy for me though as it means my blood sugar will just start rising unchecked starting at about 4am.

When travelling, though, what's dawn to me? ;) It takes about a day to adjust for every time zone crossed. So even though I was just in Europe for a week, my "dawn" was slowly moving from the west coast of the US over the Atlantic all week. I needed to be aware of this as I set my pump's clock.

If you change your pump's clock to the destination time zone on the first day, your basals won't reflect your physical reality. You'll get more insulin at 3am local time, for example, but you likely needed it 4 or 7 hour before.

I've found that for simplicity's sake I set my basals while travelling to two 12-hour values, night and day. For example, on this trip I set to 0.6U/hr during the day and 0.5U/hr during the night. This allowed me to see when the dawn rise was happening and deal with it using a bolus, rather than risking a nasty and unexpected low at a seemingly random time. Use temporary basals to smooth things out. I'll set 4 and 6 hour temporary basals as well to "tap it down" or "float up."

Super BolusPhoto by kirinqueen used under CC

One of the most advanced and most powerful techniques is the Super Bolus. I tend to be a little prejudiced against CDEs (Certified Diabetes Educators) (sorry, friends!) unless they are diabetic themselves. No amount of education can match 24 hours a day, 7 days a week for 20 years. The Super Bolus is one of those techniques that we find after hard work and 3am suffering.

Since even fast-acting insulin often isn't fast enough you'll sometimes want a way to give yourself more insulin now without an unexpected low in 2 to 4 hours.

What you can do is turn off your pump effectively by setting a temporary basal of 0U/hr, and then give yourself the saved amount on top of your planned bolus.

Here's an example. You want to have some ice cream. You take 5U of insulin, your basal is 0.5U/hr. You eat the ice cream and have a bad high sugar in an hour and then a nasty low 3 hours out. The insulin didn't move fast enough to cover the ice cream, and when it did finally start working it took you low because your basal was ongoing.

Instead, you could take 6.5U of insulin and set a 3 hour temporary basal of 0U/hr. You have taken the 1.5U that would have been spread out over 3 hours and instead stacked it on top of the big bolus. The net amount of insulin is the same! You're just clipping that big high and bypassing that nasty low.

You'll need to find numbers that work for you, but the Super Bolus is a powerful technique for avoiding highs and still being able to eat some carbs.

Off-Label Drugs

There are a number of interesting new drugs out for diabetics that aren't super common but if you're interested in hacking your diabetes and you have a willing endocrinologist they could help you.

Symlin is a brand name synthetic amylin and replaces another missing hormone in Type 1 diabetics. Symlin is another shot you would have to take in addition to insulin. We tend to digest food really quickly and that causes nasty post-prandial (after eating) blood sugar spikes. Symlin will slow your digested to that of a normal person and clip those high sugars and allow your insulin to work. Talk to your doctor because it's serious stuff and not to be trifled with. Symlin induced low blood sugars can be really challenging to pull up out of. If you can get past the first two to four weeks of nausea it can be a powerful tool. I took Symlin for a number of years but now I only use it for a few large meals a year like Thanksgiving and Christmas.

Victoza is a new drug for Type 2 diabetics and is explicitly not recommended for Type 1s. However, if your doctor feels it would help you as a Type 1 it can be given "off label." It is a GLP1 inhibitor that also slows absorption of food and its movement through the gut. Finding the right dose can be a challenge, but since Victoza is a daily injectable you can adjust the dose one day at a time.

UPDATE/Correction from Karmel: "Minor point, but Victoza and Bydureon are GLP1 (with a P for glucagon-like peptide) agonists (that is, analogs)-- they mimic the action of GLP1, not inhibit it. Some T2 drugs with similar effects like Januvia are DPP-4 inhibitors, where DPP-4 inhibits GLP1, making a DPP-4 inhibitor a positive regulator of GLP1. But GLP1 we want"

Bydureon has a similar effect to that of Victoza except you take it once a week. It's also a Type 2 drug that is off label for Type 1s. It takes about a month to build up in the system before you see its effects and it can also cause significant nausea.

Order of Food

What a silly heading, but yes, the order you eat can affect your blood sugar. If you drink juice and eat bread before eating a chicken breast your blood sugar will rise faster than if you eat the chicken breast first. If you have a meal with fat in it then eating the fatty part of the meal will slow down whatever comes next. While cheese isn't really good for you, you can slow down the food that comes after it by eating cheese before crackers and an apple, for example.

Lowering A1C by Sleeping

Here's another trick that was so fundamental to getting my A1c down. You're asleep for 6 to 10 hour a day. Nearly a third of your life you're asleep. This is the perfect time to have great blood sugar. There are few feelings worse as a diabetic than waking up after a long night only to discover that you've had high blood sugar all night long. You've been marinating in your own sugar and you didn't even know. What a horrible feeling.

I try not to eat after 8pm so that I have from 8pm until I go to sleep to even out my numbers. You want your numbers to be either normal or heading clearly towards normal as you go to sleep. Just as they say for a good marriage you should never go to bed angry. I say for good A1c results you should never go to bed with bad blood sugar. Even if your numbers are garbage all your waking hours at least try to get them smooth and low as you sleep. Avoid doing anything to move them around after dinner. Eat your dinner, get back to normal, then have a basal rate you can count on and set it for as long as you can.


Always be on the lookout for equipment that might allow you to better manage your blood sugar. Sometimes this is covered by insurance, sometimes it's not. It never hurts to ask your insurance company or your doctor.

I've used a Medtronic insulin pump with an integrated CGM for years. It's a good integrated system but the CGM has as considerable lag time showing my blood sugar about 20 minutes in the past. I have also been unimpressed with my OneTouch Mini blood sugar meter. I grow tired of calibrating and coding the meters and I also feel they aren't nearly as accurate as one needs for tight control.

This year I moved from my Medtronic Paradigm Continuous Glucose Meter (CGM) to a Dexcom Seven CGM. I also switched from a OneTouch Mini to a OneTouch Verio.

The OneTouch Verio is a near codeless meter from OneTouch. That means I can just plug in a strip without entering any codes or calibrations. It is rechargeable with a standard mini-USB adapter and it even as a lighted sensor area so you can check your numbers at the movies. (This is a bigger deal than you might realize.)

The Verio, in my opinion, skews high in its readings. When compared to the OneTouch Mini the Verio values are consistently 20mg/dl higher. This is actually a good thing because when calibrated with the Dexcom CGM it nudges me towards an even lower blood sugar goal.

The Dexcom Seven CGM is the single greatest piece of new technology I've ever experience since I was diagnosed at age 20. It's so profoundly amazing and so utterly indispensible I truly can't imagine life without it. It reduced the lag time for my readings from 20 minutes to less than 5. It's far more accurate than the Medtronic and the sensors can stay in for a week or more. It doesn't provide as much historical data as the Medtronic but the accuracy of the Dexcom is a thing to behold. I'm looking forward to the new Animas Vibe with the Dexcom integrated and plan on switching the nanosecond it comes out. Even though the Dexco is yet another thing to carry and keep charged I credit this CGM with helping me get the best A1c test results of my diabetic life thus far.

As with all random blog posts your read on the internet, remember this. I'm not a doctor. I'm just a random dude you don't know. Try all this at your own risk and under your doctor's supervision.

If you'd like to make a tax-deductible donation to the American Diabetes Association and be a part of Team Hanselman, you can donate securely here It is appreciated!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Why does TypeScript have to be the answer to anything?

October 2, '12 Comments [99] Posted in Javascript | Open Source
Sponsored By

vs-refactorDISCLAIMER: I don't work on TypeScript. I am not involved with that team and this is all my own opinion and conjecture.

UPDATE: After this post I sat down with Anders in Denmark at the GOTO 2012 Conference sin Aarhus and asked him bunch of questions about TypeScript. That recorded audio podcast is now available.

TypeScript was announced and folks are saying "TypeScript is clearly Microsoft's answer to Google's Dart" or "So TypeScript is Microsoft's answer to CoffeeScript."

I was chatting with Jez Humble today about the intense interest and some little gnashing of teeth around TypeScript and he offered this little gem of a quote:

It's disappointing when smart people display a profound ignorance of computing history. - Jez Humble

TypeScript has been out a day. It's way early to see if it has legs, but it seems initially promising.

TypeScript and Dart

People have compared TypeScript to Dart. That's comparing apples to carburetors. TypeScript builds on JavaScript so there's no JS interop issues. Dart is a native virtual machine written from scratch. Dart interops with JavaScript...but it's not JS. It doesn't even use the JavaScript number type for example.

TypeScript and CoffeeScript

I'm a huge CoffeeScript fan although it is a different language with a syntax of its own to learn. What I like about TypeScript - so far - is that TypeScript’s static typing could enable better tooling with warning squiggles, easy statement completion, plus smart refactoring. You also get easy navigation around code, as well as find references, rename, and more. You don’t currently get that in CoffeeScript.

So what is TypeScript?

TypeScript is a superset of JavaScript and you write it like you write JavaScript which I like. Any existing JavaScript is already TypeScript. One argument has been made that TypeScript is for people who don't want to learn JavaScript. I don't buy that. As Ward Bell said in an email:

TypeScript is not a crutch any more than JSLint is a crutch. It doesn’t hide JavaScript (as CoffeeScript tends to do). - Ward Bell

I think Ward says it well. Folks rail against static typing but they don't complain about JSLint. TypeScript offers optional type annotations - it's hardly a perversion of JavaScript.

From what I can see after using TypeScript for a few days is this. It gives you type checking, explicit interfaces and easier module exports. In fact, it's a little like getting some of tomorrow's ECMAScript 6 early in a way that's compatible with today's JavaScript. ES6 won't be out for at least a year but we can play with some of those features today.

Things that I like about TypeScript:

  • It's Open Source and under the Apache 2.0 license
  • You can install the tools easily with
    • npm install typescript -g
  • You can git the source
    • git clone 
  • You can play with it online at

Things I don't like about TypeScript (these are mostly implementation things)

  • No splitscreen editor like Visual Studio's existing CoffeeScript editor
    • UPDATE: While this isn't "official" support, Mads has updated Web Essentials 2012 with a splitscreen editor. The two teams are going to work together on a more official solution.
  • Doesn't generate .js on save, requires a build.
  • You have to add a BeforeBuild target to your ASP.NET application's CSPROJ:
<Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\\tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

I will continue to use TypeScript and evaluate it, but I think the fact that it's open source, it creates JavaScript and it feels comfortable to me as a C# programmer means it will fill a useful niche.

This quote from Luke Hoban, co-creator of TypeScript really hits the spot.

"CoffeeScript is to Ruby as TypeScript is to Java/C#/C++." - Luke Hoban

If you love Ruby, you'll enjoy CoffeeScript as it makes the JavaScript more like the Ruby. The same is true with TypeScript. It brings useful features into JavaScript in an ultimately compatible and syntax-friendly way using language constructs you're comfortable with.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Making a switchable Desktop and Mobile site with ASP.NET MVC 4 and jQuery Mobile

October 1, '12 Comments [27] Posted in ASP.NET | ASP.NET MVC | Javascript | Mobile
Sponsored By

I really enjoy working on and thinking about mobile websites. There's something about making an experience great on a pocket supercomputer phone that is so much more satisfying than a desktop. I actually got this blog looking nice on mobile devices back in 2006 when nobody was mobile except doctors and, well, all of us techies here on the blogs.

I've talked about the importance of a good mobile site before in posts like Create a great mobile experience for your website today. Please. However, some folks had asked me if I'd do a post on how to do a combination Desktop and Mobile site using ASP.NET MVC similar to the examples I used in my talks in Russia on mobile earlier this year. (There's video of those ASP.NET mobile presentations available)

When you start Visual Studio 2012 and go File | New ASP.NET MVC 4 app, there's an Internet Application template and a Mobile template. One gets you a standard desktop site - although with responsive design elements so it works on small screens - and the other gets you a jQuery Mobile application meant primarily for phones and tablets. Let's make one that switches between both.

We will do a small site in ASP.NET MVC for the Desktop, do some quick DB access, add jQuery Mobile and a View Switcher switch back and forth. I'll be using the Electric Mobile Studio from Electric Plum to simulate an iPhone. You can get a 7 day trial or you can get the Lite version of the Electric Plum Mobile Simulator with WebMatrix 2.

Quick CRUD Example

First, a model for DVDs.

public class DVD
public int ID { get; set; }
public string Title { get; set; }
public int Year { get; set; }
public Rating rating { get; set; }

public enum Rating
G, PG, PG13, R

Next, I scaffold out the Index, Create, Edit, Delete, etc. Unfortunately scaffolding doesn't do Enums (I'm sad) for my Movie Ratings so I add EditorFor() calls to my Create and Edits, and update my Index.

<div class="editor-label">
@Html.LabelFor(model => model.rating)
<div class="editor-field">
@Html.EditorFor(model => model.rating)
@Html.ValidationMessageFor(model => model.rating)

Shared/EditorTemplates/Rating.cshtmlI could have used DropDownList I suppose, but I have always found that helper confusing. Instead, I'll create a Rating.cshtml that makes a dropdown. I could change this at some future point to be fancier and not even use a DropDown.

Aside: How do you guys usually handle Enums? I've seen it done a few ways. I'd like this to be more generic, but here's what I did for the Rating editor Template. Note the nullable ? as it has to work for both Create and Delete

@model MyApp.Models.Rating?
@using MyApp.Models

<select id="@ViewData.TemplateInfo.GetFullHtmlFieldId("")" name="@ViewData.TemplateInfo.GetFullHtmlFieldName("")">
@foreach (int rating in Enum.GetValues(typeof(Rating))) {
var name = Enum.GetName(typeof(Rating), rating);
<option value="@name" selected="@(Model.HasValue ? (int)Model == rating : false)">@name</option>

OK, so there's a basic Desktop CRUD app.

Editing a DVD List of DVDs

Making it Mobile

iPhone in the Visual Studio browser menuAs I mentioned, you've probably noticed when making an ASP.NET MVC application that you can choose a Mobile template with jQuery Mobile along with the standard responsive "desktop" Internet Application. However, there isn't a switchable template. That is, one that is the regular template on Desktops but switches to jQuery Mobile (or KendoUI, or whatever makes you happy) on mobile devices.

Using NuGet, install the jQuery.Mobile.MVC package. You can either right click on References, select Manage NuGet Packages, or you can use the Package Manager Console and type:

install-package jQuery.Mobile.MVC

This package will automatically bring in jQuery Mobile as well as:

  • A ViewSwitcher partial view and supporting Controller
    • This is what lets us switch manually between Desktop and Mobile
  • A basic _Layout.Mobile.cshtml and supporting stylesheet
  • A BundleMobileConfig.cs used with ASP.NET Optimization (the bundler for CSS and JS)

NOTE: There's nothing jQuery Mobile specific about the ViewSwitcher or the techniques here. You can happily change this package for any other popular mobile framework.

We start by adding the new Bundles in the Global.asax:

BundleMobileConfig.RegisterBundles(BundleTable.Bundles); // <-- ADD THIS ONE

Since I installed the Electric Plum iPhone simulator, I'll select it from my browser dropdown in Visual Studio and run my app and navigate to /DVD.

The system sees that I'm on a mobile device and rather than using _Layout.cshtml it uses

This doesn't really look nice for a few reasons. First, I don't like the default style. Just go into _Layout.Mobile.cshtml and change the data-theme attribute to a value that makes you happy. I changed it from theme a to theme b.

Basic App in an iPhoneSame baisic app with a light background

Second, while I'm using the _Layout.Mobile.cshtml I'm still using the desktop Index.cshtml which looks lousy when displayed in the mobile layout. Remember that I only have an single Index.cshtml. If I had an the system would use that page instead when rendering on a mobile device.

I can make an Index.Mobile.cshtml with simpler markup, change the table into an unordered list and add some jQuery Mobile specific attributes like this:

@model IEnumerable<MvcApplication2.Models.DVD>
ViewBag.Title = "My DVDs";
<ul data-role="listview" data-filter="true" >
@foreach (var item in Model) {
<a href="@Url.Action("Details", new { item.ID })">
<h2>@Html.DisplayFor(modelItem => item.Title)</h2>
<p>@Html.DisplayFor(modelItem => item.Year) - @Html.DisplayFor(modelItem => item.rating)</p>

Note the data-role and very basic elements like <ul>, <li>, <h2< and <p>. I also added the client side data-filter attribute to get some nice client-side searching. Hit refresh and now it's starting to look like a real mobile site.

See the ViewSwitcher at the top there? That's a partial view called _ViewSwitcher.cshtml.

A lovely jQuery Mobile example list of DVDs

By default it will let you switch back and forth between Desktop and Mobile but only on mobile devices. Why? Check out the first line of code:

@if (Request.Browser.IsMobileDevice && Request.HttpMethod == "GET")
<div class="view-switcher ui-bar-a">
@if (ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice)
@: Displaying mobile view
@Html.ActionLink("Desktop view", "SwitchView", "ViewSwitcher", new { mobile = false, returnUrl = Request.Url.PathAndQuery }, new { rel = "external" })
@: Displaying desktop view
@Html.ActionLink("Mobile view", "SwitchView", "ViewSwitcher", new { mobile = true, returnUrl = Request.Url.PathAndQuery }, new { rel = "external" })

That first line checks if it's a mobile device making the request. Just surround that with /* comments */ and you'll be able to view and debug mobile layouts with your desktop browser without faking User Agents.

So far we've been talking about "mobile" and creating files with "mobile" in their file names and it's all been magic. Turns out we have lots of control over these things. Perhaps we want more than but also, perhaps, Index.iPhone.cshtml and Index.WP7.cshtml.

Create lines like these in your Global.asax:

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("WP7") {
ContextCondition = ctx => ctx.GetOverriddenUserAgent().Contains("Windows Phone OS")
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone") {
ContextCondition = ctx => ctx.GetOverriddenUserAgent().Contains("iPhone")

You can affect the DisplayMode collection (of which "mobile" is one) by inserting in your own. Here I'm making two more specific mobile ones but you don't need to do mobile things to change DisplayModes.  A DisplayMode could be right to left for RTL languages, or "gold" and "bronze" for customers or whatever makes you happy, based on the ContextCondition you evaluate on each request.

There's lots of choices and you've got the flexibility to do things however you like. I'll show an example of a totally offline iPhone site using cache.manifest in a future post.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.