Tagold blog

MIX09 videos

MIX conference is my favorite conference. It is always full of surprises, and it is not restricted to Microsoft technologies. It has been a habit for me to grab the links to MIX videos since MIX 07, and I'm keeping this habit for this year too :). Here is the source code to the Python program which grabs the links. It generates two files: mix09_links.txt which contain only the links so you can import them in your favorite text editor, and mix09_title.txt which contain the title of every session and its URL, so you know the title of the session.

from urllib import urlopen
import re
links_file = open('mix09_links.txt', 'w')
description_file = open('mix09_title.txt', 'w')
try:
    for i in range(16):
        url = 'http://videos.visitmix.com/MIX09/page%s' % (i+1)
        print url # for tracking
        s = urlopen(url).read()
        links = re.findall(r'<h2 class="title" title="(.*?)"><a href="/MIX09/(.*?)">.*?</a></h2>', s)
        for link in links:
            links_file.write('http://mschannel9.vo.msecnd.net/o9/mix/09/wmv-hq/%s.wmv\\n' % link[1].lower())
            description_file.write('%s\\nhttp://mschannel9.vo.msecnd.net/o9/mix/09/wmv-hq/%s.wmv\\n\\n' % (link[0].lower(), link[1]))
finally:
    links_file.close()
    description_file.close()

and for the lazy person, here are the two files: mix09_title.txt, mix09_links.txt

Python Arabic Book

A friend told me that there is an arabic book for Python, which is a translation of "Byte of Python", one of the most popular Python books. This is a good step toward popularizing Python, specially among children. Please go and download the arabic version. Read it, and tell the author about any enhancements that the book needs.

Help spread Firefox

https://affiliates.mozilla.org/

Stupid Type Systems - Innecessary Casting in C#

If List<> inherits IList<>, and MyIdentity inherits IIdentity, then why the heck the C# compiler cannot cast from List<MyIdentity> to IList<IIdentity>?????? It is the same, the compiler is not smart enough to know this. So to satisfy the compiler - acting as a good compiler slave - I have to write this

IList<IIdentity> returnList = new List<IIdentity>();
// A variable name cannot be stupider
foreach (var item in originalList)
{
    returnList.Add(item);
}
return returnList;

And people were wondering why dynamic languages takes less lines of code.

C#.Next, What it must NOT include?

There are some talks lately about the next version of C#, and what is should add. People has gone too far asking for new features, most notably the dynamic lookup

static void Main(string[] args)
{
    dynamic
    {
        object myDynamicObject = GetDynamicObject();
        myDynamicObject.SomeMethod();
        // call a method
        myDynamicObject.someString = "value";
        // Set a field
        myDynamicObject[0] = 25;
        // Access an indexer
    }
}

The above looks ridiculous to me. C# is statically-typed language, and it should stay like this. Trying to add dynamic typing to it - even if it was optional - is stupid. For me, a language must establish a few basic concept and stick to them, not try to satisfy every one out there. C# has incomplete features. These should be completed first before adding any new features. Take type inference as an example. You cannot return anonymous types from methods, because you don't know their names. It should allow something like

public anonymous MyMethod(string email)
{
    return from user in Users
    where user.Email = email
    select new { FullName = user.FirstName + " " + user.LastName };
}

It can also add named parameters, and default values for them, just like Python. It can be supported indirectly now by passing anonymous types, but complete support for them would be better. Dynamic languages are not just about dynamic lookup, and supporting broken dynamic lookup - just like the above mentioned example - is going to be, really, broken. What about dynamically adding new methods? What about using making a class as a proxy, say, for a web service? What about object-specific members - members which exists for a specific member? It can get very complex, and the only known way to allow dynamic features is to make your language dynamic. The beauty of the CLR, is allowing different languages to run and inter-operate. Unfortunately, it was designed with static typing in mind, which appears clearly in the BCL design. I wish the DLR team has these limitations in mind so they address them better, specially the importance of providing libraries which fits the dynamic languages way of doing things. One language is not enough, and one language which tries to fit all purposes is going to be very complex - just like C++. The solution is learning different languages and using the appropriate one when it fits, and integrating them when you need to.

RSS feeds for youtube

Everyone uses youtube to see his favorite videos. Most of the time, you need to subscribe to a certain user’s feed using RSS. Unfortunately, the 'Subscribe' buttons subscribes using their own notification system, and you have to be a member to subscribe.

Contrary to popular beliefs, youtube provides RSS feeds, but they are hidden. You can subscribe to a user's feed using

http://gdata.youtube.com/feeds/base/users/mtayseer/uploads

And to a certain tag using

http://gdata.youtube.com/feeds/base/videos/-/egypt

The question is: why did they hide this?

The Django book is released

Finally, the long-awaited Django book is released under the GNU Free Documentation license. Everybody can learn and suggest enhancements to the book or Django. Does Django runs with IronPython? Yes, it runs on IPCE, but I don't think that everything runs well, because the different DBMS drivers are not ported to IronPython yet.

Open Komodo is released

ActiveState, the leader in dynamic languages development tools, has released the OpenKomodo intiative. OpenKomodo is targeted at creating an open source IDE for dynamic languages and the web, based on ActiveState Komodo IDE (which is proprietary).

The First IronPython Book

Manning Publishing is working on the first book about IronPython, called IronPython in Action. You can download the first chapter for free. They have provided the chapters 2, 3 and 4 under their early access program.

Blame yourself before anybody else

Here at Silverkey, we use LLBLGen Pro as our ORM. One of the nicest features of it is prefetching related entities, so if you have a "CompanyEntity", you can tell it to fetch all related "Employee Entity". This makes our jobs easier, except when it doesn't!!! Today I had a few bugs with LLBL: Trying to save an entity threw NullReferenceException deeply from inside LLBL code. Even though it worked in some circumstances, it didn't work on others. It was easy to blame LLBL, since it was the source of the exception. So instead of letting LLBL load the related entities, I loaded them myself. This worked OK for sometime, but it started to through the same exception again. So it really appeard that the problem was not what I thought. First, I recognized two things

  1. It happens in with a certain class, so this class was the source of the problem
  2. It happens only when I changed the objects. If I didn't change them, it works OK.

The code for saving was like this

using (Transaction transaction = new Transaction(System.Data.IsolationLevel.ReadUncommitted, "SaveCompany"))
{
    try
    {
        // Save related entities
        foreach (Employee employee in CompanyEmployees)
        {
            employee.Transaction = transaction;
            employee.Save();
        }

        // Save modified fields
        _entity.Transaction = transaction;
        _entity.Save();

        transaction.Commit();
    }
    catch
    {
        transaction.Rollback();
        throw;
    }
 }

Trying to access any member of the entity now will throw a NullReferenceException. Though the entity is not null, it will try to connect to the database using the connection of the closed transaction, which will throw the NullReferenceException. It should be like this

using (Transaction transaction = new Transaction(System.Data.IsolationLevel.ReadUncommitted, "SaveCompany"))
{
    try
    {
        // Save related entities
        foreach (Employee employee in CompanyEmployees)
        {
            employee.Transaction = transaction;
            employee.Save();
        }

        // Save modified fields
        _entity.Transaction = transaction;
        _entity.Save();

        transaction.Commit();
    }
    catch
    {
        transaction.Rollback();
        throw;
    }
    finally
    {
        _entity.Transaction = null;
    }
 }

The lessons learnt: It's easy to blame the tools you use, but probably it is your fault

© 2014 Mohammad Tayseer

Theme by Anders NorenUp ↑