which programming language is best to learn?

If you had to pick one of the following to learn, which would it be & why? Perl, PHP, Java, JSP, Python, or Ruby?

I’ve dabbled in perl, PHP, and Python, but that plus a 140-character limit makes for an unsatisfactory answer, so I asked my software-engineer, has-coded-in-40-languages husband, Grant Gould, for a better one. (You may remember him from the Notes from a Techie Patron guest post series.) So, Sara, here’s your better answer:

Selecting a language to learn depends, foremost, on three things:

The set of tasks you are contemplating — do you want to build a website, a desktop or phone application, toys, useful work, …

The resources available to you — your own prior experience, knowledgeable peers, classes, etc.

Your temperament — Where do you fall on the continuum from doing abstract, mathematical thinking for fun to hands-on try-it-and-see-if-it-explodes?

With that in mind, let me briefly consider each language on the list:

Perl — I’ll say it outright: perl is a terrible language for newcomers. While there is a great deal of dispute as to perl’s general suitability as a swiss-army-knife language for experienced developers, very few people still argue that beginners should go anywhere near it. PRO: Can do anything; CON: Not for beginners.

php — php is a really convenient language for writing dynamic web content. If you already know HTML and just want to write relatively simple database-backed web applications, php is a fine choice. The language itself is reasonably clear and ergonomic and integrates directly into HTML, which can be very convenient. PRO: Convenient for small (3-10 page) web applications, lots of good online tutorials; CON: Only really useful for writing web pages. Becomes unwieldy for large sites.

Python and Ruby — These languages are really very, very similar. Both are real, general-purpose programming languages created with clarity and ease of learning in mind. Each has a framework for writing web applications (django and Rails respectively).

Python is slightly more “mathy”. It is also an older and more mature language with somewhat more tutorials and online lessons. Django is designed around relatively hard-core developers and high-performance websites, and can be intimidating to learn. PRO: A sound introduction to programming fundamentals; unparalleled online resources; CON: No easy way to write simple web applications.

Ruby is slightly more “pretty”. It is newer and has a bit of a reputation as a hippy language. Many people consider Rails the quickest way to learn how to build a database-backed website. PRO: Ruby-on-Rails is the quickest zero-to-website tool out there; CON: A little younger and (IMO) less elegant than python; fewer and lower-quality online resources.

Java is a very powerful language from the tradition of the “systems programming” languages (C and C++, for instance). It is well-suited to enormous projects and can be quickly learned by experienced engineers. But its galloping complexity makes it a tough language for beginners. Java is probably your best choice only if you (1) have access to a real class with feedback and graded projects, and (2) intend to develop something big and long-lasting. PRO: Almost unmatched for large-scale, long-term development; A solid foundation for hard-core engineering; CON: Big, complex, hard to learn.

JSP is an attempt to put a php-like syntax on top of Java. Opinions differ widely. Generally php will be a better choice unless you need high performance or need to integrate with some unusual components like a custom data source of some sort. PRO: Lets you hang with the Java people, whose parties probably have better catering; CON: lipstick on a pig.

Javascript is a scripting language for writing dynamic web pages. Most things that can be done with Javascript can be done with server-side languages, but only Javascript will deliver the sort of seamless speed and interactivity that people love these days. However most websites with Javascript also have much larger chunks of back-end server code written in some other language — the javascript is the icing, not the cake. PRO: You’ll probably eventually want to learn it anyway; CON: Widely hated. Involves you in horrible microsoft-apple-mozilla standards flamewars.

In summary:

If you are a hands-on person and want to write a tiny little dynamic website quickly, use PHP.

If you want to write a less tiny but still small dynamic website, use Ruby.

If you are an abstract thinker and want to learn how to program, use Python.

Only learn Java, JSP, or Javascript if your circumstances make them appealing for other reasons.

Give perl a miss. Even among professionals few people are more than lukewarm about it.

By the way (and back to my own words here, not Grant’s): I am both highly mathematical in my thinking and totally inclined to build something and see if it explodes. (I find perl self-indulgently unreadable, PHP workmanlike and useful, and Python lovely.)

18 thoughts on “which programming language is best to learn?”

Nice synopsis. Would actually disagree with your assertions on PHP, however. There are a number of massive sites written in PHP–the user-facing portion of Facebook being a prime example. Its success as a web application language also overshadows its utility as a back-end programming language.

In general, and as you allude to, it’s good to be well-rounded with several languages under your belt. That gives you the flexibility you need to develop interoperability.

Yeah, I’m going to have to ask him for clarification on PHP, as I’ve sure seen what appear to be large web sites in PHP (I guess I can’t distinguish “outward-facing PHP on top of a something-elseback end” from “all PHP all the time”, though).

What I meant was in the context of the original question being someone relatively inexperienced. While I have been involved with large websites in php (two companies ago, ah the olden days…), I don’t think a novice php programmer would have had much of a chance of debugging or maintaining them.

It is indisputably true that an experienced team can do absolute marvels with php.

1. Perl code can actually be very readable, and it doesn’t have to be hard to learn. The problem is that the language is too flexible for its own good; there are far too many ways of accomplishing the same thing and people end up writing code in their own preferred dialects—all of which are understandable to the Perl interpreter but many of which are not mutually comprehensible among Perl programmers. It is very much the anti-Python in this respect. (One reason Python is so easy to learn is that there is a common consensus about what is Pythonic and the result is that it is far easier to read someone elses code than with most other languages.)

2. I think PHP is ugly, unpleasant, and decidedly inelegant. There. I said it. You should still learn it, but expect to spend a lot of time trying to figure what packages are and are not built in on your system and don’t expect what you learn with one package to cary over to another.

1. I definitely agree with the “can be readable” part, but I think there is so much ability and temptation for it not to be — to make the One Regexp To Rule Them All — and to an extent there’s a macho cultural reward for doing so — that, yeah, in practice, it descends into incomprehensibility and incommensurability pretty fast. (Even though I myself am not immune to the conceptual elegance of that one regexp…It’s just a case where conceptual and visual elegance can diverge really far, really fast.)

2. You don’t see me disagreeing :). I mean, I did find it easy to learn the basics pretty fast, but the second I’d learned any Python, PHP looked grody in retrospect.

I find PHP to be an inelegant language. Frankly, the thing that turns me off the most about it is that all scripts, even non-web-based scripts, have to be embedded in pseudo-HTML tags.

That said, PHP is used everywhere. If you are not starting from scratch, and doing web development, chances are excellent you’ll find yourself looking at an open-source package written in PHP. (Here I’m thinking of all-in-one site packages like WordPress, Drupal, Movable Type, but also a number of individual libraries as well).

The one place that I find myself going to Perl again and again for is as a more powerful version of sed and awk. There’s a lot of things that I can do in sh, sed & awk that are faster and easier to do in Perl.

Command-line scripting, quick one-0ff scripts to add a user or the like often work well in Perl. Also, many admins haven’t really dug into Python, but everyone can read a basic perl program.

I’m surprised that there wasn’t a really good grouping of languages, and there are alot of things missing.

-> Java is a compiled language, so it’s fast and does just about everything. It needs to be considered in the same breath as C, C++ and Objective C. It’s also the language for Android Apps. Compiled Object-oriented language are generally bloated and not for the faint of heart.

-> Perl & Python are scripted languages that are relatively fast. You need to have a reasonable understanding of how computers work (why doesn’t a list just work like an array as in PHP?) to do these right, but Python is one of my very favorite languages -> and it will continue to be in future (see below).

-> PHP, JSP & Ruby belong together. They are pretty much intended for web pages/development and are comparatively slower than previously mentioned languages (this rarely matters these days -> much better to have readable code). Ruby is great in part because it is natively RESTful -> that means you can have an API in quick order.

-> There are a wide range of experimental languages that deserve some mention. For one, there are a group of languages in the Functional paradigm like ERLang and Haskell that are gaining traction. For instance, Python is picking up on alot of the principles of functional programming. I’ve also recently become familiar with Natural Language Programming (sEnglish) which might have some theoretical interest for Systems or Humanities librarians.

Haskell is among the gazillion languages my guest poster has used :). I am intrigued by its stylish mathiness, I admit. But since the context of this post is languages for relative newbies — maybe even “if you, as a librarian, don’t know any languages and want to learn one — something you can pick up independently and do something useful with even without huge background — which?” Do the functional languages have any utility in that context (I haven’t personally used any; just talked about them), or would they really only be useful for someone who already had a reasonable practical (and maybe theoretical) grasp of programming, and/or a job requiring substantial coding?

I’d say it’s kind of like saying ‘is learning butterfly important for swimming?’ Learning butterfly can be a real barrier to a beginning swimmer, but in the long run getting over the butterfly ‘hump’ can really benefit the swimmer down the road.

Understanding a little bit about functional coding can keep alot of bad coding habits from developing. It’s definitely not essential for anyone who just wants to make something work, but it will definitely improve overall coding ability as projects get more and more complex over time -> ie. especially if you get into development kits / libraries etc.

Either way, I’d say it deserves a theoretical mention – if only to remind that there are a billion ways to skin a cat. When I suggested that there were ‘things missing’ I really meant more C, C++ and (especially) Objective-C, since that’s what’s used to develop iPhone Apps.

Although I know this doesn’t apply to everyone, I find I learn programming languages best through tackling practical problems.

This means, to a certain extent, you may want to a pick a language that is relevant to your environment. This may depend on the systems your library uses, or the languages the communities around these systems use.

I’m more a scripter than a heavy duty programmer – I learnt a version of Basic when I was young, and found Perl a relatively easy step from there – and it’s still my ‘go to’ language. I’ve dabbled a bit in PHP (mainly to be able to do stuff in the Open Source Moodle VLE software, and of course, WordPress), and recently started with Ruby – which after a slow start I found myself liking quite a lot (although I wasn’t using Ruby on Rails – just Ruby).

What I would reiterate is that for me whenever I’ve tried to learn a language in the abstract (from a book/website using set exercises) – I’ve failed, because I haven’t actually engaged properly. It’s only when I have to solve a real problem that it clicks for me.

Perhaps if you were anything of a developer you might have already seen that there is a huge movement behind out-of-browser and server-side Javascript now. Go take a look at Node.js or CommonJS for two gleaming examples.

Javascript is an interpreted language with the same potential as any other. Now that people like Google are pushing it to new levels (V8 engine) people are taking notice and using it for more than just a brain-dead jQuery sliders.

The excellent Qt C++ framework is now using a Javascript/ECMA inspired/based declarative language for GUI applications.

You know, now that I have added somewhat to that list of languages above and am spending a lot of my day job pretending to be a developer, messing with jquery and Python on a Django site — I disagree that Django is intimidating to learn. Or rather — there CAN be some bits that are intimidating, but they were going to be intimidating in a non-Django environment as well, and Django does an awesome job of simplifying the bread-and-butter web site things we do all the time. Yes, there’s a paradigm shift in getting your brain around the MVC thing, but once you have Django gives you a ton of stuff practically for free. You need a comfort level with Python to get into Django, but given that I totally have a crush on Python anyway, that’s cool…