Posts

Embarcadero should revive Bold for Delphi

I've recently been doing some work on a Bold for Delphi application. I am really quite surprised how much I am still impressed with this framework, it really was (and still is) so much ahead of its time. Embarcadero really should revive this product and put it back into Delphi. They could make it a free addition to Delphi, or maybe even ship it with Delphi as an open source project. Embarcadero! You have a great tool here, don't hide it away, use it!

Free: One year TechNet Plus subscription

http://arstechnica.com/microsoft/news/2009/06/free-one-year-technet-plus-subscription.ars Update: The UK link from this site has been taken down :-)

Bing

I searched for "mrpmorris" on bing.com recently.  Now on Google it would show the address of my blog as the first result, which is very relevant.  On Bing it showed a page from a web chat from over 3 years ago, not very impressive. Not sure how long this photo will remain on the web for, but I found it quite interesting... http://farm4.static.flickr.com/3604/3585051300_d23a37a32e_o.png

Generation gap - update

Martin wrote to me and explained something I wasn't aware of. He doesn't catalogue best practises or only the ones he likes, he is cataloguing all patterns he can find. He said he would rather someone made an informed bad decision than an uninformed good one. Not quite sure I agree with that either :-)

Generation gap

I have just read this blog by Martin Fowler. I like a lot of what Martin writes, but this is not one of them. The article suggests using inheritance to separate code-generated classes and manually written classes. You would descend from a code-generated class instead of trying to modify the code-generated source. The problems I see with this are Attributes If I have a descendant of a code-generated class how do I attach .NET attributes to members? I’d have to override them and add the attribute in the descendant which would mean all of my members need to be virtual. Obviously this wouldn’t work for Private members. I expect you’d have to attach all of your attributes in the tool which generates the source code, but I don’t like this idea. I will explain why later. Sealed / final What if we want to create a sealed/final class? We can’t. What if we want a specific member to be sealed/final? Then we couldn’t add attributes to the members. Partial Microsoft introduced Partial clas

I've just ordered some books

Someone kindly gave me a £100 gift certificate for Amazon.  I posted a request for book suggestions to 3 groups where I would expect to receive good recommendations    http://tech.groups.yahoo.com/group/altdotnet/    http://tech.groups.yahoo.com/group/domaindrivendesign/    http://groups.google.com/group/RhinoMocks I received a lot of recommendations (thanks everyone!) - here are the ones I have bought:   Building Domain Specific Languages in Boo   Writing Secure Code, Second Edition   Analysis Patterns Reusable Object Models (OBT)   How to Solve It: A New Aspect of Mathematical Method   Object Oriented Project Design   Extreme Programming Explained: Embrace Change   Getting Things Done: How to Achieve Stress-free Productivity    Here are the books that made it onto my "future" list which I didn't have enough cash for this time around.   http://www.amazon.co.uk/gp/registry/wishlist/13GXONVVMLHZZ I generally went for the cheaper books first, so that I could get as much inp

MUMS - How good you are when things go wrong

I always say this so I have probably blogged it in the past, in light of my MOZY incident probably recently, but "It's not how good you are when things go right, it's how good you are when things go wrong". My wife and I are (unexpectedly) expecting our 4th baby.  We paid for a private scan at MUMS last week.  Part of the package is a DVD of the scan.  The scan was a really good one, but unfortunately when we got home we realised our DVD was completely blank. I phone them up and they offered a free scan.  I was still disappointed because there was a beautiful part of our previous scan that would be lost, where we were zoomed right into our baby's hand as she repeatedly clenched and reopened her hand, but I agreed because at least we would have something . When we had our scan they gave us probably double the normal amount of time.  In addition to that they upgraded our scan from a plain ultra sound to one of those 4D scans.  We were given twice as many printed ph

Bletchley Park

If you are unaware Bletchley Park played a vital part in World War II, it undoubtedly shortened the war (possibly by years) by decoding intercepted Nazi messages which had been encoded on the Enigma machine.  This site is credited with being the place where the first programmable computer was used to crack the more complex Lorenz Cipher Machine. According to this petition number 10 Downing Street... http://petitions.number10.gov.uk/BletchleyPark/ ...the park is severly lacking in funds and has at best 2 to 3 years before it is forced to close down.  The idea that a site with such a historical significance could be bulldozed and redeveloped is astonishing! Please help to preserve this computer related historical UK site by making as many UK residents as possible aware of this petition!

Locking in ECO 5

Jonas has just added the following feature to ECO 5 which should turn up in the next build. Let's say you have a package with a single class LockObject in it. This LockObject must have TimeStamp locking, but you use this package in many applications.  In ECO 5 you can set the default locking mode for a package. Now let's say you have multiple packages that you use in many applications and the locking type is different per app.  App 1 uses AllMembers locking, App 2 uses no locking at all; how can you specify the locking type?  Now you can add a .NET attribute to the top of your application specific EcoSpace class.... [UmlTaggedValue("Eco.OptimisticLocking", "AllMembers")] public class Application1EcoSpace : DefaultEcoSpace {   etc.... } Locking is determined like so: The kind specified on the class itself. The kind specified on any super class. The kind specified on the package. The kind specified on the EcoSpace.
Someone I know recently got stung by this, so I thought I’d mention it... static void Main(string[] args) {   int a = 1;   int b = a;   Console.WriteLine(AreSame(a, b).ToString());   Console.ReadLine(); } static bool AreSame(object a, object b) {   return a == b; } What’s the output to the console? Does a equal b? Even if you didn’t know the answer you will have guessed it is False otherwise this blog would be totally pointless! It’s false because the parameter types of AreSame are both "object". For a value type such as "int" to be passed as an object it needs to be boxed, so a new object instance is created which stores the value "1", but this is done for both parameters so we end up with 2 new instances both holding the value 1. 1 equals 1 for value types but the default comparison for System.Object is to compare references. If they are not the exact same object (and in this case they are not) then the result is false. Now if we typecast both a and

I don't like AccuRev

A company I have been contracting for decided to use AccuRev as its source control solution. I've not liked it from the start because it is too much work, the terminology in it is quite frankly stupid, and it is far too "chatty" when you work remotely.  Anyway, for some time now I have suspected it has been losing source code. On a few occasions I have found myself looking at source code and thinking "I could swear I have already done this!". Well, last week I wrote some pretty nice code which used multiple threads in a test case to ensure I experienced expected behavior when multiple users update the same objects in a database.  Today one of the other programmers said to me "Didn't you write more tests than this?" and showed me the tests.  My multi-threaded tests were gone! I knew it all along, but now it is indesputible, AccuRev has been losing my work!

The Pragmatic Programmer

My copy of this book has just turned up. I am book hungry these days, can't wait to read it :-)

Connascence

I’ve just finished reading What every programmer should know about object oriented design . The first couple of sections are a bit useless really, but the 3rd section is very good. I particularly liked the section on the difference types of connascence in software. There’s some basic information about it here if you fancy a brief overview of what it is about. It’s a really good book, I recommend you read it! Should only take a day if you only read the 3rd section.

I've just ordered a Java book

Image
http://java.sun.com/blueprints/corej2eepatterns/index.html It was only $0.41 used in the USA, came to about £6 with posting to the UK. I don't write Java and at the moment have no interest in learning it, but I expect I will be able to read it without problems (never really looked at it). So why did I buy this book? Because it is about this... That's why :-)

Prism - Invariants, and pre/post conditions - update

Just found out that I can do this too public invariants   Overdraft >= 0 : ’OverdraftGreaterThanOrEqualToZero’;   Balance + Overdraft >= 0 : ’BalancePlusOverDraftGreaterThanOrEqualToZero’; end; Then in my handler routine I get that message! if not IsValid then   throw new Exception(ErrorMessage); Excellent :-)

Prism - Invariants, and pre/post conditions

I’ve been looking at Prism some more recently. I’m a bit annoyed with myself really because someone has been telling me to look at it for years but I wanted to concentrate on C#. Now that I am looking at it I see things in there which I really like. Recently I am looking at invariants, pre-conditions, and post-conditions. First let me show you the invariant support. An invariant is like a class constraint, it specifies a condition which must be true but when must it be true? type   BankAccount = public class   public     property Balance : Decimal read write;   public invariants     Balance >= 0;   end; The invariant is enforced each time a public method exits. Actually it is enforced after the post-conditions of a public method exits but we don’t have any post conditions yet. class method ConsoleApp.Main; begin   var account : BankAccount := new BankAccount();   //The next line throws an assertion error   account.Balance := -1; end; Property getters and setters are considered

Injecting into the ECO cache

In my previous post I showed an interface ILockable. The actual interface is public interface ILockable {   Guid GetLockID();   Type GetLockObjectType(); } Any lockable resource implements this interface. In its constructor it creates an instance of a class which descends from LockObject, a Document class for example would create an instance of DocumentLockObject which descends from LockObject. The "Document" class would store away the ID of the DocumentLockObject in a private attribute. Now when my LockingService is asked to lock multiple (un-related) instances which implement ILockable I want to do this 1: Create a new EcoSpace 2: Load objects efficiently 3: Get locks 4: Update the DB 5: Dispose of the EcoSpace If I experience an OptimisticLockingException then loop and try again. The item I would like to discuss is #2, "Load objects efficiently". In my model a LockObject has a *--1 association to Session identifying which session has locked it, I want to en

Setting the ID of an ECO object before it is saved

This might seem like a bit of an odd requirement. I am currently implementing an offline pessimistic locking service in an ECO app. This will mean that I can use a LockingService to place read/write locks on objects. As usual I have gone for an interface approach (ILockable) rather than making all my lockable classes descend from a base Lockable class. Remember, it's what I DO , not what I AM . The idea is that I have a Lockable object which holds a list of Sessions. These Sessions indicate who has a read lock, and who has a write lock on the object. Each ILockable business entity will create its own private instance of Lockable when it is created. The thing is, this application will at times need to lock thousands of objects in as little time as possible. As there is no common ancester for these ILockable classes I can't just use EnsureRelatedObjects to traverse an association name and load all LockObject instances in a single select. I decided that what I needed was to

Using a GUID as the key in ECO

Drop a DefaultORMappingBuilder component next to your persistence mapper. Point PersistenceMapperxxxxx1.NewMappingProvider and RuntimeMappingProvider to point to this new component. On your PersistenceMapper component expand SqlDatabaseConfig and click the [...] next to KeyMappers, ensure that you have an item named "GuidMapper" with the MapperTypeName set to "Eco.Persistence.GuidKeyMapper". If not then add it. On your DefaultORMapperBuilder set IdKeySignature to System.Guid (case sensitive). Set its IdMapperName to GuidMapper. Now regenerate your DB.

Prism AOP - 4

I’ve played a little more with Prism. I find it a little difficult to mentally code on two levels. Level one being the code I am writing for the aspect, and level two being the code I am writing which will executed by the target. Having said that, as soon as I ran my app and saw the output everything was worthwhile. Here is my Person class type   [aspect: EcoAspects.BusinessClass(’DomainClasses.Package1’)]   Person = public class   private     FFirstName: String;     FLastName: String;   protected   public     property FirstName : String read FFirstName write FFirstName;     property LastName : String read FLastName write FLastName;   end; here is the code which uses that class class method ConsoleApp.Main; var   P: Person; begin   P := new Person();   for A in typeOf(Package1).GetCustomAttributes(true) do     Console.WriteLine(a.ToString());      P.FirstName := ’Peter’;   P.LastName := ’Morris’;   ShowGetValueByIndexResult(P as ILoopBack2, 0);   ShowGetValueByIndexResult(P as ILoop

ECO – Ensure related objects

Sometimes you have a list of objects (say List<PurchaseOrder>) and you want to get all associated objects (say OrderLines) for all the orders in the list. There are 2 ways of doing this in ECO You call a PersistenceService method which takes the list of orders and a string identifying the association name. I don't like this approach because the name of the association may change during modelling and this wont be picked up as an error until runtime. You use the overloaded method which takes an IAssociationEnd. I don't like this either because you have to find the IAssociationEnd instance from the meta-model at runtime, and to do this you'd probably use a name anyway. So, what's the alternative? public static void EnsureRelatedObjects<T>(this IPersistenceService instance, IEnumerable<T> objects, Expression<Func<T, object>> member) where T : IEcoObject {     MemberExpression memberExpression = (MemberExpression)member.Body;     instance.Ensure

Prism AOP - 3

I am playing with Prism’s new Aspect Oriented Programming feature. As a learning exercise I am implementing some of the features ECO requires on a class. If all goes well I will end up with aspects I can apply to plain classes and have them run in ECO. One of those features is the ILoopBack2 interface. In order to tackle this interface a small piece at a time I have created my own ILoopBack2 interface, so far with only one method. ILoopBack2 = public interface   function GetValueByIndex(I: Integer): System.Object; end; This method allows the ECO to evaluate OCL (Object Constraint Language) expressions such as "self.FirstName" and have them route via the class’s property, just in case there is any logic in the getter. By implementing an interface which uses an index to identify the property to read it is possible to avoid reflection. So, getting on with it, here is my class definition type   [aspect: EcoAspects.BusinessClass(’DomainClasses.Package1’)]   Person = public cla

AOP 2

This is fun :-) I’ve created an aspect like so type   BusinessClassAttribute = public class(System.Attribute, ITypeInterfaceDecorator)   private     FPackageName: String;     property PackageName: String read FPackageName;   protected   public     constructor (PackageName: String);     method HandleInterface(Services: RemObjects.Oxygene.Cirrus.IServices; aType: RemObjects.Oxygene.Cirrus.ITypeDefinition);   end; I can now decorator my class like so type   [aspect: BusinessClass(’DomainClasses.Package1’)]   Person = class   end; I can ensure this class  exists in the aspect implementation method. constructor BusinessClassAttribute(PackageName: String); begin   FPackageName := PackageName; end; method BusinessClassAttribute.HandleInterface(Services: RemObjects.Oxygene.Cirrus.IServices; aType: RemObjects.Oxygene.Cirrus.ITypeDefinition); var   PackageType: ITypeReference; begin   PackageType := Services.FindType(PackageName);   if (PackageType = nil) then     Services.EmitError(’Package cl

My first AOP

Here’s what I did. 01: I created a support project which just has a logger class in it. namespace EcoSupport.pas; interface uses   System.Collections.Generic,   System.Linq,   System.Text; type   Logger = public class   private   protected   public     class procedure Log(Message : String);   end; implementation class procedure Logger.Log(Message : String); begin   System.Diagnostics.Debug.WriteLine(’Log: ’ + Message); end; end. 02: I created an Aspect which decorates methods, giving me the opportunity to intercept all method calls on the class it decorates. namespace EcoAspects; interface uses   System.Collections.Generic,   System.Linq,   System.Text,   RemObjects.Oxygene.Cirrus,   EcoSupport; type   [AttributeUsage(AttributeTargets.Class)]   LogAspect = public class(System.Attribute, RemObjects.Oxygene.Cirrus.IMethodImplementationDecorator)   private   protected   public     method HandleImplementation(Services: IServices; aMethod: IMethodDefinition);   end; implementation method

My next new best friend

http://blogs.remobjects.com/blogs/ck/2009/02/06/p251 Read the comments I posted to see why I like it!

Unemployed

My employer's support contract has finally come to an end which means I have to look for another job, haven't had to do that in a while! Drop me an email if you have any positions vacant, in the meantime it's time to do a little "networking".

Unity - contexts

The outcome of this fairly long exchange on codeplex has made me very happy!

The BNP need my help

It seems they are unable to spell the word "money", because every time they send me their drivel of a newsletter they always want money. Usually it is for their "Van of truth" (which amuses me immensely) but this time it is to help them to become "the most technically advanced political party in the UK". So, what are they going to do to earn this esteemed title? Set up our own BNP call centre Set up the party campaign central office Purchase 18 computers/screens/software Activate our brand new central database platform Recruit more staff to cope Train all staff in new systems Set up central mailing and telephone points for party Open our new logistical distribution warehouse Riiight. Call centre – Surely other parties have these? Central office – I am pretty sure other parties have these! 18 computers / screens / software – Screens? Are they going to watch TV on them? MONITORS! At least we are talking I.T. now though. Central database

No Silverlight?

I'm trying to view this page in Firefox. When it loads the browser tells me I need Silverlight, so I download and install it and then restart my browser only to be told I need to install Silverlight. That's not impressive at all!

Delphi flickers

My app has a wizard approach, the current control appears within a panel with Align set to fill the hosting panel. My first wizard step control merely had an image on it which resizes with its parent control. When I resize the form the host panel resizes, which resizes the wizard control, which resizes the image; and boy does it flicker! I just had to spend some time upgrading my old Delphi DIB controls to D2009 just to get an image that doesn't flicker, crazy! By the way, I tried the same thing in VS2008 and there was no flicker at all, and I thought Delphi was supposed to be the tool that produced fast UI apps.

Synchronising downloads and updates (2)

There was a potential deadlock in the last piece of code. When you obtain any kind of lock you will mostly use a try..finally block to ensure the lock is released when you have finished with it. The using() command expands to a try..finally block so the original code might look okay, however if you mentally expand the code you will see the problem. using (FileLockingService.FileReadLock(product1.ID)) {     //Some code here } This becomes var disposable = FileLockingService.FileReadLock(product1.ID); try {     //Some code here } finally {     disposable.Dispose(); } So why is this a problem? In a single threaded application it isn't, but this is a website so there are multiple threads running at the same time. Now take into account the fact that a web request has a timeout, what if the thread is aborted after the lock is obtained? Ordinarily this isn't a problem because the acquisition is followed immediately by a "try", but if we expand this code further it is ev

Synchronising downloads and updates

Apparently my boss used to be annoyed with something on his old website. When he wanted to upload an updated binary he often couldn't because his product was so popular that someone was always downloading it at the same time. He'd have to continuously hit Delete in his FTP client until eventually he'd slip in and manage to delete it before updating the new version. This obviously isn't an ideal solution because: He constantly had to sit there for around an hour trying to delete it. Once deleted from the disk any user attempting to download would get a 404 – Not Found error. During upload any user attempting to download would get an Access Denied error of some kind. For this website I have decided first of all to only update the files via a HTTP form post. So firstly any long running upload will not deny access to the currently available file, this eliminates problem 3. Additionally, using a form post means I can overwrite the existing file, so this eliminates problem 2.

The best tool for the job

If I had to write a large business app which accessed a DB, or a website, I would use .NET without hesitation. When it comes to small apps (less than 10MB) that will be downloaded by home users what should I use? I have such a project coming up soon, my boss has bought D2009 and wants me to use that because he is paranoid about people reverse engineering the binaries. I'm a little hesitant but I must admit that I think in this case Delphi 2009 probably is the best tool for the job, and I like to use the best tool for the job rather than the tool I like to use best for my job. Hopefully things will go smoothly, it will be nice writing apps in two different languages.

Music to fight to

An odd title for a coding blog I know, but I love martial arts too, especially competitive ones. I'm just putting together a CD for my car. The tunes on the CD music really make my adrenaline pump, so I am putting together a compilation of tunes which make me want to win a fight...with style! Nirvana – Smells like teen spirit. Fat boy slim – Right here right now. William Orbit – Adagio for strings (Ferry Corsten Remix with first 2 mins cut off). The Prodigy – Breathe. The Prodidy – Firestarter. Chemical Brothers – Block rockin' beat. Chemical Brothers – Setting Sun.

PayPal doesn’t do discounts

I can't believe it, I really can't! I'm writing a shopping cart for a website. One of the features required is to give the user an X amount discount off their next order when they buy a specific product. So let's say the user has a £20 discount on their next order, how does PayPal let me apply that? Simple answer, it doesn't! You can't send a cart line with a negative price "Discount for 20 GBP", nor can you send a cart line with a positive price but a negative quantity (that was desperation). The way to do this apparently is to send a cart total. YES! By sending the entire order aggregated into a single order line. NOOOOOOO!!!!!! So PayPal wants my user to order £100 of goods, click Check-out, and then be presented with "Total for your order £100 (£20 discount)", that's it? In my opinion, that's not very good. In fact, considering PayPal is probably the largest Internet payment organisation in the world I consider this to be

More Balsamiq madness!

Someone pointed this link out to me today: http://www.screensketcher.com/examples.html It's another application along the lines of Balsamiq. This app does seem very "sharp", it has very snappy response times etc, which is nice and everything BUT I still don't like these kinds of apps! I do prefer the name though, it suggests "I sketch screens" rather than "I am a bottle of vinegar ".

This is just a test

Image
I've just spotted a "Publish to Blog" option in Word 2007. So I thought I'd give it a spin and see what happens. If it works then Blogging is going to be a much more pleasurable experience. My spelling is atrocious. I find complex formatting on BlogSpot is terrible. I will no longer have to edit HTML just to get my code to look right. Talking of code, I had better try that out too...     public class PreSaveConstraint     {         public readonly IObject Instance;         public readonly string Name;         public readonly Func<bool> CheckIsValid;           public PreSaveConstraint(IObject instance, string name, Func<bool> checkIsValid)         {             if (instance == null)                 throw new ArgumentNullException("Instance");             if (string.IsNullOrEmpty(name))                 throw new ArgumentNullException("Name");             if (checkIsValid == null)                 throw new ArgumentNullException("Che

Proof of the existence of God

Finally there is proof that God exists. The proof has come in the guise of a product named Balsamiq . Balsamiq allows you to create mock GUI when specifying an application. Rather than having graphics that look like real forms etc it uses a pencil drawing lookalike approach. Here is my reasoning. It does nothing you can't do for free in the IDE you undoubtedly already have. The result looks far worse than a mock up you can create in your IDE. Once you have the mock up you can't do anything useful with it except export it as an image or print it. You can't, for example, actually use that for a real form later in the project's life cycle. The result looks crap. Not poor, crap! It looks like a 7 year old has drawn it with a wax crayon....a blunt one. Balsamiq brought in revenue of over 100,000 US Dollars in its first 5 months. Now the way I see it is this. Lots of people are sending money to a guy to buy software that does something they can already do much better f

ASP.NET Development server and PayPal instant payment notification

I am currently developing part of a website where I pass cart information to PayPal to accept payment. PayPal will call back a "secret URL" on my website to allow me to confirm the cart details haven't been tampered with. I hate installing software I don't need. This is especially the case with software like IIS which just feels so intrusive, which is why I use the ASP.NET Development Server when creating websites. The problem with this server is that it only accepts connections from the local machine. My computer is behind a hardware firewall and my web server wont accept remote connections, so how can I test my PayPal IPN call back? Simple. Obviously I have to open a port on my firewall and direct it to my machine. So I opened port 80. Then I used this tool to list on port 80 and redirect all traffic to port 10101 (the port my ASP.NET development server was listening on). The result is that a remote computer can now make a HTTP request to my computer, and I