Slashdot videos: Now with more Slashdot!

View

Discuss

Share

We've improved Slashdot's video section; now you can view our video interviews, product close-ups and site visits with all the usual Slashdot options to comment, share, etc. No more walled garden! It's a work in progress -- we hope you'll check it out (Learn more about the recent updates).

An anonymous reader writes "The Australian Informatics Olympiad programming test is being run in a couple of months. I'm an experienced programmer and I'm thinking of volunteering to tutor interested kids at my children's school to get them ready. There will be children of all levels in the group, from those that can't write 'hello world' in any language, to somewhat experienced programmers. For those starting from scratch, I'm wondering what language to teach them to code in. Accepted languages are C, C++, Pascal, Java, PHP, Python and Visual Basic. I'm leaning towards Python, because it is a powerful language with a simple syntax. However, the test has a run-time CPU seconds limit, so using an interpreted language like Python could put the students at a disadvantage compared to using C. Is it better to teach them something in 2 months that they're likely to be able to code in but possibly run foul of the CPU time limit, or struggle to teach them to code in a more complicated syntax like C/C++ which would however give them the best chance of having a fast solution?"

Having competed in a handful of collegiate programming contests about 10 years ago, the CPU time limit was never even a passing concern. Granted, we were coding in C++, but even in Python, any solution that hits the CPU limit on these contests is quite likely an unnecessarily complex algorithm. I always considered the CPU limit to be a safeguard against programs with infinite loops or REALLY slow solutions, so that the teams wouldn't claim "no, really, it works!" and drag the contest on for hours insisting that the right answer will reveal itself shortly. If your solution works, but has complexity of O(n!), I'd have a hard time calling it acceptable.

If one of our entries was rejected due to exceeding the CPU limit, it was always due to a problem in our logic that the sample data hadn't triggered, but that the actual test data had.

In a programming contest memory leaks and such are meaningless. In fact, algorithmic complexity is also nearly meaningless. O(n^3) solutions that you can code in 5 minutes win over the O(n lg n) solution that takes an hour to code up.

Pascal has a is very simple and clear syntax and semantics. It has strong and static typing, making many errors very easy to catch at compile time. The case for Java is similar but the syntax and semantics are a bit more complicated.

C is terrible to teach, they'll have to deal with pointers all the time. Reading something from input? Pointers. Passing by reference? Pointers. Strings? Pointers. Sure you may omit that those are pointers but the segmentation faults will show up for regular reality checks. Same for C++. Python means working with dynamic typing. PHP dynamic and weak typing. Don't get me started on Visual Basic.

Some algorithms are better suited for some languages or paradigms than others. Quicksort, for example, relies on mutability to be efficient. A language like Haskell, where the list to be sorted would be recreated a bunch of times, would not be well suited. Even with the same algorithm, it would run slower. Sometimes the language dictates the algorithm that would be best to use, or what data structures make sense. That said, I think I would have to recommend, of the languages listed, Python because of its general reputation for being easy to learn. Plus, it has decent support for several paradigms. Want to be OO? Cool. Want to functional? We can do that too. It opens the mind to more ways of thinking about a problem than more single paradigm languages, and that can be very useful in this sort of contest.

When I first read the list I thought "Pascal". The reasons are that it's a structured language, it is very easy to use and it's able to teach extremely useful concepts like linked lists, recursive algo's etc.

However... It's nigh on useless these days to have "Pascal" on your CV (I'm sure both the Pascal developers out there will disagree - Yes I'm looking at you Delphi devs...)

I did C, Pascal and COBOL at UNI and since then I have spent some 15 years writing VB (3->.Net), C, C++, C# etc. In the last 2 years I have been working mostly with Java. And I hate it. It's slow, memory hungry, it's tools are Sh*t (Matisse's creators are on drugs).

That being said, pick up your local paper (or go to Seek - also bleh) and look at the proportion of jobs advertised these days that require Java. It's quite significant. That's the sort of thing that you should be looking at when making your decision. Sure, you'll find a few that require any of your listed languages. And sure, when these kids have finished UNI and want to work in IT (poor bastards) Java will be dead and buried, but there'll be a million and one "Legacy" systems lying around that use Java.

Oh and teach them some database skills. The local UNI here puts out graduates that don't know anything but Cross joins and have no idea what a left join is...

I read over quite a few already and find it funny people are saying things like python are the easiest of the bunch to learn. Command line easiest? really?

As much as I don't like MS, their VB is by far the easiest of the bunch to learn. And you won't have any speed issues at all to deal with, it executes extremely fast. It's an event-driven language also which makes it easier to compartmentalize things and avoid confusion for new users. Debugging in C can be a nightmare. VB does a great deal to force proper coding, it's hard to write something that compiles that doesn't run anything like it should, and with breakpoints and stepping, a higher level language like vb is very easy to debug. Strong typing is another plus.

Beware of people replying back with what's easiest for them. You're going to get a lot of that.

As the summary says "Accepted languages" (presumably the competition rules), I would tend to agree. They're not going to ask your students to complete something that those languages cannot reasonably accomplish. Bad C++ code will be slower than halfway-decent Python code. Teach a good foundation, and let the chips fall where they may.

Agreed. I've done a couple of these programming competitions in my youth (heh:P ) and in my experience, the runtime limit is in place to force you to use a more efficient algorithm, not to force you to streamline your brute force approach. So there might be a problem that would take an hour to solve using brute force, or a couple of seconds using dynamic programming, for instance - choice of language isn't going to affect the performance appreciably compared to choice of algorithm.

The difference between C++ and Python isn't simply that C++ has a more complicated syntax.

In C++, the kids will have to wrestle with the static type system and the lack of automated memory management. (Problems that can be partially overcome with a lot of "greenspunning" that requires significant C++ experience).

The number one factor in performance is the choice of algorithms. A Python program with good algorithms will beat a C++ program which uses poor algorithms, or which does stupid things like copy aggregate objects in order to avoid memory management difficulties.

It's sad that the list of languages includes only immature dynamic languages du jour like Python and excludes mature dynamic languages that have good compilers. Bad education!

or teaching a language to non programmers children and sending them to Informatics Olympiad after two months is pretending too much?In addition to the language, you must first teach them very basic concepts like variables, loops, recursion...As soon as they start to digest them and write their first "Hello World"... BANG! You send them to Informatics Olympiad!

The CPU time limit is less important in this instance than the two months you have to teach them. In that amount of time, starting them from scratch, you won't likely get to the point of teaching them algorithm analysis and optimization anyway, much less benchmarks and profiling.

Consequently, Python will probably be a good deal *faster* than C, because its low-level stuff has already been optimized by people who know how.

If you use C, can you imagine getting new programming students, within two months, to the point where they are implementing hash-based associative arrays and a fast stable sort routine? I can't. In two months, working in C, you'll be lucky if they can remember how to copy a string.

Do they realise how much of the world's systems run Perl? And given that it's pretty much built into every major OS (yes, Windows needs a download). Wow, this is mind-boggling. I still can't get over it. And the fact that simple Perl is just that - so simple. Hello World is a one liner. No classes to define, no libraries to import, no header files to include.

There is an incredible performance penalty for most object oriented code written by beginners: they aren't taught to avoid the layers of abstraction that eat away at your performance, and they often hide incredible errors behind layers of abstraction that make debugging a nightmare.

Python seems a good compromise: as a scripted language, it's quite portable. It has good text processing, there's a large base of small examples to teach students with, and it doesn't suffer from that horrid mass of badly written, interdependendent, unstable and unnecessary utilities known as CPAN that clutters a lot of Perl programming.