Scott Hanselman

C++ killed my grandpappy - Is C++ hard and where are the C++ coders hiding?

June 29, 2010 Comment on this post [52] Posted in Source Code
Sponsored By

After learning BASIC and ASM, for a job I started coding in C, when Hello World on Windows was 92 lines of code. (Apparently Hello World is easier now, says Pete Brown)

One of my first big projects was an app called Foolproof that kept kids in high school from breaking into their school's lab computers. It had a C core engine, a TurboVision DOS component and a 16-bit Windows C++ App. I did the DOS, Win16 and later the Win32 API all in C++. Later I did some VB3, then Delphi, then worked at Nike doing Java (right when RMI was starting, and HotJava when we wrote once and debugged everywhere) until I finally ended up in managed code, mostly doing C#.

Some folks don't know Microsoft has a free C++ Express Edition of Visual Studio 2010 and that it's one of the most used free versions out there. Someone is coding C++, and they are doing a lot of it.

Are you coding in C++, Dear Reader? What are you doing?

Most "managed people" cringe at the idea of using C++, thinking it's perhaps a language of the past and that it's not even possible to write Windows Apps in C++ without a Master's Degree. ;)

However, I just noticed there's a new project called Hilo with source to show people how to use the shiny new things in Windows 7 from C++ and how to make modern Windows applications that have animations and magical stuff that managed people assume belongs only to them.

The first drop of "Hilo" is apparently the first of many, all moving towards building a larger application. This first sample is a content browser (touch enabled!) for looking at videos and photos (yeah, yeah, I know) but you could totally use it to browse other stuff or use it as underlayment for your own app. This from the Windows Team Blog:

The main technologies used in Hilo: Direct2D, Windows Animation Manager, Windows Touch, Libraries and the Shell API.

  • Direct2D: For high performance and high-quality rendering of graphics.
  • Windows Animation Manager: To give the application a unique personality and to improve the user experience.
  • Windows Touch: To provide a more natural user interface through which the user can just “point” and “do”.
  • Libraries: To enable the application to provide users with a single, coherent view of their files.
  • Shell API: To navigate the images, to optimize by using the pre-built thumbnail cache and also to provide icons from actual content.

Even if you're not going to start coding C++, it's always a good idea to "see how the other half lives." For me, it's a return to what I thought I knew, and a way to look at C++ with fresh eyes.

What surprised me was that this app was written against Windows itself, with no frameworks. I always assumed you kind of needed MFC or some other library to be productive.

I'm not sure why I remember it this way, but C++ always made me think of regular expressions, and I assumed my code would **be &all like->this.you~know? You do need to know more about Windows, to be sure, as there is likely a decade of managed programmers who have forgotten what a message pump is, but it wasn't as scary as I had remembered.

Hilo Browser

Just download C++ Express, then the Hilo source, and build it. It has some cool effects with the carousel, like inertia when it spins, scaling, Z-ordering, hardware graphics acceleration. Now all they need is a designer! ;)

As an interesting example, it uses Direct 2D and has an animation for the orbit of the carousel. I removed all the if (SUCCEEDED(hr)) code from this snippet below because that's still the one thing about C++ on Windows that irks me. Don't judge then, judge me for yanking it for brevity.

This source is extremely defensive, dutifully checking HResults at every step. I mean, seriously, if it doesn't Succeed, what are you going to do about it? If (NOTSCREWED(hr)), you know.

For this source, the salient point is that there's some nice high-level Animation constructs like timers, transitions and storyboards.  For some wrongheaded reason I thought it'd be a pile of math so I was pleasantly surprised.

HRESULT OrbitAnimation::Setup(D2D1_ELLIPSE targetEllipse, double targetOpacity, double duration)
{
HRESULT hr = S_OK;

// Animation objects
ComPtr<IUIAnimationManager> animationManager;
ComPtr<IUIAnimationTimer> animationTimer;
ComPtr<IUIAnimationTransitionLibrary> transitionLibrary;
ComPtr<IUIAnimationStoryboard> storyboard;

// Transition objects
ComPtr<IUIAnimationTransition> centerXTransition;
ComPtr<IUIAnimationTransition> centerYTransition;
ComPtr<IUIAnimationTransition> radiusXTransition;
ComPtr<IUIAnimationTransition> radiusYTransition;
ComPtr<IUIAnimationTransition> opacityTransition;

// Initialize animation variables if necessary
if (nullptr == m_centerX)
{
hr = Initialize(targetEllipse, targetOpacity);
}

// Retrieve animation objects
hr = AnimationUtility::GetAnimationManager(&animationManager);
hr = AnimationUtility::GetTransitionLibrary(&transitionLibrary);

hr = AnimationUtility::GetAnimationTimer(&animationTimer);

// Initialize storyboard
hr = animationManager->CreateStoryboard(&storyboard);

// Create one transition for each orbit variable
hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.point.x, &centerXTransition);
hr = storyboard->AddTransition(m_centerX, centerXTransition);

hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.point.y, &centerYTransition);
hr = storyboard->AddTransition(m_centerY, centerYTransition);

hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.radiusX, &radiusXTransition);
hr = storyboard->AddTransition(m_radiusX, radiusXTransition);

hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.radiusY, &radiusYTransition);
hr = storyboard->AddTransition(m_radiusY, radiusYTransition);

hr = transitionLibrary->CreateLinearTransition(duration, targetOpacity, &opacityTransition);
hr = storyboard->AddTransition(m_opacity, opacityTransition);

hr = AnimationUtility::ScheduleStoryboard(storyboard);

return hr;
}

I was also pleased to see that intellisense worked nicely for everything typed as well as -> deferenced pointers, as seen in the screenshot below. Call me an intellicrack addict or weak-minded but it does speed things up once you know what you're looking for. The C++ Express SKU was a small download as well.

C++ Express Screenshot of Code

I'm not saying it's all puppies and cotton candy, but it's not the post-apocalyptic-Where-is-John-Connor-wasteland I thought it would be. I'll be giving C++ another look as I aim to learn (or relearn) another programming language this year (along with Scala). I'll report back as this application gets bigger and more interesting.

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

The Weekly Source Code 53 - "Get'er Done" Edition - XML in the left hand becomes HTTP POSTs in the right hand

June 26, 2010 Comment on this post [13] Posted in Open Source | Source Code
Sponsored By

I wrote some code tonight in about ten minutes with a "Get'er Done" attitude. We all do that (I hope). It's one-time code that will solve a one-time problem. As such, it isn't always pretty, but it often is interesting.

I've got this silly website called OverheardAtHome that is a collection of silly quotes and stories that my kids (and your kids) have said around the house. It was running on DasBlog (just like this blog) for the last year or more, but the sheer workflow of populating the site was getting tiredsome. DasBlog isn't setup for screening external submissions and promoting them to posts, and I wasn't really interested in extending DasBlog in that way.

Instead, I needed to move OverheardAtHome to a hosted blogging solution, preferably a nice free one as it doesn't make any money. It's just a hobby. I like Tumblr so I figured I put it there. Tumblr has a very basic HTTP API and their native UI supports User Submissions, so it seemed like a win.

DasBlog stores its content not in a database, but rather in an XML file per day. I've got a few hundred XML files that make up the whole of the content on OverheardAtHome and it's very basic stuff.

Here's what I wrote, using the Tumblr API from CodePlex written by (I believe) Jeremy "madkidd" Hodges, who is also a Developer on Graffiti CMS, coincidentally. It's a nice little abstraction on top of HttpWebRequest that uses a little HttpHelper class from "rakker."

I figured I could use PowerShell or something script-like, but this was very fast to write. There's no error handling, but interestingly (or not), there were no errors in hundreds of posts.

using System;
using System.Linq;
using System.IO;
using System.Xml.Linq;
using System.Threading;

namespace TumblrAPI.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Started...");

TumblrAPI.Authentication.Email = "myemail@notyours.com"; // Console.ReadLine();
TumblrAPI.Authentication.Password = "poopypants"; //Console.ReadLine();
Console.WriteLine(TumblrAPI.Authentication.Authenticate().ToString());

if (TumblrAPI.Authentication.Status == TumblrAPI.AuthenticationStatus.Valid) {
Console.WriteLine("Now make some posts...");

DirectoryInfo di = new DirectoryInfo(@"C:\overheardathome\xml");
//Get the DasBlog XML files, they are like <entry><title/><content/></entry> and stuff
FileSystemInfo[] files = di.GetFileSystemInfos("*.dayentry.xml");
var orderedFiles = files.OrderBy(f => f.Name);

XNamespace ns = "urn:newtelligence-com:dasblog:runtime:data";
foreach (FileSystemInfo file in orderedFiles)
{
XDocument xml = XDocument.Load(file.FullName);
var posts = from p in xml.Descendants(ns + "Entry") select p;

foreach (var post in posts)
{
TumblrAPI.Post.Text t = new TumblrAPI.Post.Text();
t.Title = (string)post.Element(ns + "Title");
t.Body = (string)post.Element(ns + "Content");
Thread.Sleep(500); //Tumblr will API limit me if I bash on them.
Console.WriteLine(" Response from text post: {0}", t.Publish());
}
}
}

Console.WriteLine("Done, press any key...");
Console.ReadLine();
}
}
}

Comments? What's a better pattern for left-hand/right-hand bulk crap like this, Dear Reader?

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 219 - Demystifying Microsoft's Application Server: Windows Server AppFabric with Karandeep Anand

June 25, 2010 Comment on this post [1] Posted in AppFabric | Podcast
Sponsored By

Windows Server AppFabric Logo My two-hundred-and-nineteenth podcast is up. Microsoft's Application Server is out and it's called AppFabric. Scott chats with Karandeep Anand from the Distributed Application Server group at Microsoft about Windows Server AppFabric. It's released and it's part of Windows itself. How does it relate to Azure? What's included, and where's Velocity?

NOTE: If you want to download our complete archives as a feed - that's all 219 shows, subscribe to the Complete MP3 Feed here.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting, ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visit www.telerik.com.

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)

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

Ultimate Developer PC 2.0 - Part 1 - Building a WEI 7.9 and RFC for building a GOM (God's Own Machine)

June 23, 2010 Comment on this post [66] Posted in Hardware | Musings
Sponsored By

Got enough acronyms in that title?

  • WEI - Windows Experience Index. How fast is your machine? If you say "I've got a WEI 6.0" you've got a good machine, for example.
  • RFC - Request for Comments. This is crowdsourcing. I want to know what YOU think we need to do to make a machine that is so fast that it'll max out at WEI 7.9 and be a GOM.
  • GOM - God's Own Machine. If the Good Lord had a computer, it'd be a 7.9. We want to build that machine.

Pete and I are finally ready to build it. Specifically, I got permission from my wife to build a WEI 7.9 machine - a GOM (God's Own Machine.) You can go to your start menu now and type in WEI and see what your Windows Experience Index is. This used to be capped at 5.9 (and arbitrary number) in Vista and now the max is 7.9 in Windows 7.

We'll post the result on http://weishare.net, and it looks like there's a 7.8 up there now.

You can see from my laptop, for example, that I have a crappy video card (actually I think I'm using the lesser of my two video cards), but everything else is awesome. Of course, your machine is only as capable as its slowest part, so your WEI is the lowest subscore. My disk is an SSD, so it's great.

My W500 is a 4.6.

It's been believed that a 7.9 is either not possible, or is really really expensive. Either way, it's not easy. We've got US$3000 and we're going to see if it can be done. We've enlisted some engineers directly from the Windows Experience Index team and Pete and I are going to interview them in the first week of July for my podcast.

Parts List

Here's what we're thinking of starting with, with an initial parts list courtesy of Chris Kirk and friends. At this point I'm cheating a little as I have a case already and I'm pretending DVD drives are free.

We need your comments, Dear Reader. Can the elusive 7.9 be built for less than $3000?

Related Links from our Previous Ultimate Developer Rig Build in 2007

    Your thoughts?

    Ukrainian translation of this post

    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

    Do they deserve the gift of your keystrokes?

    June 23, 2010 Comment on this post [18] Posted in Blogging | Musings | Productivity
    Sponsored By

    There are a finite number of keystrokes left in your hands before you die. - Me

    One of the most influential (to me personally) posts Jon Udell has written was his classic "count your keystrokes." I've mentioned this post in a number of my talks, including my talk on "Tips to make your blog suck less" at Blogging While Brown this last weekend. This point, in particular always seems to resonate with people, so here's my own take, before you read the original.

    Let break it down. I'm 36 and change. I'll live to be 80, let's say, and I can type 100 words a minute (but 50 of that is errors and the backspace key) so let's say 50WPM. If I type for 6 hours a day, 5 days a week, 50 weeks a year, for the next 44 years, that means there are 198M keystrokes left in my hands. Max. Period. And that's generous; it's likely 10% of that.

    5.1CPW * 50WPM * 60m/hr * 6hr/s a day * 5 days/wk * 50 wks/year * 44yrs = 1,009,800,000 keystrokes left in your hands.

    Let's assume the average length of an English word is 5, plus a space, so six. That's a ceiling of 168M more words I can type in my lifetime. Nothing I can do, short of dictation, or some new brain invention is going to create more keystrokes. I am I/O bound by my hands. The keystrokes they contain are finite. And this assuming my hands don't give out.

    Drink that in. OK. So now, next time someone emails you ask yourself "is emailing this person back the best use of my remaining keystrokes?" That includes both 1:1 and 1:many emails. You could even add a little hubris to it and say: "Does this person deserve the gift of my keystrokes?"

    Instead, consider writing a blog post or adding to a wiki with your keystrokes, then emailing the link to the original emailer. (Like this email, er, blog post, for this example.) Send them to http://www.letmegooglethatforyou.com or http://www.letmebingthatforyou.com and teach them to fish.

    UPDATE: This is about reach and effectiveness vs. efficiency. If you email someone one on one, you're reaching that one person. If you blog about it (or update a wiki, or whatever) you get the message out on the web itself and your keystrokes travel farther and reach more people. Assuming you want your message to reach as many people as possible, blog it. You only have so many hours in the day.

    The best way to get more email is to reply to it. The best way to get less email is to stop answering it.

    Conserve what remaining keystrokes you have left, Dear Reader. Or, use them in the comments area here and give me the special gift that is your keystrokes.. ;)

    Related Links

    P.S. This blog post is 435 words or 2362 keystrokes. Hope it was helpful. I've only got 1,009,797,638 left!

    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.