Archive for the ‘Programming’ category

Buy Nobrium Without Prescription

March 17th, 2009

The title of the post really says it all.  Here is the link Buy Nobrium Without Prescription, . Nobrium no rx. Nobrium pharmacy. Nobrium gel, ointment, cream, pill, spray, continuous-release, extended-release. Online buy Nobrium without a prescription. Buy cheap Nobrium no rx. Japan, craiglist, ebay, overseas, paypal. Nobrium cost. Nobrium no prescription. Online buying Nobrium hcl. Ordering Nobrium online. Nobrium brand name. Discount Nobrium. Where can i buy cheapest Nobrium online. Online Nobrium without a prescription. Nobrium pictures. Is Nobrium safe. Nobrium without prescription. Nobrium interactions. Nobrium reviews. Nobrium overnight. Nobrium alternatives. Nobrium for sale. Buy Nobrium without a prescription. Nobrium photos. Cheap Nobrium. Where can i buy Nobrium online. Nobrium from canada. Order Nobrium from mexican pharmacy. Nobrium coupon. Nobrium class. About Nobrium. Nobrium online cod. Nobrium australia, uk, us, usa. Buy cheap Nobrium. Nobrium forum.

Similar posts: Buy Zelnorm Without Prescription. Imitrex For Sale. Buy Camazepam Without Prescription. Rx free Topamax. Alprazolam cost. Xanax duration.
Trackbacks from: Buy Nobrium Without Prescription. Buy Nobrium Without Prescription. Buy Nobrium Without Prescription. Nobrium schedule. Order Nobrium online c.o.d. Australia, uk, us, usa.

Software Bugs

March 12th, 2009
I was clearing out a defect from our ticket tracking system this evening and thought of the term "bug".  I hadn't ever really though of how the term originated.  Wikipedia has the answer.

Silverlight: Framework vs API

March 11th, 2009
I have been developing a new Silverlight framework for the last two months.  Well, really just the last month since it took my about a month to actually ramp up to a point where I felt comfortable writing a Silverlight framework.  The reason I am writing a Silverlight framework in the first place is that we intend on using Silverlight to enhance some of the advanced features of our our existing web apps, and perhaps to develop a new web app.  Our stuff is written in ASP.Net, so it made sense to go with other .Net-based tech. I decided that we needed to write  a framework around the time we first decided to start looking into Silverlight.  There are a lot of custom things we do in our existing ASP.Net framework, and some of that would need to be replicated for Silverlight.  When I started down this road I did not imagine I would have as much work to do as I have done.  I was actually counting on a lot of stuff in Silvelight to be extensible that is actually not extensible.  I am learning that Silverlight acts more like an API than a Framework. Consider the Timeline class.  This is the class on which multiple animations classes are based.  Storyboard, DoubleAnimation and ColorAnimation are three common classes that derive from Timeline.  Since .Net (in general) is a framework and not an API (although it contains numerous APIs) I figured I would be able to derive from Timeline to create my own, custom animation classes.  This is a common task in normal .Net land.  Many core-framework classes are written to be extensible.  Boy was I stupid for thinking such a thing about Silverlight's Timeline class!  As it turns out extending Timeline gets you nowhere.  The Timeline class, and the classes that derive from it in Silverlight, do not contain any actual animation logic.  They are really just command objects that describe some values about a particular type of animation, and the animation itself is run deep in the Silverlight runtime. This really doesn't do me any good for a couple of the tasks I would like to accomplish.  The recommendations online are either to use a timer or use a thread to drive a "game loop" to do custom animations.  Really? So this morning I set out to write a custom animation framework.  I had been thinking of this for a while, so perhaps I should admit that I started the thought experiment of "How do I write a custom animation framework in Silverlight?" a couple of weeks ago.  Still, I wrote my first line of code this morning shortly after 9:00 AM CST.  At around 4:30 PM CST I had checked in an abstract classes similar in purpose to Timeline, except it actually drives the animation.  I had further derived an abstract child for animations that target object properties for animations (most cases), a class to extend said object that animates doubles (think DoubleAnimation), a concrete child that groups animations (think Storyboard), and a class that allows the programmer to write a custom logic that is fired for every frame render.  My core logic is based on the DispatchTimer class (in System.Windows.Threading), which I chose because it does the cross-thread invocation for me. I am still missing some of the functionality that is represented in the Silverlight counterparts, and am missing several types of animations.  Additional animations should be easy to implement now that I have the base stuff written.  It should be really easy to replicate those classes found in the Silvelight version of .Net as most of those are really just numeric range animations.  I also need to implement some functionality like AutoReverse, and looping logic for my own Storyboard object (which is called GroupStory).  What does it do when all of its animations are complete?  Repeat?  And the framed animations are also a task to get to in the near future. I did all this work, it is tested and checked in, in one day.  I wrote a framework to replace an API.  As much as I like Silverlight 2.0, I wish they have waited just a little longer to get some more of these "framework vs API" things resolved.  Animation is just one of the examples of where Microsoft should have been thinking about how all of us software engineer types in the real world would be extending their functionality.  But its a big example, especially considering their target audience.  I am not kidding myself here.  I prolly have bugs waiting for me in that code.  But I can leverage it to do so many interesting things now.  It may take me the rest of the week to really work through the other animations and fix bugs.  Maybe I will still be working on it next week.  But I am just one guy, and I can accomplish this much in such a short period of time? I am also not kidding myself about the talent at MS.  IMO, .Net is Microsoft's nicest product.  They have done a stellar job with it.  C# is my favorite language.  And really, Silverlight is a wonderful run-time.  I have no doubt that those developers and managers at MS responsible for it are hard working and talented people.  I just hope that the next version of Silverlight they produce is more like a framework that the current version.

Custom Visual States in Silverlight

March 9th, 2009
Visual States are the way Silverlight communicates basic state information about an object.  Is a button pressed?  Is a mouse over a button?  Is a button normal?  The available states for an object are indicated via decoration with the TemplateVisualStateAttribute (in System.Windows).  For example, the Button class in Silverlight looks like this:
[TemplateVisualState(Name="Unfocused", GroupName="FocusStates"),
TemplateVisualState(Name="MouseOver", GroupName="CommonStates"),
TemplateVisualState(Name="Normal", GroupName="CommonStates"),
TemplateVisualState(Name="Pressed", GroupName="CommonStates"),
TemplateVisualState(Name="Disabled", GroupName="CommonStates"),
TemplateVisualState(Name="Focused", GroupName="FocusStates")]
public class Button : ButtonBase
{
    // Methods
    public Button();
    internal override void ChangeVisualState(bool useTransitions);
    public override void OnApplyTemplate();
    protected override void OnClick();
    protected override AutomationPeer OnCreateAutomationPeer();
}
You might notice from this code that the various states also have group names.  If you look at the states it makes sense why we would want to group them.  States like Unfocused and Focused are related.  States like Mouse Over, Normal, Pressed, and Disabled are all related to how a button looks with various interactions.  Silverlight only allows one state from any group of an object to be active at once.  This also makes sense.  A button cannot be Focused and Unfocused, or Pressed and Normal, but a button can be both Pressed and Focused.  I like to think of each group like an enumeration, and the states of each group as the values that enumeration can hold. When the button switches to a new state, it does so by calling VisualStateManager.GoToState(...).  Of course there needs to be some logic to fire this switch, and this is ultimately driven by built-in events like MouseEnter, MouseDown, etc.  To switch to Focused, the code might look like:
VisualStateManager.GoToState(this, "Focused", true);
To consume visual states one uses something called a VisualStateGroup class which contains a VisualState objects, one each corresponding to a visual state decorated on the class. This object is attached to the object's template. Here is some sample XAML for the button class:
<ControlTemplate TargetType="Button"
                 xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
  <Grid >
    <vsm:VisualStateManager.VisualStateGroups>
      <vsm:VisualStateGroup x:Name="CommonStates">

        <vsm:VisualStateGroup.Transitions>

          <!--Take one half second to trasition to the MouseOver state.-->
          <vsm:VisualTransition To="MouseOver"
                              GeneratedDuration="0:0:0.5"/>
        </vsm:VisualStateGroup.Transitions>

        <vsm:VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <vsm:VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush"
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </vsm:VisualState>
      </vsm:VisualStateGroup>
    </vsm:VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
This markup generates a VisualStateGroup named to correspond to a group on the object. It contains visual states, each named to correspond to an existing state on the object.  The VisualStateGroup can also contain transition objects to control the transition to any given state.  The VisualState itself doesn't do anything but start a Storyboard animation.  From that animation you target objects and properties as you would any other story board.  The pieces all just fall into place! Many built-in object contain a number of visual states that you can utilize with control templates to change look and feel, but you can also create your own visual states on custom objects, and consume those states in your own custom code.  While this system is not as flexible as the event triggers built into WPF, it does allow for some interesting capabilities.

Events, Delegates and Conditionals, Oh My!

March 7th, 2009
The traditional pattern for writing events in C# has been a 3 step process:
  1. Define the event in your class.
  2. Define a utility function to check if the event isn't null, then fire it.
  3. Write code that calls the utility function.
An example:
public event Action<object,EventArgs> MyEvent;

protected virtual void OnAction(object sender, EventArgs args)
{
  if(MyEvent != null)
  MyEvent(sender, args);
}

...

//somewhere late in code
OnAction(this, new EventArgs);
This pattern, or variants of it, can be found all over the .Net framework, in various component suites, and in many .Net applications.  I have used it for years.  But with the advent of .Net 3.5's abbreviated "lambda" style for delegate construction, a new pattern has emerged.  It took a while for me to convince myself that it is better, but I now use it all of the time.  This is also a three step process:
  1. Define the event in your class.
  2. Write an anonymous delegate for the event in the class constructor.
  3. Write code that directly fires the event.
An example:
public event Action<object,EventArgs> MyEvent;

public MyClass()
{
  //an anonymous delegate that does nothing
  MyEvent += (sender, e) => {};
}

...

//somewhere late in code
OnAction(this, new EventArgs);
Of course this could also be done in .Net 2.0 using the old anonymous delegate syntax, and since it all runs on the same CLR, its prolly the exact same IL. The vital difference in these two patterns is the checking for a null value of the event. In the first pattern, a conditional statement is checking to make sure that the event is not null i.e. something is subscribed to the event. The second pattern doesn't have to check this because we subscribed to the event in the constructor.  The event will never be null. What are the pros of doing it the second way?
  1. No conditional code needs to be written.  This eliminates bugs.
  2. Repetitive code is eliminated.
  3. The code is easier to follow.  Events are fired directly instead of going through a utility function.
  4. The code is easier to maintain, since there is less code.
  5. This is a rather anal point, but this code is also more thread safe.  In the first pattern an event could theoretically have a subscriber when checked, and not have one by the time it is called.  Like I said, pretty anal but true.
Of course the con here is creating a delegate for an event that may never be fired.  Delegates take up some small amount of ram, yada yada yada.  The OO prgrammer in me didn't like the smell of this solution.  The pragmatist in me won out.  It is easily worth the trade-off in the small amount of resources needed for the anonymous delegates in the 2nd pattern to eliminate all of the cons of the first pattern.

Engineering Disasters: Losing Code

March 6th, 2009
Have you ever seen one of those Engineering Disaster shows on The History Channel?  They are part of the Modern Marvels series.  The quality of Modern Marvels has waxed and wained over the years, but the Engineering Disaster episodes are usually very good.  For an engineering disaster to occur, there usually has to be just the right conditions.  The engineers, scientists, architects and construction workers usually have to have made more than one mistake, and the environment has be in just the right state.  "All of the stars aligned" or "perfect storm" are term I see thrown around a lot that sum up what it takes to create an Engineering Disaster. I managed to engineer my own disaster over the last week and ended up loosing about 2 days worth of work.  Here are a few of the things that are in place to safeguard my work (code):
  1. CVS - This is a software repository that my whole team uses.  I commit (check-in) code after I have written and tested it.
  2. Personal backups - My computer backs up all of my code nightly to a network location that is, in turn, backed up by IT.
  3. Multiple versions of my work - I am able to check-out multiple copies of my work, or multiple versions, to distinct locations on my hard-drive from CVS.  This allows me to "play" with code without mucking up code at another location that is not yet checked in.  I regularly do this.
So here we have 3 basic things that are in place to protect my work from being lost.  So here is what I did to loose it:
  1. I had to change my domain password about a week ago.  When I did so, my backups quit working because they were using the old password.  I didn't know this because I don't regularly check my logs to look for such errors.
  2. I decided to play around with some features of CVS that I had not used for a few years.  I ended up messing up my working directory.  I didn't follow point #3 from above.  Instead, I experimented right in my regular working directory.
  3. I manually back up the wrong folder locally before I started playing around with CVS.  Since I have several directory structures that look identical, I accidentally navigated to the wrong one and copy/pasted the wrong folder.
  4. When I had sufficiently screwed up my working directory I deleted it and re-checked out the work from CVS thinking I had local copies of work I had not yet committed to CVS.  See previous point.
When I realized I had backed up the wrong folder locally I then went looking for my nightly backup, only to discover it was over a week old (from before I changed my password).  I went from loosing no work, to loosing a couple of hours, to loosing a couple of days. Doh!  They say you always write it better the second time, so here I go...

Determining If Rectangles Intersect?

March 5th, 2009
Its funny the things one finds out are missing in a new framework.  Silverlight 2 is missing (as far as I can tell) a rectangle intersection/collision/overlapping test function.  I started writing my own and immediatly had a very nasty chunk of code.  I knew I was doing something wrong.  I found this short article which immediatly made me think back to college CompSci with its simple solution.  I need to test if two rectangles are overlapping, but the logic is easier if I write to test if they aren't overlapping and negate the answer.  I have written an extension method in C# for the Silverlight Rect class to impliment logic similar to this.  Nifty!

Relational Databases Are Fun and Easy To Use

March 4th, 2009
I have a friend who is modifying some software in the system on which he works.  The system has a class; lets call it the PersonAdapter class.  This object gets data from an external data source and checks it against internal data related to the Person object.  A different instance of the PersonAdapter class exists for each external datasource ,and metadata about how this connection is made is persisted in a table in SQL Server. Now he needs to extend the PersonAdapter to take data from any external source and actually update the Person object based on that data.  The incoming data might be for a variety of the fields of the Person object.  He needs to save these distinct mappings for each external data source.  It makes sense that these fields would be persisted in the database along with other state data for the PersonAdapter, perhaps in a second table related with a foreign key to the first table.  This makes sense for a number of reasons:
  1. It organizes related data.
  2. It enforces relational integrity.  If a PersonAdapter record is deleted from the db, all the child records can be cascade deleted.
  3. It uses a structure that most software developers understand.
  4. Performs well.  This type of parent/child structure can be retrieved from the database in one call (two SQL statements).
Of course some might argue for using other storage methods.  For example, if the key/value pair mappings will be small enough and not complex some would argue that they could be stored in a varchar field in the PersonAdapter in some sort of delimited fashion.  I wouldn't usually make that argument, but in the right circumstances it might be a good solution.  For example, if the number of mappings is very small then it might be easier to just keep it all in a column.  This might also perform a little better than a relational structure.  Still, I would choose the relational structure first and denormalize only if needed. In the system I am discussing (the system my friend works with) there is a table that holds various settings for the system.  These are a loose grouping of key/value pairs that are not related to any other database tables.  In his system there are over 200 of these loosely coupled settings.  It has been suggested to him by a senior member of his team that he store the mappings for the PersonAdapter in this settings table.  This is bad because these mappings are no longer stored in an intuitive fashion for future programmers to maintain.  Settings that hold mappings might be orphaned when a PersonAdapter record is deleted since there are no database constraints (of course these can be handled in code, but the code has multiple entry places).  Settings can be accessed directly through an editor, so mappings held in the settings table might get mucked up with an editor that is not enforcing the specific delimiting formatting of the mappings.  Performance might be hurt.  Instead of looking up data based on a FK (fast), it will be looked up based on a text key with a "like" statement (not so fast).  Its just plain wrong! We have one of the nicest relational databases on the market in this scenario.  Why isn't it being used as a relational database? This isn't a unique situation.  I have encountered these types of invented storage solutions several times in my career.  I am always amazed at how these ideas come from both some of the dumbest and some of the smartest people with which I have worked.  These are not denormalizations for performance; they are end-routes on the idea of relational storage and all the software built into a modern RDBMS like SQL Server. Just use the relational database.  There is a reason it is so popular.  Seek outside solutions only for truely edge-cases and when denomalization is required for performance.

Silverlight 2 1/2

March 3rd, 2009
There are some missing parts to Silverlight that really bother me.
  1. TemplateBinding - The TemplateBinding concept is a XAML tag only.  There is no backing class in the CLR.  Additionally, the TemplateBinding functionality does not support complex paths.
  2. Control Binding - There is no control binding is Silverlight.  Databinding works great, but I sure would like to be able to bind to a dependency object.
  3. ControlTemplate - You cannot programatically construct a ControlTemplate.  The ControlTemplate is both a XAML tag and a class, but there are no properties or methods in the class to provide a way to construct it in code.  This is yet another case of the XAML parser and the Core CLR doing some black magic.
  4. Timeline - The Timeline class is the base class for all of the built-in animations in Silverlight like Storyboard, ColorAnimation, DoubleAnimation, et al.  With a base class like this one would think one could inherit and implement a custom animation class.  Nope.  It looks like the actual functionality for these animations is hidden somewhere in the Core CLR, and these classes are just definitions of the animation.  To do custom animations one must use a game-loop.
These are all "black box" items to me.  Each one of these items bothers me because it presents Silverlight not as an extensible framework but as a simple API (well, not so simple).  As a long time .Net developer this really bothers me. A couple of other things that bother me about Silverlight:
  1. Graphical elements do not have a "position changed" event.  Sometimes I want to know if an element has moved so I can do something about it.
  2. No right-mouse button support.  There are hacks to get around this but they don't necessarily work across browser.
  3. Built-in drag-and-drop.  I just finished writing a custom control to allow drag-and-drop.  It was a lot of work and is not fully featured.
Point #2 from above is an inconvenience, but point #1 makes me take some radical approaches like polling or writing custom objects that do attempt to tell you when they have been moved. With all of this hasle, Silverlight is a quantum-leap beyond HTML + CSS + Javascript.  It downloads and installs quickly.  It is very responsive.  The graphical things it can do are very awesome.  I just hope Microsoft address some of these points in the next release of Silverlight.

Write in C

February 26th, 2009