Archive for the ‘Architecture’ Category

Rant: Moving Targets

A trip back in time.  In 2000 we were starting a large project.  The architecture was pretty standard stuff – database server, application server with business objects, semi-thin desktop client, featuring bi-directional communication between the clients and the server.  All were Windows native applications.  During the design phase the question about the inter-tier communication technology came up.  Back then, Windows DNA1 was the super-dee-duper stuff out there, praised by Microsoft as the prime guide to making distributed applications.  We decided to follow its wisdom, and built the communication layer on top of Distributed COM and COM+.  Oh, why, why?

(more…)

Posted by Nik on May 25th, 2009 No Comments

Coding Horrors: PHP’s strpos()

I decided to start a column where I will point my finger at repulsive coding and software engineering cases, which happened to be released to the unsuspecting public too hastily and / or without good thinking.  Someone will say it’s easy to criticize.  I don’t care.  Someone has to tell the plain facts and the sooner we raise our voices, and the louder, the better.  Demand for programmers has spawned numberless hordes of dim-witted script-scribblers, who claim themselves programmers, and who spill out hideous crap to the innocent audience out there.

The choice for my first rant is PHP’s function strpos().  Actually, PHP itself deserves a scorching rant, and maybe I will come to it eventually.  Right now, I will only focus on this specific function.

But what’s wrong with strpos()?  It is a simple routine, available in a basic library for virtually any language out there.  It merely checks the occurrence of a substring in a string.  And so it does.  Except for this very peculiar unique behavior, stated in the official documentation:

Returns the position as an integer. If needle is not found, strpos() will return boolean FALSE.

If you know that strings in PHP are zero-based and the frivolous nature of PHP when it comes to type-safety you will be already on your toes.  It is a realm for unspeakable bugs out there.  The warning in the official documentation, and the vast number of user comments in the official documentation page are a living proof of the disaster.  Please read these notes, really.  They would be hilarious, if the fact that something like this made it to the broad audience weren’t so sad.

I really wonder why the hell a simple function like this should possibly return values in more than one type, and for no apparent reason.  Just tell me the added value, please! 

Sadder, no one ever bothered to fix this ill behavior.  Yeah, I know compatibility will suffer.  And compatibility is important.  But when you have something that broken, hell, deprecate it!  State clearly that there is a replacement, and that this freak should no longer be used!  Instead, PHP guys got themselves busy with implementing half-assed OOP features in the language, and useless exception support.  Maybe I should just say “Go, Open Source!”.

Posted by Nik on December 23rd, 2008 2 Comments

Multiple Threads in the UI - Please, Don’t Do This at Home!

I was having a nice chat with a friend of mine - a .NET Framework and Windows Forms programmer, and he said:

“It is not possible to access and modify the contents of a window from a thread other than the main one of the application.  And this is how Windows is designed”.

Well, he was wrong.  His mistake comes obviously from the fact that Windows Forms in .NET Framework does not allow you to do so.  If you try to access a control (i.e. a window in Win32 terminology) from another thread, you get a slap on your hands with a nice exception.

In Win32 you definitely can modify from another thread the contents of a window, created in another one.  But believe me, you should not do it.

(more…)

Posted by Nik on August 5th, 2008 2 Comments

High Uptime with Ctrl+Alt+Del

Except for very rare cases, programmers always work with black boxes.  We rely on routines, libraries and frameworks, for which we usually know nothing but what the documentation says.  You have the OS, you have its API.  You may have a managed environment like Sun Java and Microsoft .NET Framework.  On top of that, you usually have a few frameworks and libraries.  The latter are likely to be white boxes, but are usually too intricate to easily trace issues inside.

These complex environments easily end up with various stability and performance-related issues for your applications.  Especially nasty are memory weaks, which are difficult, not to say impossible to trace and resolve.

Recently we had a strange experience with a project in Java.  The system was working quite properly for many weeks with good uptime, when the project was upgraded to Java 1.6.  After the upgrade performance would start declining after a few hours, the applications consuming all the memory available.  We spent days trying to find the weak spot in our code, but to no avail.  Then we reverted temporarily the project back to Java 1.5 and, what do you know, the problem was gone!  However, we had to use Java 1.6 for various purposes.

We ultimately came to a solution - servers, running our application, get restarted every couple of hours automatically, one by one, to ensure the availability of service.

This solution looks dirty, rude, and defies all good design and programming practices.  Unfortuantely, sometimes you cannot help it.  You cannot trace and fix a problem deep in Java’s runtime, or NET’s runtime, or one or another closed source library.

I myself felt quite uncomfortable with that solution, until I learned from a good source that the same practice is used by…  Google.  Yes, Google do restart their servers on a scheduled basis.

I am still not really happy with this approach, but knowing that the big and smart guys out there do it as well is at least some comfort.

Posted by Nik on May 22nd, 2008 1 Comment

Desktop vs. Web

One of these days a friend asked me over IM “why bother creating desktop applications, when you can do it as a web application”?  Then I avoided the question, knowing I can’t answer it in a single sentense.  The more I though of a short answer, the more I got myself weighing the pros and cos of the two, and finally the answer became - “because sometimes you have to.“  In this post I will share my reflections on the subject.

(more…)

Posted by Nik on May 8th, 2008 5 Comments