The Ugliest Code I’ve Written in a While

  1. private EventHandler<MyEventArgs> NameObscured1(IMyForm form)

  2. {

  3.             return new EventHandler<NameObscured2>((sender, eventArgs) =>

  4. {

  5.                 form.TabControl.Enabled = false;

  6.                 IAsyncResult iar = null;

  7.                 Action bg = null;

  8.                 bg = new Action ( () => {

  9.                     NameObscured3((s) => {

  10.                         form.StatusLabel.Owner.Invoke(new Action(() => {

  11.                             form.StatusLabel.Text= s;

  12.                             form.StatusProgressBar.Value +=2;

  13. }));

  14.                         return false;

  15. });

  16.                     NameObscured4(sender, eventArgs);

  17. });

  18.                 Action enableForm = () => { form.TabControl.Enabled = true; form.StatusProgressBar.Value = 0; };

  19.                 AsyncCallback callback = (_) => { form.TabControl.Invoke(enableForm); bg.EndInvoke(iar); };

  20.                 iar  = bg.BeginInvoke(callback, null);

  21. });

  22. }

The question is… How can I make this more readable, and is it worth spending the time to do so?

Nesting lambdas to 4 deep cannot be a good idea, but honestly, factoring each one out to a method might actually make this code LESS readable IMO. In this case, it is just a damned shame that some things can be done cross threads in a Windows Forms application.

I’m guessing this is a sign that I am too tightly coupled and should have some kind of mediator which will then Invoke property updates on the correct thread, but I don’t have that now.

Moral of the story: don’t write nasty nested lambdas like me.

Professional Programmers have a Responsibility

…To themselves and to the industry.

On a private mailing list I recently read a message which included this paragraph – this paragraph is totally off topic to the topic of the mailing list.

Author name has been excluded to protect the unprofessional programmer. (license breaker facilitator)

I’ve been working professionally as a programmer for nearly 20 years and I’ve rarely seen businesses that pay for Enterprise licenses, much less an "Enterprise" license that is only good for one Developer.  There will be tons of license abuse at this price point within businesses. Heck, most of the places I have worked at outfit their Developers with Visual Studio they got from one copy of the MSDN.

My response is this:

It is your professional responsibility as a programmer to point out to these businesses that they are breaking a EULA and if the software make found out they would likely be on the hook for hundreds of thousands of dollars in fees.

These types of business should be buying a copy of MSDN for each developer — that is how it is licensed. Or they should be investigating other options. And there ARE other options, whether it is Express editions, or a program like bizspark or open source such as SharpDevelop.