First Programming Language – Python/Ruby?

A little while ago we had an interesting discussion on what programming language should be taught to CS majors. I think that overwhelming number of people agreed that C++ is a solid choice because provides students with a very solid, low level background. The argument was that skills such as manual memory management will make them better programmers in general.

I partially agree with that notion but then again my exposure to C++ remains limited. I worked with it a little bit back in high school then moved over to Java in college and never looked back with exception of few parallel processing assignments I did in grad school. Even today the mere thought of manual garbage collection and funky pointer arithmetic makes me shudder. I can do it, but it is a chore and a major pain in the ass.

So while C and C++ remain good languages to know (or at least to have dabbled with) they are probably not the best languages to start with. Neither is Java for that matter. Let me show you why. Let’s do a simple hello world in couple of languages starting with C++:

#include 

main()
{
    cout << "Hello World!" << endl;
    return 0;
}

Not very complex bit of code but it could have been simpler. If you are showing this to people who have never programmed before you have to explain bunch of things. For example you need to explain the include statement and avoid mentioning the pre-processor, class headers and libraries because it will confuse people. You will need to hand-wave over the main() invocation and the return statement because you don't want to introduce functions in the first 5 minutes of your first lecture. So you tell them all of this is standard boilerplate they will just have to remember for now.

Java is even worse:

class HelloWorld 
{
  public static void main( String args[] ) 
  {
     System.out.println( "Hello World!" );
  }
}

Now you need to explain away the whole class structure, methods, and tell people to ignore that damn String args[] argument they are bound to ask about. I believe this is why a lot of Java instructors turn to BlueJ for their introductory classes. They try to hide away the ugliness and verbosity of the language using the little GUI driven IDE where objects show up as little square boxes you can click on. I mentioned that I consider this practice to be harmful. Why? Because it teaches students to click rather than code. It builds a reliance on a gimmicky IDE, and stops them from learning how to use the language. I worked with some of these students and half-way through the semester none of them could independently write a self-contained Java program because they did not reach the point in the book where they teach them about the main method. They could not experiment, and build tools and small utilities for themselves because they were tied to a cumbersome IDE designed for doing programming exercises rather than programming. But I digress...

Rather than turning to silly tools like BlueJ why not simply pick a language that works? Do you know what was the first language I learned? It was BASIC. And no, not the Visual one. The good old BASIC where you would do:

10 PRINT "HELLO WORLD"

Horrible, horrible language but we all had a blast working with it and making infinite loops using Goto statements before we have learned that it was considered harmful. Of course after a semester I moved on to C++ and had a blast with it too. But that's because I discovered my new passion - programming. My brother took the same Basic class few years later and had tons of fun too. In fact, he enjoyed coding in that archaic language so much I almost thought we will have two code monkeys in the family. But he was unable to make the leap to C++ the way I did and gave up on programming altogether.

This got me thinking. First programming language should be something just as simple. You want to allow people to create working code with as little boilerplate and memorization as possible. You want them to just jump in and go crazy - you want to give them that immense joy of programming that both me an my brother experienced in a Basic class. But you don't want to use Basic because it is ancient. You want to give your students an environment they could install on their home computers. Something they could run on their machines and mess around with. Enter Python and/or Ruby. The syntax of these languages is simple, concise and fun.

Let's do Hello World in Python:

print "Hello World"

Or in Ruby:

puts "Hello World"

See what I mean? No boilerplate, no hand waving, no cryptic keywords. It just works. Not to mention that both Python and Ruby come with an interactive console. Students can just type in some code, hit enter and see it work. This allows them to just jump in and play seeing the results in real time. For the first few class sessions they can just learn the basics of the language and create simple iterative scripts in the console - completely interactively and without worrying about compiling, or naming their files the right way (like in Java). Eventually you will want to show them how to create and run script files but initial I think that interacting with a console would be a good initial experience with a programming language.

Both Python and Ruby can be used to teach students the bare bone basics such as branching and flow of control, loops, working with lists and arrays, functions, recursion, classes, methods and objects, inheritance, polymorphism, closures and etc. Some of those concepts are difficult to learn as it is. Throw in a very rigid type system, a verbose syntax and standardized boilerplate that "you don't need to understand just yet" and you double if not triple the amount of cognitive processing needed to comprehend them.

Python, Ruby and similar languages make it easy. The syntax is terse, concise and very readable. The dynamic structure of the language and the presence of an interactive console means that students can code fast, and get immediate feedback. This is the way programming ought to be - quick, fun and interactive. After a semester or two you could graduate them to the craziness that is C++ or the kingdom of verbosity that is Java. But by that time they will already have a solid foundation and will be able to learn the quirks of the new language.

What do you think?

And no, I don't think I did a complete 360 on my position from the linked post. I'm just trying to look at it from a different direction. I really think that my position was influenced by my dislike towards BlueJ which aims to hide the ugliness of Java under a point, click and drag like interface. In effect they learn a "safe" subset of the language which IMHO is wrong. I think they would learn more and better just using notepad and the command line javac compiler rather than this funky IDE. After all, this is how I learned.

But in retrospect, I realized that this may not be the best way. Some people would excel in such environment, but not all. After all, I had my wonderful adventure with BASIC, and then C++ before I ever touched Java. I already had the experience of easy, fast and interactive coding. Perhaps this is the way to go then. Instead of hiding the ugly parts of Java why not toss it altogether the first semester. Introduce students to programming with a dynamic, interactive and easy to read language such as Python or Ruby. Then, once they get the basics toss them onto the deeper waters of statically typed, compiled, overly verbose "enterprise" scale languages.

This entry was posted in Uncategorized. Bookmark the permalink.



25 Responses to First Programming Language – Python/Ruby?

  1. mcai8sh4 UNITED KINGDOM Opera Linux Terminalist says:

    I also started with BASIC (back in the good old days of the BBC micro), over time I progressed to TURBO PASCAL. I found this language had quite a nice steady learning curve, enabling people to grasp the programming basics, without going into too much depth. Then, at uni, we moved onto c, then c++. Whilst at one stage I was quite competent, I now only really have memories. Now-a-days my programming (if thats the correct term) only consists of bash scripts (useful and enjoyable, but limited). I’ve been promising myself to learn python, but still haven’t found the time (bad excuse I know). Hopefully I’ll find a good online tutorial, that can keep my attention long enough so I can get back into coding.

    Reply  |  Quote
  2. astine UNITED STATES Google Chrome Windows says:

    I started first on (Turbo) Pascal and later moved to C/C++. It’s a good one for teaching as it makes each programming construct explicit and forces students to learn what they are doing, though by now, it is horribly obsolete in terms of paradigms available. I like Scheme as a teaching language as it’s very flexible (you can teach any construct with it) and very simple. It’s also quite interactive, even more so than Python or Ruby. Of course, the whole lisp metasyntax thing could be liability when trying to teach students basic concepts that would be better demonstrated with a language built to support them specifically, but there are always trade-offs.

    Reply  |  Quote
  3. I learned BASIC first, but that is because it was back in the seventies and BASIC was on every popular computer back then (Apple, Atari, Commodore, TRS).

    I think it is still a good place to start, although a lot of poor programming habits can happen, like “spaghetti code”. Pascal is good to learn top-down programming and dynamic data structures, but isn’t around much anymore. Object oriented programming requires C++ or Java, but I still think old-school methods need to be taught first. I have seen a lot of crap OOP code just because the programmers lack the older methods.

    Reply  |  Quote
  4. freelancer SWEDEN Mozilla Firefox Windows Terminalist says:

    Ah, BASIC. The first programming language I used. It will always have a special place in my heart. Personally I think it’s a great place to start, as long as you don’t try to get too advanced with it. And if you later move on to C++ and someone can’t handle it, then programming really isn’t for them. I mean sure, they need to learn OO, but first they need to learn loops and stuff, and that can be done just fine in BASIC without any overhead. As for Python or Ruby, I have no opinion, since I haven’t used any of them.

    (Yes, I realize BASIC is horribly outdated, but I’m speaking from a conceptual point-of-view)

    Reply  |  Quote
  5. I think that Python makes a great first language. One can easily learn the fundamental programming concepts with it. Its interpreted nature makes for a great flow. You can start with console-based programs and easily move to GUI or Web-based. It is also very flexible. It can be used in several styles like scripting, procedural, funcional, object-oriented, aspect-oriented… And it scales, in the sense that you can use it for real-world projects. I think you’ll find several articles on this subject.

    Also, I think Ruby would be a very solid choice too, but I favor Python because I think it can be more easily grasped.

    Reply  |  Quote
  6. Mohan UNITED STATES Mozilla Firefox Fedora Linux says:

    Been interested with Python so in the summer I shall tackle that and Ubuntu comes with Dive into Python anyway! :-D

    Reply  |  Quote
  7. Mart SINGAPORE Mozilla Firefox Windows Terminalist says:

    I started out in C back in uni, around 2003.

    #include

    int main() {

    printf(“Hello world!”);
    return 0;
    }

    Pretty easy to explain actually. Learnt variables (declaration and initialization), functions, methods, classes.. All the basic concepts of programming.

    But I got lost when pointers came about.. :P

    Reply  |  Quote
  8. BASIC languages are easy to understand. but not advanced like C++

    Reply  |  Quote
  9. ths GERMANY Mozilla Firefox Windows Terminalist says:

    I started with different assembler languages and considered BASIC a great leap forward.

    Dijkstra’s “goto considered harmful” was a major milestone in the 60s when he published it in the ACM, but nowadays noone remembers what it was really about. He only considered the goto *into the middle of a loop* harmful, not goto per se (a halfway modern example would be Duff’s device, see the comp.lang.c FAQ for that). You need goto (or it’s machine code equivalent JMP).

    After that I started pascal on the Apple, and returned to 6502 assembler for a long time (years). With the rise of PCs I started Turbo Pascal, then 8086 assembler, which is horrible, then I turned to 68K assembler, which is wonderful.

    At university I used Scheme, Lisp, Forth and Prolog. While being in Fidonet I wrote a nearly full-fledged BBS and mailer system in gnu-C for OS/2, including a UUCP bridge. My first real job after working 4 years for the university’s computing centre was a bit of C as well, later it was Prolog, perl and some Javascript (Tivoli Monitoring).

    My current job involves Java, perl, sh, awk, and a bit of JACL (the tcl based controlling language for websphere scripting).

    Perl is a good starter, and later you can throw in the OO parts and have ready-to-use production-proof modules for CGI, RDBMS interfacing, XML parsing, AJAX, network protocols and everything else. I love perl!

    #!/usr/bin/perl
    print “Hello world\n”;

    Reply  |  Quote
  10. Paul AUSTRALIA Galeon Debian GNU/Linux says:

    I started out with Commodore Basic on a C64, later moved to Pascal in university (which is the first language they taught to all first year students) and then on to C.

    Interestingly, about three years later, the university started teaching all first year students Miranda (very similar to Haskell) as their first programming language. Odd choice to go with a functional language, but I suspect it made them very good at recursion :)

    But I agree, Python is probably a good choice, as a student can get their code up and going quickly without having to learn how to pull in various I/O libraries first…

    Reply  |  Quote
  11. Take Lua for a spin,… the single most easy language to start programming with.

    Reply  |  Quote
  12. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    I was thinking about mentioning scheme and perl as other possible starter languages. But I reconsidered.

    Perl is a great language, and I love it to death but it does allow you to get more cryptic and ugly than you could imagine. Observe:

    #!/usr/bin/perl -iD9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L'6
    @A=unpack"N*",unpack u,$^I;@K=splice@A,5,4;sub
    M{($x=pop)-($m=1+~0)*int$x/$m};
    sub
    L{$n=pop;($x=pop)< <$n|2**$n-1&$x>>32-$n}@F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c
    ^$d},sub{($b|$c)&$d|$b&$c},$S);do{$l+=$r=read
    STDIN,$_,64;$r++,$_.="\x80"if$r< 64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8
    if$r<57;for(16..79){push@W,L$W[$_
    -3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A;for(0..79){$t=M&{$F[$
    _/
    20]}+$e+$W[$_]+$K[$_/20]+L$a,5;$e=$d;$d=$c;$c=L$b,30;$b=$a;$a=$t}$v='a';@A =m
    ap{
    M$_+${$v++}}@A}while$r>56;printf'%.8x'x5 ."\n",@A

    This script computes SHA1 of the stdin and I found it here just by googling “cryptic perl”.

    Python on the other hand forces you to structure your code in a way that is clean and readable because of the white space thing and lack of semi-colon line terminators.

    I was a TA in a introductory Java class one semester and I had the “pleasure” of grading the coding assignments and I saw many, many, many programs which looked like this:

    public class Foo { public
    Foo(int a, int b)
      {  this.a = a;
    this.b = b;} 
                       public bar(){
           return a+b;}
       }

    We actually had to cut points for indentation because people would write the code whatever way they wanted. Python sort of forces you to develop god habits early.

    Scheme is a great language to start with but it is probably not something the students could use in their daily life. Python knowledge will allow them to start writing useful scripts – and there are hundreds of libraries out there that will let them interface just about anything. If they want to try their hands at a web design they can set up a Google App Engine account and mess around with it. Same with ruby – it’s one of the hottest, most talked about languages on the Internets these days. Students will feel they are learning something that is relevant. Scheme is more or less a teaching language and most people don’t use it for real world stuff – they usually go with Common Lisp or other more complex dialect.

    Reply  |  Quote
  13. Mohan UNITED STATES Mozilla Firefox Ubuntu Linux says:

    [quote comment=”10654″]BASIC languages are easy to understand. but not advanced like C++[/quote]
    That is true, but those BASIC languages can be used as a stepping stone so that the new comer can feel comfortable.

    Reply  |  Quote
  14. dawgit GERMANY Internet Explorer Windows says:

    You guys make me (feel) old. When I went to High School, computers were the size of High Schools, Basic hadn’t been realeased yet, little on tought anywhere.
    anyway…
    I do believe that Basic * was the first language I did learn. From that we went right ing into DOS and started to tweak the actuall OS. (To do what is was that we wanted / needed it to do in the first place.) This drove the ‘High Paid’ ( & High Cost) Software Vender Reps (now called consultants) Crazy. First because they were clueless as to what we were actually doing, and second because, we had pre-empted any possible future business dealings with the “Organization” I was with. They would just walk away shaking their heads. Oh-well. It worked though, and very effectively at that. Perhaps, even in what we today call, an ‘Open Source’ enviroment. Example:
    There would be a ‘Challenge’, to get a computer to do what x (#) of people did in y (amount) of time, quicker. Sgt. Snuffy, in one shop, and Sgt. Duffy, next door, would come up with a method to do that at the OS level. They would than walk (no internet yet) it a bit to Sgt. Scruffy’s shop, let him and his monkeys play with it“Their” Software.
    Oh-well, it’s all history now. After that I think I went on to Assembly, C, and so forth. Now, if I need something done, I search for “Best Methods”, learn what-ever I need to know, and run with it.
    Why all that (above) rambleing? My point here: 1) people still need to know the “Hows” in the simplest and most basic form, to be able to build on it, sucessfully. 2) The most trusted, trustworthy, safe, and secure systems are still those built useing the most basic and simplest software programming languges. (‘C’ and ‘Ada’). The rest is just ‘fluff’ and ‘eye-candy’ for the web only brained users, from ‘Shake & Bake’ (psudo)programmers. They look good but…
    Let’s teach the next bunch of programers to be better than us, not just ‘prettier’. Yes, it takes longer, (like any of us learned anything over night) but we’ll have true “Quality” over “Quanity” in the future Programs.
    Just my 2 € cents. -d

    (* Please don’t ask me which Basic varity I was useing, there were many, I don’t rememder that, that far back -d)

    Ps. OT… Any one into Ada? I’m starting to (try) (re-)learn Ada, the 2005 version. I’m a rather “Old Dog”, and it seems a little slower these days. -d

    Reply  |  Quote
  15. Matthew UNITED KINGDOM Mozilla Firefox Ubuntu Linux says:

    My first coding was done in BASIC on an Amstrad CPC when I was a kid. I’d spend all day typing in a game from a magazine, then hours more debugging it. But I lost interest and let it slide.
    Cut to present – I switched from Windows XP to Kubuntu about 18 months ago, and it got me interested in programming again. I tried a few languages and found them a bit tough (Java and Perl were the main ones). Then I got a book about Python, and for the first time since BASIC I feel like I’ve found a good language to learn. I also agree with your comments about IDE’s – I’ve been using Vim for all my programming, and it’s the best way to go IMHO.
    I actually think it would be a good idea if computer and operating system vendors made more effort to encourage people to program. With my Amstrad, I got a BASIC interpreter built in, and a book the size of a phone directory to teach me how to use it. Why couldn’t manufacturers include appropriate development tools, such as a Python or Ruby interpreter, on Windows PC’s together with a nice easy PDF document called “Learn to Program” on the desktop? Or if Microsoft insisted on using one of their languages, they could include Visual Studio Express? I’ve considered submitting a proposal like this on Dell’s IdeaStorm – any thoughts?
    Apple have done better by including Xcode with OS X, but it still seems to be aimed at converting existing developers and doesn’t have much in the way of resources for beginners.

    Reply  |  Quote
  16. IceBrain PORTUGAL Mozilla Firefox Debian GNU/Linux Terminalist says:

    I started using BASIC aswell and learned Javascript, C, PHP, Python and some other languages for 7 years before going to college and having my first programming classes.
    My first BASIC interpreter was a chinese video game which couldn’t even save the code, so I would write it on paper and rewrite it every time, and loved it! :P

    But yes, Python is much better as a learning language, although I like the strict and controlled memory consuption of C.

    Reply  |  Quote
  17. Paddy3118 UNITED KINGDOM Mozilla Firefox Windows says:

    With Python first and not dropping it, you get an easy intro to programming – proceedural, OO and functional styles.

    move on briefly to assembler, then C (not C++), so you can teach about computers from the ‘lower-levels’ i.e. what’s under the hood. You can switch back to Python for those wanting to program things like games, GUI’s, CGI, databases, concurrency, data munging, …

    – Paddy.

    Reply  |  Quote
  18. Jason Aren UNITED STATES Mozilla Firefox Windows says:

    I am not a complete “newbie” to programming- I have done some basic programming in java (I finished one of those “21 day” books doing all of the examples, and yes, I know they don’t make you a programmer!) and I have hacked together several web sites using PHP and wordpress. I understand the concepts of constants, variables, if/then statements, for loops, etc. and OO programming.

    Now I want to master a language. I am leaning towards C, as I understand it will give me a good foundation as a programmer (learning about memory management and lower level computing) and make other languages easier to learn. My concern with Python is that I already know the basics of programming so it might be a better use of my time to learn something lower level as a foundation.

    Thoughts?

    Reply  |  Quote
  19. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    @Jason Aren: Well, I’d say it depends on where you want to go with this stuff. You should definitely mess around with C for the low level but there is other stuff you want to learn.

    For example, buy yourself few books on patterns and algorithms. Algorithms especially can probably be better understood when working with a language such as Python. They just have a nicer syntax so you can actually see the logic of your code past the boilerplate!

    So C will let you become a better programmer teaching you about memory management and different ways to optimize your code at the lower level.

    A higher level language will help you learn the high level programming stuff – you know, the knapsacks, traveling salesmen, graphs (graphs are important!), trees and etc..

    Reply  |  Quote
  20. Jason Aren UNITED STATES Mozilla Firefox Windows says:

    Luke Maciak –

    Thanks for the advice. Since my life is serial right now and not parallel, I need to chose one over the other at this point.

    My interests: AI, natural language processing, data analysis (financial, economic) and web/network (for pulling / pushing data and text).

    Will going from Python to C put me at any disadvantage than doing the reverse? My thought is to do Python, and when a situation where I need better performance, start working on C.

    Thanks again!

    Reply  |  Quote
  21. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    @Jason Aren: C is not really a language for doing web stuff. You are best to stick with Python and/or Ruby for that. Or pick up Jython (python that runs on JVM). I think it is quite fast now, and will allow you to work inside of a Java based ecosystem.

    For data analysis, language processing and all that stuff it is really a tossup. The whole “C is faster because it is compiled” thing is a myth. It used to be true back in the day, but the technology grew by leaps and bounds these days. The truth is that a JIT compiler can optimize stuff at run time – it can actually see what is going on, what kind of data you work with and choose the most optimal way to compile it. A traditional compiler does not have access to this information at compile time. So interpreted languages can be as fast as compiled ones these days – if not faster.

    If you use C for language/list/data processing you are going to have to write a lot of code to test for array bounds, make sure your memory is allocated and released properly. To me this is more work than it is worth. If you stick with python it will make your life much easier.

    The only area where I would recommend using C would be writing operating systems and/or compilers where you actually do want to be anal with memory location.

    Reply  |  Quote
  22. Jason Aren UNITED STATES Mozilla Firefox Windows says:

    So would you go Java over Python for my purposes?

    Reply  |  Quote
  23. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    Only if you are terribly worried about performance issues since these days Java ships with a better JIT compiler and performs better under most circumstances.

    Here is another benchmark which shows that to beat unoptimized Java, you actually need to put some thought into your C code. Python lags behind a bit, but if you use Psyco you can pretty much compete on speed with Ruby.

    The thing about Java is that it is a forest of syntax compared to Python. It is statically typed, and loooves boilerplate code.

    Here is my thing: I think it is good to learn new languages. I’d suggest picking up Java, and messing around with C++ just to see how they work. Do few small projects with them and see how you like them. Since you know Python fairly well you should probably stick with it while you are learning new concepts since it won’t take much effort for you to “think” in that language. Trying to learn something new in an unfamiliar language can be a bit overwhelming. Besides, most of these things are universal and you can easily translate algorithms and pattens between languages.

    I guess what I’m trying to say is not to commit to a single language. A lot of people make this mistake and box themselves in as Java developers or C developers and they never branch out. The truth is that a programming language is a tool – and you need the right tool for the right job. Some things are done best with Java, some should be done with C and some should be approached with a highly dynamic language such as Python or Ruby. It depends. A good programmer can switch languages like gloves.

    If you are fairly proficient with Python then it might only take you 2-3 weeks to become “fluent” in Java. Same goes for C++ – if you commit yourself to a project and you work on it for few weeks you will notice that you can suddenly think in that language fairly well.

    So I’d say, learn both C++ and Java and see which one you like better. Ok, here is the list of languages you should definitely dabble in at least a bit before you die:

    – C++ (low level stuff)
    – D (to see C done right)
    – Java (high level, static typing, OO madness)
    – Lisp (the be all and end all in functional languages)
    – C# (just to see how the .NET ecosystem works)
    – Perl/PHP (for the shits and giggles)

    So…. Um.. Yeah, I’m not much for advice here, eh? I’d say stick with Python if you are about to start a new huge project. If you think that C++ or Java will give you better performance, then try them. Java might be easier to pick up because you have garbage collection and no pointers.

    And again, if you already know a programming language, learning another one is just a matter of few weeks. :)

    Reply  |  Quote
  24. Paddy3118 UNITED KINGDOM Mozilla Firefox Windows says:

    Python lags behind a bit, but if you use Psyco you can pretty much compete on speed with Ruby

    I think you mean compete with Java. Normal Python is faster than Ruby.

    Reply  |  Quote
  25. Jason Aren UNITED STATES Mozilla Firefox Windows says:

    Thanks Luke.

    Given that I don’t have a firm foundation in any programming language yet and have just hacked around with Java, PHP, and Python, with which would you start? I don’t expect to work seriously on a big project at this point – I realize I have a lot to learn – but would like to set myself up to start doing some (minor) work on the project ASAP.

    Basically, I want a good language to learn from, that will be a good stepping stone to other languages, and that will be useful for AI / Natural Language, some data analysis, and web/network (though I know a decent amount of php, so can use this for web stuff that is not performance critical).

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *