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.
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())
3: // my potentially blocking code here
1: public partial class WaitMessage : System.Windows.Window, IDisposable
3: public WaitMessage()
9: #region IDisposable Members
11: public void Dispose()
17: // Deconstructor: make sure the window is disposed
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()
3: StackPanel panel = new StackPanel();
4: panel.HorizontalAlignment = HorizontalAlignment.Left;
5: panel.Orientation = Orientation.Horizontal;
7: Label pickLabel = new Label();
8: pickLabel.Content = "Pick ";
9: Label ofLabel = new Label();
10: ofLabel.Content = " of ";
12: // LOOK THIS:
13: IntegerTextBox cumulativeBox = new IntegerTextBox();
14: IntegerTextBox maxPicksBox = new IntegerTextBox();
15: maxPicksBox.KeyUp +=
16: delegate(Object sender, KeyEventArgs args)
18: cumulativeBox.MaxValue = maxPicksBox.Integer;
19: if (cumulativeBox.Integer > maxPicksBox.Integer)
21: cumulativeBox.Integer = maxPicksBox.Integer;
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.