Musings of an anonymous geek

July 24, 2007

Looking for the Twitter Kool-aid

Filed under: Technology — m0j0 @ 7:09 am

So, *another* person asked if I’m “on twitter”, so I went and got on there. Whatever. As far as I can see, it’s a useless distraction, but people seem to be obsessed with it. I’m convinced that these people don’t have any real work to do.

Once you sign up, the only thing you can really do is send email to your friends to recruit them. How egomaniacal do you have to be to send email to all of your friends saying “hey, come and see what I’m doing at any moment in the day – because I *know* you’re interested in that”…..?

Maybe there’s some hidden useful purpose that I haven’t found yet. I’ve at least set up the IM gateway so I never have to go to the web page. More on this as I dig.  In the meantime, if you’re doing something with twitter that’s actually useful, please let us all in on it!


July 21, 2007

Where does that Python DB handle go?

Filed under: Python,Scripting,Technology — m0j0 @ 11:33 am

UPDATE: Well, that didn’t take long. My solution works, but there’s a better way. Create the connection in main(), and create separate *cursors* for each Host. Cursors are cheap, and you reuse the connection. Thanks to Brend on #python ( for the enlightenment.

Python has been a wonderful language to get to know so far. However, one thing I didn’t really miss about Java and C++ were the decisions that are kind of forced upon you when you have various objects working together in a program, controlled by code in a “main” function. Here’s one decision I was faced with that took more thinking than I’d like to admit to make.

I have a class, we’ll call it “Host”. Of course, there are also methods for that class, like Host.record_name() and Host.update_mac() and the like. These methods are just wrappers around some SQL.

I also have, of course, a “main” function, which is where we create instances of Host and call the methods we need on the objects.

The question now is, where exactly should we create the handle to the database? There would appear to be 4 choices (without getting overly absurd):

  1. In main() and then pass the handle to the class’s ‘init()’
  2. In main(), but pass the handle to each method of any object that needs it.
  3. In Host.init(), so methods can refer to it without creating it themselves.
  4. Inside the individual methods themselves.

I chose option #3. The only part that bothers me about it is that a new “Host” is created, and then destroyed, for each of a couple thousand lines of a file. Hence, there is the overhead of setting up and tearing down a database connection a couple thousand times every time this script is run. I’m not sure (yet) what the cost of this will be.

Certainly, the cost will be less than if I did it for each *method* that was called, so that insures that option 4 is probably not the right way to go.

The semantics involved in creating the handle in main() and passing it to Host’s init seemed less than straightforward to me. It seemed there was the potential for main to pass in a copy of the handle at object instantiation time, have the object be destroyed when it’s done doing its work, taking the connection with it, and then main still thinks it’s a useful handle and tries to pass it to the next object that needs to be created. If that’s not the case, then what is the status of this thing that main created? What will happen if main tries to pass it to another object?

Of course, this problem would also exist if we passed it to each method that needed it. It would also be more overhead, and it would seem needlessly draconian, especially since *every* method of the object in question would need it.

If I’ve misunderstood something, or have made a poor choice, feel free to clarify/flame/enlighten me in the comments 🙂

Technorati Tags: , , , , , , ,

Social Bookmarks:

July 19, 2007

Why you should write: common myths debunked

Filed under: Big Ideas,Productivity,Python,Technology — m0j0 @ 8:38 am

I give a talk that advocates writing. I do this because I owe my career to people who wrote down what they knew and made it available in one form or another; either free on a web site, or in a book that I bought.

When I started editing, one of my jobs was to encourage people to write for whatever publication I was working for at the time. I’m now Editor in Chief for Python Magazine, and I’m back in the role of encouraging people to make their knowledge available for others (including me!)

Python Magazine is going well in terms of authorship, but with all of the Python coders out there, I should be overwhelmed with article proposals! When I talk to people who clearly know what they’re doing, or are doing something cool, and ask them to write, the responses are, by now, pretty predictable – and mostly based on misunderstandings, myths, and other untruths. I thought I’d take a few minutes to address the most common ones here:

“I can’t write”

The king of reasons for not writing is this one. The problem isn’t really that the person literally cannot write. The problem is twofold: first, the person has absolutely zero confidence in their ability to write. Second, the person doesn’t understand what an editor is supposed to be doing to earn his keep.

I’ll tackle the second part of the problem first: an “editor” is not some gray haired guy with a cigar screaming about deadlines and rejecting 99% of everything that hits his desk. An editor is someone who works *with* writers. It’s not *supposed* to be an adversarial relationship – and it *is* supposed to be a relationship. It’s supposed to be a working relationship where the writer tries to relay concepts in a way that the *editor* can understand. In return, the editor asks questions, pokes, prods, and makes suggestions that help morph the article into something the *readers* will understand.

Further, the relationship may begin before a draft is ever submitted. I’ve helped lots of writers develop their *abstracts*, so that by the time they sit down to write the article, they have some clear idea where they’re headed. And the word is *helped*, not *dictated*. It’s not me passing back a marked-up copy and saying “fix this and do that”. It’s me writing back saying “I’m a little confused in this part, how does this work?” or “can you provide a use case in which someone would find this useful?”

Finally, this excuse may have foundations in a perceived language barrier. If English is not your first language, you may feel like you’ll never get published in an English publication. Not true. If you have the knowledge, and can write enough English to relay the concepts, a good editor will work with you to develop it into something suitable for publication. It may take a bit more time, but that’s usually not a problem. In technical publishing, knowledge trumps prose every day of the week.

“I don’t know what to write about”

One day while you’re coding, just stop. Stop and take stock of what you’re working on. In all likelihood, there’s an article in there. If you’re thinking “there are a thousand articles about this already, in addition to the online docs”, you need to know three words: “Fresh, relevant content”.

A thousand articles have been written about just about everything! Why do you think that is? In the tech world, it’s because technical people tend to pay close attention to the date of publication to figure out if the content is fresh and relevant to the current version of whatever they’re using. Because technology evolves, there is often a need to get updated information to the readers.

The other part of this objection is the idea that the reader can get the same information from online documentation, or that what you might write about is just too easy for anyone to find useful. This is usually based on an assumption that because the writer learned it in an hour reading online docs, that everyone can/will/wants to learn that way. I hate online documentation, especially for programming languages. So do lots of other people. That’s why people buy enough technical magazines for my publisher to let me head up another one!

Also, people read about things in magazines that they may otherwise never read about if it were online, and they get inspiration from these things on occasion. Why? Because it’s there. When I go to get my oil changed, I bring a magazine with me to read while I’m waiting, and I read stuff I wouldn’t normally seek out online because I have time to kill. When you see people at the DMV (or MVS, or wherever people go to get their licenses renewed or cars inspected), a lot of them have magazines with them. They have time to kill. Inspiration can come from the strangest places. So whatever it is you’re doing, write about it, and inspire someone to take whatever it is you’re doing and do something else cool with it. Even if it’s, say, the Python tempfile module or something mundane like that 🙂

There are three things I tell people about where to find article ideas:

  • Write about stuff you know/do – this is a gimme.
  • Write about stuff you *want* to know/do – You don’t have to be an expert on Twisted to write an article about it. If you’ve done some network programming with Python at all, and are wanting to get into Twisted, research doing what you want to do with Twisted, figure out if it’s a good choice, do a proof of concept, take some notes, and write an article based on what you’ve done!
  • Write about stuff that is not done, or often done wrong – Best practices documentation is severely lacking. There are a trillion articles that talk about different ways to do similar things, but very, very few articles that say “Here are three common ways this is done, and here’s why this fourth way might be better” or “Here are the pros and cons of doing this using 2 different methods”. Because best practices documentation is lacking, things are quite often done in a suboptimal way. Articles like “How not to do web programming with Python” might cover why you don’t want to use the split() function to parse URLs, for example 😛

More on the way

I’ll expand on these and address more common reasons for not writing in future posts. In the meantime, if you’d like to give writing a shot, and you write a decent bit of Python code, I invite you to come and write for Python Magazine. I look forward to working with you!

Technorati Tags: , , , , , , ,

Social Bookmarks:

July 12, 2007

My first interview

Filed under: Me stuff — m0j0 @ 6:42 am

I was interviewed by Tony Mobily of Free Software Magazine! You can see the interview here.

Also, if you’re tired of Slashdot and Digg, Tony also works on Free Software Daily.

July 11, 2007

Python 2.5’s “partition” saves my bacon

Filed under: Python,Scripting,Technology — m0j0 @ 8:42 pm

So I was on more than one IRC channel today asking a question that I got lots of answers to, all of which looked really messy to me, so I dug into the documentation and found that in Python 2.5, strings have a new method, called “partition”.

Here’s the trouble I had, and why “partition” helps:

>>> m = "parent:child"
>>> x = m.split(":")[1]
>>> x

This is actually pretty close to what I want. I want to split m, and assign the second element in the resulting list to x. The problem arises when there is no “:”. In that case, that second line is actually trying to assign to x by referencing an index that is beyond the end of the list. You get an “index out of range” error.

So you’re left with a number of options. You can use an “if” to check for the existence of the colon.

if ":" in m:
x = m.split(":")[1]

I guess. But then I have to use another “if” to check and see if x was ever defined, or I have to initialize x ahead of time. At this point I’m onto at least three lines of code for something that takes 1 line in Ruby, Perl, or PHP. That just *can’t* be right!

You can also go ahead and just add the “:” explicitly to “m”:

>>> y = m + ":"
>>> y
>>> x = m.split(":")[1]
>>> x

Nothing wrong with that except I still think I just shouldn’t have to do that. I should be able to, as a last resort, go with regex and do a one-liner that assigns everything after “:” to x, and if there isn’t a “:”, then x would wind up being empty. Something along the lines of x =“:.*”, m) – or something like that.

Well, partition solves the problem rather nicely. From the documentation:

Split the string at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing the string itself, followed by two empty strings. New in version 2.5.

Here’s what I did with it:

>>> y
>>> x = y.partition(":")[2]
>>> x

Of course, I got an empty string in this case, but “partition” did what I wanted “split” to do – namely, assign ” or None to “x” if the separator didn’t exist. I guess what makes this possible with “partition” is the fact that it returns a fixed-length tuple no matter what, while split returns an arbitrary-length list, which would introduce ambiguities in cases where multiple splits are done to a string.

Technorati Tags: , , , , , , , ,

Social Bookmarks:

July 6, 2007

On the demise of SysAdmin Magazine

Filed under: Big Ideas,Sysadmin,Technology — m0j0 @ 12:57 pm

CMP recently announced that they will cut 200 jobs, and shut down more than one magazine in the process, folding their content into other existing magazines. There has been a lot of buzz in the sysadmin community (which I know largely as a loose collection of people who belong to LOPSA, SAGE, USENIX, or local groups of various kinds) about how sad and unexpected this is and how it’s a sign of the times or something.

You Can’t Sell a Generalist’s Mag to a Market of Specialists

I actually think SysAdmin’s demise was a long time coming – in part because, well, I’m involved in the publication of a couple of magazines, and read lots of others, and know people who work in publishing on other magazines as well as large online media outlets (some of whom I also write/edit/consult with). The plain fact of the matter is that it is extremely difficult to cover a topic like system administration in a generalist sort of way when your audience no longer consists mostly of generalists.

For example, the last two issues of SysAdmin magazine I remember getting were about Database Management, and Linux, respectively. The database management issue talked about Oracle and MySQL, and then had 3 or 4 articles on things not really directly related to databases at all, if memory serves. The Linux issue is probably of no interest to the admin who was all revved up for the Oracle articles, because that admin is probably not so much a sysadmin as an “Oracle admin”. Meanwhile, the average Linux administrator is probably uninterested in the Oracle RAC Primer.

Most admins aren’t generalists anymore unless they work in academia, research, or a company small enough that there are only a couple of people to handle the entire infrastructure. Even people who would like to be more general aren’t doing generalist things in production. I know several people who work *only* on {Oracle, sendmail, websphere, whatever-other-service-you-like} at work, and nothing else, but they run Apache, Bind, Postfix, and a few other services at home. That knowledge is nice to have, but it’s hardly something you can use to market yourself as a production generalist administrator.

So the market is flooded with mail administrators, backup administrators, storage administrators, cluster administrators, network administrators, database administrators, websphere administrators, exchange administrators, desktop administrators… the list goes on and on and on. The magazine market has mostly followed suit. There are magazines about cluster computing, DB2, AIX, SQL Server, Linux servers, Windows servers, and lots of other specialized areas. Note in that list that there are two separate magazines for two separate database products, but no “DBA’s Journal”. In killing SysAdmin Magazine, CMP is just following along with market trends.

Programming has mostly gone in the same direction. Dr. Dobb’s Journal is no longer available on your local bookshelf, but you can find php|architect, a magazine about nothing but PHP, doing well. Others exist for .Net, Cold Fusion, C/C++, Java, and now even Python. I’m sure Ruby and Lua aren’t far behind.

“I know, let’s start our own magazine!”

There are lots of naysayers out there who seem to think you need a huge staff, tons of money, and loads of other resources to start a magazine. Not true. You need a few dedicated, motivated people, and a small amount of seed money, and some time and hard labor.

An example is php|architect. It started with two guys: the publisher (who was a software development consultant as well), and his business partner, who also knew Quark pretty well – plenty well enough to do the layout. Then I came on board. So after the first issue came out, the rest were all tech and copy edited by the publisher and I, and the layout was done by the other guy. That’s really minimizing the amount of work we did, but the point is you don’t need an army.

When you’re as big as CMP and you’re looking at cutting a million bucks or something from your operating expenses, you go ahead and cut away! A small outfit isn’t playing with these kinds of numbers. A full-time editor at a company like CMP probably makes a 6-figure salary. A guy like me who edits as a side job makes something like… far less than that. At that rate, you can add another editor, a tech editor, a couple of columnists, all part time, and the advertising revenue will still cover the costs.

So if you want to see a sysadmin magazine, get some dedicated people who have half a brain and go do it!

Good luck.

Technorati Tags: , ,

Social Bookmarks:

July 3, 2007

Python Magazine Lives

Filed under: Big Ideas,Me stuff,Python,Scripting,Technology — m0j0 @ 10:58 pm

I have a confession to make: For the past 6 weeks, I’ve been leading a secret double life. By day, I’m a mild mannered system/network/database admin in academia. I also write some PHP, Perl, and Python code. By night, however, I’m an author and editor. My latest project is bigger than most. In fact, it’s an entire magazine. Devoted to Python.

I am the Editor in Chief of the newly launched Python Magazine.

Why on Earth Are You Doing This?

Python Magazine was created as a result of some rather unfortunate events in my own early experiences with Python. Getting started, of course, couldn’t be easier. It was what happened after I had been coding for a while that I had issues with. Once you needed to do something a little out of the ordinary with the language, it was hard to feel confident that the way I was going was the right way.

For example, I decided to wrap up a bunch of SQL calls in Python and expose them as an API using Python’s built in SimpleXMLRPCServer. I thought this was great, because then I could maintain a single back end API, and any language that could make an xmlrpc call could use it without me having to maintain APIs in several languages. Nice in theory, but people smarter than I questioned my decision to use the built in SimpleXMLRPCServer. The right road to take, though, was completely unclear.

As another example, I needed to get up to speed on using the python-ldap module, but found that a lot of the documentation lacked anything but the most basic of features, but I was trying to write a full-fledged LDAP management API (and accompanying command line and GUI tools). Other articles I found were outdated enough that people warned me not to bother with them, pointing to glaring issues with the code samples (which turned out to be true – some of what was in the code samples turned out to be completely deprecated!).

When I wanted to write code against a PostgreSQL server, the correct module to use was also not immediately obvious, so I had to hunt down the sites of various modules, see which ones were maintained, search for articles that weren’t 5 years old on how to use them… Gah!

What I really wanted was a resource that fed me information in a way that my brain likes to feed on information. I really wanted to learn to do things with Python the way I learned to do things with Linux, Solaris, PHP, and even non-technical things like photography, billiards, and brewing beer. I wanted a magazine.

There was no magazine. I was bummed.

How did you finagle this one, jonesy?

I have a friend named Marco Tabini. He’s a publisher. He runs Marco Tabini Associates in Toronto. He is the publisher of php|architect Magazine. He’s also a total geek. For fun he does things like writing lexical parsers… in PHP. Nobody should ever do that. He thinks it’s fun. I say pass on that if you are given the chance.

Marco and I met via email. I wrote to tell him that I had received my first issue of php|architect, and would not recommend it to a friend. I had found something like 15 errors (typos and grammatical issues) in the first two pages of the magazine. Marco wrote back and said “hey, we’re a small outfit. We’re an Italian immigrant and an Iranian immigrant, living in Canada, trying to edit technical articles written by people from all over the world with varying levels of experience with English… all for a largely American audience. Come help us out!” So I did.

Shortly thereafter I became Editor in Chief of php|architect. Now there were three of us. Oh joyous day.

Those were great times, and the magazine has since spawned its own online and on-site training, its own line of books, its own series of conferences, and even a cruise! It probably has stuff I don’t even know about because I haven’t worked directly for that particular publication since 2004.

The success of that magazine gave me the courage to go to Marco about 6 weeks ago and ask about letting me head up another magazine, this time about a topic of *my* choosing. We chatted on IRC for several hours over the course of about a week, bought a couple of domain names, settled on budgets and team members and all that, and set out to make Python Magazine a reality.

So… How’s it going?

Things are *REALLY* rolling now. There are columnists, there are tech editors, there are authors. Articles have been commissioned. Logos and trademarks are in place. The design team is rocking, the contract team is rolling, and the emails are flying. In the background, the sound of constant typewriter activity can be heard, just like on those old newscasts from the old Cronkite days. Exciting times!

That said, we still need LOTS of content. The behind-the-scenes of a magazine is that you’d really like to have something like 4 months worth of content “in the can” before “Volume 1 Issue 1” is released. I’m convinced that this has never happened in the history of publishing, but it’s a great goal to have, and I’d be pleased as punch to be the first person ever to achieve it 😉

If you’re a writer who is doing or has done something interesting with Python, or can illustrate high level concepts from the fields of computer science, research computing, or IT, using Python, we’d love to hear your thoughts!

Import This

In the end, I hope I can be a good steward to the language and community. I’ve already been in touch with a lot of wonderful people – authors and others – who’ve helped out in some way, either with the magazine, with my own buggy Python code, or both. That’s all the news that’s fit to print for now, but keep an eye here and on the Python Magazine website for more updates as they happen.

Oh yeah – and if you subscribe now, you get a discount, and a chance to win a MacBook!

Technorati Tags: , , , , , , , , , , ,

Social Bookmarks:

Create a free website or blog at