Scott Hanselman

Is there a good reason to mark a class public?

October 23, 2006 Comment on this post [13] Posted in Learning .NET | Programming | TechEd
Sponsored By

Paul Stovell was watching a talk I gave with Keith Pleas at Teched US 2006 on building your own Enterprise Framework. The basic jist was that architecting/designing/building a framework for other developers is a different task than coding for end users.  

One thing that is valuable for context is that Keith and I were playing roles in this presentation. Keith was playing Einstein in his Ivory Tower, the developer who wants perfect purity and follows all the rules. I was playing Mort the realist, the developer who just wants to get the job done. We went back and forth with white slides for Keith, Black for me, each of us declaring the extreme view, then coming together on the final slide with some pragmatic and prescriptive guidance.

Paul had an issue with the slide on Extensibility where I, as the hyper-realist, said:

  • If they extend it, they will break it
  • Use Internal more
  • Seal first, ask questions later

He said:

Frankly, I think this is crap.
[Paul Stovell

For goodness' sake, Paul, don't sugarcoat it, tell me how you really feel! ;) Just kidding. He has some interesting observations and (some) valid points.

If you are developing a framework or API for someone else to use, and you think you know more about how they plan to use your API than they do, you've got balls. [Paul]

I mostly agree with this. However, you certainly need to have SOME idea of what they are using it for as you're on the hook to support it in every funky way they might used it. It is reasonable to have some general parameters for how your API should be used. If you design it poorly, it will likely get used in ways that may end up giving the developer a bad experience or even breaking the app.

For example, in a logging service we had a method called ConfigureAndWatch that mirrored the log4net ConfigureAndWatch. It's meant to be called once per AppDomain, and never again. Because it was not only poorly named (since we too the internal implementation's name) and it didn't offer any suggestions (via exceptions, return values, or logging of its own) some users would call it on every page view within ASP.NET, causing a serious performance problem. There's a number of ways this problem could be solved, but the point is that there needs to be a boundary for the context in which an API is used. If we had constrained this more - and by doing that, we think we know more than they do - then some problems would have been avoided.

Scott goes on to give an example whereby he actually made every class "internal" in his API, and waited for users to tell him what classes they wanted to extend, and extended them one by one. [Paul]

This little bit of inspired brilliance was not my idea, but rather Brian Windheim's, an architect at Corillian. We had an application that consisted largely of base classes and developers were insisting that they needed infinite flexibility. We heard "infinite" from the developers, but not the business owner. Brian theorized that they didn't need as much extensibility as they thought, and shipped a internally basically sealed version. When folks needed something marked virtual, they put it in a queue. The next internal version shipped with something like 7 methods in one class marked virtual - meeting the needs of all - when originally the developers thought they wanted over 50 points of extensibility.

The point of Brian's exercise was to find a balance between extensibility, both explicit and implicit, and supportability.

When you mark something virtual or make a class public, as a developer framework designer explicitly expressing support for the use of that API. If you choose to mark everything virtual and everything public as Paul advocates, be aware of not only the message you send to the downstream developer, but also the unspeakably large combinatorics involved when that developer starts using the API in an expected way.

Cyclomatic complexity can give you a number that expresses the complexity of a method and offer valuable warnings when something is more complex than the human mind can comfortably hold. There are other tools (like NDepend and Afferent Coupling, Lattix and it's Dependency Structure Matrices and Libcheck and its measure of the churn of the public surface area of a framework) that can help you express the ramifications of your design decisions in fairly hard metrics and good reporting.

If you mark all your classes and methods public,  be informed of these metrics (and others) and the computer science behind them and acknowledge that you're saying they aren't right for you. Just be aware and educated of the potential consequences, be those consequences bad or good.

Can you honestly rely on people who are "just playing" with a technology to tell you which bits they will need to be extensible 12 months into the future?

You totally can't. When you're designing for Users, you do a usability study. When you're designing for Developers, you need do a a developability study.

Microsoft actually does more of this than most folks think. Sure there's the Alphas, Betas and CTPs, but there's also TAP (Technology Adoption Programs) programs, Deep Dives where folks go to labs at Microsoft and work on new technology and frameworks for a week while folks take notes. These programs aren't for RDs or MVPs, they're for developer houses. If you're interesting, ask your local Microsoft rep (whoever organizes your local Nerd Dinners perhaps) how you can get into an Early Adopter Program for whatever technology you're hoping to influence. They really DO listen. We just came back from a Deep Dive into PowerShell and got not only access to the team but a chance to tell them how we use the product and the direction we'd like to see it go.

Scotts [sic] philosophy, and that of many people at Microsoft (and many component vendors - Infragistics being another great example), seems to be to mark everything as internal unless someone gives them a reason to make it public.

That's not my philosophy, and I didn't say it was in the presentation. It was part of the schtick. The slides looked like this with Keith as Ivory Tower Guy first, then Me as Realist guy, and the "in actuality" slide last with guidance we could all agree on. However, I still think that marking stuff internal while you're in your design phase is a great gimmick to better understand your user and help balance good design with the important business issue of a supportable code base.

The salient point in the whole talk is be aware of the consequences of extremes and make the decision that's right for you and your company. (Very ComputerZen, eh?)

  

Paul's right that it is frustrating to see internal classes that do just what you want, but simply marking them public en masse isn't the answer, nor is marking everything internal.

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

PowerShell CMDLET Visual Studio 2005 Item Template

October 21, 2006 Comment on this post [7] Posted in PowerShell
Sponsored By

Jason Scheuerman from my company has created a PowerShell Cmdlet Visual Studio 2005 Template so you can create PowerShell Cmdlets using File|Add New Item.

In the screenshot at right, I've select File|Add New Item and entered get-thing.cs as the name of my new Cmdlet.

If you want to use this Item Template, drop this zip file into your C:\Documents and Settings\<YourUserNameHere>\My Documents\Visual Studio 2005\Templates\ItemTemplates.

Don't unzip it, just put the ZIP itself in that folder.

You can learn more about creating Cmdlets (they're different from PowerShell Scripts (PS1 files) in that they can integrate more tightly with the pipeline and they can use parameter binding) at MSDN.

There's more about the difference between Cmdlets and scripts in my interview with Jeffrey Snover at Hanselminutes.com.

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Onkyo TX-SR674 HDMI Upconverting Receiver

October 19, 2006 Comment on this post [10] Posted in Reviews
Sponsored By

Our Home Theater, er, Living Room, has consisted of the same Sony Receiver and random collection of goo since I worked at 800.com. Since we got HDTV it got really difficult to manage the system because the Sharp LCD has 5 inputs and the older Sony Receiver has 5 inputs and we had to do all this video + audio switching. "Put the TV/Video on Component 1 and the Audio on Optical 2" - you get the idea.

The Harmony Remote made a huge difference, and I still love it, but the receiver has been showing its age and every once in a while it will just stop making sound. Then 15 minutes later, it'll make a loud click and start up again. The Sony 925 Receiver isn't a "video switching receiver" for anything other than composite analog signals, of which I have none.

I started doing research on a new receiver using the kitchen remodel and living room repainting as an excuse. I figured since I'd have the whole thing ripped up anyway, why not put it back together right.

I decided on the Onkyo TX-SR674S (S for Silver) for a number of reasons.

  • It offers decent price/performance balance. I'm not an audiophile, nor do I care to be, so I'll never buy a $1000 receiver, and I will continue to use the same speakers I have had for the last 10 years until they burn up. I would like a receiver that can utilize what I have though.
  • It does video switching, but also HDMI video upconversion. That's not upscaling, now. Meaning, if a 480p signal comes in the Component Connector, it'll just go out to the HDMI as 480p. This means that I have one wire going to my Sharp LCD, and that's HDMI. This means I can set my TV's input and forget about it. It's also clearer than using Component Cables. Additionally my Replay TV that outputs via S-Video is also upconverted to HDMI and looks very clear. It will however deinterlace 480i and output 480p.
  • XM Satellite Radio (it's ready for it). I have XM in my car (actually Greg has mine as he's driving across the country and I pressured him to take it for a whirl) and I love it.  While we do listen to XM via the Media Center via the XBox, I would like it to be more integrated. It also has Radio Disney and XM Kids that I'd rather Z listen to over TV. (No TV for the baby) All I had to do was get an XM Antenna and it just worked. Slick.
  •  Audyssey 2EQ™ room acoustics correction. This is a fancy equalizer that includes a microphone and runs your speakers and room through a 12-step series of tests. In the process it learns the distance of your speakers to your ears and adjusts the dB level of each speaker individually to make up for crappy acoustics. It nailed the distances of my speakers and noticed that my Center Speaker is 2 feed farther back than my front speakers and added +1dB to the Center's level to compensate. Very nice, and I understand the Audyssey is well thought of amongst folks more into this stuff than I.
  • 1080p ready - It'll handle 1080p if need be, although I'm pretty much standardized on 720p. However, I've gotten rid of my Sony DVD/VCR combo (or, rather, I'd like to - $50OBO in Portland, you pick up) and I'm using the Xbox 360 as my only DVD player. The recent updates to the Xbox have pumped up the video quality and it's now absolutely better than the Sony Progressive. I'm looking forward to the HD-DVD player this holiday season.
  • Powered Zone 2 - If I ever want to run audio upstairs or outside, the receiver has a separately powered second zone.

All in all, I'm VERY happy with the receiver and how much cleaner the whole system works now and I recommend this receiver highly.

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 37 - Interview with ScottGu

October 18, 2006 Comment on this post [4] Posted in
Sponsored By

My thirty-seventh Podcast is up. This one is a surprise interview with Scott Guthrie or "ScottGu", General Mananger within the Microsoft Developer Division (DevDiv) or as I like to call him, "He from which all good things flow." ScottGu took time out of his busy schedule to talk to me about Ajax, Ajax Extender controls, CSS adapters and more.

I hope enjoy this additional interview-format show. When I get the opportunity to interview folks that I've always wanted to chat with I assume you've always wanted to chat with them too! I'm striving to avoid wasting your time, so I'll include interview shows like this one interspersed with the 'standard' Hanselminutes format, so don't worry, we're always trying to improve the show and your requests for show topics are all put in a big queue. :)

We're listed in the iTunes Podcast Directory, so I encourage you to subscribe with a single click (two in Firefox) with the button below. For those of you on slower connections there are lo-fi and torrent-based versions as well.

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

Links from the show are also always on the show site, although this show had no links to speak of. Do also remember the archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

 Our sponsors are XCeed/nsoftware, CodeSmith Tools and the .NET Dev Journal.

There's a $100 off CodeSmith coupon for Hanselminutes listeners - it's coupon code HM100. Spread the word, now's the time to buy. This coupon is good for the CodeSmith Professional With 1 Year Premier Support option.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

Enjoy. Who knows what'll happen in the next show?

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The First 12 Hours - The Medtronic Minimed Paradigm REAL-time Continuous Glucose Monitor

October 18, 2006 Comment on this post [14] Posted in Diabetes | Reviews
Sponsored By

It's finally here and I'm using it.  The Continuous Glucose System that I blogged about six months ago arrived today. Yes, I tend to be an Early Adopter and I've gotten nailed in the past (the Glucowatch sucked) but this one may just be a winner.

It's called the MiniMed REAL-Time System. It is an add-on (D in the picture at right) that "sips" intersitial fluid and reports an estimate of my current blood sugar to a pump that is exactly the same form factor as my existing pump. In fact, it's the same housing. I swapped my existing Paradigm 512 Pump out for this one, the controls are identical.

(Check out my Diabetes Explanation: The Airplane Analogy if you're not familiar with how diabetes works IMHO)

Out of Box Experience

Note: You should talk to your Diabetes Doctor/Endocrinologist and take a training on how to use this device before jumping in or you could hurt yourself. I am NOT a doctor - this is just one guy's experience.

The package arrived at 10am this morning. The one containing the sensor tips said "perishable" and was packed with ice packs. I put it in the refrigerator immediately. Travelling with these will be a little tricky, as it's unclear how quickly they degrade. Presumably in about 72 hours.

I transfered my settings over from my existing pump manually. The pump, glucose meter (the finger stick device) and continuous meter/transmitter (the one taped to my belly) all have unique ids. You have to tell the pump the unique id of the transmitter, as well as the unique id of the finger stick meter.

After attaching the new transmitter (with a big ass needle/canula) I told the pump there was a new transmitter/sensor. It starts calibrating and says to wait for 2 hours and then it'll want a finger stick. This two hour warm up happens every time you put on a new sensor - about every 72 hours. At noon, it beeped, then I did a finger stick test. You want to put on a new sensor when your blood sugar is stable. I woke up at 110mg/dl and it stayed that way for the morning. I pushed lunch out a bit to make sure it stayed that way. After the first calibration I started getting updates every 5 minutes.

Aside: You truly can't conceive of what it's like to have this 6th sense, this 6th dimension where you need a number to really know how you're doing. It's like getting a GPS when you're lost. Like fixing a speedometer in a broken car.
My sense of how my blood sugar ebbs and flows was heightened and I literally had one of the best blood sugar days of my life (since I was diagnosed at 21). It enabled me to make better food decisions and even sneak in a short walk after lunch that had substantive benefits.

I'm loving this device. I'm sure there will be troubles and it'll be harder to get through airport security, but I suspect that this is going to change the way I manage my diabetes. There's a value called the hA1C, expressed as a percentage, that measures blood sugar control over the last 3 month period. Non-diabetics have a value between 4% and 6% indicating that their blood sugar was roughtly 100mg/dl over that period. Mine is currently between 6.3% and 6.5%, which is high normal. I believe this device, plus my use of Symlin, will get that number to the normal range, thereby limiting my chances of compliations like blindness.

Nutshell

I still will check my blood sugar via a finger stick between 4 and 10 times a day. The meter will wirelessly tell the pump that I checked. The fingerstick is considered more authoritative than the continuous meter. In fact, the continuous meter is calibrated by the fingerstick.

The continous transmitter's sensor last 72 hours then the tip needs to be replaced. The larger transmitter lasts at least six months, then it needs to be replaced. It has a sealed internal battery. Additionally, it's interesting to note that the transmitter has a version number. Mine is 1.6, which tells me that they can improve the transmitter at least every 6 months and I won't need to do anything to see improvements in accuracy. The pump holds all the data and history information and includes both a 3-hour and 24-hour graph view.

You shouldn't make insulin dosing decisions based on the continuous meter - it's just a trendline that gives you an idea of what happens the other 23.5 hours that you're not sticking your figer.

Scott's Diabetes FAQ
or
Everything You Always Wanted to Ask a Diabetic But Were Afraid to Ask

Q: When did you become diabetic? How did it happen?

A: I had the flu (or flu-like symptoms) in November of 1994. When it was over, I was peeing all day long, had lost 35 pounds (I was skin and bones) and my dad, a firefighter/paramedic said, you need to get to a doctor, ASAP. My blood sugar was clearly high and suddenly I was a Type 1 diabetic.

Q: So that's Juvenile Diabetes, right?

A: It's not called Juvenile Diabetes anymore, as it can happen to folks in their 30's and beyond. There are (basically) two types of Diabetics:

  • Type I – used to be called Juvenile Diabetes or Youth-Onset or Insulin Dependant (IDDM). These folks nearly ALWAYS use Insulin. Typically these folks don’t produce any (or much) of their own insulin. If I don’t make it, I need to get it somewhere.
  • Type II – also called Adult-Onset or Non-Insulin Dependant (NIDDM). They are so different, it’s a shame they are both called Diabetes. These folks typically have decreased responsiveness to their own insulin. If they aren’t using their own insulin well, they need to be made more sensitive to it.

"Worldwide, there are about 171 million diabetics, but only about 10 percent of those have Type 1 diabetes. The vast majority have Type 2 diabetes, which is linked to obesity. In the United States, about 900,000 to 1.8 million people have Type 1 diabetes, the American Diabetes Association says."

Q: The pump makes all the decisions for you?

A: No, the pump is just a delivery device. It pushes insulin through a tube into small plastic needle-thing called a canula that is 9mm into my belly. I move it every 72-96 hours. The pump has a screw-drive internally that pushes a head against a syringe's piston. It's got some wizards and calculators, but it never does anything automatically, other than deliver a small background (basal) dose that I have to set myself.

Q: Why not just stick with needles? My [uncle|sister|dad|butcher] does two shots a day and he's|she's all good...

A: Taking insulin twice a day is the equivalent of going for a flight but you're only allowed to touch the flight controls twice. Better make those two turns count. Same thing with checking your blood sugar. If you check it twice a day, imagine flying from LA to New York and only checking your altitude twice.

Q: What's so great about a pump?

A: I can make little adjustments on the order of a 1/10 of a Unit of insulin, while folks with needles can usually only managed 1/2 a Unit and they'd need to stick themselves each time!

Q: Do you sleep with the pump on? Shower? What about sex?

A: You can disconnect it for ~30-60mins without ill effects, but everyone is different. While it's not connected, it's not delivering, so you'll likely need to compensate. It's not waterproof. I sleep with it on and remove it at other times.

Q: Is it hereditary?

A: Some Type 1 diabetes is, and many Type 2's are, but it all depends. I'm the only Type 1 in my family going back many years, but I know a girl who's entire family, brothers and sisters are all Type 1. Z has a 2% chance of being a Type 1 Diabetic, which is roughly the chance anyone has with one Type 1 parent.

Q: Can you eat cake?

A: I can eat whatever I like, it's how long I want to chase my blood sugar afterwards that dictates what I eat. It's all about the Glycemic Index - the speed that the food hits you. For example, an apple with the skin on it will raise blood sugar slightly slower than an apple with the skin off. Brown rice is often slower than white. White bread is satan. Going back to the airplane analogy, a food with a high GI will "pull back harder on the stick, making it more difficult to steady the plane later."

Q: Does it suck?

A: Big time. But what other choice do I have?

Q: Will it kill you?

A: Very likely. Diabetic typically die of diabetes before other things. Disability insurance is hard to get, as is life insurance, although the latter is easier than the former. However, the key is maintaining as normal blood sugars as possible. I know diabetics who've been diabetic for 50 years, and they didn't have 1/10th the tools and knowledge we have today. I figure if I can stick it out another 10 years, maybe 20, there will be a cure.

Timeline of Diabetes Care

  • Before 1922 - Certain Death. A childhood friend of my 90 year old grandmother was diabetic, was fed only lettuce and quickly died.
  • 1944 - Insulin is derived from Beef and Pork. Standard insulin syrunge is developed. Folks boil and reuse their needles. Blood sugar is tested by peeing on a stick and matching colors. Accuracy is +/-100mg/dl.
  • 1959 - Diabetes is divided into Type 1 and Type 2.
  • 1974 - First Insulin Pump/Backpack
  • 1983 - Biosynthetic Human Insulin is created. (Ya, seriously, this just happened in '83)
  • 1990 - Digital Insulin Pumps the size of a pager, finger stick tests take 45 seconds.
  • 2006 - Finger stick tests take 5 seconds, insulin pump communicates wirelessly with continuous meter.
  • 2007 - ?

Soon I shall eat cake.

(If you have other questions, post them and I'll answer them in the comments)

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

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