Pages tagged as ‘rant’

How super() in Python3 works and why it’s retarded

I’m deeply sorry for the title of that post, but I hope that gives the topic the awareness I think it should get. In the last weeks something remarkable happened in the Python3 sources: self kinda became implicit. Not in function definitions, but in super calls. But not only self: also the class passed to super. That’s remarkable because it means that the language shifts into a completely different direction.

super was rarely used in the past, mainly because it was weird to use. In the most common use case the current class and the current instance where passed to it, and the super typed returned looked up the parent methods on the MRO for you. It was useful for multiple inheritance and mixin classes that don’t know their parent but confusing for many.

The main problem with replacing super(Foo, self).bar() with something like super.bar() is that self is explicit and the class (in that case Foo) can’t be determined by the caller. Furthermore the Python principle was always against functions doing stack introspection to find the caller. There are few examples in the stdlib or builtins that do some sort of caller introspection. Those are the special functions vars(), locals(), globals(), and __import__ and some functions in the inspect module. Four functions, and all of them do nothing more than getting the current frame and accessing the dict of locals or globals. What super in current Python 3 builds does goes way beyond that.

Currently if super is called without arguments Python performs these steps:

  • getting the current frame of the caller as well as the code object.
  • looking at “co_argcount” to make sure there is a first argument, if there is one it gets the object from the “f_localsplus” array on the frame object. This is btw an attribute not accessible from the Python code.
  • then it checks the “co_freevars” of the code object and iterates over all of them to check if one of them is “__class__” (because accessing __class__ in Python 3 creates a special bytecode that returns the class the function was defined in).
  • It it can’t find the __class__ in there it dies. How does __class__ end up there? Apparently the compiler checks if “super” or “__class__” is accessed. That’s right. It breaks if you alias super to another name and try to call that name.
  • Once it has that information it uses that as two first arguments. The class and the reference to self

I’m sorry, but that’s a very, very bad idea. It’s way more magical than anything we’ve had in Python in the past and just doesn’t fit into the language. We do have an explicit self in methods and we do not have methods. Our methods are functions, just that a descriptor puts a method object around it to pass the self as first arguments. That’s an incredible cool thing and makes things very simple and non-magical. Breaking that principle by coming up with an automatic super harms the whole thing a lot. Defs in classes are not completely differently from defs in the global scope or within another def.

Another odd thing is that Python 3 starts keeping information on the C Layer we can’t access from within Python which is a shame. Super is one example — it’s currently impossible to implement that from within Python. The other good example in Python 3 are methods. They don’t have a descriptor that wraps them if they are accessed via their classes. This as such is not a problem as you can call them the same (just that you can call them with completely different receivers now) but it becomes a problem if some of the functions are marked as staticmethods. Then they look completely the same when looking at them from a classes perspective:

>>> class C:
...  normal = lambda x: None
...  static = staticmethod(lambda x: None)
... 
>>> type(C.normal) is type(C.static)
True
>>> C.normal
<function <lambda> at 0×4da150>

As far as I can see a documentation tool has no chance to keep them apart even though they are completely different on an instance:

>>> type(C().normal) is type(C().static)
False
>>> C().normal
<bound method C.<lambda> of <__main__.C object at 0×4dbcf0>>
>>> C().static
<function <lambda> at 0×4da198>

While I was quite happy with the Python 3 progress so far, these two things are a major, major step into the wrong direction. I really hope that will be rolled back. If there is need for an automatic super self has to go away and __class__ become a free variable all the time or super a keyword. Everything else is too magical and more magical.

Update: I posted the subject on the python-dev mailing list.

Use OS X you Git!

April 3rd, 2008

So rails is ditching trac and subversion in favour of git and lighthouse. Additionally they won’t host git themselves but rely on github. Keeping in mind that the preferred development environment called OS X + TextMate, rails is now kneedeep in closed source land. Something I could care less about as I’m thankfully not using rails or any rails powered application. But what hit me was the discussion attached to that blog post. Apparently there are quite a few pissed of Windows users left. Gosh, they still exist!

David “Fuck You” Hansson could really care less as he stated in the past “that he would have a hard time hiring a programmer who was still on Windows”. Skimming through the blog you can see enough mac users telling the windows crowd to switch and I think you can nowhere find as many mac users as in the rails community. He really did a great job converting proprietary windows developers into even more proprietary Mac users. There are some really great quotes in that blog:

The proper move is to stop using Windows for development of RoR apps.

or

Windows users, please stop complaining about others using the right tool for their jobs and just start doing the same.

You can get rid of this shit and use something serious. Really. Others are doing it and nobody ever looks back. So you can do it, too.

Yeah stupid folks. Why in god’s name are you still using windows, that proprietary crap from redmond. DDH your Führer already told you to use OS X, do so and don’t ask questions. Interestingly though is that Linus himself is not that happy of OS X (the link goes to another post, I was refering to the reply, but that one is good too) as their filesystem handling is beyond broken, at least for git’s requirements.

So I’m asking. What exactly makes OS X better than Windows? Nicer hardware? I would count that as a major disadvantage of OS X as you’re bound to vendor. The Apple support here is very weak (where weakhere is Austria) as far as I’ve noticed. Sending a notebook in for two weeks for a single broken key on the keyboard is ridiculous. Additionally you’re paying a lot of money for it. I know that the design is the selling point of Apple computers but that doesn’t mean all PCs are looking bad. A Thinkpad or one of the more expensive Sony Notebook next to an Macbook Pro and it’s pretty hard to decide what looks better. Especially in terms of quality. My Macbook Pro is a bit more than half a year old and on the silver plastic you can spot where the palms of my hands are as the color is chipping off there. But even if the hardware was the selling point you could use other operating systems on it.

There is TextMate (which was the main reason why I personally bought one) but as it turns out, it looks better in the screencasts than in real world. If you’re used to a different editor it’s hard to switch. I tried multiple times and every once in a while i was cursing why :vs didn’t work out. Together with the braindead keyboard layout on the apple computers (probably an issue you only have on German macs) gives you a ridiculous feeling. When I switch between Windows and OS X (which happens quite a lot recently) I permanently mix things up. Windows after OS X locks me out every once in a while while writing mails (as alt+l is windows+l on a windows pc, which apparently is equivalent to “lock workstation”). The other way round I close my mailer as alt gr + q (which on a German layout gives you the at symbol) is command + q on a mac, which means “close application”. Can’t count the times I killed my vim/thunderbird that way.

One point where OS X shines is font rendering. I think for artists OS X is a reasonable good choice as operating system. The system itself has a good understanding of fonts and all that but for me as developer the rendering freaks me out. In a regular gvim with bright fonts on dark backgrounds it’s especially anonying as everything looks bold and there is no visible difference between bold and nobold. I know that Windows was flamed in the past dozens of times for aligning the fonts on the pixel raster but quite frankly, I prefer that over the OS X way. It might be true that Windows will block the 300dpi screen era for another ten years or so, but so will Linux and OS X. Most of the websites or applications still depend on pixel values, and even if web designers will switch to the SVG or better vector formats, you can’t ignore the old websites. So the problems with high resolution screens are clearly not the windows font rendering.
Beside that I want to point out recent ubuntu releases have got real good font rendering thanks to the turner patches for subpixel rendering and with some additional configuration and better fonts you get everything from the OS X to Windows ClearType like rendering.

But the real problem with OS X is that it tries to be Windows and Linux at the same time and fails miserably. For me as linux user the most important detail of linux is missing: the package manager. But at the same time the beloved setup.exes are missing. Dmgs with application bundles are a nice thing in theory but they don’t work out that well. There are neither uninstallation tools norr do they provide a user experience that makes sense. The OS X mouse behavior is ridiculous and installing applications via drag/drop is just crazy. The first thing I did when I got my Mac was dragging the Firefox out of the DMG into the Dock. Then I noticed that I want to have it in the applications too and draged it there. What happened? I deleted it. The same way I managed to delete a file when moving from my harddrive to a network share. I lost the wireless connection and the file was lost. That’s ridiculous and must never ever happen on an operating system. Application management on OS X is stupid anyways. To fully remove an application from your computer you better buy a shareware that is better as that. Seems like most functionallity you want to have on a computer comes as third party application on OS X.

And why in god’s name is there no cut/paste of files in the finder? I don’t want to start ranting about the finder as I think it’s OS X weakest point anyways but that’s a stupid limitation. Drag/Drop works but Cut/Paste not? Some 1337 terminal hackery later I got Cut/Paste support in Finder but then I had to notice why it’s not enabled by default. Because the Apple implementation of this simple but useful feature is broken. If you cut a file, and cut another, not only the latter is cut. No! The first one is moved to the trash. WTF? Not even Nautilus does that wrong, and Nautilus does tons of things wrong right now.

Then OS X is inconsistent. “:” in the Finder is “/” in the terminal and the other way round. Fortunately you don’t see location bars anywhere otherwise you would notice that. Unfortunately there are no location bars so you end up using the mouse all the time. Speaking of the broken mouse: mousing on OS X files like mousing through meter deep mud. Just google for “OS X mouse” and the first hit is “mouse acceleration problem” :-/. Oh and yes, you can fix that. Either buy a shareware or hack together an application that uses a deprecated interface in the IOkit. After one week of OS X mousing my hand hurt, something I don’t have on any other operating system, no matter how hard I try. I ended up using the touchpad of my Macbook as the mouse acceleration is better there.

But back to application management for a second as that goes back to the original topic: development environment. On ubuntu you have that cool GNU userland I’m used to. Not only that, you also have a kick-ass package manager that keeps my whole system up to date. On OS X you have a BSD userland which is irritating if you’re used to GNU tools. Many applications that seems to work out of the box on ubuntu and with a cygwin installation on windows too, work completely different on OS X. Like python. Why? Because of OS X bundles, frameworks and all that fancy stuff that you have to face when developing on OS X. For example on Tiger the python executable is in “/System/Library/Frameworks/Python.framework/Versions/2.3/bin/python2.3″ and the standard library in “/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages”. A non-framework Python comes via port which is installed to “/opt/local/bin/python2.3″. The cool thing: it’s a regular python executable like you know it from Linux or Windows. The problem? It’s not in a framework, so no wxPython for you. What frameworks do? No clue man. It’s a bundle, that’s what I know. Quite frankly I don’t want to know what’s the fucking difference, it’s just annoying. Teeworlds for example has a broken mouse behavior when started from a bundle. Why? No clue. But outside of a bundle it works. I won’t argue that it’s broken, it probably comes from the old Next times. But as windows or Linux user it’s irritating. Windows is easy to understand, linux is not much more complicated once you groked where the stuff is located, OS X is just irritating.

And the biggest problem of all for me: It’s slow. Freaking slow. Slower than ubuntu on my old notebook which was a 2GHz dothan with only 512 MB RAM. And GTK is slow, very slow. All kinds of gvims I tried on OS X are so slow that you can see the refreshing while scrolling, especially if more complex highlighting is activated. My python interpreter does something 0.3 seconds every startup, so does ruby. The network is slower here too. I don’t know if it’s the Wireless LAN chip or OS X in general, but if I start up my old notebook and the OS X one, transfering files is a lot faster. And by lot I mean I haven’t benchmarked it, but I can see the difference.

Then let’s come to security. Quite frankly I have no idea how secure the system really is, but the number of security updates is annoying. While I think it’s cool that they are patched, you’re downloading something like 300MB security updates per month I think and most of them require a reboot. Feels a lot like windows, just that I don’t have to reboot windows when a Windows Media Player update is installed.

But what’s the conclusion? It’s certainly not that OS X sucks. If you like it, feel free to use it. But telling other people that they are stupid because they can’t see the ingeniousness of all Apple products is just ignorant. OS X is just another proprietary operating system, and not the solution for all of your problems. It has it’s problems too and it doesn’t have any real advantages over Windows beside a nicer design and nicer application design and the fact that it has such a low userbase that you’re not the target of malware authors. At least not currently, let’s see if that changes the next four years. With such a homogeneous environment it will become a nice target for attacks at least.

Oh. And I don’t think that linux on the desktop will be the solution either. As long as patents exist or the kernel doesn’t allow binary drivers and KDE and GNOME people can’t settle on one architecture and HIG linux on the desktop is on the best way to become the most sucking operating system on the desktop for the regular user. But for developers? A good choice!

So let’s conclude: every OS sucks. And OS X is no exception. So don’t judge users by their prefered operating system / desktop environment. And don’t tell them to use something else just because you’re too lazy to adapt.

How not to do XML

Imagine for the moment there was a PHP blog software that has the ability to dump the blog posts into some sort of extended RSS 2 feed and import from there later and probably from a different installation. That’s nice, XML is a flexible format and RSS allows extensions via namespaces. Even better, there are XML parsers for all major programming languages and from python working with XML is especially cool because of lxml and element tree. But there is a problem with that…

…that XML, is not XML. It’s called WordPress eXtended RSS (WXR) but it’s not XML? And why in god’s name did nobody notice so far? I mean, WordPress must have an importer for that.

Why it’s not XML? It has XML syntax, XML namespace declarations but what doesn’t it have? A doctype. What’s the problem? It’s referencing HTML entities! So step one for parsing: inject an inline DTD that defines those entities. Great fun isn’t it? Then it parses. I was happy and finished my work. That XML doesn’t have HTML entities is something PHP developers probably don’t know and their parser isn’t resolving any entities during the parsing process. Or worse, their XML parser expands HTML entites.

But it’s worse! I loaded another dump that happened to have some broken HTML in comments (could happen, does happen, thanks broken trackback support). What happens next? THE XML DOESN’T PARSE ANY MORE! Why? Because comments are neither escaped nor marked as CDATA. I wonder why, especially because it’s so much easier to handle embedded HTML/XHTML for dumping as cdata and not XML, especially if you are working with PHP.

But WordPress was able to import that…. so I looked at their parser…. WORDPRESS PARSES THAT WXR FILE USING REGULAR EXPRESSIONS!!! Argharhgarhghargh. That’s not XML what you are doing there, that’s nothing. WordPress can’t even parse it’s own file if you bind the WordPress exporter namespace to a different prefix! WordPress can’t handle it’s own file if you replace their CDATA foobar against properly escaped stuff. Dammit!

I can’t even write a proper exporter using XML tools because what my XML tools generate is not compatible to WordPress. And what tops it all?

Reading that in the #wordpress channel:

<nickname_deleted> why does it matter what wp's xml format has flaws?
                   adapt your importer to the flaws

ARGHARGHARGHARGH. and then the webpage says:

WordPress is a state-of-the-art semantic personal publishing platform with a focus on aesthetics, web standards, and usability.

Without further comments… I lost my faith into standards that moment. Wait a second, I lost it earlier. Still sad.

How To Kill a Game

A Söldner ScreenshotAbout four years ago I stumbled about a promising game called “Söldner — Secret Wars” in a magazine. It was an online tactical shooter and featured a fully destroyable environment, more than one hundred weapons I think, many different vehicles, aircrafts and much more. It was hyped back then in the German gaming community, probably because it was developed by a German studio called “Wings”. Long before the game was released the developers updated their online dairy about recent changes in the code, about what the game will feature and a lot more. Unfortunately they decided to release their game by Jowood, an Austrian publisher.

Why was that bad? Back then Jowood once again had financial problems and they tried to solve it by convincing the sharedholders that their next game will be a major success. They set an totally unachievable release date and the developer team at wings had to live with that. It went that far that they had to design the box are themselves even though the game was still buggy. The game was released and was still buggy. I think GameStar even omitted the rating because they wanted to wait for the first patch.

A Söldner ScreenshotHowever the game sold pretty well the first two weeks despite the bad quality of the release version and the bad reviews. It even outsold the greatest competitor at that time (Joint Operations). I was one of the early adopters and I loved to play it. Owning a bad ISDN connection at that time it was terrible lagging, especially because their netcode was a catastrophe. Still, it was great fun and the destructible environment was great. Not only that, the game was somewhat revolutionary. It was the first online game I played with an (albeit bad configured) physics engine, it used python as scripting language, it had one big map that was generated from satellite images with detailed areas where the fights took place. You could buy yourself a jet and leave the map and visit all off Siberia. Not like Battlefield Vietnam where you hit the borders of the map with a jet after roughly 15 seconds. Dammit, it would still be fun and I bet it would have been bug-less by now.

The community that appeared around that game was incredible. A wiki appeared, people tried to hack around on the code to get extra features into the game, unofficial mods appeared. There was even a project that wanted to create a mod for a medieval setting. Hell, it was great back then. But instead of fixing the bugs Jowood forced the developers to start an addon project…

A Söldner ScreenshotShortly after the addon was finished the company developing that game was liquidated. The developers lost their job and the community continued developing the closed code. The group around “project zero” continued maintaining the game until that group broke apart and the gEasy team took over the work. The gEasy team was basically just the project zero team without the founder. They did an tremendous job but Jowood once again destroyed everything. They refused to pay their bills, then the gEasy team took down the master server and Ivan Ertlov appeared on the scene. He managed to resolve the problems between Jowood and gEasy team to some extend that the master server was up and running again.

Who’s that Ivan Ertlov? Very good question indeed and I personally don’t know the full story but from what I’ve read on the forums he is called Johann Ertl and owns a company that sells guerrilla marketing and similar services. And he worked for Jowood and apparently still does, at least he is listed as community manager in the official forums. He also brought up the topic “Open Sourcing” the code after it was clear that there will be no Söldner 2. A sequel was actually under consideration and gEasy started working on that till the day they took down the master server because there was no payment by Jowood. But since some time there was no feedback any more and an open source version is somewhat unlikely.

A Söldner ScreenshotFrankly I don’t know if Jowood payed or didn’t. What Jowood did was destroying the game by forcing an early release, forcing an addon when the code was still unfinished, fired the developers. Even worse: they are telling their shareholders that everything is working perfectly and that they are releasing dozens of new games. Hell, they released Spellforce 1 and 2 which both are awesome games (just happen to have the worst copy protection ever designed), the Gothic games (the 3rd part was buggy like Söldner but probably also because Jowood forced an early release). Jowood however claims that they payed and that gEasy was lying. Who is running the portal now? Apparently Ivan’s company.

So why am I blogging about all that? Mainly because I think that topic hasn’t gained a lot of attraction. I stopped playing that game after Wings was liquidated. For one because I switched to ubuntu and on the other hand because my Söldner plugin (an in-game Winamp controller) disappeared when the forum was updated to reflect the new ownership. All the old topics where either deleted or made unreadable when Wings was closed down.

A Söldner ScreenshotWhat nobody really notices is that the game had a tremendous German community. Hell, some of them even took over the development! If Jowood would have noticed that earlier they could have made that game the freaking best online shooter available at that time. But because of their small horizon they just thought about their next quarter and decided to do what shareholders want, not what players want. But not only Jowood is to blame but the root of all evil in that case.

Krawall supported Jowood in the beginning to host their initial infrastructure needed for the game. Unfortunately the server software needed Direct X to run properly which caused a lot of trouble. One the one hand it was hard to get multiple servers running on one machine do to the way the server was designed, on the other hand you needed a windows server to host games. And because the initial code base was that buggy all the magazines flamed to game. Despite the good sales figures it magazines never wrote about the game and forced an early dead which harmed the community. A release six month later, a linux server from the beginning, no addon and good press coverage would have avoided all the problems this game was facing in the past. And it would have saved Wings, the game they were working on beside Söldner, and in the end of course Jowood which would have had a lot less bad press.

Especially the gamers hate Jowood for their buggy products now and I doubt that they will be able to continue to ignore all the user feedback and push alpha versions as release versions for much longer.

I’m especially interested what the Wings guys are doing now. I know that former Wings community manager and sound designed Marc Olbertz is working at Blizzard but that’s about it. It’s sad what happened there and that Austrian’s only game publisher caused all that.

Funky fact: The communication with the master server worked via jabber, the physics engine was ODE and the scripting language was Python. All open source technologies I never saw in a commercial game before :-)

Disclaimer: the information on this page should be accurate but it’s hard to say for sure because there is few information about this topic actually available. If you are able to understand German you can find some information in this thread on the Söldner forums: Söldner ein Abenteuer mit ungewissem Ausgang

Django’s Problems and Why 2.0 is a Bad Idea

December 12th, 2007

I stumbled about this thread on django-developers which proposes calling the Django 1.0 release Django 2.0. One the one hand version numbers say nothing. Just take Wine or Trac as two examples that are already very stable but still below the magical 1.0 release. Open Source software often takes some time until a 1.0 is released and that’s perfectly fine. However skipping a version number is purely a marketing trick IMO. Just think of Java which currently names 1.6 Java 6 whereas 1.4 still was Java 2.

With django it looks like the plan is to keep up with Rails which went to 2.0 a few days ago. While I love to see that django kicks ass and it’s moving toward a stable release I have a bad feeling naming it 2.0. Because there is currently a huge gap between rails and django unfortunately. Rails has gained really good integrated migrations, REST webservices, a debugger and many other things django is still lacking.

Django makes an incredible good framework if you get your problem into the use case of django. But as soon as you break out of it and need something that goes beyond what’s possible in django you wish you have chosen something else. The django ORM is far from optimal, the admin rocks but as soon as the number of users exceeds 10.000 users it’s impossible to use it (chose yourself in a dropdown of 50.000 users …) or becomes utterly complex. Complex data models also look awkward in the admin or become too complicated to manage. And if you want to stick with the admin you cannot replace the user model. Now what do you do if you have a forum and want to count the posts? Use a UserProfile module? And how do you want to display a list of users sorted by their number of posts?

Yes there are ways to hack around it but the more complex the application becomes the more you of django’s strengths become obsolete. The application I’m working on right now now is only using two more contrib modules. The auth and the admin, and it looks like we have to drop them too, due to the limitations. All applications in that project hack around ORM limitations, we have an incredible number of recreated base middlewares, we have to monkey patch the request object to hack in subdomain support.

I was talking with David Cramer from curse gaming about some of the issues and he told me that they have forked django at a given point and patched the ORM. The django template engine was replaced by Jinja (our application does the same) and they are caching the hell out of the application to scale it. Bryan McLemore from the curse team told me some time ago that some pages have up to 30 queries on a page.

I don’t want to say that django fails in what it’s doing. But it’s far from 2.0.

One Code Styleguide Per Programming Language Is Not Silly

November 4th, 2007

I love Python but there are things where I look at Ruby or Java and want to switch right away. What do have Ruby and Java in common? Nearly all of their libraries follow the same function/method/class naming conventions. foo_bar_baz in Ruby and fooBarBaz in Java. In Python there we have that PEP8 thing, but not even the standard library is PEP8 compatible. Many people tell me that not having the same naming guidelines for all libraries is a problem. I would argue that different naming guidelines among different libraries is a bigger problem than different indentation etc.

The reason for that is that in Python we often subclass clases from other libraries. Just take the threading module as example. Now we are forced to use different names in your own libraries/code too. Now one has to start thinking about the names of methods. (Is is get_some_foo() or some_foo or getSomeFoo()). It becomes even worse if you use mixin classes with one styleguide in a subclass of a class with a different one. I’ve seen people using the `DictMixin` in classes with camel case method names. But even the lowercase names are not coherent. Is it iteritems or iter_items? This example might be answered easily because I never saw iter_items but I saw countless occurrences of both getcurrentuser and get_current_user.

The more different name styles in a code the more I have to use dir(), help(), external documentation or the ipython source introspection. And that’s not the fault of the library developers, it starts with the python language itself. The internal types are all lowercase although they are classes. It’s true that this is because of backwards compatibility (when dict, list and others were just functions) but a big language change like Python3 would have made changing some of those names possible.

</rant>

Working hard on a bad Image huh?

Oh apple, what are you doing. Yes, I’m quite mad about you recently. Additionally to the funny problems I had last week I now have two more. The scroll “wheel” of my myghty mouse broke and my TFT thinks contrast is for sissies. The contrast problem is btw fixable by plugging in an external monitor and rotating it clockwise and counter clockwise from the display control panel.

But what really, really makes me mad is how closed their stack is. Although their operating system is based on an open source kernel nearly all of the other stuff is closed like nothing else. I was a happy iPod user the last years but I will be the last one i buy. Now where they have a checksum in their stupid binary crap library they call iTunes DB which makes it impossible to access it with other tools I’m just not interested in it any more…

cogitations driven by wordpress