Carlos Ble

Carlos Ble

I am a professional software developer, I solve problems.

I also teach and mentor developers to build better software.

Working as an independent professional since 2009.

Can I help you?

  • Do you need high quality tailor-made software?
  • Need training on TDD, clean code or refactoring?
  • Is it risky? do you need advise?
  • May I pair with you to write better code?

Events

Upcoming public training courses:

  1. [in English] May 5, 6 & 7
    TDD - Train the Trainers (iSQI)
    Potsdam, Berlin
  2. [en Español] 23, 24 y 25 de Abril.
    Curso de TDD con examen de certificacion iSQI
    Madrid
  3. [en Español] 29, 30 y 31 de Octubre.
    Curso de TDD con examen de certificacion iSQI
    Madrid

Conferences:

  1. I'll be at SocratesUK 2014
  2. I'll be at the London Test Gathering Workshops.

Archive for October, 2007



Nice blocking UI

Boxerp has a responsiveness engine that lets you launch operations in background easily as displaying some kind of message to the user along with an option to cancel the call. However, there are times in which the operation is supposed to be fast so you don't launch a different thread but use the current one.
What happen then if the operation is delayed for any reason?. I think is nicer to show a message in the meanwhile, so I came up with this idea:

   1:  using (new WaitMessage())
   2:  {
   3:    // my potentially blocking code here
   4:  }
And the class for WPF:
   1:      public partial class WaitMessage : System.Windows.Window, IDisposable
   2:      {
   3:          public WaitMessage()
   4:          {
   5:              InitializeComponent();
   6:              Show();
   7:          }
   8:  
   9:          #region IDisposable Members
  10:  
  11:          public void Dispose()
  12:          {
  13:              Close();
  14:              GC.SuppressFinalize(this);
  15:          }
  16:  
  17:          // Deconstructor: make sure the window is disposed
  18:          ~WaitMessage()
  19:          {
  20:              Dispose();
  21:          }
  22:          #endregion
  23:      }

I haven't stress the window and I need to make sure the garbage collection is going to be ok but it is working so far. The window opens at the begining of the block displaying a message so that the user knows the application is supposed to be working ("Please wait..."), and it is closed at the end of the block. I'm going to add this feature to Boxerp making it extensible for Winfows Forms and Gtk#

When you're learning something new and eventually you figure it out, you got a fresh algorithm or rules in your mind, to understand how to use that. At that point you can explain it to somebody else and he/she will most likely understand the thing faster. However, when you become an expert your brain works automaticly and it is more difficult for you to explain it to somebody else. You forget that it is not straigforward to figure that out when you don't know it yet. Somebody else might be yourself within months, after a while without using that thing. This is a another good reason to write documentation and unit tests as the functionality is being implemented, that is, as the code is being written.

I had a bunch of ideas on how to explain the rationale behind applying generics when I was learning them. Now I just use strongly type structures and generic collections as much as I can but I would find it difficult to explain.

I'm know trying to leverage "new" features of C# and this time I'll post my thoughts about them. One useful manner of taking advantage of Anonymous Delegates is to use them as event handlers.

   1:          private void createDynamicPlaceholders()
   2:          {
   3:              StackPanel panel = new StackPanel();
   4:              panel.HorizontalAlignment = HorizontalAlignment.Left;
   5:              panel.Orientation = Orientation.Horizontal;
   6:  
   7:              Label pickLabel = new Label();
   8:              pickLabel.Content = "Pick ";
   9:              Label ofLabel = new Label();
  10:              ofLabel.Content = " of ";
  11:  
  12:                  // LOOK THIS:
  13:              IntegerTextBox cumulativeBox = new IntegerTextBox();
  14:              IntegerTextBox maxPicksBox = new IntegerTextBox();
  15:              maxPicksBox.KeyUp +=
  16:                  delegate(Object sender, KeyEventArgs args)
  17:                  {
  18:                      cumulativeBox.MaxValue = maxPicksBox.Integer;
  19:                      if (cumulativeBox.Integer > maxPicksBox.Integer)
  20:                      {
  21:                          cumulativeBox.Integer = maxPicksBox.Integer;
  22:                      }
  23:                  };
  24:  
  25:              panel.Children.Add(pickLabel);
  26:              panel.Children.Add(cumulativeBox);
  27:              panel.Children.Add(ofLabel);
  28:              panel.Children.Add(maxPicksBox);
  29:  
  30:              _dynamicPanel.Children.Add(panel);
  31:          }

If there wasn't an anonymous delegate I'd need a subscriber method but more importantly, I'd need to save the reference to the two textboxes, as the code in the subscriber needs them. It would imply having some kind of structure in memory to reference them, it means more lines of ugly code.