Ivan Krivyakov's Blog

Premature optimization is the root of all evil

October 29, 2010

Possible WPF Bug: Input Field with Invalid Input Not Highlighted On Startup

I am building a WPF demo, and I wanted to include validation. My scenario cannot be simpler: I show a form to create a shipment, and when you click “Save” button it checks the inputs and screams if something is wrong by marking appropriate fields with red. The application uses MVVM.

Finding meaningful WPF examples for this scenario proved to be surprisingly hard.

Apparently, WPF validation does not support this scenario easily. There is no easy way to say: hey, can you please run validation for the whole form now? One can probably look at INotifyDataErrorInfo, but I did not go that far.

So, OK, I am fine with validating things as you go. But then if the form comes up with an empty value for “City” and this is invalid, the “City” field should be immediately highlighted as red, no?

Well, it seems to work fine in .NET 4. In .NET 3.5 SP1, however, the value will become red only after the first change. Validation functions (IDataErrorInfo.Item["City"]) gets called on form load, and I return “Please enter City”, but the validation framework seems to ignore it. If I just go ahead and hit “Save”, validation framework won’t report any errors.

Occasionally, though, it may also work under .NET 3.5SP1, I have an app that seems to be working just fine. I built a simple repro case that works fine under .NET 4, but fails to validate under .NET 3.5SP1. I could not, however, build a reliable repro case that works under .NET 3.5SP1.

This very simple thing – to validate a form on “GO”, proved to be too elusive, and I definitely don’t like enumerating my property names as strings in some indexer.

October 25, 2010

TFS and the KISS principle

How do you copy an SVN label to a folder?

svn serverpath/tags/label destdir

How do you copy a TFS label to a folder? Watch my hands:

mkdir destdir
cd destdir
tf workspace /server:mytfsserver /new myworkspace /noprompt
tf workfold /map tfspath .
tf get tfspath /version:Llabel /recursive
tf workspace /delete myworkspace /noprompt
cd ..

Why such a striking difference? SVN is built around “all parameters are explicit” principle. Export this to that. End of story. TFS on the other hand uses multiple levels of “invisible” server stored settings.

1. The tf get command does not accept the destination. It takes the destination folder from a list of mappings from a TFS workspace.

2. It does not take workspace name as a parameter either (well, it may, but then you can’t use label syntax). Instead, it relies on some mysterious algorithm to find “implicit” or “current” workspace. I could not find exact description of this algorithm during casual browsing of MSDN, but it seems to derive current workspace from current directory — another hidden and unreliable dependency.

3. If current workspace cannot be determined, tf just exists, proudly saying something like “unable to determine workspace”.

4. There is no explicit way to “switch to” a workspace. You just create it and it becomes tied to the directory current at the time of creation. Or something like that. Not really fully documented (or I could not find where). Then you need to add any mappings you want to it.

5. When you are done, don’t forget to delete your workspace, so the global namespace is not polluted with temporary stuff. I would not even ask what happens if some other process on the same machine tries to get the same project into another directory at the same time.

6. tf workspace /delete command would ask are you really sure to delete the thing. You can give it a /noprompt switch to shut up, but this switch is not documented at the time of writing (MSDN documentation).

7. tf workspace /new is even more interesting – by default it would open A GUI DIALOG!. Dear Microsoft people! Opening GUI dialogs from command line tools is a bad, bad, bad idea. Command line tools tend to run in batch modes on computers that nobody looks at. There will be no one there to enter the data and click “OK”. Mixing the GUI world and the command line world is inconvenient at best.

Bottom line: this is the first line I had to deal with the tf utility and I am appalled by the design of the whole thing. You can finally get what you need, but it is very, very painful.

October 21, 2010

On the State of Hotel Industry in Israel

In recent days I was doing some serious hotel booking in Israel, and I must say I am appalled by the state of the hotel industry there. I am quite intimately familiar with the cost of living and real estate prices in that country, and in comparison the hotel prices are not just high, their are through the roof.

First of all, if you planned to spend less than $100 a night, forget about it, in any part of the country. You might get some apartments for $70 or so, but their owners are usually very reluctant to rent for only a couple of days. And I am talking November, which is considered “off season”.

Second of all, the hotels are concentrated in a few key areas, mostly around beaches. There are absolutely no (detectable) hotels in small towns like Rishon Le-Zion, Yokneam, or Givatayim. Nearest hotel to the Ben Gurion airport that charges below $150 is located in downtown Tel-Aviv and does not have parking.

The concept of cheap motels in suburbia does not exist. To give you some comparison: in New Jersey if all you need is a place to sleep and you don’t insist on being within walking from New York Times Square, you can get a room which is not a total dump at $60-70 a night, or even lower if you catch a good deal. A basic 1 bedroom apartment in a safe neighborhood in the Greater New York area would cost $1200-$1500, which makes it $40-50 a night on average. So, the price of low end (but still decent) hotels is only slightly above the price of a good (not luxury) apartment. Of course, a hotel room is much smaller than an apartment of equivalent value, but this is not the point.

In Israel a decent low-end hotel which is not a total dump and has a parking would cost at least $150 in urban areas and around $120 in the middle of nowhere. It does not matter whether you call them, e-mail them, use Hebrew language sites, or English ones. The price would be the same through all sources.

At the same time, a decent apartment costs no more than $1000 a month, and much less in the middle of nowhere, unless we are talking about beach-front property rented to tourists. But even then anything that is not a huge villa would go below $2000 a month. This makes $33-$66 a day, which is 3-5 times lower than a price of a basic livable hotel. This disparity is even higher in suburban and rural areas.

Something must be seriously wrong there. I think, two factors play key role here. The American hotel market, especially in suburban/rural areas, is designed for Americans – tourists and businessmen. We don’t have crowds of very rich Japanese, German, or Martian visitors coming to Fairfield, NJ. Israeli market is clearly oriented towards foreign tourists who allegedly have more money than the locals, and prefer to hang out in Jerusalem, or on a beach in a big city, and pretty much nowhere else. This is why there are no cheap hotels in more remote areas – nobody would use them. This unfortunately makes Israel look like a third world country, not very far away from the Bahamas or Dominican Republic.

The second factor is limited competition. Given the cost of living and real estate, hotel prices could be much lower. I am not sure what is the reason for low competition. On may blame the level of corruption and taxes. It may be difficult to open an hotel without “connections”, and if you do, you risk it being immediately shut down for a random violation of some 200 year old Turkish law you never heard of.

The thing is, when the British came they continued to use the laws of the Ottoman Empire with some modifications, and when Israel was established, it inherited the Mandate laws, albeit most of them were later superseded by new legislation.

Whatever the reason, Israel easily outprices places like Moscow, St. Petersburg and most American cities, and hotel prices there approach those in Manhattan.

October 15, 2010

One Hour Iteration, or How Much Agile is Too Much

Agile programming is called “agile” because it provides faster feedback cycle than traditional methods.

In the traditional world, first you write a functional specification document. Then you have the users “sign off” on it, which takes weeks or even months. Then go away into your coding cave, and within a couple of months (or years) produce a shiny product only to discover that anything that can be misunderstood was misunderstood. And the users go “yes, we may have said we need it half a year ago, but this is not what we want”.

There is, however, an opposite side of the spectrum: instant gratification development. This kind of development breeds in highly dynamic business environments such as hedge funds, where Excel Macro is king, and yesterday’s data is well forgotten past.

This development “process” has only two basic rules:

1. Any task must be completed and demoed within several hours (ideally), or 1-2 days. If it takes longer than 2 days, it is too long.

2. There can be only one pending goal at any particular time, and it must be achieved as quickly as possible (see #1). Anything that does not directly serve the current goal is a waste of time.

These rules produce a number of corollaries:

C1. Test plans are a waste of time. They would use old data that by definition is a pile of garbage. We can’t afford to spend our time testing useless things. We must do business.

C2. Putting requirements in writing is a waste of time. Anyone with a half brain can remember the single outstanding requirement. Other requirements are either already implemented, or don’t matter.

C3. Bug tracking is a waste of time. Anyone with a half brain can remember the single outstanding bug. Other bugs are either already fixed, or don’t matter.

C4. Refactoring is a major waste of time. It is dangerous and delays accomplishment of the current goal.

C5. Any programming construct fancier than a “for” loop is scary and it is probably a waste of time.

C6. Anyone who says that hacking the software till 11PM on Friday night is unnecessary and dangerous, is a lazy renegade, and must be dealt with accordingly.

This is as “agile” as it gets. This kind of environment is ideal for doing trades or producing prototypes, but it is not suitable for producing working production software. The tragedy is that the business owners are sometimes so entrenched in this mentality, that they resist any attempts to change it. Under these circumstances, developers have three choices, each worse than the other:

- shut up, submit to the process and be blamed for all failures
- speak up, be blamed for low morale and ultimately get fired
- walk away

But whatever the choice, please don’t call it agile :)