Good Language Choice For School Programming Test?
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?"
Python is faster than you think.
If there's a runtime CPU limit, then why is Java even an option?
Master it and everything else seems easy.
It depends whether you are trying to teach them how to program, or teach them how to win. If you teach them something hard to start with, they may become frustrated and quit. If you teach them something easier, they may not win the competition. Personally, I'd lean towards teaching them, rather than pushing them into something they aren't ready for.
You don't want a test that favors kids who have studied that particular language in the past. I suggest the Turing-complete language LaTeX. It's the only way to be sure.
OK C could be a computationally fast solution, but I'd go for Python anyway. Why? Mainly this: How many new C programmers (i.e. less than 1 or 2 years experience) can write programs without obscure memory leak/access problems? How much time have slashdotters wasted looking for elusive segfaults in C code? I know I've wasted hours, days, chasing buffer overruns in school assignments. Or worse are the ones you don't see; they only trigger on the examiner's machine..
English, Vulcan, or whatever the local human language is. Or just give everyone a translation device.
Oh, you mean the language for the programs. My bad, I thought you meant for the instructions and problem description, sorry.
But seriously....
Your first line is to see what eligible language the students mostly know already or what is taught in that school or school system and go with it.
Barring that, go with whatever is commonly used in most university college freshman programming classes. It may not give them the best chance to win but learning it will have practical value.
If you know the types of problems they will give, everything else being equal go with the language that is best suited for the problem type.
Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
What a ridiculous limitation! CPU time is only interesting for hardcore programming these days. If you're writing a cutting edge game or analyzing data from an radio telescope, sure, but if you're teaching kids to program: keep it simple. Teach them how to write their name 1000 times, and if they want to do that faster they'll discover C for themselves.
I'm guessing that the CPU limits are generous and are more about filtering out bad algorithms than bad languages.
For example, someone using stooge sort instead of quicksort...
While the language used would increase the budget, the algorithms used will very quickly swamp any language gains.
When I did programming contests, they were more bound on thought (how quickly you can come up with an algorithm) and then implementation time. Rarely did compute time come into it.
For Python, can they use: Psyco as a library? That would help being practically a Just In Time compiler. It's x86 architectures only but that should be what they're running. As a side point I find it irritating that a language that is designed to be friendly and powerful is disadvantaged by counting CPU cycles: especially since in the real world those are plentiful compared to the scarce resources available for the hard work of debugging. And in Python if the CPU is your constraint - which it isn't in most programs - then you write that little bit of CPU code in C or C++ and call that one part from Python. This keeps the rest of the program easy to debug and portable.
Shh.
I heard it worked for the GPL!
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.
-- I prefer the term "karma escort."
Really
If they hit it, they're doing it wrong or you have the next Rain Man meets Linus Torvalds in your class.
But if you're worried, I'd say go with Java (what I would say really is go with C# but since you can't do it)
But python is fine so don't worry.
how long until
I think you're interested in teaching the principles, rather than the mechanics of the programming process. If so, avoid steps like compiling - with its time overhead. So, no C-derivative.
I'd go with an interpreted language in order to get directly to the problem - my guess is that yr stated concern re 'efficiency' is unjustified here. Ideally, it's Pascal for its clarity, but I don't know of an interpreted Pascal. So maybe - a surprise here - PHP.
AS
I would go with Pascal. And if not, Java.
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.
Unless these kids already have a programming proficiency, go with your gut.
The exercise is as much about allowing them to test the programming waters as it is about them winning. If you are starting with a blank slate, that means you need to create an environment that is intriguing. If YOU think Python is the thing, you'll be passionate ... and that is a lot of what makes a good coach/tutor in an olympiad.
Further, I think you could do a lot worse than Python. It is really a great language and is popping up in a lot of disciplines as the scripting tool of choice. It will perform well and has great characteristics that make it well suited for someone learning the ropes. Plus, the language is modern enough to be relevant should they desire to pursue IT further.
I would stay away from C/C++. In the hands of novices in a timed activity, I would wager it would be more trouble than it's worth.
The little guy just ain't getting it, is he?
Any CPU limits should be generous enough to accommodate correct solutions in any of the permissible languages.
The forgotten language....... For numerical stuff it still works great.
C, C++ and Java are not an option. They all need years to master and have numerous non-obvious pitfalls. Pascal is pretty limitad and definitly a historic design. PHP is obscure in palaces. Visual Basic still is a bad joke, confined to just one platform and wioth numerous design problems.
On the other hand Python is fine, with the only thing to master the indention. Not on the list, but Ruby would also be nice. And for a minimalistic, yet powerful language, loot at (again not on the list) Lua.
Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
Despite the performance issues, Python is still useful for a huge number of things. The performance issues are generally only a problem for HPC, high-throughput server programs, and high-end gaming. I would be less worried about that and more worried about what impact it will have on the students.
In this context, the main advantage of Python over C/C++ is that it's a relatively fun language and will be more likely to catch the attention of the students. It will allow them to take on more complex (and interesting) projects in a shorter time. It would also be more valuable to future non-programmers, who could use it for scripting.
On the other hand, it seems to me that those students that are going to be programmers in the future would be better off being exposed to things like static typing and pointers. C would be much better in this regard, so if the students are being tracked towards programming majors then it would probably be a better choice.
I participated in an ACM programming contest once, and you're not looking at the time issue correctly. I remember one problem that involved complicated time calculation that was impossible with writing in C/C++ from scratch on short notice, but it's easy with the Gregorian calendar class in Java. Good programmers can handle any mainstream language syntax, but the capability of the language and its libraries are much more important when programming time is even more important.
While I wish I could say Java, I think that Python is easier to teach for beginning programmers. If the kids have some experience, though, you should teach them Java or C++.
Explain the situation to your students; give them the options available with pros and cons for each; and let them decide for themselves.
If you have students just beginning, the most important thing you can do to help them is to introduce them to a language/framework they can tinker with themselves. C and C++ can be problematic if the students run Windows at home. Be honest. If the students have as little experience as you say, the students will get far more benefit from becoming familiar with a language they can use at home, on the weekends, or whenever they feel like tinkering than they will being shoehorned into using C to fit under a competition's "CPU limit". Disclaimer: I have no personal experience with VB or Pascal, so I didn't comment on them.
Program it in python, then use shedskin if you find processing time starts to become an issue.
After the test has come and gone, will they still be interested in programming? Only if they've had fun doing it. For that you want something they can learn quickly and do significant projects with. In short, Python.
Look at the questions from previous years and implement some of them in python and see if your going to have run time issues.
if you have no issues, then chances are the kids are not either (since your teaching them, they will code in your style until they learn their own)
A Tale of 2 idle hands
I tried teaching my self some Python a while back and found it very easy. The only experience that I had before in any computer language is MEL (Maya Embedded Language). I bought a book called Game Programming (Publiser: Wiley, ISBN 978-0-470-06822-9) and over my two week Christmas break I was able to build a nice little top down shooter with programmer graphics.
It uses the pyGame library for most of the heavy hitting (like writing to the screen and the like) but it also introduced me to Objects and Classes as well as how to think in small steps to help break down what I was trying to do.
I always suggest this book to artists that I meet who wants to get into scripting. And most of them who have borrowed it end up buying it for themselves when thay have to give back my book.
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...
dnuof eruc rof aixelsid
Probably because there would already by a module that solves the problem.
Brainfuck.
The FAQ says the International competition offers fewer options, "Note that at the IOI only C, C++ and Pascal are permitted." If you're only considering the AOI, Python seems likes the most efficient, portable approach.
Perl is very simple to learn (check out "Robert's Perl Tutorial"). Perl allows the programmer to do what he wants - regardless of the style. There's even English.pm. Perl has many upsides ie: it's a powerful parser and indispensable toolkit... and highly embeddable. If there was ever a seed language to learn, it's Perl.
There's also the fact that Perl programmers are real unix men - and let's face it, you'd rather have real unix graduates than Ruby fannies?
On the plus side, you could make a really spiffy "Hello World".
I won't join Slashcott. OTOH, If Beta goes live, I just won't be back until it's fixed. Sorry Dice.
If you want to give these kids a solid foundation to build on that will instill good habits and understanding of how computers work - C.
Java runs on top of an engine written in C - same with Python. They're great for doing that they do which is providing a massive library to take out all the menial tasks, but those menial tasks are the ones that teach people how everything works in the first place. How do they become a menial task if no one ever learned they were there?
Do we teach calculus without first teaching numbers and then general addition, subtraction, multiplication, division, etc etc etc
I have spent years beating the bad habits of Java out of programmers. Garbage collection is all nice and wonderful but it prevents programmers from having to think about memory at all. Taking that Java programmer and trying to get them to write even simple C/C++ code or even something as basic as assembler is damn hard! Everything they have learned has to be re-grounded. It's like boot camp - break them down to so they can be built up into something useful.
It's easy to teach someone who knows C how to write C++, Java, Python, or the zillion of other languages out there.
BASIC... Beginners All-Purpose Symbolic Instruction Code. Anny student can become proficient in BASIC within a couple of weekends while gaining the self-confidence to tackle a variety of programming challenges during the competition. Python has the stupid whitespace as indentation issue. Java is a horrid language for beginners due to its comlexity.
I assume you want something that'll give the kids an advantage in the competition, and be useful if they want to start programming seriously.
Pascal - it was nice back when Reagan was in the White House and Michael Jackson still had his nose, but it's obsolete.
PHP is for writing dynamic web pages. It's good at what it does, but it isn't really a general-purpose language.
C and C++ are faster than interpreted languages. That is, sometimes they're slightly faster. And they're almost always harder to write in.
VB? Go fuck yourself.
So that leaves Java and Python.
I've yet to see a Stooge Sort that works well with n>4. Fortunately, I've never seen an input size > 4 so it's kind of moot.
Maybe if they had Moe Stooges this would be a problem.
Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
Go with assembler.
www.jsdb.org
I'm a proponent of teaching C/C++. If you know those, you can learn Python, Java and PHP. Visual Basic is not a consideration nowadays.
Regardless of language, teach proper logic. A good coder in any language will have a better run time than a bad coder in any language.
As a person in a place to teach, I truly urge you to teach logic before syntax. Logic before language. It's very important.
Be aware if your language choice is based on build-in constructs, such as C++ vector. They sometimes are prohibited. Though if you are allowed to use standard library choose the language with the most powerful one/best known to you. In this case you will never face a need to recall quicksort algorithm, but simply call sort() method which is faster than everything you probably can write.
If you're going to run into a time limit at a programming contest, you're not doing it right. If you have a good algorithm, it shouldn't matter - the judges will make sure that their reasonable algorithm wont hit time limit bounds on any problem.
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.
I work for the Department of Redundancy Department.
Ruby, Python, Erlang, ARM Assembler.
Have fun.
I'd start by avoiding Fuck, Shit, Damn... you get the picture.
weinersmith
For example, someone using stooge sort instead of quicksort...
That depends. If you're putting Moe in front of Larry, or if you're putting Larry in front of Curly. And if you add Shemp, well then, you start getting into reeeeaaallly intersting stuff! Nyuk,nyuk, nyuk. Woowoowoowoowoo.
If you have not yet considered Logo yet, perhaps you should do. The language itself as a procedural language, combined with turtle graphics can not only provide instruction but visual feedback as well which IMO is important to students these days. If they can see cause and effect it keeps them interested for longer.
I put together a really great algorithm to weigh the available choices and their tradeoffs, but I ran out of cpu cycles before mom sent me to bed.
We can sort of classify the languages into "slow" and "not slow" in various ways.
This should come as no surprise. Pascal was intended as a teaching language. None of the other languages was designed for teaching, unless you somehow equate Visual Basic with BASIC.
The second choice is probably C, but you'll have some issues teaching about declarations/definitions (inside out) and string-related stuff. The meaning of '=' is also not compatible with normal math notation.
The third choice is probably Java. You get most of the trouble of C, less speed, and greater need for boilerplate sourcecode bloat.
Your assumption that Python is inherently slower than “compiled” languages demonstrates naivety that most mature engineers have moved beyond. I would recommend you avoid teaching others until after you have better educated yourself.
I think java is the best because it has good IDE (eclipse, netbeans etc...) . Good IDE may help you learn the language quickly write code fast. Btw, top ten in topcoder, 8 use C++ and 2 use java :)
http://www.topcoder.com/tc?module=AlgoRank
Are programming contests measured in time like a few hours? If so, that's a mistake and I would want kids to do that.
You realize C was considered “high level” at one point? Your comment about the Java “engine” is likewise baloney. Your post is saturated with ignorance and it is shameful you have positioned yourself to impose any habits on anyone.
+ Serious real world scalable language used in both business and science
+ Freely available on a wide variety of hardware -> gives access to any child with any kind of computer
+ Learn OO from day 1
+ Java collections give students access to data structures and algorithms without having to get bogged down in writing them at a low level
- Never learn to implement those low level data structures in algorithms (but don't forget you have just 2 months!)
- Slower than C
- Not as close to the hardware as C
Overall a decent compromise.
These posts express my own personal views, not those of my employer
Teach the kids Scheme! Seriously, it's a better transition from pure math to programming. (http://www.teach-scheme.org/)
Programs written in Visual Basic, Java, PHP or Python may run slower due to the overhead of the associated interpreters and/or virtual machines. The judges may at their discretion increase the time limits for these languages accordingly. Contestants should note that this will not give these languages an advantage
That's how contests with multiple language choices almost always work. It's really easy to implement a naive solution in C that performs 10x better than a good solution in Python, even for fairly large inputs.
With that rule in mind, I say go for Python all the way.
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!
These types of programming contests are all about whether you can come up with a clever algorithm for solving the problem. With the right algorithm, CPU time limits should not be a problem for any of the languages; but if you're using the wrong algorithm, you're going to run out of time regardless of what language you use.
(Note: I was once a contestant in the Australian Informatics Olympiad as well as the International Olympiad in Informatics, and in subsequent years I have also tutored kids participating in the contest. None of the kids were at the beginners level, however.)
That's is so true. I started with Basic in school, continued with Pascal in the university, learn myself assembler and decided to go with C/C++. ...
Then, I learned Java, Javascript and started my own website.
Later I discovered Linux I was pleased that most of software written on C/CPP using some frameworks like QT. I tried RoR and was surprised with ActiveRecords. And so on
You have to be open minded and feel each situation, because there are some reasons why we have so many co-existing languages today.
I think if you are worried about the efficiency of their solution you ought to explain complexity/order notation, and then apply it to a some practical data structures, like arrays or hash maps. Even more awesome if you get them to do some time measurements in easy language X so to demonstrate the effect of complexity. At crunch time, if they can judge the design trade-offs of their model&implementation, then that will eclipse any speed benefits of a compiled language. Good luck!
C shouldn't even be on the list, neither should Pascal.
C++ is my favorite language but there's no way you can learn it in that time scale.
VB is almost obsolete and too much tied into to MS APIs.
That really only leaves Python or PHP.
Python is cute but it's not really very good for writing software that has to be published/deployed.
I'd go with PHP because it's much more useful for getting jobs, etc., after the competition.
No sig today...
What is it that you're programming that can't be done with scratch ?
Nullius in verba
I've participated in local and regional Informatics Olympiads, and went to the IOI once. I was involved in training local students a few years ago, so I know quite a bit of the ins and outs of these competitions.
All the languages have pros and cons, but PHP and VB obviously aren't suitable (if only for their encouragement of crappy coding practices). Java offers little advantage over C/C++, and it forces OOP onto you so it adds an unnecessary layer of complexity for the students.
The "industry standard" of competitive programming is C++, since it offers near-C speed with the power of various algorithms (eg. sort) and data structures ( maps, sets, priority queues ). Those who intend to take the competition seriously should be using C++ as their primary language. But then judging from your requirements the vast majority of your students won't fall into this category, so I wouldn't recommend C++, at least not at this stage.
Python generally is a good first language for its simplicity and power. There are a few problems with using python for competitive programming though. First, speed can become a problem for *some* contests, which have rather tight runtime constraints. The contests that cater for a wide range of languages are usually better in this respect, but a lot out there are primarily C/C++/Pascal/Java. Secondly, the fact that python supports a range of built in advanced data structures and algorithms means that you may lose the chance to teach them how to implement the basic stuff, eg. using a binary search tree to implement a map (typing `` mymap = {}; mymap[foo] = bar; '' is surely easier than implementing a BST yourself). You might ask why learn to reinvent the wheel when most modern languages provide these features, but these data structures and algorithms is the core of informatics olympiads, and one needs to learn from the basics. That being said, if the timeframe is just 2 months, I think teaching python might be most rewarding for the students.
C and Pascal are basically on the same league. C is a bit more "archaic" than Pascal in terms of the way it does things, but feature-wise they are roughly equivalent. The languages are simple, fast, and bare bones enough to force the user to implement the basic stuff. In the long term they are good languages for teaching data structures and algorithms, but require a bit of patience on the part of the student since you need to know quite a bit before you can do anything "flashy" with them.
My experience with most average students is that they usually struggle to form precise ideas on what to tell the program to do, and then when they do have rough ideas they then fail to write a syntactically correct program, and if they really do write a syntactically correct program the program usually fails on correctness for most inputs, or simply do the wrong thing. Running time shouldn't be a concern before the students actually get a correct program, and my experience is, unless you have really really bright students, most of them probably won't be able to come close to writing a correct program within competition constraints, so don't worry too much about running time.
In short, I recommend python, but in the long term you might want to think about using C/Pascal. And if you restrain yourself to a subset of C++, it might work too.
Don't quote me on this.
Using a non-accepted language is bound to win them points
Even though I do 99% of my work in Java, C/C++, VB, or shell scripts, the few times that I have written in Python, it was an absolute pleasure.
The libraries that I used kicked Java/C++ library asses, to the extend that what was going to be a "short" 500 line program in Java dealing with parsing images, turned into an 80 line program in Python.
The best part is, it was extremely easy to debug as I wrote, since just about any line I dropped into the source file, I could check with the interpreter.
It also only took half an hour to pick up from other OOP languages.
I <3 Python
while(1) attack(People.Sandy);
Generally, when teaching kids how to program, you should not teach them a "simple" language. You need to teach them the core concepts of programming, and there's no language better than C/C++ for that. First you teach them basic concepts in C, then you add OO using C++. Once they understand the fundamentals as used in C++, they will be able to convert to any of the other languages fairly easily. On the other hand, if they start off with an easier, but - for lack of a better term - less precise, language, they will have a much harder time ever transferring to other languages. C++ is the best teaching language for exactly the reason why many people don't like to program with it - it makes you understand the differences in the concepts you are using.
I can understand the desire to simplify things for the sake of the competition, and maybe for some of the students you might need to, but I think you would be doing them a disservice in the long run.
It's only useful for getting a job if the job is web development. I should hope that many students would aspire to better than that.
What I find interesting is that no one has mentioned that what's actually more important than the language itself is the available libraries/toolkit/frameworks that it comes with.
Let's face it, after you've learned a few languages it pretty much comes down to "what is printf called this week?" when you pick up a new language (functional languages aside). Getting familiar with frameworks is actually what takes the most time.
C++ and C are pretty bad in this department. STL is nice but only gets you so far. Threads? Nope (not yet). Sockets? No. XML/encryption/whatnot? Sorry. You have to write an awful lot of code to come up with this or find (and learn!) a support lib that does this. (I do C++ for a living.)
So I'd say: Python. Or C#/Mono (but that's not on the list, why?)
Geek by Nature - Linux by Choice.
Your responsibility as a teacher/trainer/coach is toward the kids and not towards the olympic committee.
And, based on your question, I think you are about to fail them: if you raised the question only with 2 months in advance and expect to make a kid (that doesn't know to write a "Hello world" in any language) suddenly so highly competitive that the speed of execution is the main discriminant.
But again, no wonder... what can I expect from someone turning to Slashdot to get answers that are going to influence the life of some kids!
Questions raise, answers kill. Raise questions to stay alive.
I did pretty well in this particular comp (several years ago) and I used Pascal at the time.
If I knew back then all that I know about programming today, I'd be using C++.
But given that I didn't, I would recommend Python.
Everybody should start learn from Perl. Only potentially real programmers can withstand such brain abuse...
1 - syntax is similar with C
2 - they can create things that they can see firsthand, use firsthand and show off to others firsthand on the web. (great incentive and motivation)
3 - php is an enterprise level language itself, used with many serious web presences and has serious backing with more to come. it will be a good start for them
4 - its easy to learn and possible to make extremely complex applications with, as well as making 20 line, working and useful scripts.
Read radical news here
I can only respond to this statement by quoting Wolfgang Paul: "Not only is it not right, it's not even wrong!"
And since it's a programming contest, the limits on coding time are probably a more difficult obstacle than the limits on run time.
I agree about C. Nasty for novices, and that's because of pointers. For instance, does *n++ mean (*n)++ or *(n++)?
But Pascal? No, I don't agree. Pascal hasn't been an important language since the 1980s, C still is. The C syntax is superior. Efficient syntax is important in a programming contest. You can type "{" and "}" faster than "begin" and "end" and "If () { }" faster than "if then begin end". The curly braces are less clutter on the screen, and better for those whose first language is not English. Passing by reference in Pascal is lame, what with having to add "var" to every such parameter. C isn't great either, with the pointer syntax for that, and then having to pollute the function body with '*' characters. I like C++ a bit better there, with the '&' in front of the parameter.
I would pick C++ ahead of C, not for the OOP, but for things like '&' and not having to use the keyword "struct" as much as you have to in C, or, rather, not having to do that boilerplate typedef trick so you don't have to type in "struct" all the time. I'd pick something with C syntax ahead of C++, in this case, Java or PHP. Nice features of Java are automatic garbage collection and not having to sprinkle asterisks everywhere, but Java has some other features that are a pain, particularly this business of having to put each class in a separate file, and the rather clunky "classpath" environment variable. PHP on the other hand is another of those languages that insists on a funny symbol in front of every variable reference, a common tradeoff for not having to explicitly declare every variable. Still, being able to bang out a quick script is very nice, so I'd go with PHP over Java.
As this is a programming contest, I'm putting a big premium on minimum amount of typing and display space. Quickly banging out code is everything, and if it's dirty, so be it. Having to flip back and forth between multiple files can be a real time killer. Boilerplate such as "main" in C/C++ and the "begin" and "end." of Pascal is also bad, just more lines of crap you have to shove into your code and scroll past before you can get to the business of banging out a solution. So, a scripting language seems best.
Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
Start off with only writing functions in the main class. Thus starting them off with procedural programming.
If they grasp that soon enough, then you might be able to teach OO. Sure OO can be hard for newbies, but it is possible to teach OO in a very short time. (I've done it a few times. But that was with adults with some programming experience. Adults have better focus than kids.)
Also, I see Java as a much better/gentler languange for beginners than C. I don't know Python, so I don't have an opinion on it.
And if they do want to continue programming after your course, then a free Java IDE is only a download away.
The elements of good foundation in programming do not require a computer.
It requires that someone understand that programming is nothing more then looping and branching.
Teach them to wite their 1st program on 3x5 cards and stay away from the any language that has a runtime that prvides more then the most basics functionality.
Even if they end up using a garbage collected language they need to understand memory allocation and manipulation.
3x5 cards can emulate memory perfectly and can teach them the fundamentals of a stack ( no pun intended ).
.
One of the biggest problems I see today are "programmers" who do not have a clue as to hat the machine is doing, all they know is you go out and google for a library that will to "stuff" for them without ever knowing what the stuff IS or how it works.
Hey KID! Yeah you, get the fuck off my lawn!
http://wiki.python.org/moin/PythonVsPhp
this is from python's own wikia. i dont see why some of you try to lord it over everyone over php. and despise the latter.
Read radical news here
why is python no good for software that is to be deployed?
If you mod me down, I will become more powerful than you can imagine....
C may well be a perfectly fine language, depending on the types of programs that are typical in these sorts of contests. For anything mathematical in nature, C is a decent choice; there's minimal bloat (hence faster performance) and it has a very simple syntax. If the questions involve lots of string manipulation, on the other hand, C is out.
The same logic applies to Pascal, except that it's basically not used anywhere anymore, making it not particularly useful in the long term. That may or may not be a good reason to avoid it, but it is certainly worth considering.
I tend to agree, however, that PHP is probably the best compromise. It's a broadly used language, it is close enough to C at a syntactical level that students can easily learn C in the future (and, consequently, C++, Java, JavaScript, etc.). More importantly, it is the only language on your list other than C and Pascal that can be used completely procedurally without the need to teach young students OOP. That's a rather big advantage; younger kids may have a hard time with such an abstract concept. And it still provides built-in Perl-compatible regular expressions, stacks, arrays, associative arrays, simple string concatenation and manipulation, etc., unlike pure C or Pascal.
Check out my sci-fi/humor trilogy at PatriotsBooks.
You probably want something small and imperative. I'd recommend either Python or some not-too-clever dialect of BASIC. Either will do fine for one-page programs, which sounds like what your students will be writing.
My experience is that strong static typing is vital for programming in the large, but is a serious impediment to beginners. The extra protection and performance it offers usually isn't neccessary for one-page programs.
C is pretty poor for doing mathematics. Go with a functional language for that. Or Fortran, if you need speed.
This is a student's programming contest, right? Why are you even concerned about compile time or "startup" time?
Normally there is a time limit during which the competition runs. The faster your tools are, the more time you have to write code.
A kid might need 50 tries to get his program right.
Python is cute but it's not really very good for writing software that has to be published/deployed.
ROFL
That was meant to be funny, right?
I competed in the 2004 Australasian Informatics Competition (which was renamed to Olympiad in 2005 iirc), and at that stage I had been learning C++ for about 2 months, and had very little programming experience before that. Although I had a lack of programming experience, I still placed within the top 100 students in Australasia and got my school a grant for new computers (which I never got to use).
Now that I have learned other languages as well (Python, Java and Pascal), I would honestly say there is no clear cut advantage to any programming language. No problem required OOP, it was moreso about the problem solving and getting it into algorithms rather than a test of programming. While efficiency is a marking criteria, it doesn't feature anywhere near as heavily as actually solving the problems. I only finished 2/4 of my programs and did (in my opinion) fairly well.
If you want to tutor them for this competition, tutor them in a language that they feel comfortable with and is accessible to them where they will be taking the test.
PHP is not really what I'd suggest as a good choice. Unless you're doing web development it is fairly unused. And even if you ARE doing web development, its had plenty of bugs and major language changes from release to release.
PERL would be a better choice from a pure "usefulness in getting a job" standpoint. It can be used for web development, and a whole heap of other tasks.
But having seen the range of things python has been used to implement, and what I've heard about how easy it is to learn (i'm not a python coder at the moment), I'd agree with the GP that it is a fine choice.
I run: Windows, OS X, Linux, FreeBSD. Just because you have a hammer, doesn't mean everything is a nail.
If the same rules apply for all students and if only one programming language is allowed, CPU shouldn't be an issue.
What are the objectives? If it's a thorough introduction of the system that lies at your finger tips, choose C as it is intended to access the hardware as directly as possible (without having to write assembly.) Choose an OO language if you want to teach OO. If you want the kids to actually use the language think of applicability.
For instance, I'm very proficient in Perl but I would never ever teach it as a first language because getting to the basics is too tough. The data types are too general and friendly and don't make you think enough about what you're doing. For an OO language I'd take openness, applicability and development environment into consideration. In short, I'd choose between C and Java.
I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
We run python on our embedded 125 MHz ARM systems. For most things it's just as fast as C - on tight loops, you can get 40% faster in C, though not as often as you might think. Sometimes the Python is even faster just because it's optimized for things you normally want to do. Really, most of the time is in the launch, so as long as there's already an instance of python in memory linux's shared pages takes care of that.
More to the point, you can develop 10x faster in Python than C++. Literally. And it's so much easier to learn and more intuitive. And I say that as someone who is considered the company expert on C++. There are times when I still use it, but for instances where speed of development is a big deal? Never. Rather we write in Python then if necessary do tiny sections in C and call them from the Python. For any kind of problem I can see being asked at a competition like this the speed of development and the freedom to work out a smart algorithm via rapid iteration (if you don't have the experience to know already) will swamp the CPU overhead. If you really want an ace in the hole give your smartest student the task of learning how to call C from Python (you don't need C++ at all if you know both of those).
I'd also say Ruby - you can crank out stuff in Ruby even faster than in Python (though it's not as maintainable thanks to all the perl-y syntax) but this doesn't seem to be on the list here. And Teaching Visual Basic or PHP to students who don't have a very specific need for either would just be a crime.
Python; but stay with ver. 2.5, if speed becomes an issue just compile with Cython with minimal changes. This is probably a worthwhile pedagogical exercise, if time permits anyway. Optimization after functionality. Also, while Python 3.1 is probably best for an individual aware of backward incompatibility; for a classroom, use Python 2.5 to avoid confusion over the vast majority of code examples and books that hopefully the students will want to explore.
...are meant to sidestep the halting problem. I've never seen a programming contest problem that couldn't be solved within the time limit with a naive O(n^3) algorithm in the slowest interpreted language available.
Python will be fine.
There's no failure quite as dissatisfying as a complete and total solution to the wrong problem.
I have participated in plenty of contests and know enough about the rules to say that you don't have to worry about runtime and memory usage differences between programming language. Depending on the language used, a solution can take longer or use more memory so that the programming language is pretty much moot and the algorithm is the important bit.
Usually, the runtimes are used to filter algorithms to ones that use the correct runtime. If a problem is about sorting, they will want a O(n log n) algorithm. Nearly any O(n log n) algorithm will work and anything higher (usually O(n^2)) will fail.
Now that we've leveled the playing field we can get to the language features. My language of choice for these contests is C++ for two reasons. The first one is personal: i know C/C++ pretty well. The second one is a main advantage: the C++ STL provides a larger number of containers and standard algorithms with runtime guarantees which greatly speed up writing code if you know how to use them. Many of the newer languages do provide these kinds of libraries, but in my limited experience with the other languages i have been unable to like them as much as the STL for this purpose. The fact that you have runtime guarantees in the STL makes it particularly suited for this contests, where runtime is key.
In the end it all depends on what you want to teach tho. I would dare to dive into C++ with new students, as long as they are eager to learn and show a reasonable level of thinking like a programmer. If you know a lot more about python and can explain and use the algorithmic basics of runtime and memory usage well in python, go ahead and use python. Any language which allows you to strictly adhere to runtime instructions will work.
Teach them Logo, it was good enough when I was a kid.
Be seeing you...
I'm not sure if this is allowed but it has largely the same syntax as python plus the JIT compiler of mono/.net which i assume adds a fair chunk of speed. they can take the knowledge of python and do real things with it after the contest too
This is a joke. I am joking. Joke joke joke.
Well, Python is not a good langage for several reason.
Main reason is the indent craze.
I agree that it's important to give proper indenting to your code... but relying on indenting for the syntax is lmooking for trouble..
Think about
if (a) {
b();
if (c) {
d();
e();
}
}
and compare with
if (a) {
b();
if (c) {
d();
}
e();
}
Only difference between the two code is ONE tabulation. And as there are no matching pairs of markers (braces, if...fi, ...) there is no way for a syntax checker to see that something went wrong. That's the kind of mistake that'll be a nightmare to find but that could easily be done (even more when you do a lot of copy/paste)
Speaking of copy-paste, you'd better have a VERY GOOD code editor if you want to be sure that indenting is still correct.
C/C++/... have code reformatters which can take care of applying the same code structure (indenting style and size, position of the opening brace, ...) so there is no need to force it through the programmer's throat
But it's also a "marginal" langage... see TIOBE index...
1 : Java 18%
2 : C 17%
3 : PHP 10%
4 : C++ 10%
5 : VB 7%
6 : C# 4%
7 : Python 4%
8 : Perl 4%
If you want to teach something to your students, teach them something that'll be useful in the future... PHP is a good choice : easy to learn, lots of demand, powerful libraries, clean syntax,...
If you read the contest rules, you'll see that the judges may increase the time limits for interpreted languages at their discretion. It's intended that, as much as possible, no particular language has an advantage over another.
Well, it's true that the JVM may take some time to start... but once it's running, JIT and other make it run quite fast... You see game servers hosting hundred of players on a "normal" machine (not 8-CPU 4-core or similar), web sites using JSP, ...
And if you don't start to use the latest API (reflexion and similar) and stick to "standard" java, it'll make you create clean code...
But I agree that starting the JVM is rather slow... Even slower if you start it in "server" mode (but then, you'll get a speed increase while running the code)
Well, while Python is definitively an interesting language, the original teaching language (created to teach programming, and taught before the first compiler for it existed) is Pascal. The original Pascal is of course somewhat outdated by now, but the useful version was pushed onto the PC by Borland in the form of 'Turbo Pascal' (dirt cheap, graphics capable, screamingly fast - in '86!).
The language (later called 'Delphi' under Windoze) managed to stay around for a long time despite Borlands best efforts at lousy support. I still use it quite a bit, especially as the compiler is still extremely fast.
These days you'd want something like FreePascal using the Lazarus interface (http://www.lazarus.freepascal.org/), which is not only free but runs on Windows, Linux and Mac. A 'Hello World' is done within minutes by an absolute beginner, who can then concentrate on the code itself instead of the interface :)
Free PC version of ChipWits at http://www.breueronline.de/klaus/chipwits/
PHP is a great language to teach people programming on because it's simple, and practical, I think your aim should be to teach them something that they can use rather than to get them to win any contest. After a few PHP lessons, and a dollar or two for a cheap hosting solution, they can have something cool to show for it.
The MAFIAA is a bunch of mindless jerks who will be the first up against the wall when the revolution comes
Used Pascal, and then I used it in the ACSL contests with no problem.
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!
I've written millions of lines of python in production and i've never found the indentation to be a problem. i could just as easily make the arguement that curly bracket hell is worse, because there's nothing forcing proper formatting.
if you do have indented incorrectly, just like any other compiler it tells you what line the error is on. it's not a problem.
If you mod me down, I will become more powerful than you can imagine....
Presumably for these beginners, you're teaching programming concepts: symbolic logic, input, output etc.
So while you could dive right into programming languages as we know them, or give them something like Turtle/Logo
My kids' primary school uses Scratch for this. Of course, you could just give 'em actual Logo via KTurtle.
please! whatever you do, just don't think of using C#!
in fact, C# isn't even a programming language anymore since it has context-sensitive statements. so there really even is no reason to think such foolish thoughts.
Go Python or C.
Python - interpreted and OOPsy. Simplified and limited C curriculum is easy to understand.
Visual Basic - never really used it, although my first language was plain old BASIC.
Pascal - no use in learning this language any more. C++ simply sucks. Java is a better choice than Pascal or C++.
Re-read his example - he was saying in languages with braces it's obvious that you want e() if (c), and the compiler can check that; without braces in python it's one keystroke's difference, or a dodgy copy/paste.
Explicit braces does help code clarity. Also it annoys me when people argue the significant whitespace is good for beginners because it enforces good coding style, because it does not. Not only that, but it often gets in the way for non-beginners.
For example, long().chained().method().calls() can only be split inside brackets unless you use the god-awful \, which makes the code harder to read and/or harder to refactor.
Not to mention that you can make multiple();statements();on();one();line() - again, python thinks it's fine, but that's not good code style. You can't do brace matching to jump to the top/bottom of a code block, and you have to use "pass" to show you really did mean to leave that placeholder method empty for now, rather than just typing {} to come back to later.
About 75% of my work is in python at the moment, and there are many things I like about it, but saying that it enforces good coding style simply isn't true - in every language there will always be a way for bad programmers to write bad code. At least if you hand me a horrifically-formatted piece of perl, c# or javascript, you can just send it through a reformatter, which will be able to change indentation based on brackets and give you code which is laid out perfectly, without needing to worry that the whitespace it just added has broken the functionality.
It's not as if python saves us from that problem - not all indentation is equal. I frequently run into code that uses two spaces or a tab character for indentation, whereas I use 4 spaces. If I'm copy/pasting a snippet from documentation or a snippet site, I need to make sure its indentation is the same as mine. Not to mention what happens if you copy it from or paste it into a source where leading whitespace is lost. Trying to paste a few lines of python code in a chat client is frustrating at best.
Now, if you'd said that the lack of braces makes code more concise vertically, that it makes it look "cleaner" then I may agree, but if you want to teach people to write good code, teach them re-usable language-independent style guidelines at the same time you teach them algorithm design etc - the compiler is the wrong place to learn good code layout.
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.
Cut that out, or I will ship you to Norilsk in a box.
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.
And you can write poetry with it! (bonus points?)
You've just invented your own dynamic memory allocation implementation.
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.
You need to teach them flowcharts. Teach them a little about sorting algorithms. With respect to databases, they should at least know what the acronym CRUD stands for. At least introduce them to the name "Don Knuth" if not pull some simple examples from his books. They really need to know about common bugs like off by one errors, etc. Have at least a short discussion about each line of:
http://en.wikipedia.org/wiki/Software_bug#Common_types_of_computer_bugs
The folks telling you to teach then the vi editor or python or javascript whatever are confusing the trees with the forest. Learning to program by memorizing Stroustrup is like learning to drive by memorizing the Chilton technical manual, interesting, but a complete waste of time. On the other hand, a kid with a plan will succeed even if all they can write in is BASIC. A kid who knows Shakespeare can write something interesting with a crayon, at least compared to an idiot in front of the worlds most powerful word processor.
The kids also need to learn the patterns and anti-patterns, for obvious reasons.
http://en.wikipedia.org/wiki/Anti-pattern
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
"Science flies us to the moon. Religion flies us into buildings." - Victor Stenger
C falls apart as soon as you need datastructures; there's almost nothing in the standard library.
C++ is much better in this regards; it and Java are the most popular languages for these contents AFAIK, along with Pascal in some areas.
I'd still rather use Python if I knew the time limits weren't going to be too strict, though.
I've coded algorithm-centric code in PHP, and it's awful. It's clearly a template language, and not a very well-designed one at that. Neither the standard data structures nor the standard library is up to the task.
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.
In my experience time limits are there to prevent students using primitive algorithms (the ones with exponential asymptotic performance).
N.B. I would have recommended Perl instead - but I'd refrain :)
Python should be and is in fact fast enough for most tasks. Taking algorithms into account, C gives only marginal advantage: bubble sort would suck even if you'd write it in assembler.
P.S. If that is still concern, one can allow interpreted languages to have e.g. twice more time compared to compiled languages.
All hope abandon ye who enter here.
It most probably won't work, because, face it, they are kids, you will spend most of your time trying to get them to understand quirkiness. The thing is that what they won't solve in time, they probably won't solve at all, and unless you are doing difficult stuff or you are squeezing c++ (wich you probably won't get kids to do right), python is comparable to c++ (maybe between 4 and 5 times slower), and when it comes to VB, it will just mess with their minds...
IMO, teach the kids anything they're liable to retain. Python's a nice choice for clarity mixed with power. Yes it would be nice if the kids really did well but even if they don't, having them walk away truly enjoying their experience programming seems far more a beneficial end than being frustrated with complicated syntax.
I'm not suggesting dumbing it down; just suggesting that this tutoring goes beyond the contest.
Ask the ones you plan to tutor what they wish to learn.
I'd have to agree with that, and I say that as a developer for a company which uses Python for 95% of the code we write. I actually stuck out as a candidate simply because I'd done a couple courses in school that used Python, not as the focus of the course itself, but simply as a choice of language to implement the stuff we were learning. Python is without a doubt my favourite language to write in as of right now. It's easy to quickly get working code going, it has nice debugging features, and it's actually even fun (at least for me).
I like to think of online DRM as something akin to a college -- you pay for lessons until you learn something.
Please, use the right tool for the task, Pascal is compiled and has clean simple syntax which is easy to catch.
All the other languages are more complex, and whatever people say, interpreted languages still lag behind in general terms when it comes to speed.
IANAL but write like a drunk one.
They have to *implement* something.
What are they going to do with their cards then?
Honestly chaps, some of you are snobbish and insufferable.
IANAL but write like a drunk one.
You know it. It is the worse language to teach good programming practices.
IANAL but write like a drunk one.
I'd go with PHP because it's much more useful for getting jobs, etc., after the competition.
Depends on whether the job you're after is asking you whether you can program, or whether you know a specific programming language. I'd go after the first type of jobs. For anyone who knows programming, learning a new language should be matter of hours for the basic syntax and maybe a few weeks of actually working with it to become familiar with it.
A well designed java app would probably run very close to C++. Depending on what they do, using easy caching, streaming and string manipulation techniques by using StringBuffer when possible can make all of the difference in the speed. I would pick java because is a powerful language with very strong rules and without the pitfalls of writing code in C/C++. I have 20 years experience working with C/C++, Java, Pascal. I only ever venture in C/C++ just to write low level hardware dependent stuff. VB is a joke. My choice would be Java.
Here's a simplistic logic flow*; use and modify as desired.
If the student is a complete beginner || lousy coder, or knows programming in a language other than the contest requirements, or he/she knows Visual Basic, start with a mature, stable language that has reasonably consistent syntax. Among the choices available, there's simply no contest-- pick Python**.
Else, if the student is reasonably versed in one of the languages (other than VB), tutor the student in various algorithms and data structures using that language. Observe the code he/she writes and try to identify bad habits and suggest workarounds, etc.
Else (meaning you don't have the time to do the above, which is understandable), give them all a crash course in Python and drill them regularly.
* NOT pseudocode. Don't even try to compile this. I can see the programming professors cringing at the first conditional clause already.
** I'm a Ruby coder myself, so if I had my druthers, I'd pick Ruby. But rules are rules...
"We are Microsoft. You shall be assimilated. Competition is futile."
"immature ... like Python" and then "mature ... good compilers" What languages would you be talking about exactly?
If you have not done so already, I would recommend using http://www.codechef.com/ as a source of practice tests for your students, it has tests in various degrees of difficulty and CPU limit. As many may have mentioned, programming competitions tend to have different CPU seconds for compiled lang like C/C++ and interpreted lang (Python, Java). Codechef does something similar, though you may want to check if the difference is reasonable for the competition you're preparing for.
Also, the site has a lot of foreign participants and daily ranking for benchmark tests, this way your students can see where they rank and you can help them improve.
As for language choice, I'd choose Java if you wish to orient your students to a more collaborative projects, or Python for more solo projects. Most other languages on your list have various problems listed above by others and won't get the students as far as these two would.
...implement LISP interpreter in your chosen language.
I'd use the Lego Mindstorms robotics set, with an NXT processor. That way, the programming results are more tangible and you can solve just about any problem likely to come up in a programming contest with it. For some fun, check out the First Lego League challenges. http://www.firstlegoleague.org/
PyPy has recently released their Python 2.5 - compatible version of Python with a GIT.
How many of us ran BASIC or Logo on a home computer that struggled to keep up with our more complex programs? It is OK to learn a first language and grow out of it to the point that you never use it again. The important thing is that you learn from it.
It seems to me that your worry is misplaced by being concerned about CPU time when a new C programmer is going to sink a tremendous amount of time debugging compared to a new python/php/javascript/whatever programmer.
Java isn't really any easier than C, although I like both languages I've been doing this for a while. When I first started I messed around in BASIC for a decade before learning C, Pascal and asm in the same year.
“Common sense is not so common.” — Voltaire
If it is "Standard Pascal", I would vote against it, but if it is something more recent, e.g. Delphi or Free Pascal / Lazarus, I think that's the ideal choice.
"Write it in C"
http://www.youtube.com/watch?v=XHosLhPEN3k
Speaking of copy-paste, you'd better have a VERY GOOD code editor if you want to be sure that indenting is still correct.
You can develop code outside of vim??
This is an honest question: I have tried to use Python a few times but the significant white space drives me off. Can you explain how you solve this issue (in psuedo code):
Function here() // remember to remove
line 1 does some stuff
line 2 if statement
inside the if
print debug info to console
line 3 more stuff
I put those print statements in all over the place when writing code -- and yes I *also* write tests using TDD. But getting a quick print helps a lot. But if I tab the print, it's easier to miss it later. I know some other programmers who do the same thing.
Do you just suck it up and tab that line in to it's proper place? Any other thoughts?
It kind of bugs me that I can't have the code look on the screen how I want it to look, rather than how the complier/interpreter wants it to look. Like I said, I'm not hating - I'm asking. Python seems like a nice language barring this mental barrier for me.
I do like Java a lot but Python will force them to make nice neat code, it's easy to learn, has awesome features / support and it's fast enough.
Plus you can just have them open it on the command line and type stuff in and get instance feedback from their work. They won't write a huge program this way but at least while starting out at first it doesn't require either compiling things on your own or learning an IDE at the same time.
Go for python, that will prepare them to code in: http://en.wikipedia.org/wiki/Whitespace_(programming_language)
No seriously .. take this with a grain of salt, because this is written by someone who has so far managed to avoid learning python, but knows the other languages: Python syntax is unique, and it will not prepare you for the goodness of the many curly-braces languages.
In my initial sifting, I would not rule out php as programming language if the programming exercise benefits from graphics, which most likely it doesn't in such a contest though.
I think Java will do fine because it has easy looking string operations, and not too many weird standard invocations, like in C "#include <stdio.h>".
I would consider C++ first if not for its weirdness of having the same operator code for bit-shifting as for simple input and output.
In fact, if the problem involves file handling, I think C appears to be more easy to handle this, at least on first sight to the student(which I think is important - don't scare them stiff on first sight of a language). I mean the java way is easy too in practice, but you have to string two objects together to handle file reading or writing in a standard invocation.
I look forward to many python counter examples to my concerns, as /. seems to champion python.
Hey don't blame me, IANAB
Here's what I do:
I use an editor that can understand Python indentation. This is easier than you think, as the editors not capable of this are too limited to do much coding in anyway.
Then all you do is go to the end of the line before where you want to insert your new line, create a new line and hey presto the next line starts off correctly indented.
Any decent coder is going to configure their editor to automatically indent anyway no matter what language they use, so it isn't really any extra work. Except for trivial edits, I find I need the same kind of indenting features when coding in PHP too.
That's not what he's asking - he likes to put his debug print statements at the start of a line to make it obvious where to pull them out when debugging later. Automatic indentation is not a solution to his problem.
@Unequivocal: Exactly, it sucks. I do exactly the same thing in other languages, but you can't do it in Python. I resort to dropping a debug() function into my code, and then:
Function here()
line 1 does some stuff
line 2 if statement
inside the if
debug(debug info to console)
line 3 more stuff
It's not ideal, but at least that way you can search for it afterwards. It does have the added bonus feature of being able to change debug() to return without doing anything when you make your code live, just in case you left a debug statement somewhere.
I would say python cause it also teaches them good coding style
It would appear that most people have responded with knee jerk "my language is better than yours" without actually reading the question, or the referenced material. Well done, all of you have just failed your job/contractors interview.
Short answer: Use C. Teach them it well. Teach them about data. Teach them about "restrict". Challenge them to win.
Long answer:
First observation: This is not a "programming" competition. Its a mathematical computing competition.
Second: There are winners and losers. Therefor not everyone gets 100%. Either contestants write code that fails to do the job, or contestants write code that doesn't do it fast enough. Finally, in the event of a tie, the judges may select winners based on other criteria (than just pass or fail) and therefor they could conceivable use execution time as a decided. Do you know if they have done so?
Much of the judges’ input data will be far more taxing than the sample input given in the
question statements, and may push your program over the time limit. In this way, efficient
programs will be rewarded.
But:
Programs written in Visual Basic, Java, PHP or Python may run slower due to the overhead
of the associated interpreters and/or virtual machines. The judges may at their discretion
increase the time limits for these languages accordingly. Contestants should note that this
will not give these languages an advantage.
Well, that sounds completely and utterly arbitrary. When dealing with C-like java, which is what you will use for the problems you'll face in the competition, java is not much slower than C if its compiled, but it may not be. And VB.NET (NOT VB6) can be as fast as C. Python is always interpreted.
How will the judges increase the limits?
Its likely that the judges will they will benchmark their ideal solutions against each other. If the java version of the same solution in C takes 20% extra, then that is the extra time they allow. So it should be safe to write in java or python if you want to.
But why?
I assume from your choice of competition that you are teaching students to go on to mathematical and scientific endeavours, not programming. This is an important difference. For example, until "recently", you were better of programming large data sets in FORTRAN, because C was unable to optimize properly thanks to pointer aliasing. However, the GNU C++ compiler that they are using will support the restrict keyword, so it can handle large data sets. Java, python, etc are languages for the web, not for scientists. (Ok, unless you are using java as a scripting language to drive something like Mathematica, but this is NOT what we are discussing here).
Teach them C. The competition specifies GCC/C++ 3.4.4 or later, which means you can use the __restrict__ keyword also, if they get the hang of writing algorithms.
Here are some more of the rules, for my peers whose internet connections cannot reach Australia.
Program Restrictions
Students should write a computer program to solve each problem.
Programs should read input only from the input file(s) specified in the question statements,
and should send output only to the output file(s) specified in the question statements. The
input and output files should be assumed to be in the current directory. Any output to
the screen will be ignored, and no input from the keyboard will be supplied.
The format of the input file will be specified in each problem statement.
The desired format of the output file will also be specified in each problem statement. If
you do not adhere to this output format, you may lose marks for your solution. The only
exception to this will be that judges will ignore any spaces at the beginning and end of each
output line.
Each solution should be a single source file, written in one of the following languages:
– C
– C+
I think many many people here are going overboard? Has anyone actually been to the website to have a look at the sample challenges?
From what it looks like, the contest is more about coming up with an appropriate ALGORITHM - that chain of simple logical actions required to solve the problem - and then implementing it in the language of your choice. Further, the challenges and solutions are really really easy if you can see them. The execution time limits are there to discourage brute-force algorithms that cycle through every possible solution to see if it works because they're not as elegant and they're just not needed. At the end of the day I don't think it matters what language you choose, as long as the algorithm is right and it's well written. I'm going to defend BASIC and say that it's still an easy to learn and useful language - but I'm not going to defend VB as I think it blows, Turbo BASIC was the shiznitz back in the day!
Example: That bacteria samples problem. An experiment involving bacteria - which doubles in number every day - has been ruined. All you know is how many bacteria you had at the end, and that the start number was odd. You want to know how many days the experiment ran for and what the start number was.
Solution: Take the end-bacteria number, and keep dividing it by 2 until you have an odd-number. The number of times you divide equals the number of days.
After initialisation and clean-up, you would only need a few lines to implement this algorithm.
Go for ease of use over speed.
If the contest allows entries in Python, then you would expect that python code is capable of running fast enough to win the contest.
Teaching programming is good. It has lots of up scope. Recently I found a training center in Toronto which teaches software programming starting at the age 7. It is really cool. Kids at the young age itself well trained to do stuff of their own. The way I foresee is , programming will become a regular job for many people life just as watching TV.
Mississauga | Toronto Web Design
Why not Perl?
I'd like to buy homeland for our 10 million people. http://twitter.com/mahadiga
Indeed. Pascal was designed as a teaching language. There is much to be said about using the right tool for the right problem. If teaching programming is the problem then you should indeed us a language which is designed for precisely that problem.
BTW: the other well known teaching language is BASIC but I would go for Pascal.
I think variant array have not made it into C++ yet so there is C code which won't run in C++. And there where some more features of the current ISO C which did not make it into the current ISO C++.
Martin
>"Eve online has stacks of code written in python. If that isn't "published" enough for you, then Civ4 runs a stack of python code as well. "
I don't mean that kind of "published". I mean getting Joe Sixpack to install a Python app on his machine.
If I Google for "Python deployment" the first hit is this: "One of the most-frequently asked questions of all time is this: "I have a Python application I've developed; how do I deliver it to my customer/friend/...?" "
If the 'typical answer' is this: "tar up the source and send it. It's reasonable to expect that the end-user's host will have Python installed." then I'm not so sure Python is ready for the big time.
No sig today...
If you want the kids to win the competition, then Python would be your best choice because they can provide more features with less code. If you want the kids to learn the most about programming, then definitely choose C. It is the foundation of all the other programming languages. If you start with C, they will have the background to learn any of the other languages.
It is hard to choose the best one since they are not replaceable. What about introduction to programming without specific languages? What if you ask kids about their preference? Also look at Programming Language Comparison
The CPU Limit is there mainly so they can abort programs rather than wait for potential infinite loops. Or at least that is what it was for in the programming competitions I participated in. Get some example problems before making a decision, but I'd definitely lean toward a scripting language, and something with a robust set of shipped libraries.
"Sometimes it's hard to tell the dancer from the dance." --Corwin Of Amber in CoC
php has infinite number of functions because there are infinite number of modules and extensions that can be put in to perform functions ranging from encoding operations, graphic operations to roasting your bread in the morning. of course there is going to be many functions.
Read radical news here
A popular tax preparation program, installable on Windows systems, is written largely in Python. It is definitely designed for the Joe Sixpack market.
Dropbox is mainly written in Python, and that just has a standard Windows installer. There is no indication that Python is in anyway related to it when you install it, but its there.
Irrespective of cpu time constraints my experience with python is that by dumbing down it discourages the programer from organization of there code resulting in horible messes. Wheras with c++ or C (especially C oh beautiful C) the code is nice and I don't have to fuck around with pretending that memory that holds an int is different from memory that holds a char etc. The hand holding sucks when you know you just want to flip a single bit in a register somewhere instead of including 2 different libs and messing around.
Referencing a post here on /. a while ago, benchmarks across most of the available languages show java running with the server VM (selected by passing the -server option on the command line) is faster than all languages other than C and Clean. Given that your students will probably be able to solve any problems set using only single class of completely static java so you don't necessarily have to teach them OO programming I think Java will provide them with much more power for much less pain than C or C++, is just better than VB full stop and is significantly faster than Python or PHP (which is incidentally the slowest language of those benchmarked).
I'd also point out that Java has some of the best editors (Eclipse, Netbeans), that take the pain out of debugging.
... I don't have any.
But I like to laugh about programming-language fanboyism:
http://blog.aegisub.org/2008/12/if-programming-languages-were-religions.html
http://despuesdegoogle.com/wp-content/language-fanboys.jpg
"I may never prove what I know to be true, but I know that I'll still have to try" Dream Theater "The Spirit Carries on
I don't know about non-German speaking countries - we just have this expression (usually uttered by teachers in the face of completely unmotivated kids):
You're learning for your life, not for the school!
(Nicht für die Schule - für das Leben lernen wir.)
Teaching kids Pascal is teaching them something they won't really use outside of school. Ever.
Furthermore, you're not teaching them functional or OO development, both of which are probably closer to 'life' outside of school.
So, if you want to show kids relatively easy development, stick with Logo (doesn't get much simpler, and you can teach kids enough in a day for them to program some relatively simple graphics excercises - like drawing polygons, ...
I don't think anyone ever coded commercially in logo, but for that it's simple, it's functional, ...
Otherwise, if you have more time, I guess C or Java are likely to have some more relevance to what's happening in the outside world, and if you stay with simpler, pure command line style programs, there won't be much bloat to learn either.
Still, without a proper grounding in development (i.e. not language specifics, but rather going into algorithms, being able to estimate on whether an algorithm is good or not), I'd rather people leave it, instead of making kids believe that this is kind of 'all it takes'.
I've been to many programming competitions like that (and always came 2nd.. Damn it!)
The contests I've been to (local versions of ACM ICPC) that allowed Java and C/C++.
I've also tried TopCoder's contests and Facebook's.
In the ACM contests the algorithms aren't really time-consuming so Java's slowness doesn't really matter, however, because the input and output are in files, Java's approach to dealing with files is very annoying.
In TopCoder there are many options (VB (not .NET), C/C++, Java, Python, and I think Perl), again, time isn't of essence here.
In Facebook's algorithm contests however, the algorithms are pretty complicated and need to be damn efficient, I did have a hard time with Perl because it's slow, however, they claim that all the algorithms can be run in the allowed time limit.
I guess it's pretty clear that time isn't a big issue in these contests (well, except Facebook's but that's because if you solve the problems you can apply to work there!).
Laith Juwaidah http://www.ljuwaidah.org
the perfect is the enemy of the good; It's more important to have something running now and to iterate on that, than to have something that will work better if we can get it to run at all. Only if it proves that it's too slow should you worry about optimizing. And at least then you can look at it run, find the bottle neck and fix that, instead of wasting your time, from the beginning, in a much more difficult, but faster language.
I've programmed in both for years, and the syntax of python is much more complicated than C.