Monday, April 28, 2008

Introverted Programming: reading around

It may become quite depressing to read blogs, listening podcasts and work with professionals. You are constantly reminded that you should know that you don't know anything. It is comforting to know that others knew the same but knowing that is still disheartening, you know. You know what I mean.

What will make your life much more cheerful is keeping the state of blissful ignorance of this modern and ever changing stuff. What good can come out of taking on many emerging ideas? Half of them will be forgotten and buried within a short time and you'd never guess to avoid wasting your time on the doomed one. Being a mental coach potato will save your nerves, time and dignity. When technology will settle, one can always read "In 24 hours" or "Step by Step" book or wrestle a training course out of the management. Follow the job security guidance and you will be safe for the rest of your time.

Sunday, April 27, 2008

What's ya doin'?

That's interesting - I was reading an article with a notable headline Do you know what's leaking out of your browser? and got distracted by a pretty cool Microsoft Forefront Server flash commercial.

Purely accidentally I right-clicked the Flash and (for the first time in my life) chose "Settings...". What I have found is pretty scary. What in the world is this setting for?! What kind of pervert would not just enable the access but would like to keep it? Obviously the developer's goal was to make the "Allow" a first-choice action. So far the "Deny" is pre-selected but what if the future release will decide to "improve the customer experience" by knowing the customer more intimately? Or not even just do that but hide this setting so the user wouldn't worry. Do you know exactly how this feature works anyway? I don't.

Adobe must be aware of some controversy but doesn't seem to be too worried that people could find it disturbing. The support site casually lists the Setting Manager abilities:

To specify whether websites must ask your permission before using your camera or microphone, you use the Global Privacy Settings panel.

In other words "You can change colours, set updates frequency and, oh, by the way (yawn) - you can disagree with somebody spying on you. Mmmkey?"

Are you still worrying? Caaamon! They have the article that will comfort you: Can others use my webcam to spy on me?:

Ads and other applications that use the Flash Player cannot access your webcam without your explicit permission to do so.

That's a relief - people who delivering their advertising (unsolicited) to my house should be allowed to peep explicitly. It is just a spam, after all. But what if next time it will be an anti-terrorist campaign form the NSA? Hmm...

MSN Messenger can control your input devices too, but you have to turn it on in the first place - sic perform a conscious and explicit action. Development using "advance" (here: questionable) Messenger features is subject of registration and approval (most likely the government will obtain it pretty easy but at least it's a paper trail). Does the Adobe have this kind of regulation? Peer Guardian, people!

P.S. It's not like I suspect that you are doing something in front of your computer that you should be ashamed of, but still.... :)

    Friday, April 25, 2008

    The blog I most sorely miss

    It was a year already without the Kathy Sierra's blog - my temple of inspiration, taken away from me so untimely.

    I always envied her amusing charts(is there some kind of software for that?) and it was giving me ideas for my shamelessly secondary presentations (which people happened to like). The Zombie Function helped me to cope with the 8-hour "How we can increase meetings efficiency" department meeting. After Stop Your Presentation I got rid of freshly created slides so auditorium suffered less while I was expounding my ridiculously wrong (at the time!) version of the Continuous Integration algorithm. I did my fair share of Just-In-Case learning but seeing the problem recognized helped me with my therapy and I am clean now (seriously, sir, I am OK. Just the last Ruby book and I quit). Head First books are still amazing.

    Blog was good, pictures were good.

    So long.

    That's what I need...



    Interesting question: does it come stackable?


    Wednesday, April 23, 2008

    Enum.TryParse with .NET 3.5 extension methods

    Among other awesome features introduced in C# 3.0 are amazing extension methods. It looks like taking on board dynamic-language-oriented people like John Lam is starting to pay out for Microsoft. Now this Ruby-style can be done in C#:


    Woohoo! The feature is quite powerful and if you think about that - a little bit intimidating for a static-language mind. Ruby people will be definitely more comfortable with the idea of such a freedom.
    A release earlier - in .NET 2.0 - Microsoft gave us TryParse method, a good way to write cleaner code and improve performance avoiding costly Try-Catch blocks (judging by the messy code it was the last-minute addition, though). Sadly, for some reason the Enum type wasn't equipped with this useful feature. That means it is a good reason to try out some extensions...

    The following code is a first attempt, which is more in line with the traditional TryParse syntax:

    public static bool TryParse(this Enum theEnum, Type enumType, object value, out Enum result)
    result = theEnum;
    foreach (string item in Enum.GetNames(enumType))
    if (item.Equals(value))
    result = (Enum)Enum.Parse(enumType, value.ToString());
    return true;

    if (Enum.IsDefined(enumType, Convert.ChangeType(value, (Enum.GetUnderlyingType(enumType)))))
    result = (Enum)Enum.Parse(enumType, value.ToString());
    return true;
    return false;
    The usage is obvious:
    bool result = type.TryParse(typeof(StatusEnum), "SerialMonogamist", out parsedEnum);
    I avoided using a brute force approach with catching parsing errors - it defeats the whole purpose of having TryParse in the first place. The parse attempt is split into string and number parsing. The reason I didn't use the Enum.IsDefined(enumType, value) for strings is it will fail for a numeric values with type different from the enum's underlying type. I assumed that parsing Int16 or Int64 to the Int32-based enum should work flawlessly (mind the Overflow exception).

    A little bit different but more elegant code with generics:

    public static bool TryParse<T>(this T theEnum, object value, out T result)
    result = theEnum;
    foreach (string item in Enum.GetNames(typeof(T)))
    if (item.Equals(value))
    result = (T)Enum.Parse(typeof(T), value.ToString());
    return true;

    if (Enum.IsDefined(typeof(T), Convert.ChangeType(value, (Enum.GetUnderlyingType(typeof(T))))))
    result = (T)Enum.Parse(typeof(T), value.ToString());
    return true;
    return false;
    The method call looks cleaner (CLR is smart enough to deduce a proper signature even if generic type is omitted) but a bit less readable:
    bool result = theEnum.TryParse("HonestHusband", out parsedEnum);
    I've put some small test coverage project together and you can use it when trying to perfect my humble code. Good luck! Now it should be less reasons to hate C# generics :)

    Monday, April 21, 2008

    Adding XHTML Friends Network tags to your site

    Jut another Web 2.1 feature - XFN - XHTML Friends Network tagging. It may grow up into the some kind of Friendorati network, it may not. I like that it inserts nice tiny pictures and shows some personal relations with people you writing about. Doing that why do not do it with some standard?

    First - the CSS file (I think it belongs to the Phil Haack).

    Second - the linking standard: <a class="xfnRelationship" rel="guru" style="position: relative;" title="Just an example" href="" />

    And last but not least - nice images:

    friends Friends as a monolithic group
    colleague, co-worker Colleague who you have no idea about
    colleague-met Colleague who you met (hurray!)
    friend Friend (colleague in T-shirt)
    friend-met Friend who you met
    guru Perfect way to annoy people by marking them as minor geek celebritiesMartin Fowler) and to point out humbly that you met The guy
    spouse Spouse (that's right - handcuffs :)
    sweetheart If you use "spouse" tag, I would avoid publishing this one
    sweetheart-met Aggravating circumstance
    child Surprisingly there is no picture for a child-met tag
    parent I guess when Friendorati will unfold, families will use these tags to find their own
    XFN This blog is XFN-compliant

    Sunday, April 20, 2008

    They're watching us...

    There is some kind of weird genetic conspiracy present, I swear. I have those small, really small black flies in my office (fruit flies?), completely harmless non-disgusting (you can't really see more than a flying dot) things. My daughter always lives apple bits and grape brushes so they can survive. I practice catching them in the air and got already pretty good at this - I need just 1.25 strikes in average.

    What weird about all this (except the fact that I am blogging about it) is there is always just one fly in the air. Like there is some kind of kamikaze airfield and squadrons are waiting on the runway to take off one at the time when the comrade has fallen.

    Always. Just one. Immediately replaced by another. I am sure I killed it.

    And The Voice told me that it has noticed it too...

    Saturday, April 19, 2008

    Make it happen, stop the waste

    One of the most important mantras of the "Waste elimination": Make it work, Make it right, Make it fast. Following the word of Agile Development and Good Practices I couldn't help but notice that developers, freshly "awaken" to The Truth, have trouble to follow these three Commandments in the right order - including me. 
    The "work" and "right" balance is confusing. When you just got all the power of unit testing in your hands it is very easy to be carried away from "just enough" approach. I am not talking about "just-in-case" features here - only about over-polishing. People get stuck perfecting their code while the resulting package is stalled or kept unstable and managers couldn't resist but blame the Agile for an increased development time.

    Keeping "make it fast" the very last makes sense - until you will have had some statistics from a live application you very likely will waste time, fixing wrong parts which do not affect performance and potentially even missing a real performance hole. Developers can be are smart and experienced enough to anticipate and predict clogs but nevertheless it is a good idea to merely keep an eye on possible bottlenecks and put a minimal efforts eliminating them just for now.

    Oh, and you can reduce the time waste even outside the office - fast-forward through the boring parts of life.

    Thursday, April 17, 2008

    ASP.NET Dynamic Data

    It's all over the place and I won't even bother to link it. I only hope that after Scott Hanselman and Scott Guthrie will pass the architecture to a drone floor production line, it won't be handled to the same summer interns who screwed up built the VS 2005 SqlDataSource wizard ;).

    REST Web Services

    Bringing simplicity back to the Web computing. Automatic proxy generation grossly overcomplicated and "overcoupled" the simple idea of Web Services. The REST approach claims that it can help to resolve it with Resource Oriented Architecture vs. Service Oriented Architecture if latter is understood as a piling of strongly-typed RPC-like interfaces.

    I just started reading a "RESTful Web Services" book by Leonard Richardson and Sam Ruby (David Heinemeier Hansson has authored foreword). It published by O'Reilly so it should be quality reading. Examples are in Ruby, Python and Java but they are amazingly possible to read.

    Also a group of ThoughWorkers including Martin Fowler and Chris Stevenson just recorded a podcast about the REST architecture.

    Wednesday, April 16, 2008

    How to achieve 6000% performance loss using Regex

    RegularExpression namespace contains a RegexOptions enumeration with one of the values we will look closely on - RegexOptions.Compiled. MSDN, humble and terse as usual, briefly informs that this option compiles the expression to an assembly (no kidding!). And the given example treacherously shows you how exactly to create regular expression using this option. It won't hurt deep if you, like me, fearfully use regular expressions as a doomsday weapon, but any mass operation could get you in trouble. The way the sample code uses this option, the component performance may degrade drastically - up to 6000% for a just few hundred operations (if you interested, you can find the test details here).

    Just do not use RegexOptions.Compiled at all. Definitely not in the instance's Match method. This code is evil:

    Regex rex=new Regex(pattern, RegexOptions.Compiled);
    Match m = rex.Match(input);
    If you really, really want to compile the regular expression, use the static method instead:
    Match m=Regex.Match(input, pattern, RegexOptions.Compiled);
    Even then you have to keep in mind the Regex cache sizing (though you can control it through the Regex.CacheSize property) and by using the static method you give up the control over the regular expression lifetime.

    The noticeable advantage can be gained only if you do a massive processing - at least a thousand iterations for the same middle-complexity pattern. For a fewer iterations the "start" price will eat out the performance gain.

    Another way to speed up the regular expression is to use Regex.CompileToAssembly method but it will take more steps and expression should be recompiled when changes are made.

    The Coding Horror and MSDN blogged about this quite a while ago. It doesn' seem that .NET Framework SP fixed this problem as it was announced. Another MSDN article claims: "The 2.0 Regex class no longer caches parsed regular expressions created by Regex instance methods, it only caches regular expressions created by Regex static methods." Then obviously this behaviour shouldn't exist! I wasn't really determined but I wondered through the Regex code and apparently the static method creates the instance behind the scene and both approaches use the same path. So the issue could be with a memory management or a threading synchronization. Or it could be a setback from the dark side of the Force

    Oh, and I found this sample of a highly maintainable code in the Regex class:

    if ((options < RegexOptions.None) || ((((int)options) >> 10) != 0))

    Sunday, April 13, 2008

    A bad and ugly developer

    I started once my agile introduction session with the beloved fail often, fail early principle and as soon as I saw the reaction I couldn't help but emphasize the importance of being the worst and being the lazy for software craftsman. This never fails - now I've got their attention :)))

    Saturday, April 12, 2008

    FSDL - what's that?

    How do you get incentive to read and learn from a job posting?
    It should be a good encouraging posting. And what makes the posting good (aside of the "$105/hour")?

    It shouldn't list all the technologies which recruiter just googled while typing.
    It shouldn't require an "Expert knowledge of MS Sequal Server 2000-2008".
    It better not invite to the "fast-paced and dynamic environment" which is just a lacquer cover of a permanent disaster recovery death-marching.
    It should be vacancy from the visible innovative company.
    It should emphasize dedication to the certain development practices over the proficiency in the certain development tools.
    It should fit your skill set 100%.
    And nevertheless it should discourage you from applying by requiring an "excellent understanding of FSDL", even with the "best development practices".

    Done. I am all over the Internet, looking it up. I skipped "Fédération des Syndicats Dentaires Libéraux" and "Fantasy Sports Dynasty League" and dug into the Frogans Slide Description Language.

    One day I will see RoR requirement for a Senior .NET Developer and will finally find a willpower to move past the Pickaxe's Chapter 2.

    This is how smart companies could spread innovation even through a job board.

    CMS: migrating content

    A good article about migrating content to a new CMS. I will use this one as a migration document template. With quite extensive involvement in the CMS implementation during the last few projects I always had a trouble pursue clients to pay more attention to this important aspect. Unconsciously they expect that dev team will retype existing content somehow and always look surprised when a pretty new site has "Lorem ipsum" all over the place.

    Microsoft Virtual PC

    Just to make your life easier from the very beginning if your guest clock is screwed up:
    - Check the BIOS option for your Virtual PC and turn off Advanced Power management (VPC Help contains instructions on how to access BIOS).
    - Make a change to your .vmc file (it's just an XML). Under the section /integration/microsoft/ add the following text:

    <enabled type="boolean">true</enabled>
    This should prevent the Virtual PC from attempts to synchronize guest time with the host OS. Just keep in mind that VPC will again re-synchronize with the host OS on reboot unless there is previously saved state for this image.

    Friday, April 11, 2008

    Upcoming Toronto .NET user group session

    This Monday, April 14th, 2008 the Toronto .NET user group is running a session about SOA - SOA The Microsoft Way (sounds a little bit like perversion advertising). The interesting thing is - it should include a topic on ASP.NET Profiles. I wish I could attend to hear what new is happening with this screwed up feature but I have another very important meeting. I would love to hear comments from those who attended...

    Saturday, April 05, 2008

    Great generic lists sorting guide

    Implement sort and custom enumerator in generic list - I wish I had something like that last year when I've wasted a whole day investigating this topic (just to forget a few months later :)

    Friday, April 04, 2008


    © 2008-2013 Michael Goldobin. All rights reserved