Amazon.com Widgets Nick Hodges | A man's got to know his limitations

Even More Changes to HTMLWriter

By Nick at January 09, 2011 05:19
Filed Under: Delphi, Software Development, Unit Testing

Okay, so if you are actually using THTMLWriter, I’m sorry – but I made another pretty major change to it, one that will require you to again make changes to any existing code that you have.  Such are the perils of using pre-1.0 software I suppose.

These changes are made at the suggestion of a number of you fine people, and I’m grateful for your wisdom and for taking the time to critique my work and make such good suggestions. 

Interface Only Access

If you have an interface you want people to use, then you should provide a way for them to use it.  In fact, the really cool thing to do is to make it so that it is the only way to do it.  One iron-clad rule of interfaces is that you should never mix interfaces and instances of the classes that implement them.  The interface is the important thing, not how the interface is implemented. 

An interface is a “promise” of a specific service, and a consumer of an interface shouldn’t care about the implementation details of an interface.  Indeed, that is one of the main advantages of interfaces – that you can “switch out” what you use to actually implement the interface.  If one of you guys things my implementation sucks and want to create a new one, you can simply create a class that implements IHTMLWriter and use that instead without changing any of the code that you have using IHTMLWriter.

So What Did I Do This Time?

Okay, so here’s what I did.

  • I created three standalone functions that return a reference to the IHTMLWriter interface.  They correspond to the three constructors that are included in the THTMLWriterclass.  This is the only way to “get at” the IHTMLWriter interface. 
  • I “hid” the entire THTMLWriterclass in the implementation section of the uHTMLWriter.pas unit.  Now, you can’t even get at the class even if you wanted to.  You must deal exclusively with the interface. 
  • I put the two interfaces I created – IHTMLWriter and ILoadSave -- in their own units.  This way, they aren’t coupled together and can be used separately if desired. 
  • I put all the /// comments in the interface unit instead of on the class. 
  • I had to make changes to the tests to support the new way of grabbing an interface reference.  I made the names of the functions similar enough to the code you current have that it will just be a matter of deleting a few characters.  Of course, all the tests still pass.

What’s Left?

I have a few more things to implement – mostly support for some less common tags that go in specific places inside a <table> tag.  After I do that, I think then I’ll declare THTMLWriter to be an official 1.0 release.

Update on THTMLWriter

By Nick at January 06, 2011 03:56
Filed Under: Software Development, Delphi, Tech Stuff, Unit Testing

I’ve made a fairly significant change to THTMLWriter.  (Even if you aren’t a use of THTMLWriter, please keep reading, there’s a valuable lesson at the end.)

What Did I Do?

I created an interface – IHTMLWriter – which simply lists the public interface of the class – and then had THTMLWriter implement that interface.  Not a big deal.  The big deal is that now the Fluent Interface is done with the IHTMLWriter interface instead of the class itself.  This shouldn’t be a big deal if you are using the class – you merely need to change the variable declaration to IHTMLWriter, and remove any code that destroys/frees the class you may have created. 

Why did I do this?  Well, I have to confess that it was partly because I could.  But I also think that in general, interfaces are better to deal with, particularly with the fluent interface.  I’ve noticed that interfaces appear to be the typical way that such things are implemented.  In addition, an interface limits the scope available to the consumer of a class.  If  you can only use a class via the interface, I as the developer can decouple the implementation from the interface – something that is always good. Plus, if one of you fine people feels like there is a better way to crank out HTML, now you can do it, too, using the same interface. 

The Valuable Lesson

Here’s the part that you all need to read:  I was able to make this rather large change with a lot of confidence because I had a pretty extensive set of unit tests to back me up. 

The initial change – creating the IHTMLWriter interface and changing the class to implement and use it – broke everything.  No test would pass, and the test program did nothing but raise access violations.  So, of course, I went to work and fixed things up.  I had to change a little architecture, alter the way a few things were done, and generally fix things up. 

All of my debugging was done on the test project.  It provided a perfect, simple reproduction of the bugs.  The unit tests enabled me to easily step through simple examples and find the places where the bugs were and where things weren’t working right.  And eventually the tests all “turned green”. 

GoingGreen

And let me tell you, turning green is sweet!  First, it feels really good. I kept running the tests and watching that little green bar slide across because it felt great.  Why did it feel great?  Because I knew that my changes were complete and  because I had confidence that things were all working as they were supposed to.   The only way that was possible was because of the existence of the unit tests.  Without them, I’d never really ever be sure that things were back to normal and working.

Time Well Spent

So the unit tests allowed me to forge ahead with confidence, provided me with a useful and powerful vehicle for testing and debugging my changes, ensured that I would know when I was done, and enabled me to prove that things were working as they should – all while making a fairly substantial change to a fairly complex code library. 

And some people say they don’t have the time to write unit tests.  I say you don’t have the time not to.

The Developer Solutions Conference

By Nick at January 03, 2011 21:57
Filed Under: Delphi, Software Development, TechBiz

Hey, I want to give a shout out to the folks at RemObjects and Developer Experts and their upcoming conference focused on Delphi – the Developer Solutions Conference. It’s taking place February 8 –10 at the MGM Grand in Las Vegas. Now, I can only assume that the vast majority of you are always looking for an excuse to go to Vegas, and now you a have one. 

Sadly, I won’t be able to attend, as the conference is falling right around the time of a major release for us.  I really would like to be there.  I always love hanging around with Delphi Geeks, and so I hate missing this opportunity. 

More information:

If you are looking for a stimulating conference and even better, a reason to go to Vegas, why, you should register and go!

Flotsam and Jetsam #18

By Nick at December 30, 2010 02:30
Filed Under: Flotsam and Jetsam
  • Cool Thing Done with Delphi of the Week:  Now this is the kind of thing where Delphi can really shine – connecting to hardware.  I’m sure some of you got an XBox 360 Kinect controller for Christmas, and if so, you can now write a Delphi app to use it.  Simon Stuart (aka LaKraven) continued his string of writing Delphi interfaces to interesting things (he started with TTwitter, or maybe even something before that that I don’t know about!)  by writing TKinect, a component to connect to, well, a Kinect controller.  Smile  And then the folks at the IT Security Lab made some really cool demos.  The 3D stuff is particularly cool. Definitely worth a look, just for the coolness factor. 
  • As a general rule, I find most everything Seth Godin says to be interesting, but I thought that this post was particularly interesting.  Made me thing “Grow where you are planted”. And it made me think that your job doesn’t have to be that which it is “supposed” to be.  For instance, being a waiter might seem mundane, but you can make it an opportunity to learn how to delight people, as Godin deftly points out. 
  • Great list -- 29 tech phrases you should be punched in the face for using.  And just for the record, I only type “LOL” when I actually do LOL.  Winking smile  (And while we are at it, here’s another great list.)
  • I ran across an interesting coding technique called “Spartan Programming”.  I agree with much, but not all, of the tenants.  I’m definitely in favor of limiting scope as much as possible, creating small interfaces, limiting horizontal and vertical complexity, and minimizing coupling,  But I can’t say I’m a fan of limiting the size of variable names or limiting character count in general.  In that area, I think it pays to be clear and verbose.  I do agree, though, that routines should be short and sweet.  In any event, interesting ideas.
  • Cool Delphi Code of the Week:  TKBDynamic in the kblib project on GoogleCode.  This is a small but really useful library that lets you easily write records to streams, even if the records have relatively complex structures.  Pretty cool – and it isn’t even yet taking advantage of the new RTTI.

Using Your BitTorrent Powers for Good, not Evil

By Nick at December 27, 2010 12:10
Filed Under: Tech Stuff

I’m a big fan of the BitTorrent Protocol.  It’s an amazingly simple yet clever protocol for easily and efficiently moving bits around on the internet.  By grabbing small chunks of a given file from multiple peer computers anywhere in the world, it can quickly and efficiently move files from one place to another. 

Sadly, BitTorrent has a bad reputation, as it is commonly used to move pirated software, music, movies, and TV shows around in violation of any number of copyright laws.  But the fact that it is used for nefarious purposes doesn’t make BitTorrent itself evil or illegal, anymore than cars are illegal for being used as bank robbery getaway vehicles.  It’s a shame that many companies and other organizations feel that they can’t avail themselves of BitTorrent because of its bad reputation.

In fact, there are plenty of legitimate uses for BitTorrent.  Many companies do use it to distribute their software.  For instance, Ubuntu provides torrents for their Linux distributions.  It’s a nice way to make large files available to customers fast and free – there’s no bandwidth limit or any fee associated with BitTorrent.  But be advised of one thing – once a torrent is out in the wild, there is no getting it back. It is totally roaming free out on the Interwebs.

Below is a screenshot of my µTorrent client, showing the torrents that I’m serving up from a server at my house.  Those Ubuntu files are quite popular, and because there are so many “seeders” (that is, other people making the file available for downloading), I was able  to download many of those files at rates over 2MB per second meaning I was downloading 650MB files in a matter of minutes.

Torrent

In addition to the Ubuntu files, I also went to ClearBits.net and downloaded a number of legal, free-and-clear torrents. I leave my client running 24 hours a day, and gladly give up some of my upstream bandwidth to support the good folks at Ubuntu and the furthering of the distribution of fine literature via completely legal torrents.  I like to think of it as a small contribution back to the community and doing my part to contribute to the legal side of BitTorrent.

So if you haven’t checked out BitTorrent, give it a look.  There are plenty of legitimate uses for it out there, and there’s no reason you can’t be using it  to distribute your software -- and maybe even providing a bit of bandwidth to the world. 

This Wild Year of 2010

By Nick at December 26, 2010 04:28
Filed Under: General, Personal

This year of 2010 ended up pretty dang good, considering I got fired from my job about half way through it.   For that, I am very thankful.  I’m really quite happy in my new job, my new house, and  my new state.  Things are going well all around. This wasn’t something I fully expected, and so it is an especially nice place to find myself.

In addition, many of you sent words of encouragement and support throughout the year, and for that I’m grateful. 

So all in all, 2010 was a pretty good year. Here’s hoping that 2011 is an even better year for all of us.

Flotsam and Jetsam #17

By Nick at December 15, 2010 08:24
Filed Under: Flotsam and Jetsam, Delphi

Listening

By Nick at December 12, 2010 05:23
Filed Under: Leadership

Imagine this (it shouldn’t be all that hard):  You are a widget manufacturer.  You’ve been tasked to figure out how to make 1000 widgets.  You’ve been planning for weeks.  You’ve gathered data, run the numbers, made estimates, and come up with a plan you believe in. You’ve left a little wiggle room for inevitable unknown obstacles.  You’ve put it all into MS Project and up on the screen in Powerpoint slides.  You are an experienced team – you’ve done this all before many times --  and the guys doing the work are battle-hardened  veterans who know their business.  Everything looks good.

Now it’s time to present your plan to the executive team. You lay everything out in a Powerpoint presentation that you’ve reviewed seventeen times.  But when they hear the plan, they say:  “Sorry, but that’s all wrong.  You say you can make 1000 widgets in fourteen months.  We say it only takes eight months to make that many widgets.  Get to work”.

Terrific.

Now you and your team know how long it will take to make 1000 widgets – 14 months.  But somehow your “leadership” has decided that it only takes much less time than that.  Never mind that these guys have only been with the company for a year or so, and have no real experience with the difficulties and the process of building 1000 widgets.  They are the bosses and their style of “leadership” seems to be to assert their all-knowing authority over the guys who actually know what is going on.  It seems to them that “leadership” means being a hard-ass and “pushing” the team to get more out of them than is possible.  Bottom line:  They didn’t listen and they didn’t trust you.  Why did they ask you to do all that planning when they were just going to tell you the schedule anyway?

We all know what happens next: after about seven months, it becomes hopelessly, overwhelmingly, manifestly clear that there is not going be 1000 widgets on the loading dock in a month.  Now everyone is scrambling to adjust course.  This, naturally, is a vastly worse situation than if they had merely planned on the 1000 widgets being available in 14 months from the start. Or agreed to make the number 500 in seven months instead.

True leaders listen to their people and believe them.  Good people tell you the truth they know they will be trusted.  The last thing you want to do is create a situation where your folks start “gaming” you and telling you what they think you want to hear.  This is a direct result of not trusting them.

If you are a leader and you don’t believe what you are being told, then it is overwhelmingly likely that you are the one with the problem.  You either need to radically change what you are doing or get new people – and again, it is very, very likely that you are the one that needs to change, not your people.  And if you have the wrong people, that is probably your fault, too.

The people in the trenches are the ones closest to the issue, and they know best what is happening “on the ground”.  Believe them, and you can adjust your plans and needs accordingly from the start.  Don’t believe them, and your plans will get adjusted anyway.  You can’t  make a baby with three women in three months, and if your plan requires that you do that, your plan is in trouble no matter how much of a hard-ass you are.  And the team knows that you can’t get a baby in three months, and they will be the ones who suffer for a bad plan.  They learn not to trust you and their morale goes into the tank.

Building and maintaining trust in both directions is a critical requirement for a good leader.  Trusting your people will engender their trust in you. It’s a virtuous circle.  Sometimes you even need to trust them even when they are wrong to help build future trust and to show that you believe in them.  If they trust you, they’ll follow you. Their morale will be up.  They’ll do the extra work and they’ll put in the effort because they want to.  People who are trusted and believed do that as a matter of course.

And isn’t that what we want our folks to do?

Be a Rockstar!

By Nick at December 09, 2010 04:56
Filed Under: General, Delphi

I am hoping that this will get people to stop teasing me about TSmiley sort of in the same way that hitting yourself in the head with a hammer makes you forget that it hurts when you hit your hand with a hammer.

Strange Poster

By Nick at December 08, 2010 07:51
Filed Under: General, Delphi

Someone posted this in our developer lounge this week:

IMAG0035

Flotsam and Jetsam #16

By Nick at November 30, 2010 03:42
Filed Under: Flotsam and Jetsam
  • New Delphi Blog of the Week: From Zero To One  The author made an interesting comment on my THMLWriter post, and has given me some ideas.  Looks like an useful set of downloads as well.
  • THTMLWriter Update:  As per the excellent suggestion by Francisco Ruiz, I’ve added a new feature for attributes, enabling you to declare attributes as an indexed property with two strings.  Great idea. 
  • Document Insight has been released and for the present, it is on sale for half price.  I have been making extensive use of Document Insight with the THTMLWriter project, and can easily say that it is one of the coolest Delphi plugins I’ve ever used.  It does exactly what I want, and it is utterly intuitive.  Very nice.  The XMLDoc feature of Delphi is cool once you really start using it, and Document Insight makes it pathetically easy to do.
  • Cool Delphi Open Source Project of the Week:  DotNet4Delphi – This is a brilliant idea, actually.  First, it utilizes generics to create a nice set of collections and lists based on the same set of .Net classes.  But the fun part is that it creates TDataset descendants than enable you to hook those lists and collections to data-aware controls for display and editing.  Very cool idea indeed.  Add this to the growing list of very excellent libraries for Delphi that are taking advantage of generics, RTTI,  and anonymous methods.
  • In Flotsam and Jetsam #14, I mentioned Cliff Stoll’s horrifically inaccurate prediction about the Internet.  Could this be the greatest single example of “Claim Chowder” in the history of the tech business?

Novell, Attachmate and Embarcadero

By Nick at November 25, 2010 12:29
Filed Under: TechBiz

As you’ve probably seen/heard, Novell has been purchased by Attachmate.  I can remember when Novell was a real high flier, right up there with Microsoft and Borland.  Of course, that was in about 1995, but hey, they were all up there during those heady days before Delphi was released.

I also remember when there were some pretty strong and perhaps well founded rumors that Borland and Novell were going to merge, or one was going to buy the other, or something.  Would have been interesting at the time, I guess. 

Anyway, Marco makes an interesting point (via Olaf Monien) – that Attachmate is owned by Thoma Bravo, the same equity firm that owns Embarcadero.  Attachmate is one of those companies where you can stare at their website for a long time and still not be clear about what they do or why you’d want them to do it for you.  (Sort of like Microfocus, who recently also acquired a formerly high flying company….) 

The Thoma Bravo guys were always pretty mysterious.  They never seemed very interested in any particular business needs that Delphi might have had after the Borland years.   They did seem interested in making money, though.  Nothing wrong with that, as that is pretty much exactly what private equity firms do.  

I can also say that being a “sister company” in the Thoma Bravo family to Novell/Attachmate probably means little to nothing for Embarcadero.  TB owns a number of software firms (did you known they own InstallShield, for example? They also own Plato Learning, a former client of mine in Minneapolis who was at the time a pretty big Delphi shop.)   But as far as I know, we never had the occasion to cross paths with any of the other “family members” when I was at Embarcadero.. TB seems to be buying up properties at a fairly furious rate, though, so perhaps that will change at some point. 

I hope so, because there are any number of things that Novell in particular is involved with that might make for some good synergies with Embarcadero, most notably the Mono project and MonoTouch for the iPhone.  It would be cool to see those two members of the “family” working more closely together. For example, one would hope it would make it easier for Embarcadero to include MonoTouch with Prism and RAD Studio. 

Anyhoo – it was an interesting point that Marco and Olaf brought up.  Something to think about and keep an eye on for sure.

Flotsam and Jetsam #15

By Nick at November 22, 2010 07:42
Filed Under: Flotsam and Jetsam
  • A lot of things bug me, but the thing that is bugging me a lot lately is a seeming proliferation of popup windows without a button that says – more or less -- “Save and make me go away”.  For instance, I use LiveWriter to write these posts, and the category drop down box doesn’t have any way to tell it “I’m finished”.  Apparently  you are supposed to just nookaybuttonknow that the way to apply your selections is to click somewhere outside the dialog.  I find this to be bad design and, well, irritating.  I like to know that when a dialog goes away, it has either definitely or definitely not saved my settings.  When clicking outside the box to make it go away, there’s no way to know for sure.  Very irritating.  What’s wrong with a good ol’ “Okay/Cancel” set of buttons? 
  • Hey, this is cool:  The mighty Joel Spolsky himself answered one of my questions on StackOverflow
  • Not surprisingly, since I added moderation to the comments here, I’ve gotten very few of the “Great post, this is exactly what I was looking for, I’m going to bookmark this site and come back later” comments.  What a shocker, eh?  Smile
  • I just discovered that there is a Reddit just for Delphi stuff.
  • If you are looking forward to 64-bit Delphi, then this StackOverflow answer from the prolific and always informative Barry Kelly is must reading.
  • Interesting Article of the Week: Implementing a Partial Serial Number Verification System in Delphi by Brandon Staggs.  Ever wonder where those four-chunked serial numbers come from and how they work?  Brandon does a pretty good job explaining it all and giving a “getting you started” implementation.  Good, interesting stuff.
  • As Allen Bauer taught me – “Shipping is a feature”.

Announcing THTMLWriter

By Nick at November 22, 2010 00:44
Filed Under: Delphi, Software Development, Tech Stuff

I have started an open source project on GoogleCode called THTMLWriter.

THTMLWriter is a Delphi-based class library that enables you to create HTML code and HTML documents. It uses the fluent interface to make creating HTML text easy and natural.  You can create HTML Documents or HTML “chunks” by  using any tag as a base.

THTMLWriter is all class based.  I started out trying to do some fancy things with interfaces, but it just got too complicated, and so I opted to go with the “simplest thing that will work” option, and now you can write code that looks like this:

 

Temp := THTMLWriter.CreateDocument;
     TempHTML := Temp
                  .OpenHead
                    .AddAttribute('dweezle')
                    .AddText('farble')
                  .CloseTag
                  .OpenBody.AddAttribute('ding')
                      .OpenSpan
                        .AddAttribute('this', 'that')
                        .AddStyle('font: italic')
                        .OpenDiv
                          .AddAttribute('floo')
                          .AddText('Blah')
                        .CloseTag
                      .CloseTag
                      .AddText('Hoorah')
                      .AddBoldText(' Shadooby')
                      .OpenBold
                        .AddText('Goombah')
                      .CloseTag
                  .CloseTag
              .AsHTML;

 

The project more or less produces XHTML code at the 4.01 level – I’ve tried to be XHTML-compatible, but I confess I haven’t been fanatical about it.  That is one of the things I want to in the future.  In addition, I want to update the project to support HTML5.  I’m still thinking about how to do that.

The project is pretty complete – you should be able to construct most HTML constructs.  I’ve provided a lot of overrides and default parameters for many of the “normal” attributes on a given tag.   I’ll continue to update the project with improvements and refinements.  I’ve used HTML & XHTML Pocket Reference from O’Reilly as my guide. I haven’t quite implemented everything, but it’s definitely at the point the that it is ready for you fine  people.

The project includes a full set of DUnit tests to give you confidence that the code actually does what it is supposed to. 

I have added a lot of XMLDoc comments to the code, but it’s far from complete. I’ve used the Documentation Insight plugin from DevJET software – the guys who do the Delphi Spring Framework.  (I can’t recommend this plugin enough – an outstanding contribution to the Delphi community, above and beyond the amazing Delphi Spring Framework.)

You can get the code from Google code using Mercurial.  We are planning on migrating our codebase here at Gateway Ticketing to Mercurial after the first of the year, and this project was my learning curve for using Mercurial.  Now that I’ve been using Mercurial – a distributed source control system – I wonder how we as developers ever managed to use anything but a DVCS.  It is that good and that powerful.  I heartily recommend looking at migrating to a DVCS.  It’s so much more flexible and more powerful than a server based solution such as Subversion

I’d be very happy to add anyone to the project who is interested in contributing.  I’ll also be happy to integrate submitted patches as well.  This have been a fun project to keep my toe in the water of coding – being a manager now means I don’t get to code as much as I want --but living alone in Pennsylvania while my amazing wife moves our house out here has given me a lot of free time to code.

Enjoy and let me know what you think.

Flotsam and Jetsam #14

By Nick at November 12, 2010 07:10
Filed Under: Flotsam and Jetsam
  • One hidden benefit of working at a ticketing company:  Unlimited book marks!
  • Video of the WeekTeacher has trouble showing a video.
  • This article by Cliff Stoll cracked me up. Written in 1995, it basically says “This whole Internet thing is a big mess and will never take off”. The article was a companion piece to his book Silicon Snake Oil: Second Thoughts on the Information Highway.  Stoll is probably most famous for writing one of the first tales of hacking and security on the Internet called The Cuckoo's Egg .  I’m sure that he’s utterly embarrassed by the article – and probably the book -- today. And if he’s not, he should be.  Winking smile
  • I posted this comment on StackOverflow: “Empty catch/except blocks aren't code smells, they are code putrids.” By the way, that whole question is worth reading.  Some good wisdom there.
  • And while we are on the topic of good questions to read, this one about people’s favorite programming quotes is pretty fun to read.  My favorite quote:  “Some people, when confronted with a problem, think ‘I know, I'll use regular expressions.
    Now they have two problems.
    ”  What is your favorite?

My Book

A Pithy Quote for You

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."    –  Abraham Lincoln

Amazon Gift Cards

General Disclaimer

The views I express here are entirely my own and not necessarily those of any other rational person or organization.  However, I strongly recommend that you agree with pretty much everything I say because, well, I'm right.  Most of the time. Except when I'm not, in which case, you shouldn't agree with me.