TurboGear

by Zef Hemel

On my still continuing quest for a perfect Python on Rails (a.k.a. an easy-to-use web framework for Python), TurboGear is my latest find. TurboGear is not a framework written from scratch, but rather a composite of a couple Python components:

* Kid, for Zope-like templates.
* Mochikit, for AJAX stuff on the browser side.
* SQLObject, a nice object-oriented database wrapper. Very close to what I developed myself as Adia (with the same idea of extracting SQL CREATE statements from the model defined in your Python code).
* Cherrypy for the controller side.

I’ve been playing with this framework today (there’s a nice 20 minute tutorial on how to create a simple Wiki, also available as screencast). I played with the example a little and without much effort added a couple of fields to the database and to the forms. It all seems nice. And I like the fact that it uses already existing components which are developed by different people. This way not everything has to be maintained by one person or one team of people. It comes with a built-in webserver, so testing is very simple.

TurboGear requires Python 2.4, you can get find more information and downloads here.

I gather that some people got the impression that LINQ is just reinventing SQL, while actually it goes beyond normal SQL. It’s not just for database access, actually that’s just one application of it: DLinq. Well, of course this depends on how you define a database. Because, let’s face it, LINQ is just a way to query data sources. Whether that’s a traditional database (SQL Server, MySQL, Oracle), an in-memory data structure or even an XML document (XLinq ladies and gentlemen).

LINQ brings the declarative expressiveness of SQL to any data source. If you got a big array with customers in memory, you sometimes just want a sorted list of their names. In SQL that’s really easy to write, but since you got this data in an array, it becomes harder to extract this data. It’s doable, but isn’t simply writing something like from customer in customers orderby customer.name select name and be done with it, more convenient? Don’t start posting examples of Python or Ruby code in which this can be written shorter. Just trust me that there are many occasions where the SQL-like LINQ is a convenient and readable solution.

XLinq is actually more than a way to access XML data easily. It’s a whole XML API that greatly simplifies the previous one. It offers a much simpler way to build XML trees for example. This is especially true if you use VB9, in which you can do this:

Dim BillTo = <billTo country="US">
      <name>Robert Smith</name>
      <street>8 Oak Avenue</street>
      <city>Old Town</city>
      <state>PA</state>
      <zip>95819</zip>
   </billTo>

But even if LINQ was just language-integrated SQL, that would still be a good thing. This would allow for syntax checking of SQL queries at compile time, a nice thing to have.

I’ve been away from reading tech weblogs for a while and a lot has been happening, apparently. Most notably, I think, is Microsoft’s LINQ project. LINQ stands for Language Integrated Query.

Here is the MSDN site, and here’s an explanation of what it is and does. What it comes down to is that it integrates SQL-like querying into the programming language (C# and VB.NET in this case). So that you can do stuff like this:

string[] names = { "Burke", "Connor", "Frank", "Everett",
                   "Albert", "George", "Harris", "David" };
var query = from item in names
            orderby item
            group item by item.Length into lengthGroups
            orderby lengthGroups.Key descending
            select lengthGroups;

If you look at this piece of code you’ll notice a few things. What’s that var type thing doing there, that looks kind-of JavaScript-ish. Then of course you’ll notice the new query syntax: from something in something, select this and that, orderby this. This syntax, however, is just syntactic sugar. This:

var query1 = from p in people
             where p.Age > 20
             orderby p.Age descending, p.Name
             select new {
                 p.Name, Senior = p.Age > 30, p.CanCode
             };

Is exactly the same as writing this:

var query1 = people.Where(p => p.Age > 20)
                   .OrderByDescending(p => p.Age)
                   .ThenBy(p => p.Name)
                   .Select(p => new {
                       p.Name,
                       Senior = p.Age > 30,
                       p.CanCode
                   });

There’s another new thing here, the something => bla > 20 and the new { … } notation. But there’s more. Extension methods for example. What’s all this stuff and why do we need it?

Well, the C# 3.0 team needed all this new stuff to make LINQ a comfortable working environment, to make it usable, and I think that’s great. I’m all for LINQ. I’m not so sure, however, about the side effect: language features.

Programmers had to struggle with C++ for many years. It was hard, its syntax is complex and hard to understand. Luckily Java came around. It cleaned up the language and made programming simple again. Then C# 1.0 came along, it added a couple features to the Java stack, but nothing major. Then C# 2.0 (and Java 5) came along, those added a major new feature: generics. For a lot of people generics are still hard to grasp.

And now C# comes with stuff like anonymous methods, anonymous types, lambda functions which can be interpreted in two ways, depending on how you store them, and extension methods. I must say I love those features and I can appreciate them. But I’m a weird guy, I like getting into the dark corners of language syntax and semantics. Not many people are like me. They just want to learn a language quickly and get things done.

I wonder if C# 3.0 doesn’t make things too hard. C# is statically typed, which has its advantages, but also makes things a lot more complicated as you will see if you read the LINQ article. The kind of stuff queries return are usually of some generic type, which can be very complex. This is where the var keyword comes in. It basically tells the compiler “I’m lost, you figure it out” (and it saves typing). At compile time, the var keyword is replaced with the type of what the expression assigned to it returns.

So, here’s my question. How far are we willing to drag on the huge beast that is a static language? If you look at a language like Ruby or Python, they already got most of the features that C# had to add to make this happen, but in Ruby and Python they’re not half as complicated. In Ruby you could already add methods to existing classes, anonymous methods (in Ruby known as blocks) are something a Ruby programmer breathes, anonymous types? var keyword? generics? Don’t need those.

If we want to carry on in the direction that LINQ is heading, and I think we should, shouldn’t we sacrifice this one thing: static languages? This makes things a lot simpler in many ways, and the sacrifice may just be worth it.

Computers: Avoid

by Zef Hemel

Hi, if you’re reading this and just started finding your way in the (to you still) amazing world of computers: stop while you still can. Seriously, the deeper you dig, the more crap you’ll dig up.

Sorry about that. I’m back! It has been a while since my last post on this blog. There are a couple of reasons for this. First of which is that I had other things to do. As you know, I just moved into Dublin and was getting to know it; figure out where the good stores are. My parents came over for 4 days and we explored more of the city together. The other is that I’ve been fighting with the internet connection we have here, and we haven’t been on speaking terms for a while.

If you live in Dublin, you undoubtedly heard of this marvelous thing called RipWave. Which is a device that allows you to wirelessly connect to the internet, you don’t need a phone line or cable to use it. It uses a radio signal (I think). Problem is that it’s crap. The speed is supposed to be 512kbit up/512kbit down, but I’m very happy if I can get it up to 20kbyte/s downstream (using a killer download accelerator), usually it’s like 2-4kbyte/s. The signal is bad, sometimes you don’t have a connection at all, sometimes it’s fast, sometimes it’s slow. It’s basically a phone line connection on steroids, but without the steroids and with the phone line half broken.

On top of the privilege of being allowed to use RipWave, I bought a wireless router when I came to live here. It was a D-Link one. At first it would crash after a couple hours — only way to bring it back up was to restart it. I found new firmware on the D-Link website and put that on. Then it didn’t connect to the internet at all. I tried changing every setting in the whole damn thing — nothing. I downgraded the firmware to an older version. This time it seemed to work. However the router rebooted itself sometimes. Sometimes every couple of hours, which would be bearable, but sometimes every few minutes. Why!? Why can’t a device like that not just work?

I searched around the internet, and apparently there are a lot more people having similar problems with this device. They advice to install older versions of the firmware. I tried about 5 versions: no results (it wouldn’t even start up normally with most). How can a company get away with such a bad product?

Anyway, yesterday I returned the router. The guy in the shop said they sold about thirty of those and never heard any complaints. Whatever. I bought a cheap Linksys router somewhere else and it seems to work fine. If I ignore the crap internet connection I’m fairly happy. We requested a smart telecom internet connection which is supposed to be 2mbit down/128kbit up. But it can take a couple of weeks before we get it.

Anyway, try to avoid this stuff if you can. Computers (and all things related to it) are nothing but trouble.

Dublin

by Zef Hemel

Well, for almost a week now I’m living in Dublin and I like it so far. Until recently I lived with my parents and this is the first time that I’m living on my own. And it’s in a city where I’ve never been before, in a city I’ve never been before, speaking a language that I’ve never… ok, well I’ve spoken English before. But still, it’s kind of a big change.

I live in the south of Dublin, about 7-8 minutes from Aungier Street, very nearby St. Patrick’s Cathedral (I can hear its bells ring pretty well). This is all very close to the city center, so that’s pretty great. But there’s people everywhere. Always. When I go to the shop I walk through streets filled with cars, busses and people walking the sidewalk. That never used to be the case in the neighborhood of Groningen where I used to live. It was fairly quiet there. I never lived so close near a city center before. It’s stinky… but I can overcome that.

A couple of days ago I walked around the Trinity College campus, compared to the amount of people walking around it, it’s fairly quiet inside, although it appears to be one of the city’s primary tourist attraction (and how many people can say they study at a very popular tourist attraction?). The campus looks great. I made a couple of pictures of Dublin and Trinity College:


See the pictures.

I live in an apartment building called Newmarket square. I share an apartment with a Russian guy named Vassili. He has the bedroom and I got the bedroom-turned living room. The kitchen is in the same room as the living room, which is too bad. Because if Vassili has to cook, he practically is doing that in my room. But usually he’s hardly home. Just this week had some problem with his working visa, so he has been home all week. Usually he’d be working and taking classes from 7 in the morning ’till 9 in the evening, also eating there. So I won’t see him much.


Some pictures of my room/house

I got an Irish mobile phone number now, you can reach me at +353 85 1587524, or just plain 085 1587524 if you’re calling from within Ireland.

My classes start at October 10th, so that’s still almost a month away. My parents are flying in tonight and will be spending a couple of days here.

Off to Dublin Soon

by Zef Hemel

Just a couple more days and I’ll leave to study and live in Dublin, Ireland for a year. My airplane leaves at 7 p.m. next Tuesday evening (September 6th). I’m looking forward to it.

I also managed to get a room there, which is quite a relief. It seems to be a nice room quite close to the center of the city. And it’s fairly affordable in Dublin terms (Dublin is the most expensive city in Europe).

My studies at Trinity College start at October 10th, and there’s a fresher’s week before that. But I’ll have a couple of weeks to get to know Dublin, a city where I’ve never been before.

This week I’m doing my farewell tour. Tuesday I visited one set of grand parents, yesterday I had a goodbye party with friends, today I visited my current (or actually, former) university for the last time (and said goodbye to the people there), tomorrow I’m visiting my other grandparents and this Sunday is my aunt’s birthday party where I’ll be saying goodbye to even more people. It’s kind of strange to do all these things for the last time. For a year at least.

Looking forward to going there!