Archive

Archive for April, 2010

On Choosing a Programming Language

1 April 2010 14 comments

People often ask me, “What language should I learn? PHP, Perl, ASP, Python, Java, C, C++, Objective C?” It seems like what they’re really asking is, “What is the ‘best’ language?” And the answer is that there is no “best.”

The most common reason for choosing one language over another is that a client, customer, or environment may demand one or a selection from a small set of languages. That makes the choice easy. But what if there are no such restrictions imposed? If you really have free choice, how do you choose one language over all the others?

Different languages have different strengths and weaknesses. They’ve usually been designed for a particular purpose, or to replace another language or set of tools that became cumbersome or inefficient after years of use.

For example, the C language was designed in the early 1970s as a general purpose language for writing operating systems and systems-level tools. Before C, most of this work was done in assembly language. In 1972, Dennis Ritchie was working on new operating systems at Bell Labs and needed a language that could be easily ported to different architectures and operating systems. Existing languages were either too big or not flexible enough. So, he created C (named after its predecessor, B). Because C is small, powerful, and portable, it remains remarkably popular after 40 years of use.

By the mid 1980s, a lot of systems administration tools were being created using a combination of shell scripts and other tools such as awk, sed, and grep. In 1987, an engineer named Larry Wall decided that there was a need for a more cohesive and robust tool for this purpose, so he created Perl. Since then, Perl has grown and evolved, and remains a viable language for scripting and even for mid-sized web application projects.

Today there are hundreds of languages available, dozens of which have a large enough footprint to be considered for any given project. So, given the chance, how do you choose?

Criteria for Choosing a Computer Language

First, what is your application? You will need a different kind of language for writing a desktop application, such as a word processor or a web browser, than if you are building system administration utilities, such as a whois client or configuration manager, or building web tools, such as a content management system or a database maintenance backend.

Desktop applications tend to be resource-intensive and use a lot of operating system features, such as graphics, widgets, dialog boxes, etc. These applications often require the use of a software development kit (SDK) that matches your operating system, so you will likely need to use a language that’s compatible with that SDK. For Microsoft Windows, that could be C++, or for Mac OS X it could be Objective C. Sometimes you can get around that limitation and use a different language, but it’s usually a lot more convenient to use the language that matches the SDK.

For web applications, a scripting language is usually called for. The dynamic nature of the scripting languages (Perl, PHP, Python) works well for web applications. Web servers tend to be dynamic creatures and a language that can easily move from one environment to another can be a real advantage. Also, these applications tend to get updated frequently, so the short development cycle of a scripting language that doesn’t require a separate compilation step helps a lot.

Sysadmin tools, like web applications, can also benefit from the more dynamic interpreted languages. Perl and Python were designed specifically for this purpose. Python’s superior object model makes it an ideal choice for larger sysadmin and web projects, while Perl’s long legacy and large installed base makes it a great choice for projects that require a larger programming staff or ready availability of skilled developers.

So, What Language Should You Learn Next?

Why can’t I just answer your question and tell you what language to learn?

If you’d like to learn Perl or Python, you’re in luck! I’ve just finished my Perl 5 Essential Training course on lynda.com, and I’m working on a similar Python 3 course to be released later this year. So I’m happy to recommend those languages. But I would never recommend them for systems work.

If you want to become a well-rounded programmer, I will always recommend that you start as low-level as possible, which for most people is C. You will get a great introduction to how computers work and develop skills that will serve you well as you learn other languages later on.

Where you go from there depends on your goals. For applications coding, I suggest C++ or Objective C; for web or sysadmin work, I suggest Perl and Python (both, not either). Object-oriented (OO) programming is here to stay, so C++ and Objective C will serve you well for years to come, and Python’s OO model is superb. Perl is simply essential because so much existing code is written in it, and it’s a great language for smaller projects that don’t require a lot of indirection or OO patterns.

Please note my biases here: I’ve never been a fan of PHP or ASP. These languages exist for purposes that have little to do with their merits, and their design and implementation show this. The question asks for my opinions, and my recommendations necessarily reflect them. That said, I have worked in both PHP and ASP and will continue to do so when clients or development environments require those languages.

The bottom line: learn as many languages as you can and pay attention to their distinctions and commonalities. As you do so, you will necessarily develop an eye for patterns and paradigms that can be borrowed from one environment and shoe-horned into another, making you a more effective and more efficient programmer. You will also gain satisfaction from your growing mastery along the way.

—Bill Weinman, April 2010