Archive

Posts Tagged ‘20/20 hindsight’

So… Where Do I Begin?

January 27th, 2009

Previously I made the claim that learning a language affects how you think. Here’s my take on what you might want to try, if you are thinking about picking up programming.

This article, while designed for someone who hasn’t yet started programming, must needs contain some technical terminology. I originally considered littering the text with footnotes, but who likes reading footnotes? (Unless they’re written by Dave Barry, of course!) Instead, read this glossary thingy first, which should serve a as a mild introduction to some basic “lingo.”

This is obviously going to be for a very specialized audience–the intersection of the set of people who read my blog and the set of people who aren’t programmers but could see themselves maybe becoming one someday. Hopefully it will be at least mildly interesting to those of us who don’t belong to the empty set :)

My reasoning behind my suggestions is based on equipping you not only with a tool that will help you accomplish some task, but that will stimulate you intellectually and help you think about programming. It will also hopefully provide a solid foundation that you can build upon so that you will find it easier to program in future languages you may learn (perhaps ones that are more task-oriented).

As such, I will start with some I think you should not learn as your first language, and why. Obviously, I’m not saying you should never learn these (quite the opposite in the case of some); just that they maybe shouldn’t come first.

  • C – An excellent language, and incredibly useful (still today one of the most-used languages in spite of its simplicity). It also has a small syntax and standard library, making learning it on a superficial level quite easy. However, based on the criteria I mentioned above, I cannot recommend it as a first language. It lacks too many helpful abstractions, and indeed tends to force you into pretty specific coding styles. This is a pity, because I’d really love to recommend it on the virtue of what it teaches you about how many other programming languages work “under the hood.” Learn it second!
  • C++ – Built off C, C++ had the aim to deal with the aforementioned lack of abstraction–in other words, just as you don’t need to know how a car works to drive one, you shouldn’t necessarily have to know how a computer works to write programs for it–but still be compatible with C code. It became quite popular in its day, and indeed there is still an enormous amount of programs written in C++ around. However, while I applaud its goals, its execution is lacking. It’s ridiculously complicated in about every way you can think of, and when you combine that with the lack of any training wheels or even safety belt (a wrong move can crash your program or corrupt data, and often it is unable to tell you why)… you’re asking for trouble. There are certainly C++ zealots around, but I’m just as certainly not the only one who thinks that learning it well is not worth the titanic time investment.
  • Java – Many people will disagree with my putting Java on the not-learn-first list; indeed it’s the one they teach you first at BYU and lots of other schools (although only ones striving to be “practical”–Computer Science programs that take a more academic approach tend to use other example languages). Java came along as an answer to the madness that was/is C++, and became very popular in the business world. I reckon it’s still the Biggun’. One of its most interesting features is that it is cross-platform–that is, your program will run on Windows, Mac OS X, Linux, etc. (This is not a typical thing!)

    I say don’t learn Java first, because quite frankly of the Java-like languages it’s not the best. It lacks some features and is quite verbose; you end up writing a lot of boiler-plate code all the time. I can also say that from personal experience, if you learn it first, it makes you think “in Java.” And in hindsight, that’s not how I want to think :)

  • Javascript and PHP – Two good languages, and ones you more-likely-than-not will learn eventually. I don’t recommend them as first languages for a couple reasons. For one thing, they are very loosely typed–this means they are very willing to “try and guess what you meant.” This is a pro as well as a con, but I think you will appreciate it more–and it will bite you in the butt less–when you have some experience under your belt and you actually understand what “loosely typed” means and how it applies to code you write. Another reason to steer clear of them is that they are almost the trademark “newbie languages.” This has a number of implications:
    • No real community to speak of. Most of the people who program in them do so not out of a love for the language, but out of desire to get something done quick. The “community” is a lot of people who would be new like you–and when you’re new to a language, I’ve found it’s helpful to know where to find experienced people.
    • Lots of code for these languages that’s out there on the internet–both example code and libraries (that is, code that others have written to perform a task so you don’t have to write it) are written by people new like you. Again, as a newbie programmer, you want to learn from and use code that is as close to professional quality as possible.
    • Security gotchas. Though this kind of thing does of course get better as time goes on, rapscallions are well aware that code in these languages is both very popular and often written naively. Thus if there are vulnerabilities, they are going to be found out and exploited.
    • General lack of emphasis on proper coding style, algorithms, etc. As very permissive languages, they permit you to write steaming piles of… code.
  • Perl – I have a soft spot for Perl, but as one of the most organic languages out there, it has become a bit overgrown with decade-old weeds. Additionally, it has a lot of subtlety and complexity, and lots of syntax. Unlike C++, it can’t wreak havoc on your whole system, but I have accidentally erased files before by getting the file-opening syntax wrong. (I know that came off as anecdotal FUD, but I was merely listing an example. Again, I like the language, in spite of its quirks.)

    Perl has a dedicated and experienced community behind it, that I’ve found to be helpful and excellent. It’s also got probably the largest collection of freely-available libraries of any language out there. But in reality, I wouldn’t recommend it as a first language, and even as a second language I’d recommend waiting for its next incarnation to come out (which has been in the works for many years now. The language’s designer recognized that Perl needed a complete rewrite, and so it’s taking awhile).

  • Visual Basic – If we were speaking of “classic ASP” or Visual Basic 6, all of the above commentary would apply, and then some. Nowadays, however, you’d be more likely to encounter VB.NET, which is built on the .NET framework and (though I’m overgeneralizing) is essentially a way to write the same code as you could in C#, but with different syntax. However, that being said, there are no benefits to doing so, and the code you write is both ugly and dissimilar to any good language. So there’s simply not a reason to start here.

I believe that about covers the most common starting points for a new programmer that I wouldn’t endorse. There may be others, but I don’t feel qualified to comment on languages that I myself haven’t learned to at least some degree.

Anyway, the more interesting stuff: what do you learn, then? Haven’t I just ruled out like every popular language?

Well, understand it is quite random which languages end up becoming popular; indeed, the only thing they really have in common is that they are generally not the best of their kind–or even if they were originally, others took what they did right and combined them with other stuff done better.

Assuming you fall into my target audience (you want to learn what will be helpful in the long run, recognizing that as a brand new programmer you won’t be writing 3D games and huge financial systems for a while anyway), you are have lots of pretty good options available. Here’s a list! I’m going to put it in order of “amount of brain-stretching required”–you can decide for yourself, based on your various capabilities, which might work best for you.

  • C# – I’m a tad hesitant to recommend this as a first language. It was my first language, and it is a good language, yadda yadda. Syntactically, you can think of it as a significantly better version of Java: it has several constructs that Java doesn’t, making it much nicer to code in. It’s also got tremendous IDE support, which I think is good and bad as a programmer seeking to learn the ropes (but that’s a topic for a different blog). And when it all comes down to it, it will get you in a mode of thinking that is similar to a Java programmer’s: somewhat roundabout, somewhat repetitive, somewhat verbose.

    If you do choose C#, try and take advantage of the features that new versions have offered, and continue to make a great effort to do so as future versions are released. One of its big advantages over Java is it continues to introduce solid ideas from other languages every couple years. Note that it isn’t strictly Windows-only anymore; the effort to get it on other platforms has been actually quite successful.

  • D – I’m going to make an exception to my rule here, and list a language I’ve never learned. I do so because D is one of the languages I’ve only ever heard good things about–which is rare in the world of programming languages. D is, in short, what C++ should have been (or should be). It’s even designed to be able to fill that close-to-the-machine niche if needed. If you learn it, let me know how it goes!
  • Python – This is probably the most popular language out there that is the most solid and straightforward. It was designed to avoid trickiness and to be very uniform; indeed, their motto (paraphrased) is “There should be one way to do things.” This even includes how the code looks on a piece of paper: all very uniform. There are lots of newbie resources available, tons of example projects written in good style that you can study, and plenty of libraries to help you do all sorts of stuff.

    With as much praise as I have for it, I’m actually not the hugest fan of the language, simply because I tend to prefer a system that allows for a bit more cleverness. (There are also some aesthetic quibbles I have with it.) But you could do a lot worse than learning Python first. It will especially help with getting you in the habit of writing well-formed code, in any language.

  • Ruby – Ruby is similar to Python in some ways, but different in philosophy and in the sort of coder it tends to attract. It was my favorite language for a long time, and I think it scales well: you can start by writing in Python-like style, and as you learn new tricks, incorporate them. The result is both simple and concise. It commonly uses certain programming constructs that, while they may exist in a language like C#, don’t play as big a role–therefore in Ruby you get to appreciate their power more frequently and understand them sooner.

    Ruby was also designed with “metaprogramming” in mind–that is, you can play with how the language works. This isn’t really important to know as a newbie; I mention it as part of showing that there’s definitely “growing room” for your brain as you learn this language.
    Note: Don’t confuse Ruby with “Ruby on Rails,” which is a framework written in Ruby. I don’t recommend jumping into Rails right off the bat, without learning Ruby first.

  • Scheme – Scheme is a great little language, unfettered by frivolous syntax and unnecessary complexity. It is a “Lisp,” meaning one of a family of languages that share an important trait: they are incredibly easy for humans and computers to parse. This means you can easily write code that writes code. Programming in a Lisp is very fun if you don’t mind stretching your brain a bit–and I’m writing this blog for those that don’t.

    One nice thing about Scheme, is it is used as the example language in several books about how to learn programming the right way. (Most programming books are closer to either “how to learn Language X the right way” or “how to do task X with Language X”.) Also great is a couple of these books are free: SICP and How to Design Programs. I also recommend The Little Schemer.

  • Haskell – I’m learning Haskell now, and consider it to be the closest thing out there to the “holy grail” of languages. It’s incredibly well-designed, and is packed with cool features, and it has one of the most helpful communities I’ve yet encountered. It’s also the most brain-stretching of any language I’ve mentioned on this page. Though I’m sure some would disagree with me, I am of the opinion that it was designed by smart people, for smart people. Or, that is to say, that smart people will be able to harness it best. (Standard disclaimer about not measuring your self-worth by whether you can code in Haskell, yadda yadda [even though I personally measure my self-worth by everything I can't do... but that's for another blog.]

    I just mean that there is a lot you can do with a language like it if you have the tools upstairs, unlike, say, PHP–which is like “programming to the lowest common denominator.”) I won’t launch into any significant description of the language here, as someday I plan on writing about it more–hopefully in a fairly approachable way.

Of course, there are many other good languages out there. Again, I’m a bit limited by what I’ve had time to digest personally. Also, some languages are worth learning, but perhaps not first. Let your intuition guide you–learning a language should be fun and interesting, and if it’s not, something is going wrong. If you absolutely aren’t enjoying one of my recommendations, don’t let that turn you away from programming in general; by all means give something else a shot.

I’m only able to speak out of hindsight, and indeed it’s probably that warped kind of hindsight wherein if you went back to your old self and gave him advice, he’d probably just look at you funny. But such is life, and such is programming.

Vaguely Instructional , ,