Part of the development of one of my pet projects, the UML Designer, requires some type of custom canvas to display the UML graphs. Sounds easy, especially since I’ve done similar things in Java. Unfortunately reality proves me wrong every time.
I started out by creating a custom component, which inherits from the Panel. This would give me pretty much a blank object that could be added to the GUI. The painting part on its own is not that difficult either. Done that hundreds of times. The problem is in adding the various objects to paint on top of the panel to the panel before drawing commences.
Ok, I’ll try to explain a little better. I keep track of what to draw in an array inside the custom panel. This because these objects contain more information then just how to draw. But they are not part of the component list of the panel. I need to add them dynamically just before drawing and remove them again after drawing. But I’ve yet to find the correct way of doing this.
Tried adding them in the onPaint method, but this doesn’t trigger them to be painted. So I’ll probably have to intercept the WM_PAINT message sent to the panel and attach the
Since PHP 5.x we are encouraged to develop in a more object oriented way. This is why they developed class support for us
. Now to make our web applications even more modular you might consider putting each class in a seperate PHP file, just like Java and C++ developers have been doing for years now. But here is where it becomes tricky, how does PHP know which files to load automatically.
Of course you could include every single file that you might need manually at the top of your index.php. But what if you don't need every single class every time a page is loaded, do you really want to create that kind of an overhead in loading un-needed files? I didn't, so I started looking into the autoloader functionality of PHP. What this feature does is allow you to scan through files in the predefined include directories and attempts to locate the class.
So what I did was build a simple autoloader function to scan each file in predefined directories to find the classes, and if found to stop. To my surprise this was working rather well. All classes that where needed would automatically get loaded by my little autoloader function. However somehow one particular class was not able to be loaded for some reason. The setup was something simple, something like:
All of the classes loaded beautifully, except for class D. For some reason when I tried using it I got exceptions that class C was undefined. When I added some debugging to find out which files where loaded I did see every file for classes A, B and C being loaded, but the actual classes defined inside where not added to PHP. Somehow I have magically created a black whole in PHP that would include files and then forget to create the class definitions internally. To this day I still haven't figured out why PHP refused to store the actual classes in its memory.
The quick fix I applied was ugly and stupid, just manually load the classes and build a big if statement around them to prevent duplicate declarations using the class_exists function.
In a previous post a couple of weeks back I stated that I started on developing a UML designer. Mostly because I couldn’t find any recent releases that are free and work decent any more. Since some time has past and a lot of work has been done its time for a quick update.
Initially the idea was to develop the application in C++.Net which was a challenge to say the least. I was disappointed when I couldn’t integrate older C++ libraries I had already written with the .Net application. So as all angry people I abandoned this course of action all together and switched over to C#. Lets just say this put the work back a couple of weeks, as I have no knowledge what so ever on C# development
.
So what have I been up to since this idea popped into my head:
It is unfortunately still way to early to release anything useful that can be played with. Mainly because much of the interface is not even working yet. Even so I have included a screenshot of what it looks like. There is still a lot of work to be done, just a short list would be:
And of course the nice to haves way down the line, all based upon an existing UML design:
As I recently started a new job I also had to dive into a completely different culture. Programming and code style wise that is. One of the things I came accross was the choice to always use static members. But is this desirable in programming and good conventions.
Personally I think static members should be reserved for helper classes and singleton instances. But why?
One of the main reasons for reserving it for helper classes is simple. A lot of 3rd gen programming languages don’t allow functional programming, hence you need to create a class to support generic functions. In a way you are just trying to store some simple functions in a namespace (C++/.net) or package (Java), but this is not supported. I believe this is fine when all members are static.
A second reason for a static member is to support singleton, or factory model classes. In these situations it is desirable to have one single access point to get an instance of a class. But no other methods should be static.
If you are thinking about making a member static then ask yourself the following question: “Why does this need to be static?”. And the following answers aren’t good once:
So try and be careful when using static members. And as always just keep thinking when programming and designing code.
Sometimes when you are developing you encounter the stranged errors. Today is just such a day. I’m right now having issues with memory access violations in on of the programs I’m developing.
This on its own is not that big of a deal, but I can’t seem to trace down why it’s happening. If I debug the function that causes the error has no issues. No memory violations, but when I continue running (without debugging every single call) then all of a sudden at some point in time I get a memory access violation.
Now I don’t exactly know where it’s comming from. It may have something to do with the fact that the object I’m deleting is a prototype of a prototype. And also occasionally gives me an error during compile time that I have no destructor in the class. But when I compile the files one by one it does not give this error. And the class in question does have a default destructor.
Hmm, guess it’s time for some real line by line debugging and digging into the internet about the obscure error message I got.