[| box e |]
Sunday, May 10, 2009
An (F) Sharp Pain in the Butt
Saturday, March 07, 2009
I Must Have Dosed Off for a Year
Thursday, January 10, 2008
Xheo-du
I think this underscores the problem with Microsoft's help format. Help is cut up into a hierarchical collection of factoids and it is very difficult to read linearly (i.e. there is no start and there is no end, so in general you can only read a snippet of the available documentation). Why can't someone produce a nice PDF from an existing VS2005 help file (or maybe somebody can?...).
Wednesday, January 09, 2008
Xheo Shmeo
For those of you who don't know Deployx is a software license package for .NET. It is very complete with a lot of features and is also very expensive. We would like to use it to write our own centralize licensing server so that corporate users could simplify deployment (and we could get paid for what we are doing - a big change). Unfortunately it is a black box and a brick sXXt house. I don't know how it works, I don't know how it is supposed to work if it did work. I don't know when it is working and when it is not working. All I know is that is it not doing what I hoped it would do.
The documentation is minimal and the support staff surly (when they answer at all). If there were any other product that might be able to do my job I would have bought it.
Depression... depression... depression.
Tuesday, September 19, 2006
What about AOP?
However, when coding tricky projects we have been faced with times when we wished that we could inject code compiler at compile time - a typical thing that AOP will allow. In addition, I can see the utility of AOP for a lot of developer tools, for example, TypeMock - a C# mock object framework, uses AOP extensively. This brought me back to AOP.
I decided I would try (again) to do something with AspectJ. It seems to be one of the big guns of the AOP world (in CACM and IEEE Software, there were articles that originated with this project). In addition, there are very good AspectJ tools for Eclipse. This time, to help me I bought the Addison Wesley book on AspectJ with Eclipse (I forget the name just now). And decided I would try to read it over the summer holidays.
To my surprise, the book offered a new picture of AspectJ. In its introductory chapter it actually solved a real problem (serialization of objects) with something that seemed to be an AOP application (not a just a developer tool) that was useful. Much of the authors claims made sense. That is, use aspects to modualize objects that are in different inheritance hierachies. The serialization example was very convincing.
The idea is that a lot of busness objects should not mix thier busness logic with there "book keeping" code (for example how the object is stored). The result was similar code that cut across a number of unrelated objects could be treated in a unified way.
The more I looked at the examples presented by the author and the more I thought of it, the less excited I became. I am, however convinced that if used as another programming tool, AOP can be useful, but if you abuse the AOP hammer, I think you will end of with a big, complex, distributed mess. Here are my main beefs,
- In Holub's Pattern book he makes a convincing pitch that objects should be able to save themselves in context. According to Holub, getter and setter (or properties if you come from C# land) are evil. I believe Holub in this case. The serialization aspect can not just save everyone by looking set and get methods and use them to serialize the object. Object serialization is a task the object must participate in. This is made clear in Holub's book. Otherwise, we trade modularity of the serialization code for a tangle of aspect and object code, with the guts of the objects exposed in the wild, rather than carefully concealed.
- I note that in AspectJ you can write point cuts on private join points. For example, we could execute a bit of code every time the program accessed a private field. Is this really a good idea. Is it not really fragile to use a private point cut? The implementing private method has made no contract to exist and may be changed at anytime. This type of aspects might be good to hack to do something like unit testing with mocks, but we can not write application code like this.
- Aspect interpretation is hard... too hard. When I read my first paper on AspectJ the authors emphasized that tool support would be required if the framework was to be adopted. I think that tool support is good, but tool requirement is bad. That is, if when I write a point cut I need a tool to show me which objects (might be affected), then I am in trouble. I think that writing point cuts is like writing regular expression. Seems easy until you have to do something really hard. Sometimes you ge more hits tht you think you will and it is very difficult to see the difference. With this, the advantage of AOP (localized code for dispersed object) becomes a disadvantage. You never know which objects will be hid by an AOP bug and the object and aspect code are dispersed, so you might have a hard time locating the bad line of code.
- Your object can not count on aspects (usually). Here is a philosphical point. Should the object know there will be an aspect attached to it. If not, why does it not implement all the code required to do its business (rather that stuffing some code in a aspect). If it does know, why is it not more specific about its contract with the aspect. I think this is where I am now. I would like to use aspects, but I would like my objects to expose a public point cut interface that could be used by the aspect for stuff the object would have had to do. Then and only then can the object remove "non-business" code. Otherwise, the only thing we have done is created a dependance between the object and the aspect that is implicit, required but very weak (can you ship the object without the aspect - AspectJ say - go ahead).
So there is my 2 cents worth on AOP. I think when we do AOP the objects would do well to define a set of exposed point cuts. I don't think we should bend over backwards looking for aspects - aspects are suppose to deal with cross-cutting issues. If there are no cross-cutting issues using an aspect (or inventing an abstract cross-cutting issue) is just making things more difficult than it needs to be (I had the impression to read an article like this in IEEE Software). Finally, I don't think that an aspect should ever point cut a private or protected or package join point. Maybe for a developer tool, but not for a application. An OO programmer would not use reflection to execute a private method just because he could after all, so an aspect should not do the same thing.
Thursday, April 06, 2006
On 10 Things Jim Mischel Hates About C#
Jim's Top Ten
1. No Anonymous Inner Classes
Anyone who says they don't like the syntax of anonymous inner classes misses the point of C-like languages. That is, minimizing the amount of text minimizes the amount of errors and using common idioms eliminates common errors. No anonymous inner classes ensure that there is always a large amount of boilerplate infrastructure to hack up everytime you ever want to implement a class that will only ever be created in one place (does IEnumerable and IEnumerator mean anything to you). I hate creating private named IEnumerables when I could easily do the same thing with an anonymous class. The syntax might be something pascal programmers are not use to, but we are after all highly paid programmers. Besides, putting the code right beside where it is used rather than in some dusty corner *always* makes it easier to maintain. I can not see why anyone would prefer not to use anaymous inner classes at every opportunity... must be a hold over from our BASIC days.
2. Interfaces Can't have Inner Objects
How many times do you implement an exception that is only thrown by an interface method, or an enum that is only used in an interface. Why can not these be inner classes and enums on the interface itself. This allows the internals to be encapsulated within the interface and it reduces namespace pollution by seldom used items.
3. Enums aren't Objects
Enums can not have any body. But this is not the way they are used. Enums often have services they have to perform, like showing as a translated string, saving themselves in a persistence framework or just display themselves in the UI (as a drop down menu for example). These are real needs (google whack "enum C# ToString" and you will see what I mean). Enums should not be just a short list of ints. In an object oriented language they should be full class objects.
4. I Don't Like Delegates (and I like Events even less).
The syntax of delagates still confuses me, their place in the object hierachy confuses me (e.g. what is "this" when you are in a delegate method). I don't think there is a need for a function wrapper in an object oriented language. An no, there is nothing object-oriented about a delegate.
I can say the same for events, except the syntax is even worse and more confusing. How can this:
button.Click -= new Event (myEvent);
remove an event listener when I just created a new delegate. I think the entire event system in .NET was made so that the people who implemented VisualStudio had an easier time (and to hell with the people who have to use the generated code).
I don't think I have to go to 10. I am disapointed Jim just came up with the same "don't like C conditionals" ... blah, blah, blah. C is about minimizing typing, using standard implementation idioms and putting the code near to where the action is taking place. I think if you don't like these ideas, then, effectively, you won't like C or any of its decendants (no sweat). Having said that, there is lots of things about C# that we don't have to like (assuming we like C). I listed a few. I think if you have not felt the same need, you aren't really trying. Almost every day I code C# I miss anonymous inner classes and inner classes on interfaces.
Sunday, March 19, 2006
XML, Strings and "Simple" Text Processing
When I went to implement a simple parameter editor, I thought... after editing, maybe my XML document is non-conforming. I think I will reload it into an XML document after editing to test its validity. Much to my disappointment, when I did this everything broke. All my XML elements were XML encoded as <node-name> and when I reloaded the document I got lots of errors. What went wrong.
In fact, when I loaded the document into the XML document and later stored the document inner XML (in .NET C#) the new text contained an node giving the encoding of the document. Since this was being stored as an XML node in my parameters document, the XML framework thought it must be text and encoded it for me. This show why XML sucks. You can not just blindly add text to a document. If I would have added XML that was not well-formed in a single node, this could break my containing document.
To counter this I decided to base64 encode the xml text and push it into a CDATA section of my parameters document. Okay, the text of my parameters document would not be as easy to hack, but I could guarantee that any parameter could be put in the document without breaking the container. This is the source of today's rant. I find the C# API for such a task is crappy.
First, what I expected to do was to create a string object that was the base64 representation of my initial string object. But the Convert method for creating a base64 string takes a byte array (okay that is logical), but to create a byte array from a string you have to get text encoding object and call the GetBytes method. One would expect that string could expose a constructor that takes and encoding and a byte array and a GetBytes method that could create a byte array. I spent 1/2 hour looking though the crappy .NET documentation trying to find the objects collaborating in the string to byte array sequence before stumbling upon the correct incantation. Then I spent another 1/2 hour doing the same thing for converting a byte array back to a string.
The basic problem here is that you should be able to say, "string, give me a byte array representation of yourself - here is my encoding scheme" - I think this is the Java strategy and I think it is the logical one. What .NET has is "encoding, here is a string, take a peak inside its current implementation and representation and give me a byte array represetation of it". I think it breaks encapsulation and you really have to have a lot of experience working in domains where character encodings are important (i.e. where 99% of all north american programmers like myself don't work) before you even guess where the solution might be located.
The second problem is that all the .NET documentation (no... make that all Microsoft documentation) is broken in the 1/2 screen factoids with circular references between every three pages. Examples are designed to make people quit trying. For example, I recently looked at the documenation for getting directory information and an example program was presented showing how to print out the various parts of a file path without showing what the various method calls should return... I suppose they expect you to create a project, copy and paste the example code and run the example if you are really interested in knowing what the method calls do, rather than just clearly explaining it in the description of the methods.