Posted in March 2009

Sunday Selection 2009-03-22

I missed last week’s Sunday Selection due to a number of reasons ( not the least of which was that Spring Break was starting and I really wanted to catch up on my sleep). But it’s Sunday again and time for another installment of Sunday Selection.

Reading

Sharpening your saw Computer science is probably a field where things change very quickly and the only way to stay on top of your game is to keep your skills sharp. This article by Jeff Atwood makes some arguments for why you might want to practice your skills and points to some great resources.

Web IDEs to become mainstream As a programmer I take my tools very seriously. I get very frustrated when I’m forced to use tools that aren’t up to scratch. One of the problems I’ve faced in this regard is that I work on multiple machine and need to keep configurations unified across all  of them. A proper web-based IDE could make that a lot easier.

Media

The future of the Java platform Java is one of the most popular software development platforms available today. If you do any sort of work on Java at all, it’s probably in your best interest to keep track of how the platform is developing.

Software

Google Chrome 2 beta In a recent cracking contest, Safari running on OS X was the first browser to fall. On the other hand Google Chrome was the only browser to remain undefeated after a day. That’s even more incentive to check out the new Beta which includes some interesting features like improved speed and zoom features.


Programmer Procrastination

I talk a lot about productivity on The ByteBaker, mostly from a programmer/student perspective. However, I have to admit that I do procrastinate. Take today for example. I really should do some work for my group C++ project, but I really don’t feel like it. However, I don’t want to be feeling guilty, so instead I did something useful so I could feel good about. Today I wrote a draft for an upcoming conference paper, read a chapter of the Dragon book and then I read up on a new, interesting programing language called Factor. And now I’m writing this post instead of programming. So now that I’ve accepted the fact that I won’t be getting any work done, I might as well list some of the pseudo-work things I do when I want to procrastinate and not feel bad about it. 

1. Program something else

This is my favorite and the most productive. I like programming, so writing some code to avoid other work makes me feel very good. In fact, I have procrastinated on particular programming projects by programming something else. I find this works best when I program using a completely different language or toolkit than I what I was using before. In the past, I’ve used Python as a break from Java and Java as break from ML. You get the idea.

2. Raid Wikipedia or the bookshelf

Reading something interesting, especially if it’s related to your work is a great way to feel like you’re doing something useful. Just today I was reading the Dragon book because I’ll be working on a code optimization-related project over the summer. I didn’t need to do it yet, but I did anyway and I feel pretty good for expanding my knowledge base. If you don’t have a book at hand and still want to read something, Wikipedia is great place to start. It’s easy to spend hours just hopping from one topic to another reading interesting articles.

3. Write that blog post you’ve been thinking about for a while

A lot of my fellow students procrastinate by watching TV or playing video games. I like to write because I think it’s a much better procrastination tool. Once you start writing about something that you find interesting and you get on a roll, you can go on and on and completely forget the passage of time. Even better, there’s something to show for it at the end. While I’ve taken up writing a blog post as an example, you can actually write anything you want. Whether it’s a blog post, or a chapter of that novel sitting on your hard disk or a letter to a loved one, open a text-editor or word processor and start hitting the keys. Very soon any thoughts you might have had about getting real work done will be far far away.

4. Stay in touch with people 

No matter how old you are, there are probably a bunch of people whom you once knew that you are no longer in regular contact with. When you’re busy with everyday tasks, getting in touch with these people often isn’t the first thing on your mind. That’s understandable, but when you’re avoiding work, why not put that time to good use by keeping in touch with old friends? I can’t really say that I do this very much, but you never know when your contacts can come in use. 

5. Start that new operating system/programming language/web framework you’ve been thinking about

Let’s face it: one of the ultimate expression of your skill as a hacker is making your operating system or programming language or something on a similar scale. Any project of this size is going to take time and effort so you might as well get started now while you have nothing better to do (or more correctly, you do  have something better to do, but you won’t do it). Be warned though, projects like this have a tendency to either fall by the wayside or take over your life. But who knows, you might just be able to come up with something useful.

6. Find a fellow procrastinating programmer and strike up a conversation.

I put this at the end, because it’s probably my favorite. And it’s social too. I’ve had some very interesting conversations with fellow procrastinators (and no, they weren’t all about code). If you’re lucky you can come up with ideas for new fun projects or even attract a larger group and get even better ideas thrown around. One great source of conversation topics are the TED videos.

 

I hope these have given you some good ideas for productive things to do when a bout of procrastination hits. I’d love to hear back on the things that my fellow programmers get up to when work isn’t worth it.

Programming in your dreams

I just read three really good essays on how programming is very similar to dreaming and why it’s important that programmers not be woken up from this trance-like state unless absolutely necessary. Here are the articles and I encourage you to go take a look at them yourself. If your job involves interacting with programmers in any ways, they’re a must read:

It might seem strange to compare programming to sleeping or dreaming. After all, sleeping is meant to be relaxing and refreshing, while programming can be rather strenuous and mentally draining.  However, the similarities are hard to ignore. For most people, it takes about 90 minutes after falling asleep to actually enter REM-sleep, the portion of sleep where you actively start dreaming. REM sleep is also very easy to disrupt and wake up from. Similarly when programming it takes a certain amount of time to get into the state of flow and reach your peak effectiveness. Any break in either REM or the programmer’s flow state requires a siginificant amount to recover from.

Being a college student with a full load of classes and activities, I’ve always been interested in finding the most effective way to write good code in the shortest amount of time. I’ve been spending the last few days working on an individual C++ project and thanks to that I’ve been able to remember some of the things that I noted in the past, but ever actually put into words. I’m going to try to put into text some of the things that I’ve learned are important for programmers to understand and put into practice.

Firstly, writing code, writing good code, doesn’t happen in bursts. Not unless you’ve been thinking about the problem (or something similar) for the whole day (probably more). Don’t get me wrong here, epiphanies and ‘aha’ moments do happen, but only if there’s been a substantial amount of time, knowledge and mental effort already existing. You can’t have the final piece of the problem fall into place unless all the other components are there already. Complementary to this, brute force doesn’t really work all the time either and randomness certainly doesn’t either. Programming is intelligent work. If you come across a problem, it’s a bad idea to start by throwing every solution in the book at it. Spend some time to lay out a careful plan and then execute. Use tools like debuggers and profilers. Over the past two years I’ve seen more than one fellow student (including myself at times) get frustrated and start changing code at random, hoping the problem will somehow disappear. Sorry, it doesn’t work that way and you know it.

Of course, just because programming requires intense sustained concentration doesn’t mean that you should make marathon 10-hour non-stop coding sessions a daily occurrence, especially if you’re a student doing a bunch of other things at the same time. To steal a line from my professor, there’s a reason coding death marches are called death marches. Be careful to pace yourself. When you’re on a roll it’s easy to glide from one problem to another, slaughtering your bug list in the process, but do try not to get carried away. At the very least, stand up, close your eyes and stretch once an hour. Also make sure you keep a full bottle of water near you at all times. Yes, I said water, not a caffeine drip. Please don’t flood your body with stimulants more than once a day. All that being said, distractions are dangerous, which is why you need to be proactive in avoiding them. Take breaks on your time. Every time you finish a major milestone, try to rest for a minute or so. I’ve found it’s possible to take a break without interrupting my flow state if I schedule the break myself. On my project I took a little walk break when I finished a class and when I’d finished a group of related tests.

While you’re scheduling your own breaks, make sure to eliminate or at least minimize unexpected interruptions. A room with a door that can be closed is good. A “Do not interrupt” sign with a board next to it for messages can be useful too. For students in labs, that’s not really an option. However, even if you do have to work in an open workspace, there are some things you can do. Sitting away from the door and facing a window or wall helps. Earphones are usually a good idea for keeping out sound, and if you’re an audiophile ( I think many programmers are) all the better. Also don’t feel committed to answer every time someway waves to you. Sure it’s not perfectly polite, but you’ll working better if you focus on your task and the person who waved to you will probably forget in an hour anyway. And please take measures to avoid checking email or Facebook or Twitter every few minutes.

Four: Cowboy coding is bad. (I’m not sure if 4 is the right number, it seemed a nice round number to me.)  It’s one thing to have faith and confidence in your coding abilities. It’s another thing to rush into a battle without surveying the battlefield first. It’s important to read the problem description carefully and have some amount knowledge about the problem domain. If you just jump in and start coding, you’ll find yourself making a lot of silly mistakes and false starts and end up wasting a lot of time and effort on clean-up and rewriting what could easily have been running code the first time around.

Paul Graham has a very nice (and similarly themed) article about how programmers work. To be good programmers we need to be able to keep the problem space in our heads, just as good mathematicians can manipulate complex sets of equations and formulae in their head. In fact, Princeton physicist Edward Witten is known for manipulating whole blocks of complex equations in his head while staring out the window. This doesn’t mean that you need to memorize every line of every file you’re working on, but it does mean that you shouldn’t be constantly looking through API documentation to find what you need. As you can imagine, doing this needs more than just mental aptitude. No matter how good a hacker you are, you’ll need some time every time you start to bring everything up into your mental RAM so to speak. You also need to be proficient in the language and toolkits you’re using. This is easier to achieve if you use roughly the same set of tools for most of your work. This is also the reason that a lot of great hackers seem to prefer a highly customizable editor like Vim, Emacs or TextMate. Having powerful text editing functions and hooks into other programs just a few keystrokes away is incredibly more powerful than having to navigate a rigid point and click GUI.

The process of writing good code isn’t an easy one. As I’ve tried to explain, there’s more to the process than just sitting down with a problem statement and pumping out the code. However, while getting into the zone and staying there requires a lot of care and caution, once you’re there, the process can be rather relaxing. I’ve realized (and I’m sure you have too) once you’re in the state of flow, you can stay there for hours at a time without thinking about anything else. In fact, no matter how much other stuff I might have on my mind, everything disappears when I get started coding. This may be true of other activities that require deep concentration, but the truth is, I’ve never found anything else that requires as much concentration, but is as enjoyable. However, the flip side is that once I’m done, I’m mentally exhausted and I can’t do anything else that requires thinking until I’ve taken a long break (physical exercise helps). Yes, it’s a compromise, but if I’m going to go to all that trouble to write some good code, a little tiredness is acceptable.

As an ending note, programming certainly isn’t for anyone who doesn’t enjoy working quietly alone. But we already knew that, didn’t we? As for the rest of us, I hope this post agrees with some of the things that we’ve all seen in our work. Have fun programming in your dreams.

Moved to a new home

Those of you who tried accessing the blog a few hours ago might have been seeing some unusual template changes and changes in the post order. That’s because I just moved away from WordPress.com to paid hosting and it took me a while to get everything set up and running properly. Right now it’s mostly the same blog, but with a fresh new theme. In the near future, I’ll be starting to put up longer articles that are too long for a blog post and make some more customizations to the theme.

For those of you who are interested, I’m now hosted at FatCow which had a really great deal whereby I pay less than $5 a month for unlimited space and bandwidth. Even better, I’m only committed for a year, so if things don’t work out, I can easily move after that without hurting my wallet. Here’s looking forward to a year as an independent website.

Tagged ,

Not all languages are created equal

I spent the better part of yesterday (and an hour today) on my C++ project for class. The project itself is pretty simple: Read in a file that contains descriptions of cars in a specified format, convert it to some sort of internal database and then allow for simple queries and purchases. I’ve probably spent about a total of roughly 6 hours on the project which includes teaching myself about C++’s string streams and standard template libraries, learning about operator overloading, the use of consts and writing Doxygen-compatible comments for my code. I still haven’t written unit tests for it.

6 hours isn’t much as far as a college-level project is concerned, but I can’t help thinking that if I’d been using a language like Python or Perl I could have done it all in about an hour. I’ll be using C++ for a longer semester long project where I’ll be building a not-too-complicated as part of a team ,but I can’t say that I’m really looking forward to it. C++ by itself isn’t a bad language, and there are some really nice toolkits built around it (Qt for example). But given a choice, it would not be a language I would use.

I’ve spent the last two years exploring a wide variety of languages from C and C++ going up to Lisp and Prolog and exploring ones like Java, Python and ML in between. I’m far from being experienced in any of them (except perhaps Python), but there are a number of things I’ve learned about languages that I think are worth sharing.

1. Languages are tools. No more, no less.

I find myself lucky to be at a college which is certainly not a Java School, in fact Java isn’t really used much beyond the intro courses. We use a wide variety of languages and the one of the things I think that our professors are trying to teach us (even if they don’t say it explicitly) is that languages are simply tools. Like any tool, you should use the best one for the job. Of course, there is a certain amount of personal preference involved in choosing the right tool. This in turn brings us to point #2.

2. Learn as many as you can.

Now by “learn” I don’t mean “become an expert at”. I mean use it enough to know what problem domains the language in question applies to. Functional languages aren’t the best for describing complex data structures and business logic and you probably don’t want to do a lot of string processing in C. The best way to get this kind of experience would be to do a major project in each new language you learn (something you can easily accomplish in under a month working on your spare time).

3. The industry standard isn’t always the best.

By and large, the industry standard today is C/C++ and Java. They aren’t bad languages, but they certainly aren’t the best either. A simple search for C++ sucks or Java sucks will turn up ample amounts of pain. However, if you want a job as a programmer you’re going to need to know these. That being said, it doesn’t mean you shouldn’t keep your eyes out for something better. Viaweb (which later became Yahoo! stores) was written in C and Lisp. So were the first versions of Amazon. Google uses Python a lot, especially for its App Engine. Languages like JavaScript and PHP are becoming core technologies of the web. If you stick to the industry standard, there’s a whole world of goodness out there that you’ll miss.

4. When in doubt, choose expressive power.

When starting out a project, it can be an interesting question as to what language to use (unless you have a mandate from up high). The way not to make this choice is to look at what others are using. You should try to use the language that makes it easiest to express your problem and it’s solution in the most straightforward way. In many ways this the tools argument in another form. Coming back to my project, I would have used Python to write something like that since it gives good data structures and easy to use string processing. On a wider scale this means that for the most part you want to avoid non-memory managed environments wherever possible, because memory management inevitable distracts from the higher level algorithm you’re trying to implement. Java for all it’s niceness and industry strength, isn’t very expressive due to a number of really bad design decisions that it’s too late to correct.

5. Read the manual

It can be surprising how many people will start railing and ranting at some language or language feature without properly informing themselves first. A lot of the times it can seem as if the language you are using is quite simple getting in your way. For a good few weeks I thought that way about C++, especially in regard to string processing. However, reading the documentation and tutorial about your language can make a world of difference. In particular knowing about the libraries that are available and reading some example code can make a world of difference. For me, the aha moment came when I learned about string streams which made my job a lot easier. I stilll don’t think it’s very elegant and it hasn’t made me love C++, but it has eliminated a source of complaint and let me concentrate on solving the rest of the problem. (And I’ve been convinced me that yet another C++ rant is uncalled for at this point.)

Tagged
Follow

Get every new post delivered to your Inbox.

Join 338 other followers