Archive for May, 2007

Choosing your text editor

Any programmer worth his or her salt will tell you that the text editor is one of the most important things in a code-writer’s toolkit. There are tons of text editors out there, come are simply clones of each other, while some are really unique. Windows Notepad is about the bare minimum that you can get, but if you really want to be an efficient programmer, you’ll probably want something that lets you do more than simply enter text. Most programmer like text editors that allow for mundane tasks to be automated, while otherwise staying out of their way. However, all programmers have their own likes and dislikes as well as varying ideas of the perfect text editor. But how does one find their own suitable text editor?

The first step is to figure out what exactly you are using your text editor for. If you mainly code in just one or two languages you might prefer to have an editor that has inbuilt features for working with those languages. In that case it’s best to see what others like you are using and try out the choices. However, most programmers don’t spend their whole lives coding in one or two languages and as new languages come onto the scene, you probably don’t want to have to switch to a new editor every few years. This is where extensible text editors come in to the picture. Extensible text editors have a small core that deals with routine text editing tasks and also gives you a way to add plugins or extensions which are language or task specific. If you need to switch to a new language, all you have to do is find corresponding extensions (or write your own, if you don’t like what is available).

The most extensible text editor of them all is probably Emacs. Unlike most other software which allows extension via API or some sort of simple configuration scripting, Emacs packs a full-fledged LISP interpreter for a custom dialect of the language. This allows almost limitless configuration. Not only can you write simple scripts to clean up your code, you can embed full-fledged programs, like file managers and FTP clients. In fact, many people have claimed that Emacs is not a text editor at all, it is operating system squeezed into a text-editor’s skin. While Emacs may be God’s greatest gift to anyone who loves making customizations, it is not without it’s problems. Firstly, Emacs depends on lengthy key combinations involving pressing the Shift, Ctrl and Alt keys one after the other along with a few letters in a wide variety of combinations. These key combinations can be quite hard to remember unless you make it a point to memorize them and because of all the unnatural finger movement that have to do, there is quite a high risk of Repetitive Stress Injury. Definitely not fun. And to top it off, it looks like something out of the stone age. For all these reasons (and some more) a lot of people like Vi and its clones.

Vi is a text editor that has been around since the earliest days of UNIX operating systems some thirty years ago. Vi does not pack a full code interpreter, and is not as easily extensible as Emacs (though the newer Vim editor includes a nice little scripting which might be of interest if you have some free time). But that is not the only difference. While Emacs uses long key combinations to let you access a host of text editing functions, Vi requires to switch modes to manipulate the text. In the insert mode, you can type in text, use the arrow keys to move around and use delete and backspace to erase mistakes. But if you need to do something like copy/paste or find/replace, you have to enter the command mode by pressing the escape key. In this mode, you can’t type in text, but you execute commands to manipulate the text. These commands are short (generally just a few characters) and according to Vi lovers over the world, far easier to remember than Emacs’ key combos. Most people who use Vi probably use a clone called Vim, which has both command line and graphical modes, and the graphical mode actually looks pretty decent.

But are either of these really for you? Both of them have substantially learning curves and you will have to spend a good few hours learning your way around if you want the maximum benefits. Both allow extremely fast and efficient text manipulation and a good deal of customization. But a lot of people simply don’t want to spend time learning commands and simply want to get on with it. So what do they do? Why they write their own of course. There are loads of text editors out there because their creators got tired of unwieldy key combos or switching modes all the time. Most of these will not be actively developed for more than a few months, but there are some that are quite good.

Both Vim and Emacs are cross-platform running perfectly on Windows, Linux, BSD and Macintosh. One other cross platform editor that I like and have used quite often is jEdit. It’s written in Java and runs anywhere with a Java Runtime installed. It’s not as powerful as the above but there is an active community of plugin developers and a number of very good plugins (as well as an internal plugin manager that is very useful). Actual development on the editor stalled for a while after the original creator left, but it has recently restarted. The only problem is that it can be rather slow to start up, especially on older machines.

If cross-platform isn’t a necessity, then I have some recommendations for you. For Windows, Notepad++ is one of the best free and lightweight editors that I’ve used. It’s based around the excellent Scintilla editing components but throws in a number of useful extras and sports a nice clean UI. For Mac users, TextMate will probably fulfill all your needs. I haven’t had the opportunity to use it myself, but I’ve heard that it can be as powerful as Vim or Emacs. It’s not free, but if coding is your full time job, it will probably be a wise investment. Linux users have a wide galore of editors to choose from. You can use the editors that come with the two major desktop environments, Gedit and Kedit. If you are a full KDE user, Kate is a more powerful alternative. One of the newer editors that is getting some publicity is called Scribes. It’s a compact editor with a few killer features like a very good auto-complete system and good template support. But there’s a catch: it’s very dependent on GNOME libraries and if you don’t use Gnome that means a large extra download, but more importantly, unlike all the other editors that I’ve talked about, it has a single document interface, i.e. opening a new file doesn’t open a new buffer or a new tab, it opens a new window and if you’re handling multiple files, you’re handling multiple windows, which may not be the easiest of things.

Ultimately it is up to you to find your perfect editor. I recommend trying a few out before you find your match. And if nothing appeals, you could try your hand at spinning your own. With the various tools available today, it is actually quite easy to create a simple text editor (although it is quite a challenge to create an editor that is not simple).

Is Google Reader getting ignored ?

Google Reader has been one of the more erratic Google products. When it was first launched, it didn’t garner much attention. But it’s 2.0 release almost a year made quite a few heads turn and it now has quite a large user base. There have been a few improvements after that (like including video and a widget for the Google Personalized Homepage), but only the major development was probably the reporting of the number of users to services like FeedBurner. Even though Reader is now over two-and-a half years old, there is still one major feature that it lacks: search. Almost all the other services have search including much less used services like Notebook. A few hours ago, Google offered an updated user interface including a bar on top for the various Google services. Once again, Reader is one of the services that do not have this update. One would think that Reader’s substantial user base, Reader development would be one of the top priorities, but from the looks of it, Google Reader is getting ignored. With all the invest that Google is making in new services and software, is it too much to ask for a way to search through our feeds?

Falling in Love with Scheme

Since I have some three months before I start my computer science course at college, I decided that I’d get a head start and learn some real computer science (not just programming) before I get started. Though I’ve dabbled with a number of programming languages (and have a number of “beginning” books thanks to Apress publishers) they really aren’t good for computer science per se. I’ve decided to go with a long-standing computer science classic: Structure and Implementation of Computer Programs.

The book has been the textbook for MIT’s introductory computer science course for over two decades and has a wide reputation. One of the reasons that it has been regarded as a classic is that it doesn’t use any “industry standard” programming language at all. Rather it uses Scheme, a dialect of LISP, a functional programming language and one of the oldest to still be in active use. Scheme is extremely well-suited to be a “learner’s language” for serious computer scientists and it’s hard to actively use Scheme without being deeply impressed by it. Even though I have only been using Scheme for a few days, I’m already in love with it and though it isn’t quite my favorite programming language, I really enjoy using it, much more than most of the other languages I’ve used before. Here’s why:

Scheme has very little syntax

One of the things that makes Scheme stand out from most other common programming languages is that it is a functional programming language with very little actual syntax. All the code that you write is part of a function and your program works as a series of interactions between these functions. Not only are there no classes, or objects, there are not even the more common syntactic forms such as loops (while, for, do-while etc.), these are implemented via function recursion. In fact, besides the function definitions, the only major syntax students have to deal with are conditional statements in the form of an if-else idiom and a general conditional syntax with multiple conditions and corresponding actions, such as:

(cond

(test1 expr1 ...)
(test2 expr2 …)

(else exprn))

Though there are an abundance of data types, students do not really have to bother about these when they get started. All this means that any intelligent student can grasp the fundamentals of the language within a few hours and concentrate on actually learning computer science concepts and their implementations.

Scheme has a great IDE

… in the form of Dr Scheme. Though not really necessary to use Scheme, this IDE makes it very easy to get down and dirty with Scheme. Not only does it offer several implementations of the language (so it’s useful for a wide variety of CS courses), it let’s you immediately run and test code that you’re written. The standard window features both a text area for you to write your function definitions and an interactive interpreter right below it where you can directly use your functions.Along with that there are also simple debugging tools which let you step through your program to find out what’s wrong. Here’s a screenshot to show you what I mean.

DrScheme's multiple panes

Scheme really isn’t a language at all

Many programming languages are created because some people somewhere want a better way to get something done. For Scheme, however the story is a bit different. Scheme has it’s basis in mathematics and in fundamental theories regarding programming language implementation. As a result Scheme is not bound by arbitrary standards or needs to get it to work like other people expect it to. In Scheme, all the code is written in the form of S-expressions, a type of mathematical expression. Add to this it’s complete lack of syntactic sugar and the fact that it’s implementation is based on the theories of lambda calculus, and you end up with something that feels more like a slightly peculiar way to organize your logical thoughts rather another programming language. I personally have come to view Scheme as a sort of “executable pseudocode”. I find that once I’ve come up with an appropriate algorithm to solve a problem, it takes almost no effort to put it into code. This is far from the experience I’ve had with languages like C++ and Java where coming up with running code can be as cumbersome as getting a working algorithm.

Scheme fundamentally changes the way you think

Ask anybody who has worked with Scheme or any other LISP derivative for a considerable length of time, and you’ll probably hear the same thing. Scheme encourages you to put aside the implementation details of a program and concentrate on finding the optimal solution. It’s use of S-expression syntax and functional nature helps you learn to properly segregate the different aspects of a problem instead of letting you cobble everything together. Use Scheme for long enough and you’ll find your Scheme-oriented thinking spill over into other aspects of your life (like wanting to use brackets all the time (and put brackets inside brackets (which is probably something you’ve never done before))). If you haven’t used Scheme yourself, you may not quite have believed everything that you’ve read now, which is actually more evidence for the fact that Scheme changes your thought patterns. If you have a few days worth of time on your hands, go get Dr Scheme and some good Scheme documentation and dig in.

Announcing Backlog

A large part of what I post on this blog has to do with new stuff: new technologies, new services, new trends. In order to offset this large amount of information regarding new things, I’m going to periodically write articles under the heading “Backlog”, i.e. articles regarding slightly older technologies and tools, but ones which are still useful today. Don’t worry, I’ll try my best not to turn them into boring history lessons, wherever possible I’ll be drawing comparisons with modern alternatives and giving instructions to put these time-tested utilities to work for yourself. I intend to post one Backlog article a week, starting from next week. And also from next week I intend to post at least every alternate day, if not everyday. Once again, thanks to all my readers for sticking with me through a dry spell and I will try not to disappoint again.

What Silverlight Means For You

If you keep tabs on the world of web 2.0, then you’ll have heard something about Microsoft’s newest offering, Silverlight. Silverlight is an outstanding piece of technical wizardry, with even long time Microsoft critics admitting that it is a very good product. But while the technical people and the application developers may be very happy about it, what does Silverlight mean from the tech-savvy web 2.0 user who isn’t a developer, but simply a user? Right now, not much. However, given time and sustained interest in the new platform, it could mean a lot. Let’s take a look at what might come of Silverlight.

More Variety

When first announced, it sounded like Silverlight was being poised as a direct competitor to Adobe’s popular Flash technology. But the latest announcement (the one that has garnered the most interest) has made it clear that Silverlight is not quite so simple. The Silverlight plugin (which weighs in at a mere 4MB) will contain a version of Microsoft’s .NET Common Language Runtime. The CLR allows programs written in a number of popular languages like JavaScript, C#, Python and Ruby to be run directly in the browser itself. While this gives developers a large choice in how to implement their web apps, it means that users can expect to see a new generation of even richer, more feature packed applications delivered right in the browsers. It also frees users from having to understand what plugins or virtual machines are required for their selected web app and developers no longer have to bother with maintaining a plugin in addition to their web app, Silverlight does the worrying for them.

Speed

One of the major benefits for end users will be the greater responsiveness that Silverlight will allow for Internet based applications. The recent demonstrations have shown than Silverlight can run JavaScript apps many times faster than native browser implementations. No more waiting around for long periods of time for the applications to load before you can start using it. Heavy duty applications like online web suites, image editors or publication tools similar to Yahoo! Pipes will most benefit from the vast speed increase, but some of the improvement will trickle down to even the smallest pieces of JavaScript. Silverlight applications will also be able to access and alter the basic structure (the DOMs) of the web pages that they will use as interfaces. This means that users can expect far richer, more interactive programs where the program will be able to keep track of any changes made and react accordingly.

Better Multimedia

Flash is currently the most popular technology on the market when it comes to developing streaming media via a browser. But Silverlight promises to do all that Flash can do and much more. Silverlight will allow distribution of video at very high quality (720p or high definition) and will also allow native full screen viewing (as opposed to the current alternative of a maximized browser window). What might eventually make Silverlight a better option than Flash are the new web services that Microsoft is building around Silverlight (and currently distributing full of cost). A service called Silverlight already allows users to store their content and Silverlight based web programs on Microsoft’s servers. If Microsoft handles this properly, we might soon see a large number of new multimedia sites springing up offering richer multimedia and data services and overall better usability for the end user.

While Silverlight currently seems more like a developer tool than an end-user must-have, that might change very soon. Silverlight has a lot to offer for developers, especially those who have been struggling for a long time to consolidate disparate technologies like JavaScript, XML and Flash to make robust web products. Of course, Adobe will stand to lose a lot if Silverlight eclipses Flash, but Adobe already has a firm grounding in the market, which it will be trying to consolidate with the growth of rich web 2.0. In the middle of all this will fall the various web-startups who are currently using AJAX alone, but might easily be outclassed if newer start-ups start using Silverlight vigorously.

Operating Systems for Students

There are a large number of different operating systems out there, including everything from expensive, industrial strength systems to small hobbyist projects. If you’re a computer user, you’re bound to find something out there that you can put to use. But what if you aren’t just a user or even a hobbyist? What if you are a serious computer science student interested in knowing what makes an operating system tick? While there a large number of excellent books on the subject, the best way to learn (as with most things related to computers) is to do it yourself. But writing a whole operating system, or even the kernel by yourself isn’t an easy thing to do, especially if you’re starting from scratch. Most programmers will agree that a very good way to learn programming, any sort of programming, is to read other people’s code, understand what makes it ticks, and then use some of those principles in your own projects. This isn’t hard for small pieces of software, but an operating system, even the kernel, isn’t a small piece of software. Most of the kernels out there, even the smaller ones are rather complicated pieces of code. They’ve probably been in development for years, with large groups of people contributing lots of different code. If you’re new to kernel development, looking at the Linux or BSD kernels probably isn’t a good way to start learning. So what do you do?

Enter Minix. Minix is a UNIX clone, but it has been made with students in mind. Minix 1 and 2 were made by Andrew Tanenbaum exclusively for students to  go along with his book: Operating Systems: Design and Implementation. Minix 3, is still geared towards students, but is also being made usable as a day-to-day system for low resource computers. What makes Minix3 good for students is that it is compact. The whole of the kernel (it uses a microkernel design) fits into just 4000 lines of executable code. The rest of the system runs in user mode, and in case you want to take a look at those parts too, you can do so just as easily. Minix has a fully modularized design, which means that you can tinker with one small part without having to worry too much about breaking everything else.

Even though Minix is for students, doesn’t mean that is unusable as a proper operating system. Over 400 UNIX programs have been ported including a graphical X window system and networking capabilities using TCP/IP. As for programmers, there is a native C compiler and the shell, ash supports scripting. There are also interpreters for BASIC, Perl and Python (though the Python interpreter is very out of date). That should be enough to let you tinker around and learn something useful. While you’re at it, you might want to get the book as well, especially if you don’t know anything about operating systems.

However if you want something that is still in the early stages of development, but has a clear game plan, you might want to take a look at Fiwix, a project geared towards producing a kernel compatible with Linux while keeping students in mind. Like I said, it’s in its early stages so you could learn a lot if you hang around. The Google Directory on operating systems has a few listings for educational operating systems, and some of the might be worth taking a look at. But please do not jump into the world of operating systems without an adequate knowledge of C/C++ and a good grounding in operating system theory or you might find out that you bit of more than you can chew.

Living at the Command Line

The modern computer desktop, irrespective of what software or hardware you are running, is a mostly graphical environment. However there was a time, not so long ago, when the good old text-based command line was every computer user’s best friend (and occasionally worst enemy). While the command line may no longer be in vogue, it is still possible to do most tasks with nothing more than a humble text interface (and a good keyboard of course). Most of this article will be dealing with tools that are easily available for UNIX derivatives (Linux and BSD). If you’re a Mac user, then you’ll be able to find a terminal tucked into your Utilities folder. Most UNIX commands should work without a hitch. You will probably want to use Fink to install the software that I will mention here. For Windows users, Cygwin would be the best bet: it gives you a fully UNIX-like environment including support for most open-source UNIX tools. However you might have to dig through documentation a bit to install everything properly. On the other hand, if you don’t want to turn your Windows box into a UNIX clone, try Windows Power Shell, and if you do, please write back to me about it. Now, on with the show:

File Management: Strictly speaking, your command-line shell provides all that you need for file management. The shell provides you a host of various commands to let you view, search and manipulate files. These commands aren’t actually part of the shell; they are different programs that the shell calls up just like it would call up any other program. In case you do need something more than what the command line can give you, the best option I can give you is Midnight Commander. It has been around for a long time and is often considered a classic. It has two panes, and has a pseudo-graphical look about it thanks to ncurses. It also supports renaming whole groups of files at a time and can work with popular archive formats (such as tar) as if they were normal directories. You can also use it as FTP and SFTP client. It’s available for both Windows and Linux.

Text-editing: The command line is where text-editing is started and it should come as no surprise that you have a multitude of options to choose from. The good old powerhouses of Emacs and Vi are close at hand and though both have a bit of a learning curve (okay, a lot of a learning curve), it’s well worth it if you are determined to become a command line wizard.

Music: Just because you’re hell-bent on living at a command-line doesn’t mean that you have to give up all the pleasures in life. Music is one of the pleasures you get to keep. Most people today have enormous MP3 collections and it would be an awful waste if you couldn’t get to them without a GUI. For a long time, mp3blaster was the program of choice for command-line geeks who wanted to listen to music while their figures were busy tapping away. But now there is something even better: the music player daemon. This relatively new piece of great software sits in the background and will play music irrespective of whether you’re at a GUI or CLI, and is good news if you often switch between the two. If you’re using any well-maintained Linux or BSD distribution, this should be in your software repository. Once you have it installed, you’ll need a frontend to help you actually select and play music. The best one for us would be ncmpc, the feature rich, yet very simple to use ncurses front end. It also supports various formats like MP3, OGG and FLAC, so you aren’t tied to MP3s only.

Internet: The net today is a very graphical environment, but that doesn’t mean that it’s completely inaccessible to command line lovers. There are a number of text-based browsers out there such as w3m, Lynx and Links, you’ll probably want to try them out yourself before making a choice. For email, you can’t go wrong with Mutt, a mail client which depends on other UNIX mail software to give you a very flexible and very efficient mail setup. Once again, there is a learning curve, but if you are a heavy duty emailer (hundreds of emails a day) the effort will be well worth it. As for IM, I recommend CenterICQ. Don’t let the name fool you, it supports multiple protocols like AIM, ICQ, Yahoo, IRC and Jabber (and hence Gtalk) and there is plugin available which allows to use MSN as well.

Living at the command-line isn’t an easy thing to do in today’s world, and quite frankly, I wouldn’t recommend it for a long period of time. But if you just need a break for a while from all the clicking and dragging, give the above programs a whirl. The best part is that even when you have to come back to the world of GUI, you can bring your lessons back with you and use the various terminal emulators around to get some command-line magic to work alongside your daily GUI.