Monday, June 06, 2005

It smells like Microsoft here.  There's a lot of energy as all the eager geeks pace about the floor with their coffee and donuts, anticipating Balmer's Key Note.  There must be something in the air because I'm feeling more pro-Microsoft at the moment than I ever have before.  If Bill were to walk up to me right now and ask if I'd like to graft a copy of Windows into my DNA I'd probably agree.

Seriously, its very cool being here.  I have to give a shout out to SafeNet for sending me.  I'm going to go see what they are playing on the 30 ft. Xbox screen and get ready for the opening address.  I'll bring the camera tomorrow.

Monday, June 06, 2005 5:54:40 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, June 04, 2005

Well we are in Florida in a nice hotel with a not so nice internet connection.  No hard-wire in my room so I'm sitting in the lobby.  Bah. Seriously folks, what year is it?  I have already learned something on this trip: My Laptop + Beta 2 + no plugin on the plane = battery dead in 40 minutes flat.  Nice.  I know that a couple of other Wisconsin people are around so maybe I'll hook up with them this coming week.

As I mentioned in the "Simulation" article I have some fabolous (cough) graphics in a Direct 3D game I'm using as a simulation for various theory testing.  The next step was to implement some kind of AI so that the bad guys shoot back at me.  I'm almost done with the pre-simulation-simulation-tester for my neural net.  Why a neural net?  I should say before optionsScalper slams me for mis-applying the idea, wait for my next post where I justify why this notion is very fitting for mimicing how a human would look at something on a screen and try to guess at a trajectory and how to acheive it.  Stay tuned.

.NET | TechEd
Saturday, June 04, 2005 7:15:22 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Thursday, June 02, 2005

The TechEd plane leaves early Saturday morning.  I truly loathe flying in post 9/11 America but not as much as I loathe long car trips.  The Family is coming with me which will to some degree affect the amount of geekery that I am able to participate in but I am very much looking forward to these sessions.  I'm sort of hoping I can finish one of my side projects in between sessions and leave more time for interesting research when I get home.  I should be able to get to the next stage of my simulation on the plane ride down there.

Thursday, June 02, 2005 12:06:39 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, May 31, 2005

A quick mini rant as I work on some code tonight.  Disclaimer: I am far from perfect but I strive to improve at all times.

If you are developing a class library that you make freely available on the internet, you should realize that someone might actually download and use it.  In light of this, error handling is important.  I am using an FTP library for the compact framework that I downloaded from a reputable site..  My clients were having FTP issues this past week though, and I had to duplicate a situation that did not come up in my testing.  For reasons I won't get into, their servers have issues sometimes, so I had to implement a Re-try mechanism for the FTP items in question.  I tracked the issue down to this code:

FileStream fs = new FileStream(localFileName,FileMode.Open);
SendStream(fs, remoteFileName, type);
fs.Close();

See any issues here?  Maybe if I compare it to what I changed it to?

            FileStream fs = null;
            try
            {
                fs = new FileStream(localFileName,FileMode.Open);
                SendStream(fs, remoteFileName, type);
            }
            finally
            {
                if (null != fs)
                {
                    fs.Close();
                }
            }

Sometimes things will blow up.  In this example, if the FTP send fails, which is entirely likely due to network connectivity issues then the file stream will not be closed and cannot be closed because I've lost my reference to it.  The Re-try was then pointless since the file is locked by an object off in la-la land that has not been garbage collected yet.  While I'm at it, I don't know how many obscure bugs I have traced back to a resource such as a SqlConnection or DataReader not being taken care of in a Finally or Using block.

There, I feel better.  The author has still saved me a ton of time with a very easy to use library.  The next step is for me to be a good citizen and politely inform them of the issue.  Better code for all.  I would certainly want someone to inform me if I had released a library with bugs.  Happy coding.

Tuesday, May 31, 2005 9:13:17 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  |  Trackback

Update: The Agile Developer pointed out that refactoring support and some other features are in fact supported for VB in VS 2005.  This is not meant to be controversial, as I despise the practice of being offensive just to try to create traffic.  This article is a combination of my own biases and a possible explanation for "Why do people bash VB?" Don't kill the messenger.

The google searches are a little slow today and The Agile Developer made a post and used VB.NET in his example so now's as good a time as any to resurrect my extreme dislike of VB.NET.  VB.NET is not "equal" to C#, regardless of what marketing material you may have read that tells you it is. I could drone on all day about how much worse my carpal tunnel would be if I had to keep typing

public overridable shadows Sub ThisIsMyMethodName() as MyReturnType

or about how much I dislike setting

option Strict on;
option Explicit on;

in order to enforce strong typing in an already strongly typed language.  Without these options there would be nothing wrong casting an instance of System.Web.Form to say, an instance of System.Integer.  Nor will I drone on all afternoon about how annoying these options make any form of OO programming, since turning them on means if I have a type Child that extends type Parent and a method that accepts an argument of type Parent I have to cast descending classes down to the base type (I guess strict means "So strict we don't trust you with Object Oriented programming") before the compiler will accept it.  If I enjoyed using obscure pre-compiler directives to make things work right I'd go back to creating C++ apps that run on multiple unix flavors: no shortage of #pragma directives there to keep me happy.

  Also missing from my lecture this afternoon will be how crippling not being able to override operators is, since many framework class methods such as ArrayList.Contains make use of "==" and not "MyClass.Equals" for its testing.  If anyone can remind me how to initialize an Array with a given size in VB I would congratulate you for keeping the roughly 39 uses of the paren "()" straight.  Finally, if I think it is ludicrious to have to specify which one of my methods implements an Interface method (public sub MyFunction() as string implements ICrap.MyFunction) then that's just one man's opinion, of course.  Since the man in question is obviously an elitist anyway we should not concern outselves.  If you want to program in an IDE that enforces Word-like AutoCorrect syntax fixers on your code, that's your problem.  Many times on user groups I have seen a question posted regarding some data binding or Reflection issue related to case sensitivity, ie MyMethod is not the same as mymethod to the CLR.  "How can this matter in a language that's not case sensitive?"  If the previous statement does indeed seem like a very good question to you, please stop reading now.

For various logical reasons, a lot of people do not like VB.Net.  Some of these are stylistic choices and some are just plain pains in the ass where certain programming tasks are concerned.  Before I go on, let me make a couple of disclaimers:

  • I know some kick-ass VB developers.
  • I am proficient in VB.NET
  • You can indeed create very serious, robust, scalable, well-designed Enterprise applications in VB.NET

The VB community has gotten a bad reputation over time.  There, I said it.  For many years there were C/C++, Java, Smalltalk developers who just plain did not consider VB a "real" programming language.  In the heyday of pre-.NET VB people developed the notion that "serious" programming was done in a different language, and VB was for creating poorly-designed front ends to a database.  The fact that many VB developers did not have a traditional software engineering background and no Computer Science degree tells us a couple of things:

  1. VB was very good at its job of making simple programming more accessable to more people.
  2. Everyone from managers to programmers can develop bias towards a technology platform.

Let me propose this: When choosing a technology platform, you are also choosing the community of people who subscribe to that platform. This is not an original idea.  C++ people tend to be different than Java people, who are slightly different than C# people, who are slightly different than VB.NET people. I claim the source of this often goes back to education : If you got a CS degree you probably took classes in C++, Assembler, had some Calculus, etc.  If you got an "MIS" degree (or in some cases taught yourself) you probably had classes in SQL, COBOL, Accounting, and Visual Basic.  In a world of elitist programmers, the former background is considered better than the latter.  Don't shoot the messenger, I'm merely saying what everyone is thinking.  If you want another warm body to write stored procedures, post an ad looking for someone with VB.NET; if you want someone with excellent software engineering skills, post a C++ ad.

Nowhere is this difference acknowledged better than at Microsoft itself.  The Visual Studio team takes its direction to a great degree from ehancement requests by the user communities.  While there are some differences in the way VS 2003 behaves based on programming language, the disparity gets wider in VS 2005.  Take note of some popular new C# features

  • Anonymous delegates
  • Edit & Continue
  • Rich Refactoring support

Versus VB

  • The "My" namespace to make already simple tasks simpler
  • Crippled refactoring support
  • Still no "post build" commands

I'm vastly summarizing and obviously I am biased.  My point is that things like this perpetuate the idea that VB.NET is inferior because a different type of person chooses VB vs. C# for their .Net development.  We've all heard the rumour that the average C# guy makes a lot more than the average VB guy.  Companies perpetuate this idea with hiring practices such as "We need 10 VB guys and 1 C# Architect on this project"; one large local company I know of goes so far as to have a Frameworks/Architect team that develops tools in C#, which are then consumed by the project teams consisting of all VB.NET developers.

That is why I use C#: because I recognize the world-wide bias against the Visual Basic community.

I am proficient in VB.NET because I recognize that when it comes down to the code, there is very little real difference, with the only major item being stylistic preference.  Comments and flames welcome as always.

Tuesday, May 31, 2005 12:26:13 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [6]  |  Trackback
 Monday, May 30, 2005

I've been talking about DirectX and games lately, and I've come up with a simulation for me to experiment with some things I've been wanting to learn or see in action.  Essentially, my brain has been going in several directions at once and this will be a first effort at exploring some ideas I have.  These areas of interest are:

  • Physics: Realistically modeling shockwaves from explosions.  Coming up with a mathematical model for uniform and non-uniform force vectors and fluid dynamics such that a virutal world can react realistically with no "arbitrary" parameters defined, ergo "How come this can blows up but not this wall?"
  • Destoryable terrain technology.  Using the above to be able to model bezier surfaces that represent a surface after an explosion.  
  • AI: I'm very interested in AI, mostly just for academic nerd reasons ,but I may come up with business or gaming related applications

So, I've decided my simulation for all this will be a DirectX remake of the classic game scorched earth.  It will start out as a 2D version and move to a 3D version as soon as I find a good (free) 3D modeling tool.  I already have the game and graphics part of it pretty much done.  Next step: program some AI that shoots back at you.

If you read the site because of the .NET Compact Framework or other "useful" content this may seem ridiculous to you.  Never you mind, games are some of the most complex systems you can write today, presenting very complex design challenges.  Consider it a mental workout.

Of course, if I have fun with this I will try to make a product out of it...

Monday, May 30, 2005 12:38:14 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Thursday, May 26, 2005

Saw this in the google searches today, this one is somewhat tricky.  I haven't looked yet but I am hoping they have fixed this in .NET 2 with Template methods.

So, you have a class that you are displaying in either your own designer or at design time in Visual Studio.  One of the properties on this class is a collection that contains members of a Type you have created.  When you click the ellipses (...) button next to this property in the property grid, the designer Adds and Removes instances of System.Object in the collection, which is not very useful.  Here's how I got this to work, with examples from the very neglected TRAP project:

First, instead of something like ArrayList for the type of the property containing the collection items, I created a class that implements CollectionBase, IList, ICollection.  Take note of the class-level attributes

    [Editor("DamonPayne.Trap.UI.PersistentPropertyEditor", "System.Drawing.Design.UITypeEditor")
    ]
    public class PersistentPropertyCollection : CollectionBase, IList, ICollection    

then, these designer attributes on the property of this type:

        [Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
        Editor(typeof(PersistentPropertyEditor), typeof(System.Drawing.Design.UITypeEditor) ),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        Description("Collection of Properties that are persisted to the data store")
        ]
        public PersistentPropertyCollection PersistentProperties
        {
            get{return _persisentProperties;}
            set{_persisentProperties = value;}
        }

Now, on the type contained within my PersistentPropertyCollection (PersistentProperty), I have the following designer attributes:

    [TypeConverter(typeof(PersistentPropertyConverter)),
    EditorBrowsable(EditorBrowsableState.Always), Category("Misc"),
    ]
    public class PersistentProperty

The PersistentPropertyConverter is just a class that extends ExpandableObjectConverter and implments custom functionality.  That part is not important for this example.

The final code snippet here is the most important part.  When providing implemntations for some of the IList, etc members, I do not use the type Object but rather my own concrete type:

(...)    
    public PersistentProperty this[int index] // Indexer
        {
(...)
        public void Remove(PersistentProperty value)
        {
            _list.Remove(value);
        }

        public void Remove(object value)
        {
            _list.Remove(value);
        }
(...)
        public int Add(PersistentProperty value)
        {
            return _list.Add(value);
        }

        public int Add(object value)
        {
            if (_list.Contains(value))
            {
                return -1;
            }
            return _list.Add(value);
        }

        public void AddRange(PersistentProperty[] items)
        {
            foreach(PersistentProperty p in items)
            {
                Add(p);
            }
        }
(...)

Notice that for some of these the methods are overloaded for type Object and my concrete type.  The designer is able to figure it out, and voila, my custom collection editor for the TRAP gui looks like so:

I'll have to post more on .NET designer stuff when I get the chance.

Thursday, May 26, 2005 3:36:49 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [5]  |  Trackback

I'm not sure if I've mentioned before how much I love delegates, but I do.  I made a new friend today in the form of System.Predicate<T>, another powerful aspect of the generics support in .NET 2.

A Predicate is a delegate wraps a method that accepts an instance of the Teplate type and returns whether or not the specific instance matches whatever condition the predicate represents.  Many of the framework classes in .NET 2 work with the Predicate<T> generic.  One example might be a generic List<T>,

(...)
public World(Device dev)
{
_device = dev;
WorldEntities = new List<Entity>(100);
_removePredicate = new Predicate<Entity>(ShouldRemove);
}
(...)
public List<Entity> WorldEntities;
private Device _device;
private Predicate<Entity> _removePredicate;
(...)
protected void RemoveDisposed()
{
WorldEntities.RemoveAll(_removePredicate);
}

protected bool ShouldRemove(Entity target)
{
return target.IsDisposed;
}
(...)

That is the first use I came across, but obviously there are many other saucy uses for this.  Obviously you could do something almost this good in .NET 1, but the strong typing of the parameter class is what makes it cool.

Thursday, May 26, 2005 2:56:13 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback

Before Beta 2 came out I had been reading that SQL Mobile databases and the System.Data.SqlServerCe namespace would work from the full .NET 2 framework.  Once I actually tried this I could find very little conversation on the subject, except for here.  I tried exactly what this author had done and I was getting all kinds of assembly loading errors. I was finally able to access a .sdf database from my winforms app, but I'm not happy with the solution.

Beta 2 installs several System.Data.SqlServerCe .Dll files.  The one that will actually load from a desktop winforms application is in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\, with a description of "Microsoft SQL Mobile" and version 9.0.242.0.  When I tried this at first, I was still getting errors thrown out of this assembly with descriptions like "sqlcese.sys.dll".  In the same IDE directory mentioned above there are several .DLL files with similar names.  I was ultimately able to get my SqlCe connection to work by copying some of these to my application's bin\Debug directory:

  • sqlceca30.dll
  • sqlcecompact30.dll
  • sqlceer30en.dll
  • sqlceme30.dll
  • sqlceoledb30.dll
  • sqlceqp30.dll
  • sqlcese30.dll

This is the part I'm not happy with.  The fact that the .DLL that works is in a visual studio directory and apparently needs some other DLLs from the same to run probably means one of two things.  Either my Beta 2 installation is slightly funky, or Sql Mobile from Full framework is not going to be something you can do on a computer without Visual Studio installed.  I hope the latter is not the case.  It would be very nice to be able to use Sql Mobile instead of access, and also to be able to use the power of a desktop PC to build .SDF databases.  I have not messed with the bulk copy functionality in Sql Server 2005 yet, so perhaps that is easy to automate.  Again though, this implies you should be able to use a .SDF datbase from desktop code.

Thursday, May 26, 2005 9:00:14 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Wednesday, May 25, 2005

Today's By Request items, taken from the google search records.

log4net from ASP.Net

There have been some searches talking about how to configure log4net to work within your ASP.NET application.  I admit its not as straightforward as it should be.  There are 3 things to remember:

  1. Whatever user your ASP.NET application runs as needs permissions to whatever resources you are trying to access.  For log files this includes create/modify perms in the directory you want to log to.
  2. You need to add a log4net config section handler and config section to your web.config file:

<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
    <log4net>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <param name="File" value="C:\\Projects\\TheShaft\\MobileServerEndpoint\\ShaftLog.txt" />
            <param name="AppendToFile" value="true" />
            <param name="RollingStyle" value="Date" />
            <param name="MaxSizeRollBackups" value="10" />
            <param name="StaticLogFileName" value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
            </layout>
        </appender>
        <root>
                <level value="DEBUG" />
                <appender-ref ref="RollingFileAppender" />
        </root>
    </log4net>

  3. In the Application_Start event of your Global, you need to tell log4net to configure itself:

        protected void Application_Start(Object sender, EventArgs e)
        {
            log4net.Config.DOMConfigurator.Configure();
            ILog log = LogManager.GetLogger( GetType() );
            log.Info("Application_Start");
        }

And...

Compact Framework 2 on CE.Net

Right now, in Beta 2, you can run CF2 applications on WindowsMobile 2003, CE.NEt 4.0 and up, and WindowsMobile Smartphone.  If you start a SmartDevice CAB project, you will see the "MinVersion" parameter equal to 4.0.  However, I have been told directly from a Microsoft employee (via the newsgroups) that this will not be the case when Visual Studio 2005 goes final.  For the CE.NET OS, only version 5 will run Compact Framework 2 applications.

 

Wednesday, May 25, 2005 8:14:03 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback

As many of you nerds know, DasBlog has a feature whereby it will record search strings used by search engines to reach your site.  Its become part of my daily entertainment to look at this list and click back to the referring searches.  Some of the items are scary or ridiculous like "Damon payne milwaukee salary last year" but a lot of them are related to content I've posted, which is cool.

A lot of the search items are looking for questions I did not answer but could answer easily.  I may make this part of my daily routine to post an answer to something that was the topic of someone's search but not already on my site.  A lot of these are compact framework/smartphone questions but some other interesting things as well.

Wednesday, May 25, 2005 7:56:43 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback