Posts filed under 'Programming'

Chosing a development platform

technology02.pngLAMP, Zend, .Net, Struts, Ruby on Rails, Catalyst, and a hundred other development platforms all compete for you attention, all pretending to be the only thing you’ll ever need to satisfy your every needs in web or UI development.
Making a decision is really hard: you want the best for your new project and want to make the right decision. In most cases, that means not cursing yourself down the line for a choice that didn’t turn out as expected.

When you start looking into all these platforms you can be blown away by the ease of implementation and elegance of some; your head spins at all the features and claims being made and it becomes hard to achieve a rational decision.

I’ve been faced with that very issue recently and it sucks. Actually, the time spent investigating all these possibilities is really what is being sucked away.
Of course, learning about new technologies is not just fun, it’s also essential: you have to keep on top of what’s new and decide if you want to join in on the fun or just stay comfortably where you are.

I also realized that you need to get away from the coolness factor of each these much touted technologies and actually try to be objective.
During my investigation, I tried to decide what were the really important factors that I should consider to make a rational choice.

I came up with the list of the following 10 questions that I think everyone should ask themselves when choosing a platform for an important project.

1- Is the platform wide enough?

New technologies that can show amazing productivity get all the buzz. After all, that’s what we developer want: enough with the nuts & bolts! Give us a toolbox with all new shinny power tools! The problem is that often these technologies are impressive, but looking beyond the sample projects into what actual users get confronted to, you start noticing discussion threads that should obviously signal that the platform is not wide enough.
Choosing a technology that hasn’t achieved its goals can be a huge problem down the line: you implement 80% of your project in record time, only to realise that the platform you chose doesn’t support proper cross-browser detection, or that its implementation of security is way too lax, or that it only support XML for data storage and now you actually need a real database for performance reasons…
In those cases, you can of course develop those areas yourself and contribute to the project, but doing so supposes that you planed it all along and you factored that in your schedule, both in time and in cost.

2- Is it popular?

In other words: are other professional people actually using that platform in real life? I’m not talking about Joe Developer using it for his local community church website. I’m talking about businesses or large organisations actually using that software platform successfully.
If all you need is a simple 3 page website, then professional popularity amongst the Top 500 business companies is probably not that important. On the other hand, if you plan to build a large project, or you know that your project could grow large in the future, then you probably want to ensure that others have taken it there before you.

3- Is it mature?

Has the platform existed for long enough that it went through enough abuse to withstand almost anything you can throw at it?
A technology that is only a couple year old may be too young to have evolved to the point where it actually can solve most common and not-so-common problems. Technology evolves through iterations: each one is a good long hard look at what didn’t work and tries to fix, improve and extend.
A young technology may be more cutting-edge and exciting, but when you need to commit to it for a big project, its age may quickly come as an issue; its shinny surface may blind you to the black holes waiting below…

4- Are local developers available?

Always think about the future. When you’re gone from the project, who is going to look after it? Getting a web project entirely in Rebol may be cool and fun, but how many people in your city actually use that thing anyway?
Aren’t you creating a liability if you’re dead-set on choosing a platform that cannot be maintained?

5- Is it scalable?

Most projects start small but dream of ending-up big.
It’s usually fine at the beginning when the number of users and visitors is manageable, but what happens when you start to be successful?
After all, that’s why we craft our projects: we want them to succeed, we want the world to see them. When the world starts coming though, will the terrific platform we’ve chosen break at the seams?
How much overhead does the platform create? It is flexible in its database support? Is there a way to implement clustering or persisting sessions accross multiple servers?
What’s the cost in memory and CPU resources? How many simultaneous connections can you get? What are the bottlenecks? What do you need to do to compensate for them? How much would it cost?

6- Do you have control?

Some frameworks work hard for you and can make you really productive. Sometime though, they try too hard and hide too much from you.
When a feature doesn’t exactly work the way you want you have to dig deep into the entrails of the beast to make sense of it and change its behaviour.
A platform that was all nice and pretty can get very dirty and complex inside, making it difficult to adapt to your needs.
A platform should do most of the hard work but still allow you to redefine its default behaviour without much hassle. It should be built with extensibility in mind, making easy thing easy and difficult things possible.
A case in point are 4G development platforms: they usually have a fairly narrow field of expertise and tend to use graphics and nice simple paradigms to quickly build complex tasks but when you are faced with a specific issue that hasn’t been solved by the platform, you often have to resort to ugly hacks to get around their limitations.

7- Does it satisfies the essential constraints for your project?

When being blinded by something cool, we often become skewed in our judgement and guilty of lowering the importance of constraints that are actually critical for our project.
In all honesty, I really wanted to use Ruby on Rail, and I liked the principle and elegance of it so much that I came to seriously consider it, that is, until I came to my senses and looked into something that is critical to my project: support for complex Asian languages.
Ruby is being developed in Japan, so you could think that it should be able to handle complex ideographic characters well.
Turns out that the Japanese are not terribly fond of Unicode and, unless I’m mistaken, prefer to use Code Pages instead. The result is that Ruby doesn’t have great support for Unicode, and that sucks.
That’s why Unicode was created: to attempt to simplify all this patchwork of implementations that are not compatible with each other.
Because I needed to be able to handle English, Mandarin, Cantonese and probably any other language out there, Unicode is the only viable option to abstract the issue of language enough that it becomes manageable.
So because of Ruby’s poor support for Unicode, it would not be rational to use Ruby on Rails for my particular project as it would probably greatly increase the complexity and hacks necessary to manage complex Asian languages in a unified and simple way.

8- Documentation?

All framework have a more or less steep learning curve: you need to think differently to adapt to the particular framework’s frame of mind, so to speak.
Make sure that the framework has a lively community, that it has more documentation than you can swallow and that documentation is well organised.
Make sure also that there are samples, tutorials, webcasts, videos or whatever that cover the principle aspects of it.
A beautiful framework no-one talks about means that no-one will answer when you have a question. A beautiful framework without documentation is useless. A beautiful framework with lots of disorganised docs means that you’re going to waste a lot of time experimenting instead of building your project.

9- Support?

Here I mean support in the wide sense of the word: who is behind the framework. Are they likely to stay in business long after your project has been completed?
Are they commercial or Open Source? In either case there are issues for and against: a commercial venture backed by a small company may falter and disappear overnight. Similarly, an exciting open source project managed by only 2 people can suffer the same fate when they decide to move on. Support also includes what help is available to you when you encounter issues. Is there any guarantee that you could have your important technical questions answered?
If you encounter a large issue, is there someone to help you?
I would contend that the best and most serious projects should have professional help available: you can always fall back on paying someone to help you through, whether it’s the original developers, a paid-for support hotline or a third-party specialist, it’s important that you know you can get your answers when you’re stuck.
Developing for an important project without safety net is dangerous: you can waste a lot of time and effort, endangering the very project you are undertaking, if you stumble on a problem you cannot solve yourself.
Large frameworks like .Net or big Open Source projects usually have enough users and support groups and specialists that it’s likely any question you may have has already been answered somewhere or that you can pay someone to help you out when you need it most.

10- What do you know best?

Every framework is based around a particular data-management model. Every framework is built with a particular programming language in mind. Every framework demands that you learn something new. How comfortable are you with the requirements? how long is it going to take you to start to get really productive?
Like their real-world counterpart, it can take very little time to learn a new language’s words and syntax but it takes years to become proficient in it. A framework adds another layer of abstraction that you will need to get experienced at.
If you need to both learn a new language and a new framework, chances are that you are at best months away from being able to churn code without having to look into the documentation every 5 minutes.
Learning new languages and concepts is necessary, but again, if you chose that route you must be sure that your project has that learning curve built-in, otherwise you’re going to move at the pace of a turtle when in fact you chose that particular framework because you though you would be more productive and faster than a sparrow.
If you chose a new framework, make sure that you already possess most of the knowledge it requires: in my particular instance, I chose .Net and C# because I have already worked in that framework and I know it can tackle the project without me having to waste too much time on learning the platform rather than implementing the project.

We all should seize any opportunity to learn something new. Learning is often more exciting than doing the same old thing over and over again and it’s a necessary part of staying in business. Curiosity is an excellent quality that must be nurtured and indulged.
The issue is when to do it.

Choosing a new development framework is not easy. The best way to tackle the problem is to pose it as a risk analysis study.

The framework you chose should simply be the one that poses the least risk to you succeeding your project.

Add comment October 1st, 2006

Software: Cheap Microsoft Licenses

BusinessI’m not particularly pro -Microsoft but I’m not against it either.
I love Linux, got my RHCE (Red Hat Certified Engineer) a bit more than a year ago and I love Open Source, Linux and all things GNU.

The only thing I really dislike about Microsoft is its marketing, its pricing, its Genuine (Dis)Advantage that nags me every time I need to install something and its lack of openness when it comes to inter-operability with other competing implementations (here I’m particularly thinking about its network protocols that the Samba team tries to decipher and re-implement as an Open Source platform).
On the other hand, Microsoft is made of great programmers, great minds that you can watch on Channel 9 and read on their insightful blogs.

Microsoft is really (I mean REALLY) pro-developer: they understand that the Operating System alone is nothing without lots of applications sitting on top of it, and they offer developers a lot of goodies.
One such useful programme is +Microsoft Empower for ISV_. It’s a simple membership that allows a small software company (ISV meaning Independent Software Developer) to own a number of licenses for its internal use at a fraction of the price it would normally cost.
What you get is pretty wide for a small business: 5 licenses for Windows XP (whatever version), 5 licenses for Microsoft Office, 1 license for Windows 2003 Server and Exchange, SQL Server, SharePoint Portal, a MSDN Premium Subscription that covers almost anything else, including 5 licenses for Visual Studio 2005 Pro.
You also get access to MSDN downloads, beta software and tons of libraries, SDK, etc. A MSDN subscription alone is about US$2000…
The Empower ISV programme is quite cheap and depend on the country you are in.
I paid mine HK$4,260 about US$530.

To get all this you need to register as a Microsoft Partner (that’s free), then apply for the Empower for ISV programme by making a promise to release a commercial software within 2 year at most. You need to give some details and pay your due. After a few days, you get confirmation if your application is accepted or not.
As far as I know, you need to be a company and have a company website, but that may not be mandatory in all regions.
The software you get is the normal US version plus whatever local version there are for your region. My bunch of DVD came in Japanese, Cantonese, Mandarin, some in Korea and Thai too.
At least, the English version is supplied. For some software, you also get the multilingual version that include European languages as well.
You manage your licenses by login under your MSDN account.

Really, it’s a nice touch from Microsoft to give us poor developers access to all this for such a reasonable price. I can only encourage other small software companies and independent developers to do the same.

Add comment September 18th, 2006

.Net: The limits of using Reflection

technology02.pngReflection is a hugely useful technology: it allows you to get inside objects and get their intimate details, modify their values and even rewrite part of their code.
Today I wanted to build a simple treeview control that would display the hierarchical structure of an arbitrary object by going through its properties and building a tree-like structure. Useful to visualise the internals of an object and see changes at runtime.

Using PropertyInfo you get enough information about a particular property to decide if you want to display it or recurse into it if it’s a complex type that contain other properties.

The only big issue I faced was when dealing with indexers.

The issue with Indexers

Indexers are defined in code like that:
We’ve defined an overloaded indexer: one takes a DateTime, the other just a string representation of a date.

We could use them like that for instance:
Now, let’s say we want to print all property names and their values for an arbitrary object.
Let’s try on our myDay intance:
So, that part is easy: we iterate through all properties of myDay and print their Name and they value.
Problem is, when we reach the indexer property, we get a TargetParameterCountException on line 8.

We need to detect the indexer before attempting to get its value.
To do that, we need to modify our foreach loop to:
Here we attempt to get the indexer parameters for every property. If we’re dealing with an indexer, the parcoll array will contain a list of ParameterInfo related to that particular indexer.

So what really is this parcoll and its ParameterInfos?

A ParameterInfo contain information about the parameter of an indexer property.
The parcoll array will contain one entry for each overloaded indexer.
In our concrete example this is what we get:

  • pi.Name will be Items, this is standard for all indexer properties.
  • pi.PropertyType is the type of the returned class of our indexer, in our case, a System.String.
  • parcoll.Length will be equal to 2 because we have 2 overloaded indexers.
  • parcoll[0].Name will be date.
  • parcoll[1].Name will be datestr.
  • parcoll[0].ParameterType will be System.DateTime.
  • parcoll[1].ParameterType System.String.
  • parcoll[0].Member and parcoll[1].Member are in fact references to pi itself

That’s a lot of nice information about our indexer, but what if we want to get a value from it? Consider the definition for GetValue:
That second parameter is used to get a value from the indexer.

So, how do we use it?

If you know valid keys that you can feed to the indexer, then you just do that (assuming that pi is the PropertyInfo for the indexer).
Or, if you prefer to use a DateTime: But what if you don’t know anything about the values contained by the indexer?
Well, unless you use attributes to decorate the indexer or the underlying storage field with specific custom information, you’re basically screwed.

To understand why, just consider how the indexer is implemented:
When you pass it a DateTime or a string as a parameter, it just passes it on to the getter/setter as the value.
What is done with that is up to the implementer.
If you want to maintain a collection of some kind, then you need to use private fields to hold the keys and their values.
.Net doesn’t store the values passed to the indexer or the values returned by it anywhere.

Consider how .Net doesn’t give you any means of iterating through the keys and values of an indexer.
You can’t do a for(;;) or a foreach() loop, you can’t even know how many items are maintained through the indexer by directly questioning it.
So, it certainly is normal that you cannot get anything out of the indexer without knowing exactly how to access it.

The Observer Effect

In many fields of science, the act of measuring something, whether it’s an electronic circuit or a psychological experiment, can actually influence the observed phenomenon.
This is unsurprisingly called the Observer Effect.

In .Net, Reflecting on object can be very much the same.

Consider the use of Reflection when it comes to getting information about an object:
You use metadata describing the object to get more meta data information about its members You can use that meta data to direcly query the state of an object.

If you limit yourself to getting metada, then no harm is done: you’re not querying the object instance itself but the metadata about its class.

If you start querying an actual object instance for its values then you are actively interacting with it.
In most cases, if you’re just getting the value of Fields or Properties defined as follow, then it’s fine:
Using reflection, we can get the values of both _meeting and Meeting without any side-effect to the object.

Now consider this:
Now what we’ve got here is a case of lazy loading or lazy initialization.
The consequence is that by querying the Collection property we’re actually creating it, with a potential for a lot of side-effects, like the change of other properties, here maybe related to opening the database connection for instance.

So, when getting values of the properties of an object instance, we can actually completely change its state.
Whether this is a concern or not really depends on what you’re trying to achieve: you may not be able to achieve being a passive observer using Reflection unless you know about the construction of the particular class you’re dealing with.
Using Attributes, you could give hints about which Property not to query and which Field to get instead. In our case, we could add a custom attribute like [ImplementedBy("_collection")] to our Collection property for instance.

If you want to do something generic, then you’re out of luck it and have to deal with that fact.
One possible way to minimize the effect would be to not query Properties that only have a getter and no setter, but that’s not a guarantee that all properties that implement a getter/setter are going to play nice.
Then there is also the -probably rarer- case of the Property that only has a setter.
Then there is also the case of the property getter that has some in-build security and will return different things depending on who’s calling…

All this seems pretty obvious once you understand the whole picture but it’s easy to get so impressed and dazzled by the power of Reflection that you don’t realise its natural limits.

7 comments June 13th, 2006

XPO: eXpress Persistent Objects

technology02.pngXPO is an Object Relational Mapping .Net product from Developer Express, a cool company designing cool tools. It’s a programming component whose job is to abstract access to database while allowing the developer to concentrate on a simple object-oriented interface instead.

Continue Reading 1 comment June 9th, 2006

You Aren’t Gonna Need It

technology02.pngRefactoring code is a necessary thing. Unless you work in some very specific environment where casual refactoring is not allowed (like in some safety-critical applications where the most minute change has to be pondered upon by teams and committees for weeks), you cannot code perfectly on the first shot. More often, you end-up reviewing code and making it clearer, merging parts that are too similar, removing what turned out not to be useful, cleaning up the names, moving things around, etc… there are dozen of refactoring cases that usually help remove the stink out of it.

Continue Reading Add comment June 1st, 2006

Next Posts


Most Recent Posts

Categories

Links

Posts by Month