Flylib.com

Books Software

 
 
 

Code Manager


Code Manager

Although we built a very simple code manager, it was quite valuable to us. There are certainly cases in the book where I needed to show more code than I had at first realized. Since every version that ever got compiled is archived by the code manager, I was always able to find just the snippet I needed.

Knowing that the code was saved gave us the courage to make changes. We knew that we could get back to any previous state with only a little effort. If we had written the tool to roll back to a given point in time, we probably would have used it a few times. If we had needed it more than a time or two, we certainly would have written it.

In short, our code management tool was almost but not quite sufficient for our needs. Thats a pretty good place to position tools. We dont want to work on them too much, to the exclusion of customer needs, but we want them to be strong enough to serve us. Once the tool reliably saved all versions, it was good enough. Had we needed to roll back more frequently, we had the information to do so.



Coding Standard

Our coding standard evolved over time as we became more familiar with C#. We didnt pay much attention to the standard, since only a few people were involved and only one of them worked with all the code. Still, we could have done better in certain areas. In particular, Id point to our use of properties and methods .

We have not been consistent with properties and methods. On the one hand, in Smalltalk and in Ruby, we are used to not needing parentheses or other parameter indicators on methods that dont need parameters. So we were initially inclined to use properties whenever they would work. We often got confused , however, for these reasons: First, in the Microsoft .NET library, some things that seem like properties are in fact methods, and vice versa, so we were often unsure as to what to use in the library. Second, sometimes we felt the need to mimic a similar method in .NET, so we would put parentheses on something where it felt to us that it didnt belong. Third, it seemed that on some days we preferred to put parentheses everywhere.

The bottom line is that we were not consistent, and we never sat down and talked through just what our conventions should be. The code suffers a little because of that, although I hope it doesnt suffer much.



Be Ready to Use Advanced Facilities

We did little subclassing, either from real objects or from interfaces. I think we would benefit from more. In the case of our TextBox, which we did subclass from TextBox, we could have been more aggressive and given it a better interface to the TextModel. Perhaps an event-driven interface would have been good, perhaps just something that better hides the difference between the TextModels view of things (ArrayList) and the TextBoxs (a big string, or an array of strings).

I suspect that we would have done well to create a special collection class for our lines. There are casts to strings sprinkled around in the code, and we could have avoided many of these, perhaps all of them. The need to downcast collection elements is a serious flaw in languages like C#, and its being addressed in future versions. C# will have templates, for example, which will make it easier to set up collections containing objects of known type.

At one point in the Undo saga, we tried to build one class as a subclass of another. To do this, we needed to override a couple of methods . The compiler didnt like the way we tried to do it, and after a couple of attempts, we just built to an Interface instead. In this case, it was probably a better design anyway, but its not good to have the design pushed around by ignorance of the language and its syntax. In a future project, I would try to use more of the language facilities sooner. This is a delicate balance, because we dont want to slow down and we dont want to insert gratuitous differences in the code. But at this point I feel that I know parts of the C# and .NET system pretty well and that there are untapped riches that I could use if only I knew a bit more about them.