Tao of the Machine

Programming, Python, my projects, card games, books, music, Zoids, bettas, manga, cool stuff, and whatever comes to mind.

Nowak's Observation

If the code isn't elegant, it's probably wrong.

emoticon:smile

(Which implies that most of my code is ready for a major overhaul, by the way...)

Posted by Hans "presuming you're using a language that allows for elegant programming" Nowak on 2003-11-21 01:04:11   {link}
Categories: programming

Snarls of defiance

Time for another depressed rant... after a few weeks of negotiations with people who were supposedly looking for a Python/Zope programmer, they have now decided to look at a different product. In C#, of all languages.

The number of job opportunities involving C#/.NET is steadily growing. However, I don't exactly like C# or .NET. I really don't know why people use this "new" technology at all. Granted, I am not an expert, but what I've seen so far from it is not promising. It's slow, eats a lot of memory, it's difficult to use, and uses crippled languages. On top of that, there's hardly anything new about it; it's just Microsoft's answer to Java. Of course, I secretly do know why people use it -- because Microsoft touts it as the technology of the future, and that's enough for hordes of people to start using it. And if tomorrow Microsoft comes with a new technology called "Flapdoodle", those same hordes will start using that. It doesn't matter if it's any good, it doesn't matter if there are better products out there; it's enough that it has "Microsoft" on it, so managers will get a warm fuzzy feeling and can rely on the fact that they have a vast pool of programmers at their disposal.

Some people think that a Microsoft product is necessarily bad. Or even that a popular product is necessarily bad. I am not one of those people. But I mean, hell, just *look* at C#/.NET. It's not good, and it doesn't introduce anything new, but it's backed by a large company, so people use it, and nobody cares if the clock is set back 5 or 10 years. The same is true for Java, really. And, just like all games absolutely have to be 3D these days, all business apps absolutely have to be web-based. Whether a web application is appropriate for the problem at hand is irrelevant; it's just "what we do" these days, and alternatives are seldom considered.

I don't know what it is with programming these days, but I certainly don't like it anymore. Like the industrial revolution made workers disposable, the current developments make programmers disposable. I haven't been around for that long, but I remember that you had to be smart and creative to be a decent programmer. I'm not saying that those days are all gone now, but the new "technologies" certainly aren't rewarding this type of developer. Rather, they are rewarding conformists, making cookie-cutter programs in languages that won't let you do what you want, often written for people who want to know as little as possible about computers.

There are voices that claim that dynamic languages will be big in 5-10 years. I hope they're right, but currently it's still very hard to get a job like that, especially around here, a rural area where people don't even know what a computer is. Sometimes I think I should give up trying to get a programming job or even a computer-related job. I might as well go back to accountancy, there's about as much creativity there as in today's industrial programming.

The bottom line is, that programming isn't fun anymore. Sure, I can have fun with Python or Lisp or other dynamic languages, and at the same time get things done, fast, producing readable, reusable, maintainable, elegant code. Cool for those late-night hacking sessions, and maybe to get some whuffie. It won't land me a job though.

Some people may be of the opinion that I should just put up or shut up. If Java, C++ and .NET are in high demand, then use that, and get a job. If you want to use an "exotic" language, then don't complain if you don't find anything. Fair enough... but... I didn't enter software development for the money. I am not a corporate drone who will use whatever excuse of a language/tool people will throw at him. I started programming at age 12, because it was fun and creative. Later I was able to get paid for it. But I still think programming should generally be fun and creative. If not, then I might as well go flip burgers, or go back to an accounting office (which bored me to tears, literally).

Is there a way to "fix" the industry? Will software become like a manufactured product, with little or no creativity involved? Is it worth doing your own thing, because you are convinced it's the right thing to do, even if it goes against popular opinion? I still believe so... but the uphill battle becomes a bit difficult if you cannot pay your bills anymore.

*breathes*

Posted by Hans Nowak on 2003-11-20 14:24:53   {link}
Categories: general

Fun with the Dutch language

(via Ned Batchelder) Joho the Blog: The Dream Comes True. This post talks about "English" words with 4 consecutive vowels. (I say "English" because apparently it has to borrow heavily from other languages: sequoia, hawaiian, etc.)

Although Dutch and English are closely related, the way they create new words is very different. In English, you often just put them one after another: "computer" and "screen" make "computer screen". Dutch, on the other hand, glues words together: "auto" + "verkoper" => "autoverkoper" (car salesman). In that respect, it is more like German.

One peculiarity is that there really is no limit to the length of the words you can make this way. A far-fetched, but not unrealistic example would be:

  • arbeid (work)
  • ongeschikt (unsuitable)
  • ongeschiktheid ("unsuitability", is that a word anyway?)
  • so, the lack of ability to work would be arbeidsongeschiktheid
  • in the Netherlands, it is (or was) common to get a compensation if you are unable to work due to accident or illness. Such a compensation is called an uitkering. So, you would get an arbeidsongeschiktheidsuitkering.
  • an official organization is also called an instantie. So, the organization that hands out the aforementioned compensation would be an arbeidsongeschiktheidsuitkeringsinstantie.

Nobody actually uses that word in real life, but it *is* real, and so is the organization that it describes. I used to work for one...

Also note that Dutch often glues words together with an -s- in the middle. That's why it's uitkeringsinstantie, rather than uitkeringinstantie. Other combinations do not grow this -s-. There are virtually no rules for this, which adds to the language being difficult to learn. (To foreigners, *and* to the Dutch themselves...)

As for strings of consecutive vowels, Dutch has a few nice words, like papegaaieëieren (parrot eggs) and koeieuier (a cow's udder). However, with the introduction of the Nieuwe Spelling in 1995, it seems that these aren't valid anymore. (Yes, one of the favorite pastimes of the Dutch is to change the spelling around every N years, to make things extra confusing.)

The Nieuwe Spelling didn't affect the long words with consecutive consonants, though: the infamous angstschreeuw (cry of fear) is still valid, and so is slechtstschrijvend (worst-writing? writing the worst?).

But if you think this is bad, there are languages (like Slovenian and Serbo-Croatian) that have words with no vowels at all. Dutch is really no match for them... ^_^

Posted by Hans Nowak on 2003-11-20 10:28:04   {link}
Categories: general, Nederland

Short manga descriptions (1)

This category is long overdue, so without further ado, short descriptions of 10 mangas. Most/all of these mangas can be found on the Net, if you know where to look.

1. Midori No Hibi: Tough guy cannot get a girlfriend. An unknown power turns his right hand (!) into one. This is a bit of a... complication.

2. Anima: In a fantasy world, some people have traits of certain animals... birds, bats, fish, bears, for example. These people are called +anima (yes, with the "+" in front of it) and are welcomed by some, persecuted by others.

3. Chobits: (Licensed in the US) In a maybe not-so future world, the so-called persocons are very popular. These are robots that look and act very much like humans (mostly girls), and can be used as servants, data banks, etc. A lonely guy wants one, cannot afford it, but then finds a forsaken persocon in the trash. (How could it be otherwise?) It turns out that this is not a regular persocon...

4. Bokko: In ancient China, there was a clan of great fighters and strategists. Over time, the clan becomes corrupt. One man, Kakuri, leaves for this reason, and goes on to defend a city against a vast army. ... Quite an interesting manga, but not for the weak of stomach.

5. Break Shot: There are many mangas about sports, and this one focuses on billiards. Not extremely interesting; high school boy is a natural talent and wins some tournaments, etc. The billiard techniques don't seem very realistic either.

6. Detective Conan: A very talented young detective is turned into a little boy because of some strange potion. In spite of being little, he doesn't give up his detective work, determined to find the guys who gave him the potion, and to somehow return to his previous state. Of course, a 7-year-old isn't quite believable as an investigator, so he lives with his former girlfriend (who doesn't know his identity) and her father, who also happens to be a detective (although much less talented). So he goes on to solve many cases, almost all of which are credited to the lesser detective.

This is one of those strange mangas that seem childish, aimed at children, but that have a considerable amount of blood and gore.

7. Full Metal Alchemist: In a strange world, magic and technology go hand in hand. There are "alchemists", who can conjure things, turn part of themselves into metal, etc. Mildly interesting.

8. Hunter x Hunter: A bit similar to #6, in that it seems childish, but has lots of gore in some places. 1) A kid wants to be a "hunter", the meaning of which isn't really explained, but it's a kind of special agent. Candidates have to do a gruesome test; after the test, there are some quests, among which is "Greed Island", a computer game that you can enter physically.

9. A Record of Lodoss War: D&D-style fantasy done by mangaka. Not bad.

10. Kirara: A girl dies in a car accident on the way to her wedding. Her ghost comes back, but somehow ends up in the past -- her husband-to-be is in junior high, and, to complicate matters, so is she (or rather, a younger version of her).

1) This is a strange feature of quite a few mangas. Many American comics show a lot of gore too, but they're usually not childish. Mangas also tend to be very, and often overly, explicit in what they show when it comes to violence. You'd think the human body is a high-pressure vessel full of blood, ready to explode at the slightest cut. :-/

Posted by Hans Nowak on 2003-11-19 23:04:02   {link}
Categories: manga

len(x) vs x.__len__()

This seemingly simple problem had me stumped for a little while. Let's say you have a class that functions as a wrapper around another object. Something like:

class P:
    def __init__(self, obj):
        self.obj = obj

Now, is there a simple way to delegate all 1) method calls to an instance of P, to the object it wraps? (Simple, as opposed to defining all these methods yourself.) Including magic methods? Certainly. The solution is:

class P:
    def __init__(self, x):
        self.obj = x
    def __getattr__(self, name):
        return getattr(self.obj, name)

p = P("hello")

print p.__len__()        # 5
print p.__getitem__(0)   # h
print len(p)             # 5, again
print p[0]               # he

q = P([1, 2, 3])
q.append(4)
print q                  # [1, 2, 3, 4]

I have known the __getattr__ trick for years, so why didn't I see this sooner? Because I made the mistake of writing:

class P(object):

Try it, and watch the behavior change. Sure, p.__len__() still works, just as expected. But for some reason, len(p) doesn't. You'd think that len(p) would call p.__len__ internally, but apparently that is not the case, or at least not the whole story.

After looking around a bit in the c.l.py archives, it seems that for new-style classes, len() relies on slots in the type object, and apparently doesn't fall back on __getattr__. Sigh. I admire the attempt to unify types and classes, but old-style classes seemed so much simpler and more predictable... emoticon:confused

By the way, this version of __getattr__ gives a sneak peek of what's going on behind the scenes, and might be interesting for newbies:

    def __getattr__(self, name):
        print "__getattr__:", name
        return getattr(self.obj, name)

The script then generates this output:

__getattr__: __len__
5
__getattr__: __getitem__
h
__getattr__: __len__
5
__getattr__: __getslice__
he
__getattr__: append
__getattr__: __str__
[1, 2, 3, 4]

1) Or at least most methods. Note that my example doesn't catch __setattr__, for example.

Posted by Hans Nowak on 2003-11-17 23:47:13   {link}
Categories: Python

The lisping snake

The time has come to look at integration of Python code with the Lisp interpreter. It's far from complete, but this time seems as good as any.

The main problem is the difference in types. The Lisp interpreter currently uses several special objects: LispInteger, Pair, LispSpecialAtom (for t and nil), LispIdentifier. There should be more types soon, like a LispString, etc. Some of these, like the string and the integer, should be trivial to translate to Python. Others are more of a challenge. There is already code to convert Lisp lists to Python lists and vice versa, but what about other Python types, like dicts? Classes and instances? File objects?

Let's look at some (hypothetical, for the moment) example code.

(setq os (py-import 'os))
(funcall (py-getattr os 'path 'join) "foo" "bar")
=> "foo\bar"

Two conversion problems occur here: once when we call os.path.join, because the LispStrings "foo" and "bar" need to be converted to Python strings; and once when Lisp gets the return value back, in this case a Python string that needs to be converted to a LispString. This is all fairly simple. But now consider:

(setq f (funcall (py-builtin open) "myfile.txt" "r"))
(setq poplib (py-import 'poplib))
(setq pop (funcall (py-getattr poplib 'POP3) "host"))

The Lisp interpreter now has several objects: a file object, a module, and a POP3 instance. How to represent these in Lisp? I wonder if it's best to use a thin wrapper class, call it PythonObject. PythonObjects can then be manipulated by selected "py-" functions. (For example, a file object wouldn't have dedicated Lisp functions to deal with it, but you would be able to use its methods and Python functions through the py- interface.) This would work, but we would still need an extra step or two to convert numbers and strings and such.

Thoughts welcome.

Posted by Hans Nowak on 2003-11-15 20:29:39   {link}
Categories: Python, Lisp

--
Generated by Firedrop2.