Monday, June 29, 2009

In US again

As the title says, I'm in US again. Flight and train wasn't very good this time and while I was on road I slept only for about 3-4 hours in total. But anyway, I'm here finally and have enough time to sleep.

I will be staying here for quite a long time and I hope I will be able to find some fun stuff to do. I think I could start to annoy waitresses in cafeterias by not answering "Don't matter" when they ask about some options for the order, but asking them in details what each option means. Ok, just kidding, it'd be so cruel =)

Saturday, June 13, 2009

project's webpage updates automation

Currently I'm reading "The Pragmatic Programmer: From Journeyman to Master" book. And while its contents seem quite obvious and natural to me, by repeating "DRY/automate things" stuff again and again it forces my mind to re-think about possible ways of automation of various aspects of my activity.

I have a number of small projects, which are not very popular, but I prefer to keep a page for them just in case if they will be useful for somebody. However, I never liked updating web-sites because it's boring (like: ftp or ssh, edit files, re-check, edit again, you know). So after reading this book I decided to try to automate that too. Recently I moved my small pymgsrc project - a command line client for imgsrc.ru photo hosting - to github and wrote a simple script for the website update. The way it works is:

- Build a release distfile
- Load template for website (single html) page, replace %%VERSION%% with actual version (in order to update download links and info about the latest version available) and replace %%CHANGELOG%% with HTMLfied (using simple sed expression) ChangeLog entires
- scp resulting distfile and webpage to the hosting
- Viola, all done! Using only one command.

I'm very pleased with the script and that I don't have to bother with HTML editing anymore, at least while I didn't decide to alter template.

I guess the hardest part of the automation is to find pieces of work which could be automated, because sometimes you do stuff and don't understand that it could be automated, but when you finally automated it it starts to look pretty natural and you wonder why you haven't noticed it earlier.

Friday, June 12, 2009

python subprocess module

Recent Python versions show DeprecatedWarning when using various popen functions and encourages to use subprocess module. And it's frustrating because I don't quite like the subprocess module. Let's take a simple example: executing one app and piping other app, like "dmesg|grep hda". They even have this example in the subprocess module documentation so I just took it. So, take a look:


output=`dmesg | grep hda`
==>
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]


That looks lame to me. Look, original command has only 4 words used and is easy to understand. The second example has: 17 words, uses classes (who needs them here?) with some weird non intuitive constructor arguments and the final accord is "p2.communicate()[0]". What is "commmunicate()", can you guess what it does in details without looking at the docs? What does it return? What the hell is "[0]"? Seems really horrible to me.

Generally, it seems quite inconvenient to execute external applications using Python. Some people call Python 'a better shell', but it doesn't seem quite true if you need to execute external apps and in _most_ of shell scripts you really do need such things. Well, probably it's good at some sense that it forces you to split your Python logic and shell-scripting logic into python and shell scripts respectively and call shell scripts from your Python scripts and vice versa, but anyway, I don't like it a lot.

Friday, June 5, 2009

ObjC experiments

After some experiments with iPhone development and ObjC I decided to take a look at ObjC and use it to implement some simple but useful app.

As I don't use any kind of tray or docker whatever (I will elaborate on that topic) I decided to implement some app which would poll IMAP server for new messages and notify me using libnotify.

If you're interested, you can check sources on github. Actually, it's more toy than real app atm, however it seem to work alright with my gmail account. And yeah, it's pretty simple and can only work with IMAPS (IMAP with SSL).

Well... ObjC impression... surprise! Nothing is looking really impressive. What can I say. The language looks pretty natural and intuitive. I guess I like it more than C++, though I cannot be quite right in that since I don't know C++ and ObjC well enough, but I just like how ObjC feels. One more thing is that I haven't read any ObjC so I don't know best practices and design principles that should be used when wring in ObjC. I think it would worth to read some good book about ObjC.

I didn't use GNUstep foundation classes on purpose. First reason is my philosophy of writing tools is that a tiny tool should not bring such huge dependencies like GNUstep. The second reason is that it would be better to learn pure language before moving to high-level frameworks. And my understanding is that using foundation classes changes ObjC programming dramatically.

I think I'll play with this tool a little because it contains a lot of bugs and leaks (but it's more related to the C aspect of programming), will probably try to redesign it and move to playing with GNUstep classes, just need to come up with a project which would worth it.

PS Yeah, the only thing that makes me curious is "+/-" in method signatures. IIRC, they're used to distinguish class and instance methods. In the most code I've seen or wrote, most of methods were actually instance methods, class methods appear not quite often, at least for me, so I don't really get why they deserved so much attention in ObjC.