Friday, August 31, 2007

Tsk, Tsk, Tsk - PNY Should be Ashamed of Themselves

Take a look at one of my co-workers found today.  The screenshot says it all.

Tsk-tsk

No, I didn’t destroy their database.  I was about to send an email to them when I realized it was fixed.

It amazes me that a large company such as PNY would do this.  It was probably written in Taiwan by someone who makes $4/hour, but still.  It makes you think twice before buying PNY memory.

Thursday, August 30, 2007

Professional XNA Game Programming - Review

Xna-bookI just finished reading Professional XNA Game Development by Benjamin Nitchske.  It was my first attempt at using the XNA Framework.  I have some experience with DirectX, as I have been tinkering with it since version 5. Most of my work has been with the Managed DirectX bits for .NET 1.1. I found it to be much easier and readable than C++, just because of the language differences.

XNA takes that next productivity leap and really allows you to hit the ground running.  You start out with a game loop (complete with elapsed time already calculated for you), a graphics device already setup, and a managed content pipeline for imported models, sounds, and textures.  Things like graphics memory getting lost when you alt-tab are already handled for you.

But enough about XNA, this post is a review for Benjamin's book.  If you haven't heard of him before, he was the author of the first Managed DirectX game called Arena Wars, and later wrote RocketCommander. Both games are very well done and he ported RocketCommander to XNA so that you can play it on the XBOX 360. XNA Racer was also done completely by himself, which is very impressive.  Needless to say, with all that background and expertise... I had high hopes for this book.

The first few chapters introduced how Benjamin approaches game development.  He calls them "Unit Tests" but that term often implies that the tests are automated.  His tests are basically slices of game functionality that he calls manually.  For example he might have a unit test to verify that shadows work properly, or that a specific collision detection algorithm works.  He is able to setup the update and render loops using anonymous methods and execute them using batch files or manually calling the unit test instead of the main game.  I found this to be very interesting, however the code that he used to write it was somewhat ugly and unintuitive.  I coded the Pong game following his coding style and was disappointed the whole way through it.  While he does say that we will utilize better code for the next game, the code he wrote here was inexcusably bad. I got the game working, however new features and modifications would prove to be difficult because it is just spaghetti code.  I swallowed my pride and told myself, ".. it will get better."

So then I started to follow his next example: Breakout.  I have built breakout before using Managed DirectX, and it was quite fun.  I was disappointed to find out that he didn't really buid the game through the book, he rather took the reader on an exploration of code already written. And he was true to his word, the code pulled a lot of functionality into "helper" classes which made them reusable.  And yes, the code was still horrid.

I mentioned reusable code.  It wasn't reusable like you're thinking.  He actually tells you to copy the code from the previous game and paste it into the new game.  I'm not kidding.  I'm a professional developer.  This book is called Professional XNA.  Professionals don't write code like that. He begins to talk about 3D programming in a way that is -- while full of information -- poorly organized and generally boring.  I learned a lot in this section, but nothing I can really refer to later.  It was more like a stream of conciousness than organized writing.

Let me give you a hard example of how bad the code is.  At one point he is talking about how he handles car physics, which was very interesting.  Then I saw the class diagram where he implemented it.  It looked something like this:

CarPhysics-crap

What!?!? So ChaseCamera inherits from CarPhysics which in turn inherits from Player?  Sounds like an object model from the Twilight Zone. This is pure junk as an object model, and is really only there because the CarPhysics object needs to know details about what the player is doing, and indeed so does the camera. But that doesn't mean you should break all rules of OO just to achieve a hack that works.  I was so appalled by this I almost didn't finish the book.

Benjamin knows his stuff, no doubt.  I think it’s amazing that someone can build something as beautiful as RocketCommander or XNA Racer in less than a month by yourself.  But I just can’t recommend this book because of the code quality.

I will wrap this up by saying that I *did* enjoy the book because it got me into game programming again, but I find this type of writing almost intolerable.  I enjoyed to learn about some nuances around XBOX 360 vs. PC versions of XNA Games, and I especially liked his Unit Testing technique. The information on Shaders was mildly useful, albeit boring. But if you're going to be reading this book, be fore-warned that the code sucks.

I give it 2.5 / 5 stars.

Sunday, August 26, 2007

HoustonTechFest 2007 was a Hit

Houston Tech Fest 2007 was yesterday and it was an amazing success.  Over 600 people were present and I was able to see a lot of old friends and meet some new & interesting people.

I got to chill out with Brad Abrams and a few other folks from Microsoft, and it was great to meet Scott Bateman (fellow Houston blogger and advocate of Continuous Integration).  His talk was most excellent, he was very informative and it showed that he not only understood the concepts, but he was able to explain it all in a way that (I thought) was easily grasped by the audience.

Some of the other speakers included Mike Azocar, John Cook, Tim Rayburn (sorry I missed your talk again Tim!), and David Walker.

Funny thing about Tim’s talk.  I was in the room next door listening to David Walker talk about SOA and WCF, and we could hear Tim through the wall partition.  At one point I heard Tim say, “If you can’t hear me in the back, please shout out and let me know.”  I felt like shouting from our room .

I had two sessions, Advanced CSS & Javascript and ORM with NHibernate.  In the first session, I had a full room (over 100 people!) and the audience was very engaging.  It’s great to have an audience that has so many questions and comments on what you are saying.  It becomes more of a dialog, which I think makes the content so much more valuable for everyone. 

Sometime in the midway point of the talk the projector just turned off.  It’s hard to give a talk on CSS without some visuals, so I continued typing and said “Imagine if you wil…” to a room full of laughter.  About that time the projector turned on again.  I didn’t find out until later, but my friend Wes had sat on the cord and unplugged it, then silently plugged it back in.  Funny how a room full of geeks and nobody thought to check the plug when it turned off.  Ah well.

At the end of the talk I had a couple people come up to shake my hand and a little 4–year old girl came up, touched my arm, then ran away giggling.  (Don’t ask me…).  I really enjoy giving this talk and I would like to branch outside of Houston and start giving it elsewhere around Texas (and the U.S.).

My second session was on NHibernate and it was more cozy, with only 15 people or so.  I think NHibernate is a lot harder to make interesting for an intro class because it is a radically different way of developing applications that most people are exposed to.  There is so much material to cover and only a short amount of time, so I tried to focus on the code and keep the examples short and simple.  I think it was effective, though I’d like to branch off this talk and start giving more advanced lectures on NHibernate.

Thanks to all who came to the event (especially my sessions!).  I hope you all had as much fun as I did.

The files from my presentations can be downloaded here:

File Attachment: AdvancedCSSAndJavascript.zip (1161 KB)

File Attachment: nhibernate.zip (4001 KB)

Also, a lot of people were interested in the tools I was using during my demos.  My favorite text editor is E, which you can get at http://www.e-texteditor.com.  My zooming tool that I use is called Zoomit.  My launching utility is called Launchy and it saves me so much time everyday.  I use ReSharper for Visual Studio nirvana (seriously, get this tool).

Some links I mentioned at the talks:

http://www.csszengarden.com

http://www.exploding-boy.com

http://www.mochikit.com

http://www.prototypejs.org

And finally, my favorite CSS book that I keep recommending to everyone:  CSS Mastery.

Thursday, August 23, 2007

e - Text Editor - no such file exists -- ubygems

There's no doubt that e kicks ass.  On one of my computers, however I was having a problem using some of the bundles.  Specifically some of the bundles utilize cygwin to do their magic.

I was receiving this weird error, where ruby is complaining that it can't locat a file named "ubygems".  Obviously, they are referring to rubygems, and the problem exists when you have a windows install of ruby and a cygwin install of ruby.

To fix it you need to reinstall ruby gems within cygwin.  Download the latest version of rubygems from rubyforge.  Put the tarball in the c:\cygwin\home\USER folder, then open up your cygwin prompt and type:
$ tar -x -f rubygems-0.9.4.tgz  (this will change if you download a different version)
$ cd rubygems-0.9.4
$ unset RUBYOPT
$ ruby setup.rb

At this point rubygems should be installing and you should be good to go.  Back to "e goodness"!

Wednesday, August 22, 2007

Sogeti Is Hiring

My company, Sogeti, is always seeking out new candidates.  If you've got experience or are just out of college, there is a place for you.

Currently we have an immediate need for someone to help out on a project.  No development experience needed for this role.  It would be a great way to get started in a BA, QA, or PM position.   This position is in Houston, but I can always help pass the word to one of our other offices as well.

If you're interested, or know of anyone who might be, please send me an email at ben.scheirman _AT_ us.sogeti.com.

Thursday, August 16, 2007

Elegant ASP.NET Caching

So you have a central method that returns some common data, say for example US States.

public IList<State> GetUsStates()

{

    List<State> states = new List<State>();

    using(IDataReader dr = DataAccess.ExecuteReader("SELECT * FROM US_STATES"))

    {

        State theState = State.Fetch(dr);

        states.Add(theState);

    }

 

    return states;

}

Pretty simple stuff, loop over a datareader, building “State” objects based on a row in the database.

Well since this data hardly ever changes and is the same for every user, it is a prime target for caching.  (Psst, if you didn’t know, caching can be one of the most effective performance tuning techniques you can perform — if done correctly).

Now that we want to enable caching, we can create a little helper class that makes it a bit easier to work with…

This is a watered down version of the cache API, but it solves 90% of the cases.

public class CacheHelper

{

    public static bool ItemExists(string key)

    {

        return HttpContext.Current.Cache[key] != null;

    }

 

    public static void Insert(string key, object obj)

    {

        TimeSpan oneHour = new TimeSpan(1,0,0);

        Insert(key, obj, oneHour);

    }

 

    public static void Insert(string key, object obj, TimeSpan span)

    {

        HttpContext.Current.Cache.Add(

            key,

            obj,

            null, //no dependencies

            DateTime.Now.Add(span),

            Cache.NoSlidingExpiration,

            CacheItemPriority.Normal,

            null //no remove callback

        );

    }

 

    public static T Retrieve<T>(string key)

    {

        return (T)HttpContext.Current.Cache[key];

    }

}

Now that we have the utility methods in place, we can alter our US States function to enable caching:

public IList<State> GetUsStates()

{

    string statesKey = "US_STATES";

    if (!CacheHelper.ItemExists(statesKey))

    {

        //add it

        List<State> states = new List<State>();

        using (IDataReader dr = DataAccess.ExecuteReader("SELECT * FROM US_STATES"))

        {

            State theState = State.Fetch(dr);

            states.Add(theState);

        }

 

        CacheHelper.Insert(statesKey, states);

    }

 

    //now it definitely exists in cache

    return CacheHelper.Retrieve<IList<State>>(statesKey);

}

This code quickly gets repetetive and ugly, but it gets the job done.  How can we do better?

We need to be able to provide the means of getting the data, but without actually executing it every time.  This sounds like a good use for a delegate!

In our CacheHelper class we define the delegate:

 public delegate object RetrieveDelegate();

It’s just a method signature that returns an object.

Then we define another method that will first check the cache, and execute the delegate if the data is not there:

public static T GetAndCache(string key, RetrieveDelegate retrieveObject, TimeSpan span)

{

    if (!ItemExists(key))

    {

        object value = retrieveObject(); //this makes the call to the database

        Insert(key, value, span);

    }

 

    return Retrieve<T>(key);

}

Now we have a method that can be smart about caching, but it is completely agnostic of what data to cache.  Now we can refactor our GetStates() method to this:

public IList<State> GetUsStates()

{

    return CacheHelper.GetAndCache<IList<State>>(

        "US_STATES",

        delegate {

            List<State> states = new List<State>();

            using (IDataReader dr = DataAccess.ExecuteReader("SELECT * FROM US_STATES"))

            {

                State theState = State.Fetch(dr);

                states.Add(theState);

            }

            return states;

        },

        TimeSpan.FromDays(1));

}

We only have to interact with the CacheHelper once, thus we only use the cache key once as well.  There are no if statements here either.  Just a single function call that excepts an anonymous method.

This is pretty clean and it makes caching in your application easier.  What do you think?  Do you have any ideas for improvement?  Let’s hear in the comments!

Tags: ,
Wednesday, August 15, 2007

See you at Houston Tech Fest

If you're going to HoustonTechFest, then be sure to check out my presentations:
  • Advanced CSS and Javascript
  • ORM with NHibernate
It's all going down August 25th at the University of Houston.  See you there!

dasBlog 2.0 Released!

The team has been working like mad to get this release out the door and now it’s ready!

http://dasblog.info/

This is a full ASP.NET 2.0 release!   Along with the new release comes a new look for the dasBlog website (designed by me).

Check out the release notes to see all of the great new features.

Thursday, August 09, 2007

Blue October - August 4th

Me, My wife, and daughter went to go see Blue October play at the Sam Houston Race Park.  It was my 2nd time to see the band (the first being at a venue that only held 300 people).  There were a few thousand people there and it was really great to see how big the band has gotten.

Me and my baby at the Race Track before the concert
Me and my baby

My 2 favorite girls…
IMG_5490

Rocking out before the concert…
IMG_5509

Goofing around…
IMG_5512

No, I’m not stoned in this picture…
My JP Boodhoo Pose

We’re Hungry…
IMG_5554

Finally, they arrive…
IMG_5570

They played mostly songs from their new album, Foiled (which is my least favorite to be honest).  I much prefer The Answers or Consent to Treatment.

IMG_5603

 

Blue October always puts on such a great show.  The band is full of energy and Justin’s vocals seem to never end.  I don’t know how he does it… I was singing along all night and nearly lost my voice.  I guess I can let go of my hopes of being a rock god .  Well, there’s always Guitar Hero.

Wednesday, August 08, 2007

HTML 5 Sneak Peek

Check out the article over at IBM on New Elements in HTML 5.

Everyone who knows me knows that I loathe using tables for layout.  My biggest beef with it (there are many) are that it usually renders an unnecessary amount of markup for simple things.  Good CSS design reduces this drastically but there are occasions when you have a layout that ends up being as bloated as using tables.

If you need to style two sections of divs that have a similar or convoluted hierarchy, you usually have to resort to adding classes.  Classes add to the visual weight of the HTML, so I generally prefer not to use them if I can select the element using CSS.

New tags in HTML 5 will help with this even further.  These are all semantic structural tags that encourage proper design using HTML:

  • section
  • header
  • footer
  • nav
  • article

A <section> element will denote regions of the page that can easily be selected. Who knows, <section> might even replace <div>.

You’ll also notice a trend where tags have no visual representation at all.  They might be styled differently by CSS, but that’s not the point.  a <time> element could be used for programs to easily distinguish the time of a post, or the time that the page was last rendered, for example.

Check out the article, it is worth a read.  These changes are long overdue and will help raise the bar on web standards usage even further.  Let’s just hope IE plays nice this time (I think they will).

Professional Gender Transmogriphier

The other day, my cube-mate Peter Seale, posed the following question:

Do you ever wonder why the Experts Exchange website url has a dash in it?

Well, no I didn't before... but I now I am... why? (at this moment I pause for a second and think about what the url would be... )

expertsexchange dot com

That just might send the wrong message... whaddyathink?

e Goes Gold

My favorite text editor for HTML, CSS, JavaScript, Ruby/Rails, etc development just announced its 1.0 stable release.  The beta versions were very good and I rarely ran into issues.

If you aren’t using e, you should check it out:

e

If you’re like me and jealous of the Mac crowd who gets to use TextMate ( /drool ) then this is the best alternative for Windows.  (I hear there is a Linux version coming soon).

But if you’re not privy to what coolness awaits you, allow me to tantalize you with some e-excellence:

  • Keep looking up the exact doctype syntax?  Type doctype<TAB> and a context menu appears allowing you to select your doctype (XHTML 1.0 Transitional for example).   (And you should be using a doctype header).
  • Type head<TAB>, it creates the header section for you, places the cursor right where you put the title, press <TAB> again and you're ready to enter scripts and style sheets.
  • Want more? Try link, style, body, div, table, ul li ... the list goes on.

These are just the HTML bundles. There are a crap-ton of bundles that already exist for TextMate, and they are supported with e.

So head on over to http://www.e-texteditor.com and pick up a trial copy. If you like it, consider buying it. The time you save will surpass the measly $35 you spent in no time. time.

Tags:
Savings - Loans - Renegade Motorhomes - Secured Loans