Programming, Policitcs, and uhhh Pineapples.
# Wednesday, May 27, 2009

Random DevTools Entry #017

Wednesday, May 27, 2009 10:27:01 PM UTC

In software development, it's incredibly useful to be able to visualize your code interactions using sequence diagrams and data flow diagrams and what not.  Not only is the visualization a plus, the act of generating one helps tremendously in terms of working out the outline of the logic that you need to implement.  One of the biggest problems I've come across in this area are the tools: they're simply too heavy and too complex for general diagram drawing tasks in addition to being generally rigid as well.

Today, as I was about to download and install Visio, I decided to spend a few minutes checking to see if there was a web alternative.  Enter websequencediagrams.  This is an all around awesome little tool to add to your toolbox.  Not only is it free (free is always awesome), it's text based.  At first blush, this seems terrible; there's a whole syntax to learn and lots of typing.  But the syntax is incredibly easy and simple while powerful and easy to understand.

Here's an example (I've bolded the syntax to make it easier to distinguish):

Browser->App: HandleSearchClickEvent()
App->Service: ExecuteSearch(keyword)
activate Service
Service-->App: (return results)
deactivate Service
App->App: RenderResults(reseults)
note right of App:
    render URL with
    keyword in query string.
end note
App-->Browser: HTML
Browser-->Office: click:
http://../name.docx?term=keyword
Office->AddIn: ThisAddIn_Startup()
AddIn->AddIn: Check for search term
note left of AddIn:
    ActiveDocument.FullName will
    contain the query string.  This
    can be extracted with a regular
    expression
end note
AddIn->AddIn: Execute find

And here is the result:

There are also a variety of pre-defined styles you can choose to render your diagram.  It's all sorts of awesome and a real time-saver compared to traditional tools.  I personally love that it's text based; I've found that when working with Visio (and other such tools), more than half of my time is spent arranging things just to get them to line up.  A text based approach works well for sequence diagrams and gets rid of that layer of unnecessary complexity.

# Friday, April 17, 2009

WCF Load Balancing : An End To End Example For NetTcpBinding

Friday, April 17, 2009 6:17:08 PM UTC

Recently, I worked on prototyping WCF load balancing for our product, FirstPoint.  I built a simple example to test the configuration and behavior of load balancing.  Since there aren't many end-to-end examples of WCF load balancing on the web, I'm hoping this will be useful (since the Microsoft documentation on this is basically non-existent...well, for NetTcpBindings at least).

I will assume that you are already familiar with network load balancing and configuring the NLB on Windows Server 2003.

Here's a screenshot of how I've configured my network load balancer:

You'll notice that I've configured a specific port range for my service.  Also, take note of the cluster address: 192.168.1.220.  The two servers that make up the cluster are FPDEV1 (192.168.1.222) and FPDEV2 (192.168.1.223).

I've defined a simple service interface which simply echoes the message with a server name:

using System.ServiceModel;

namespace WcfLoadBalancingSample.Server.Contracts {
    /// <summary>
    /// A simple service contract definition which defines an echo operation.
    /// </summary>
    [ServiceContract(SessionMode = SessionMode.Allowed)]
    public interface IEchoService {

        /// <summary>
        /// Echoes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The input message with a server identifier attached.</returns>
        [OperationContract]
        string Echo(string message);
    }
}

And here is the implementation:

using System;
using WcfLoadBalancingSample.Server.Contracts;

namespace WcfLoadBalancingSample.Server.Services {
    /// <summary>
    /// Implements the <c>IEchoService</c>.
    /// </summary>
    public class EchoService : IEchoService {
        #region IEchoService Members

        /// <summary>
        /// Echoes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>
        /// The input message with a server identifier attached.
        /// </returns>
        public string Echo(string message) {
            return string.Format("[{0}] {1}", Environment.MachineName, message);
        }

        #endregion
    }
}  

As you can see, I've simply prepended the machine name to each response so that we can track which server we are connecting to. Here is the main program which hosts the service:

using System;
using System.ServiceModel;
using WcfLoadBalancingSample.Server.Services;

namespace WcfLoadBalancingSample.Server {
    internal class Program {
        private static void Main(string[] args) {
            var program = new Program();
            program.Run();
        }

        public void Run() {           
            ServiceHost serviceHost = null;

            try {
                serviceHost = new ServiceHost(typeof (EchoService));
                serviceHost.Open();

                Console.Out.WriteLine("Service ready.");
                Console.Out.WriteLine("Press any key to terminate.");
                Console.Out.WriteLine("============================");
                Console.ReadKey();
            }
            catch (Exception exception) {
                Console.Out.WriteLine(exception);
                Console.ReadKey();
            }
            finally {
                if (serviceHost != null) {
                    serviceHost.Abort();
                }
            }
        }
    }
}  

This should be deployed on your each of your two (or more) servers in your cluster.  The magic comes next in the configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="WcfLoadBalancingSample.Server.Services.EchoService"
                     behaviorConfiguration="WcfLoadBalancingSample.Server.Services.EchoServiceBehavior">
                <!-- Service Endpoints -->
                <!--///
                    The configured endpoint address is the IP address of the load balanced
                    cluster.  The port number has been mapped to the cluster.
                ///-->
                <endpoint
                    address ="net.tcp://192.168.1.220:12345/lb/EchoService"
                    binding="customBinding"
                    bindingConfiguration="DefaultCustomBinding"
                    contract="WcfLoadBalancingSample.Server.Contracts.IEchoService">
                </endpoint>
            </service>
        </services>
        <bindings>
            <!--///
                A simple custom binding.  Note the leaseTimeout setting.
                This is referenced in the SDK documentation, but not described
                in any way as to how you're supposed to configure it.
            ///-->
            <customBinding>
                <binding name="DefaultCustomBinding">
                    <windowsStreamSecurity protectionLevel="None"/>
                    <binaryMessageEncoding/>
                    <tcpTransport>
                        <connectionPoolSettings leaseTimeout="00:00:01"/>
                    </tcpTransport>
                </binding>
            </customBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="WcfLoadBalancingSample.Server.Services.EchoServiceBehavior">
                    <serviceMetadata httpGetEnabled="True"
                                     httpGetUrl="http://192.168.1.220/lb/EchoService/MEX"/>
                    <serviceDebug includeExceptionDetailInFaults="True" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

The most important part of this configuration file is the setting for the lease timeout. The SDK documentation references this setting, but does not go into detail on how it's configured.  Note that it seems that you can only set the least timeout value in configuration using a custom binding.

There is one particularly important thing to note here: I've set the timeout to 1 second for demonstration purposes only.  The SDK documentation mentions that this value should be set to 30 seconds.  As we'll see later, I have the client creating a new connection every 2.5 seconds (on purpose so we can test connectivity).  What I found was that with the default setting (5 minutes, according to the SDK), if you initially connect to server A and server A goes down, it will not automatically connect to server B.  I assume this is because of the lease timeout value (it throws an exception).

Also note that the endpoint is configured using the IP address of the node balancing cluster and not the individual servers.

The client side of it is pretty straight forward as well:

using System;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using WcfLoadBalancingSample.Client.LoadBalancedService;

namespace WcfLoadBalancingSample.Client {
    public delegate void EchoDelegate();

    public class EchoEventArgs : EventArgs {
        public EchoEventArgs(string message) {
            Message = message;
        }

        public string Message { get; set; }
    }

    internal class Program {
        private static void Main(string[] args) {
            var program = new Program();
            program.Run();
        }

        public void Run() {
            // Start the server.
            Console.Out.WriteLine("Starting client...(press any key to exit)");

            // Start second thread to ping the server.
            EchoDelegate echoDelegate = EchoAsync;
            echoDelegate.BeginInvoke(EchoAsycCompleted, null);

            Console.Read();
        }
        
        /// <summary>
        /// Asynchronous execution of the call to the server.
        /// </summary>
        private void EchoAsync() {
            try {
                int count = 0;
                while (true) {
                    using (var serviceClient = new EchoServiceClient()) {
                        // Call the echo service.
                        string result = serviceClient.Echo(
                            count.ToString());

                        Console.Out.WriteLine(result);

                        count++;                        
                    }

                    Thread.Sleep(2500);
                }
            }
            catch (Exception exception) {
                Console.Out.WriteLine(exception);
            }
        }

        /// <summary>
        /// Handles the completion of the thread.
        /// </summary>
        /// <param name="result">The result.</param>
        private void EchoAsycCompleted(IAsyncResult result) {
            var r = (AsyncResult) result;
            var e = (EchoDelegate) r.AsyncDelegate;

            e.EndInvoke(r);
        }
    }
}

The only thing to note is that I used a delegate to spin off a second thread to make the call to the server.  Adding a reference to the server generates the following configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="CustomBinding_IEchoService">
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" 
                                   protectionLevel="None" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint 
                address="net.tcp://192.168.1.220:12345/lb/EchoService"
                binding="netTcpBinding" 
                bindingConfiguration="CustomBinding_IEchoService"
                contract="LoadBalancedService.IEchoService" 
                name="CustomBinding_IEchoService">
                <identity>
                    <userPrincipalName value="Administrator@fpdev.com" />
                    <servicePrincipalName value="" />
                    <dns value="192.168.1.220" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

Note that on this side, the binding is generated as a netTcpBinding.

And that's it!  Deploy the service to your clustered servers and start the services and then start the client.  If your cluster has a bias towards one server, you will see that the messages will come from that server.  To test that it actually is load balancing, simply stop the service on that server and you should see that the output will be coming from the other server.  Here's an example:

You can see that after I stop the service on FPDEV1 at the third echo message, it flips over to FPDEV2!  Awesome!

Here's the full project (VS2008): WcfLoadBalancingSample.zip (16.89 KB)

Obama Says No To The Assault Weapons Ban

Friday, April 17, 2009 1:04:57 AM UTC

So can we stop the bitter tears for a bit?  Just a little?

http://www.msnbc.msn.com/id/30232095

U.S. president signals he won't seek reinstatement of assault weapons ban

MEXICO CITY - Acknowledging a Mexican drug war that is "sowing chaos in our communities," President Barack Obama signaled Thursday he will not seek the reinstatement of a U.S. assault weapons ban but instead step up enforcement of existing laws against taking such weapons across the border.
Despite a campaign promise to see the lapsed ban renewed, Obama was bowing to the reality that to do so would be unpopular in politically key U.S. states and among Republicans as well as some conservative Democrats.

# Thursday, April 16, 2009

CharlieDigital's Guide to "Teabaggin"

Thursday, April 16, 2009 1:00:49 PM UTC

This recent phenomenon of "teabaggin" (lol) amongst conservatives has been humorous on many fronts.  But it's gotten me thinking: are there people really this stupid?  I mean, that's a lot of stupid.  Some of the signs I've seen are pretty creative (creatively wrong).  Let's address some of them and see what we come up with.

I find this one quite humorous myself, as it shows: 1) a total lack of perspective and 2) it's amazing how easily you can get someone to protest against their own self interest.  If this protester didn't know, the highest marginal tax bracket under Reagan was 50%. Then clearly, Ronald Reagan meant 50% slavery right?  So 39% slavery should be an improvement.  Aside from that, what in the right mind of Vishnu are these people thinking?  Do they have any clue on what slavery was really like?  I mean, wow, get some perspective.  On the second point, Obama has already enacted a tax cut (look at your paycheck and you should see it) for 95% of Americans.  Who are the poor, unlucky 5% that have been excluded?  I'm pretty sure its not this guy holding the sign; instead, they're folks making well into 6 figure territory.

There is great amusement to be found in this picture as well.  "ZERO TAXES"?  I wonder how this old lady thinks the roads she is sitting next to were built?  How were the side walks built?  Who paid for those signals?  Who paid for that sign?  I shudder at the thought of living in a country with zero taxes.  Why?  Because it would be a shithole for all but the super wealthy.  Education and literacy rates would drop dramatically.  Commerce would slowly wither as roads and infrastructure weathered and fell into disrepair.  The old would flood homeless shelters and emergency rooms.  Crime would increase as there would be no publicly funded police...only privately funded militia (no better than paying protection to the mafia).  Zero taxes?  Why not relocate to Somalia instead.

Taxation is a necessary price to pay for living under the protection of the federal government.  It is a necessary price to pay for the services and infrastructure which service us all and enable commerce.  It funds education and improves the quality of life of all Americans (after all, the more children we educate and transform into productive members of society, the better off we are tomorrow).  Paul Begala gets it right:

Happy Patriots' Day. April 15 is the one day a year when our country asks something of us -- or at least the vast majority of us.

For those who wear a military uniform, those who serve the rest of us as policemen and firefighters and teachers and other public servants, every day is patriots' day. They work hard for our country; many risk their lives -- and some lose their lives.

But for the rest of us, the civilian majority, our government asks very little. Except for April 15. On this day, our government asks that we pay our fair share of taxes to keep our beloved country strong and safe.

He's right: aside from paying my taxes, the government does ask very little of me.  I'm neither forced to serve in our armed forces, forced to do any work on behalf of the government, nor am I oppressed.  In exchange for 20% of my income (my effective federal tax rate this year), I get to live in a relatively stable and safe society with some of the greatest degrees of freedoms of any first world country.

Of course, let's not forget that silly lady on the left either.  Excuse me miss, but you can't have defense without taxes (lol).

This one is great, too.  On the contrary, Obama's whole platform is aimed a middle class gains.  His tax policy, cuts for middle class Americans while reverting to the top marginal tax rate under Clinton (bear in mind, this is still lower than the top marginal tax rate under Reagan), seems like it's designed specifically to help working, white collar, middle class Americans.  So either this guy makes more than $200,000 or he's just stupid.  I think it's the latter.

lol. Where do I begin with this one?  I mean, what does Christianity have anything to do with this at all?  First of all, we're not a Christian nation.  Second of all, I love the guy's shirt: "Stupidity Offsets for Sale".  I think he needs to buy crate loads of them.

lol.  Still on this ACORN thing?

This one is particularly funny as Wall Street is the epitome of unfettered capitalism. Somehow, our government has been hijacked by both capitalists and socialists...AT THE SAME TIME! Amusing.

Oh, and apparently facists, too. (I rather think that this quote applies more to these teabaggin' protestors than it does to the rest of the public.)  Also: quoting Hitler on your t-shirt?  Always classy.

This one is ironic because this person has conveniently forgotten that we had this thing called an "election" on November 4, 2008.  Yeah, you know, this thing where millions of people from all across the country come out and select the people whom they choose to represent their interests.  Oh yeah, that's right, your guy lost...silly me.

But more importantly, this sign is patently ridiculous simply because it ignores the reality of how government works.  As if "THE GOV'NT" is some entity of the elite, assembled with individuals from some higher class seeking to oppress the people.  Well, I've got news for you: "THE GOV'NT" is of the people, by the people, and for the people.

I think what gets me even more are the cries of socialism, communism, and facism.  Do these people even know what these terms mean?  I mean, do they? I think these people need to have a talk with this guy:

Of course, another fun game to play with all of these tea party pictures is "Spot the Minority".  There's just something really weird that I can't put my finger on...almost every picture of these crowds is 100% white.  What's the deal with that?

What's that you say? You have more questions. Well, let's hear them.

Where's MY bailout?

Well, that's simple: you're already getting tax cut from the Obama administration.  Aside from this, check out his mortgage rescue plan.

NEW YORK (CNNMoney.com) -- The Obama administration's loan modification program is finally underway.

The Treasury Department announced Wednesday the first six participants to sign up for President Obama's plan. They include three of the nation's largest banks: JPMorgan Chase (JPM, Fortune 500), which will get up to $3.6 billion in subsidy and incentive payments; Wells Fargo (WFC, Fortune 500), $2.9 billion; and Citigroup (C, Fortune 500), $2 billion. The others are GMAC Mortgage, $633 million; Saxon Mortgage Services, $407 million; and Select Portfolio Servicing, $376 million.

Additional loan servicers will be added to the list over time, a Treasury spokesman said.

Billed as helping up to 9 million borrowers stay in their homes, the two-part plan calls for servicers to reduce monthly payments to no more than 31% of eligible borrowers' pre-tax income or to refinance eligible mortgages even if the homeowner has little or no equity. The government is allocating $75 billion to subsidize part of payment reduction, as well as provide thousands of dollars in incentives for servicers and borrowers to participate.

This is a huge bailout of the American Dream; it aims to keep homeowners (or should I say mortgage payers?) in their homes by modifying mortgages to the realities of the current market and economic environment.  Taking advantage of historically low mortgage rates, I've already refinanced and ended up saving some $400/month.  So there's your bailout.

But the national debt is skyrocketing!  Think of the children!

There are a few points to make here.  First, I must direct your attention to the Treasury Department's helpful website on this topic.  Please browse through every date range on the site.  Notice a pattern?  That's right, every generation since 1791 has left a debt. Every.  Single.  One. 

Of course, one of the fun facts is looking at the national debt between 9/30/2001 and 9/30/2008, roughly President Bush's two terms.  Let's see, it started at 5.8 trillion, and, well, looky here, ended at 10 trillion.  Whoa, I thought, like, Republicans were supposed to be all conservative-like.  Guess that's just a myth!  Let's look at another time period.  How about Reagan's presidency, the period between 9/30/1982 and 9/30/1988.  Let's see, it started at 1.1 trillion and it ended at 2.6 trillion. Will you look at that?  Ronald Reagan more than doubled the national debt. 

But let's move on from the numbers; I'm sure you protested when Bush and Reagan were in charge, too, right? 

There's another point to be made that can't be made with numbers and that's the fact that not all debt is created equally.  There are multiple parts to this.  The first is the interest rate on debt.  It has never been cheaper to create debt than it is right now since intrest rates are so depressed. Secondly, consider this question: is borrowing $40,000 to spend on a sports car the same as spending $40,000  on a graduate degree?  If your jobless sibling came to you tomorrow and asked to borrow $10,000 to buy a new motorcycle, would you react the same way as if he came and borrowed $10,000 to go back to school?

Of course there is a big difference.  One is a depreciating asset from which you are not likely to ever see any returns on and the other, an education, has a great potential to generate a high return on investment.  Likewise, spending on education, healthcare, infrastructure, basic scientific research, and developing energy solutions is an investment that is likely to yield a high return on investment.  It is spending that increases our overall capacity for commerce.  You need an educated population for high paying jobs, you need working roads to facilitate commerce, you need a new energy grid for efficiency (cost savings) and security, you need to fund basic research to drive innovation, you need to fix healthcare because it is one of the biggest factors depressing wages in the US.

If there is something that we should spend our tax dollars on, it's things like these, things that willl someday help generate commerce and thus employment and tax revenues.  And of course, keep in mind, our kids will utilize these same roads and infrastructure decades down the line.  The will go to these new schools.  They will be the beneficiaries of increased grants for scientific research.  It is precisely the next generation that will benefit the most from our investment today.

# Friday, April 03, 2009

Why Do You Play?

Friday, April 03, 2009 8:52:00 PM UTC

One of my favorite all time sports quotes:

You PLAY to win the game. -- Herm Edwards

It's so simple and so obvious, and yet, so easy to lose sight of.  Herm is right, but it doesn't just apply to sports, it applies to product development as well.  You play to win, otherwise, get off the team...you're just dead weight taking up budget.

One of my pet peeves is lack of passion.  It seems that many folks just don't get it; they're not playing to win.  They're playing for their next paycheck.

In product development, like sports, sometimes, you have to take risks.  Get too conservative, and you may see your lead evaporate.  Like sports, you play to win...always.  No team is perfect and no product is perfect, but that simply means that you play to your strengths.  In product development, this means selling to your strengths.  There's no such thing as a perfect team (as the Patriots proved) and there is no such thing as a perfect product. 

The question for product managers and coaches is how you can work with what you have and maximize your resources and work around your weaknesses.  Fail to do this, and you have failed your team as a leader.  If your running game is weak, don't force your team to rely on running plays as a primary option.  If your corners are weak, don't force them to have to cover deep.  If your defense is weak, run your offense to maximize posession time.  Work to the strengths of your team or your product; don't try to play a style that doesn't fit your personnel (analogously, don't use methodologies that don't fit your resources).

You PLAY to win the game.  So simple and yet so easy to get into a mindset where you play for that paycheck instead of playing to win.

# Tuesday, March 17, 2009

Stupid Questions

Tuesday, March 17, 2009 12:04:07 PM UTC

This one comes courtesy of Andrew Sorkin of the New York Times:

Do we really have to foot the bill for those bonuses at the American International Group?

Fittingly, he provides a stupid answer as well:

So here is a sobering thought: Maybe we have to swallow hard and pay up, partly for our own good.

Sorkin invokes "the sanctity of contracts":

...the “fundamental value” in question here is the sanctity of contracts

Welcome to the real world, Mr. Sorkin, where millions of Americans across a broad spectrum of socio-economic classes are employed with transient "contracts".  An NFL player can be cut at any time.  A grocery clerk's job can be eliminated without a second thought.  A consultant can be fired in an act of downsizing.  Long time employees can be terminated without severance.

Mr. Sorkin justifies his belief with another point that he pulled out of his ass:

Here is the second, perhaps more sobering thought: A.I.G. built this bomb, and it may be the only outfit that really knows how to defuse it.

More like they were trying to build a toy rocket and instead, built a bomb.  In this case, I would say they have no fucking idea how to defuse it because they never realized the dangers of what the created; they never really understood the risks to begin with and thus themselves lacked a fundamental understanding of how their own investment vehicles worked.  I'd say these people are the least qualified to handle this because clearly, they're the same idiots who thought that credit default swaps were a good idea in the first place. 

I'm sure many IT consulting companies would love to have contracts with Mr. Sorkin.  Even if their consultants write terrible, buggy, and unstable code, Mr. Sorkin would be convinced that because these guys wrote it, they would also be the most qualified to fix it.  Mr. Sorkin would be the the ideal IT consulting customer.  Send in your cheapest, least qualified labor and have a guaranteed income stream.  Not only that, Mr. Sorkin would be so ensconced with the sanctity of contracts, that he would feel compelled the keep employing the same guys who wrote the buggy code to the very end.

Sorkin then cites Pearl Meyer:

“The word on the street is that A.I.G. employees are being heavily recruited,” Ms. Meyer says.

Well good.  Isn't this how the free market and capitalism works?  If these guys, who were a part of the one of the greatest failures in free enterprise (dollar wise), can find people willing to pay them to ruin their businesses, then let them go.  I call B.S.; massive steaming piles of it.  The financial sector is shedding jobs at an astounding rate...let them swim and see how many want to jump off the boat.

In actuality, I think Meyer is full of shit.  AIG acquired 21st Century (an auto insurance company) in 2007 and promptly changed the name to aigdirect.  Interestingly, aigdirect.com now redirects you to 21st.com.  I guess that AIG moniker wasn't working out, huh?  You really have to dig around to find any association with AIG on the site.

At the end of the day, I'd like to see if Sorkin and his compadres would be defending the UAW's contracts or how about pension funds which are routinely raided or wiped out in restructuring?

In reality, there are lots of corporations that have figured out that there are loopholes in this bill. ... What those loopholes permit companies to do is make promises to a few sophisticated creditors to lock up all the assets of the business so that if the company ultimately fails, there won't be any sharing of the pain. The sophisticated guys will walk out with everything, and the employees and pensioners will be left with nothing.

The text of the law clearly gives a priority to the banks and the other creditors who protect themselves by contract. They come ahead of all of the employees and all the pensioners. It's been there since 1978; it is in the law today. If Congress wanted to change it, they could change it with the stroke of a pen, but that is what the statute says. ... What has changed over time is how much the banks are seizing in terms of the assets, ... so that by the end of the day, there is less and less and less left over for the employees and for the retirees.

How about you defend "the sanctity" of these contracts first and then we can talk about bonuses?

The comments are the only thing which redeem this otherwise steaming pile of excrement.

This argument would make more sense if the government wasn't forcing automakers to abrogate their contracts with their workers and pensioners. Would the columnist have us believe that those contracts that will be modified or cast away were any less legally binding than those at AIG? Balderdash...it's rewarding poor performance at the expense of the taxpayer.

— agincourt76, Seattle, WA

I don't remember seeing this argument when discussing the breaking of union contracts for the auto bailout. In fact breaking the union contracts was seen as a feature and not a bug.

— JStuddle, Los Ageles, CA

You have disgraced yourself. What have you said that hasn't been said? If anyone wants to hire these guys who ruined the world economy and collapsed their own firms, they are welcome to them. Yeah, they're real rainmakers. And do you think new people can't be hired to unwind the transactions with $165 million dollars?

— Sylvia Ellerson, New York, NY

Nothing in this piece says what it is that makes the bonus beneficiaries so indispensable. Their training? Their brains? They and only they know where the bodies are buried?

In every big company -- but especially in finance -- there are junior personnel just aching for a chance to take over from their superiors. Eventually they do. Why not now?

— donnolo, Monterey, CA

Its really very simple. Without government intervention, AIG would be bankrupt and none of those bonuses would have been paid.

The government breaks contracts in bankruptcy all the time. Of course it does set a precedent for people who loot their companies and the taxpayers. Even if the goovernment bails out the company, they may not get all the loot they expected. I don't know that is such a bad thing.

The truth is, the government ought to be going after many of these employees with criminal fraud charges. Its pretty obvious they sold more credit default swaps than their company could afford to pay off. Those were contracts too.

— Ross Williams, Minnesota

The thesis of this article is we must acquiesce in the millions of dollars of bonuses paid to AIG executives because (1) we must keep the “best and the brightest”and (2) the sanctity of contract must be protected.

The “best and the brightest” bankrupted the largest insurance company in the world. Keep them? They ought be carefully scrutinizer for criminal law violations: their conduct simply does not pass the smell test. Besides, in the financial crisis which AIG is a prime contributor, where are these so called “best and the brightest” going to go? The taxpayers inherited them, but we don’t have to keep them. Remember, AIG has been nationalized. We own it!

The plaintiff cry about honoring contracts rights hollow. Contracts ought to be enforced. That fundamental proposition is undebatable. Why isn’t the same application of the law urged in the case of the United Auto Workers?

These “bonus” given to the recipient of the taxpayers largess ought to be a “pink slip”

— David, Sherman, TX

Congratulations, Andrew Sorkin, you've just asked the Stupid Question of the Day!

# Wednesday, March 11, 2009

Integrating NaturalDocs With SyntaxHighlighter (For The Win!)

Wednesday, March 11, 2009 3:29:21 PM UTC

In working on some SDK-style developer documentation for FirstPoint, it occurred to me that we needed a way to create some all encompasing documentation which covered not only our code base, but also our markup, our JavaScript controls, CSS, and so on.  We currently have most of this stuff in Trac wiki pages, which is a great place to put them, but our Trac deployment is going away and being replaced by Jira...or so I'm told.

In light of this, we needed a way to create portable, useful, developer documentation which included a mix of some auto-generated content and hand crafted documents as well (how-to's and stuff, which would be really terse if placed in code comment).  There aren't really any do-it-all tools, but I stumbled across NaturalDocs which seemed to be the most well rounded tool of the ones I looked into (i.e. JSDocs, YUI Doc, a few others - it started off as a search for a tool for documenting UI conventions, markup, and script usage for our team) because of the fact that it allowed for the inclusion of loose .txt files which would essentially be treated like wiki pages.

You can see an example of the output at the MapQuest API documentation site.

One of the main reasons I liked NaturalDocs is because of the support for code blocks and how easy it is to write them in the loose text files.  However, the downside is that the generated output is pretty...boring.  Here's an example:

You can see that it has no intelligence with regards to the language.  Doing a little digging around the 'Net, I found a ticket for a request for support for syntax highlighting.  So I ended up rolling my sleeves up and solving this myself.  I decided to integrate against the SyntaxHighlighter JavaScript library since I've used it previously and I like the output :-).

Here is the end result:

I hadn't touched Perl in quite some time (since college), so I had to dig around in there for a bit but I was able to integrate it after a few hours of flailing.

The steps required are as follows (these steps assume you use framed mode):

In the file FramedHTML.pm, you will need to add the following lines to the method BuildFile after the call to $self->ClosingBrowserStyles():

. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShCore(), 1) . '"></script>'
. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShBrushCSharp(), 1) . '"></script>'
. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShBrushXml(), 1) . '"></script>'
. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShBrushCss(), 1) . '"></script>'
. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShBrushJs(), 1) . '"></script>'
. '<script language="javascript" src="' . $self->MakeRelativeURL($outputFile, $self->HighlighterShBrushSql(), 1) . '"></script>'
. '<script language="javascript">'
. 'SyntaxHighlighter.config.clipboardSwf = "' . $self->MakeRelativeURL($outputFile, $self->HighlighterClipboard(), 1) . '";'
. 'SyntaxHighlighter.all();'
. '</script>'

Next, to support the new getters, you will need to modify HTMLBase.pm and add the following lines:

sub HighlighterShCore
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shCore.js' );
	};

sub HighlighterShBrushCSharp
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shBrushCSharp.js' );
	};

sub HighlighterShBrushXml
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shBrushXml.js' );
	};

sub HighlighterClipboard
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'clipboard.swf' );
	};

sub HighlighterShBrushCss
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shBrushCss.js' );
	};

sub HighlighterShBrushJs
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shBrushJScript.js' );
	};

sub HighlighterShBrushSql
	{
	my $self = shift;
	return NaturalDocs::File->JoinPaths($self->JavaScriptDirectory(), 'shBrushSql.js' );};

You should add more to handle whatever syntaxes you need to handle.

By default, the code blocks are generated as <blockquote><pre></pre></blockquote>.  To support SyntaxHighlighter, we'll need to change this to allow customizing the class name on the <pre> tag.  I decided to use the suggested syntax for including this in the markup: (start code <language>).  For example: (start code js).  The first module that we have to modify to support this is Native.pm.  In the method FormatBody, I made the following change to support the extra token:

# If the line looks like a code tag...
# [CHUCK] ORIGINAL: elsif ($commentLines->[$index] =~ /^\( *(?:(?:start|begin)? +)?(?:table|code|example|diagram) *\)$/i)
elsif ($commentLines->[$index] =~ /^\( *(?:(?:start|begin)? +)?(?:table|code|example|diagram) *((?:\w+)?) *\)$/i)
	{
	if (defined $textBlock)
		{
		$output .= $self->RichFormatTextBlock($textBlock);
		$textBlock = undef;
		};
	# [CHUCK] ORIGINAL: $output .= $tagEnders{$topLevelTag} . '<code>';
	$output .= $tagEnders{$topLevelTag} . "<code class=$1>";
	$topLevelTag = TAG_TAGCODE;
	}

You can see that I've introduced a capturing group to the regular expression to grab the language type (matching SyntaxHighlighter's language strings).  The next step is to modify the generation of the intermediate <code> tag to include a class attribute. 

If you stop here, the output generation doesn't work correctly since this only affects the intermediate output.  We need to jump to HTMLBase.pm and modify the method NDMarkupToHTML so that we can generate the proper tag structure.  Here are my modifications:

# [CHUCK] ORIGINAL: my @splitText = split(/(<\/?code>)/, $text);
my @splitText = split(/(<\/?code *(?:class=[^\>]+)?>)/, $text);

while (scalar @splitText)
	{
	$text = shift @splitText;

	if ($text =~ m/^(?:<code *(?:class=([^\>]*))?>)$/i)
		{
		$output .= "<blockquote><pre class=\"brush: $1\">";
		$inCode = 1;
		}

You can see that here, I changed the regular expression used to split the intermediate output into chunks to properly split on the new markup structure.  In the if-statement, I changed the eq comparison to a regular expressoin match with a capturing group and inserted that into the output <pre> tag (for the win!).

Now be warned: this is not a complete fix.  While this addresses the major issue, generation of the proper output, I did not make changes to copy the image files and JavaScript files required by SyntaxHighlighter (sorry, you're going to have to do that yourself :-P).  The next set of steps are to:

  1. Copy the images associated with SyntaxHighlighter to the \output\styles directory (or whereever you like).
  2. Copy the scripts required for SyntaxHighlighter to the \output\javascript directory.
  3. Modify the paths in the CSS for the icons used with SyntaxHighlighter (in the shCore.css file).

Of course, the themes and CSS files are easy to include since you can specify those at the command line.

That's all there is to it!  Happy documenting!  I've attached sample files (including the modified source) for SyntaxHighlighter 1.5 and 2.0.

natural-doc-sh2.0.7z (315.01 KB)
natural-doc-sh1.5.7z (281.7 KB)

# Tuesday, March 10, 2009

The Follies of C# 4.0

Tuesday, March 10, 2009 3:43:12 PM UTC

Nikhil Kothari has been blogging furiously about Visual Studio 2010 and C# 4.0.  One of his posts covering the dynamic programming features in C# 4.0 raised some interesting discussion in the comments.

Some like Francois Ward:

I heavily dislike this. My philosophy has always been "right tool for the right job". There are dynamic languages that are vastly superior to C#, if you want dynamic. C# was meant to be a "pure" language, to do the stuff where you want as much strong typing as possible (also the reason behind Spec#), and as clean as possible.

This defeats that purpose in such a way that only an FxCop rule or code reviews could stop it from ruinning a codebase. If I wanted dynamic, I could do it in IronRuby (once thats fully out), and call the result from C#.

More so: this dynamic feature was mostly meant to help with COM interop, not as a convenience to save a few lines of code... and people are -already- thinking of ways to misuse it... Really, the .NET runtime was made so we could have all the languages we want on it, EXACTLY so we wouldn't need a "one language to rule them all" thing... The best codebases would use C# as the core, IronRuby (or something similar) for places where you need Dynamic, and F# for places where you need functional... there's no need to stick C# everywhere...and thus, there's no need to add this to C#. Its too late now, but at the very least we can make sure its not abused.

And some like poster "HB":

Why such resistance to this? Mandate to your team not to use it if you don't like it.

Every release of every programming language has the same problem. People resist the new features claiming that they will be abused and ruin everything and yet here we are in C# 4.0 and the use of 'var', anonymous <fill in the blank> and other C# 3.0 features haven't destroyed us.

For people that use a lot of Json (like in MVC), this will be especially handy

I tend to agree with Francois Ward.  While I appreciate the changes in C# 2.0 and 3.0 (moreso 2.0 than 3.0), this transition from "C# pure" to "C# bit-o-everything" is a bit disconcerting; it feels like change for the sake of change and it feels like change in the wrong direction.  As a disclaimer, JavaScript is perhaps my favorite programming language - I love how fluid the language is.  But on the other hand, I can also appreciate some of the structural rigidity of statically typed languages like C# in helping to coerce good OOP practices.

As many have made the argument "Well, you don't have to use it!", I'd like to respond from this angle. It's not a matter of whether I or any of us personally use it but rather how your stereotypical RAD developer (still the majority) uses it or rather abuses it.

I personally think that McConnell gets it right in Code Complete:

"The computer doesn't care whether your code is readable. It's better at reading binary machine instructions than it is at reading high-level-language statements. You write readable code because it helps other people to read your code."

"Making code readable is not an optional part of the development process, and favoring write-time convenience over read-time convenience is a false economy. You should go to the effort of writing good code, which you can do once, rather than the effort of reading bad code, which you'd have to do again and again"

In other words, programming in such a way as to reduce your LOC for a particular operation, while increasing the density (amount of logic in a given number of lines, words, or whatever other metric) or complexity of the statement has a negative effect on readability of the code (at least until the practices become standardized and fairly well understood). The problem I foresee with C# 4.0 is that it introduces features which will not be generally understood across the spectrum of developers. Remember: you are never writing code for yourself, you are writing code for your customers, you clients, the people who will maintain the code after your, your peers whom you work with, consultants who may not understand lambdas, and so on. You may have junior developers on your team (or even senior developers on your team) who may not be able to grasp your idea if you entwine your implementation with cool nifty tricks to reduce LOC.

From a practicality perspective -- as much as this sucks, it is always safer to program to the lowest common denominator; assume that you are writing your code for a novice to maintain and your code will be more legible, the structures will be easier to understand, and the comments will be less terse. Use patterns that are simple to understand. Use statements which are easy to read for a novice as a novice may one day be maintaining your code or extending it. For those reasons, I think that this is a mistake...a terrible mistake to satisfy a set of fringe developers who will actually "get" it and use these constructs in the proper manner.

The forward evolution of the C# language, while it does contain some awesome features and looks more and more like native JavaScript with each iteration, continues to confound me with the lack of concern for the general development community. Instead of focusing on constructs and framework extensions which promote design pattern usage, domain models, and good practices, we get extensions and constructs which undercut the effort to increase the development IQ of your average developer

It WILL be abused and then people like myself will have to go in there and try to untangle the intent of developers who misuse these facilities provided to them for all the wrong reasons just as I've seen people abuse System.Linq instead of writing good, performant code.

Microsoft's C# Future page is a good place to start with regards to some of the features coming out for C# 4.0.

Why We're Nearly FUBAR'd

Tuesday, March 10, 2009 1:41:18 PM UTC

The financial ignorance of the Average American is so widespread, that you -- yes you: sitting in your cubicle, making close to six figures at a stable white collar job -- you are probably sitting next to someone who's financially ignorant.

A story from the AP studying American's understanding of insurance yielded some astoundingly bad results:

Health: Fewer than half (49 percent) of those surveyed were informed about the cost of coverage if they leave their job and choose COBRA (Consolidated Budget Reconciliation Act) insurance to continue their health benefits. And just 58 percent were aware that health insurance will not cover their living expenses if they become disabled and cannot perform their job.

Home: Only 19 percent knew that the requirement for private mortgage insurance on a newly purchased home depends on the size of the down payment and lender; almost 30 percent think PMI is required by law.

The shortcomings in awareness conflict with what respondents thought they knew. Before taking the quiz, nearly 60 percent said they felt "very confident" when making insurance decisions overall, with only 15 percent voicing any insecurity about their decision-making abilities.

I'll admit, I'm probably one of those financially ignorant ones as well.  But I'm learning!  The problem is that there is a shocking lack of baseline financial education.  There is no standardized financial education test for high school students, as far as I know, and you know what?  Perhaps there should be and it should be a requirement for high school graduation or a G.E.D.  Perhaps two courses are in order: once in high school to cover basics for college students like credit cards, APRs, banking, paying bills, progressive tax brackets, credit scores, and so on.  Another, higher level course would cover things like renting (and your rights as a renter), mortgages, retirement savings, investing, more on progressive tax brackets, and so on as a national requirement for obtaining an associates degree or a baccalaureate.

(As an aside, one of the biggest peeves I had during the presidential campaign was the shocking lack of understanding of how a progressive tax bracket worked and the difference between a marginal tax rate and an effective tax rate.  I don't think that most people even understood the real effect of raising the taxes by 3% -- rolling back the Bush tax cuts -- on the highest bracket would be and who it would affect...)

Come to think of it, this would be an awesome two pronged approach!  Get kids educated on the basics of finance and put all those laid off Wall Street workers to good use.

But seriously, I think this is one of the biggest arguments against privatized health insurance options as a method of increasing insurance coverage and availability: people just don't know much about these things and people don't want to spend the time to dig into the details while they're healthy.  Most of the time, the materials are just too dense anyways.

There's a story in Time this week, "The Health-Care Crisis Hits Home", written by Karen Tulmuty, documenting her brother's experience with the twisted world of health insurance.  What's shocking are some of the numbers drawn from it:

When we talk about health-care reform, we usually start with the problem of the roughly 45 million (and rising) uninsured Americans who have no health coverage at all. But Pat represents the shadow problem facing an additional 25 million people who spend more than 10% of their income on out-of-pocket medical costs. They are the underinsured, who may be all the more vulnerable because, until a health catastrophe hits, they're often blind to the danger they're in. In a 2005 Harvard University study of more than 1,700 bankruptcies across the country, researchers found that medical problems were behind half of them — and three-quarters of those bankrupt people actually had health insurance. As Elizabeth Warren, a Harvard Law professor who helped conduct the study, wrote in the Washington Post, "Nobody's safe ... A comfortable middle-class lifestyle? Good education? Decent job? No safeguards there. Most of the medically bankrupt were middle-class homeowners who had been to college and had responsible jobs — until illness struck."

Scary numbers.

# Monday, March 09, 2009

More Quotes From the Basketball World

Monday, March 09, 2009 2:23:36 PM UTC

Steve Aschburner's article on Mike Miller's surprising drop in productivity contains a nice gem from Don Nelson:

"My first years with Nash, he wanted to be John Stockton,'' Nelson said. "He wanted to get 10 points and 15 assists. I wanted him to get 20 and 10. I felt he could score 20 points a game, but it took me a year to get him to. I ended up having to get angry at him. He was getting booed and he stopped looking for his shot and the team was going poorly, and finally we just had it out after a game.

"I basically told him he had to do what I asked him to do. He had abilities he hadn't even scratched the surface on, and he turned out to be an All-Star for me [in Dallas] and an MVP [in Phoenix]. I just didn't want him to only pass. He was my best outside shooter and he would never take an outside shot.''

Nash averaged 7.9 and 8.6 points in his first two seasons with the Mavericks, then bumped to 15.6 in 2000-01. He was at 15.5 (2004-05) and 18.8 (2005-06) in his two NBA MVP seasons for the Suns.

"You want them to max out on their abilities,'' Nelson said. "You want players to do what they do, if they're good at it. They can work on what they're not good at it. But each guy has his strength, and he's got to go to that.''

I think the same is true of any successful team environment: get people to max out their abilities and let them develop and work on what they're not good at; place people in position to succeed and you can drive the success of the individuals and also the team.

RSS 2.0 Atom 1.0 CDF