Python, C#, and Beginners

Published July 18, 2007
Advertisement
Python, C#, and Beginners

When it comes to recommending a language for a complete beginner to start with, the field is usually narrowed to C# and Python. Forget the details of why other languages are rejected; that's not relevant to this post. This journal entry is about something that's been bothering me for a very long time. A beginner should start with C# or Python. But which one?

The fact of the matter is that I have deep seated reservations about both languages and I don't have a strong recommendation for either. I tend to side with C#, but I'm reluctant to do it and I won't actively disagree or object to Python as a suggestion. So I decided to voice some of my concerns with the whole matter. I'm fairly interested in how all of you feel about this, so please comment if you've got anything to say in favor of either language or just in general.

C#'s an absolutely beautiful language. It's not perfect, but it's as close as I've ever seen. It really takes a lot of lessons from Java and Delphi, and working in it is a pleasant experience. Massive support from Microsoft, combined with the fact that a lot of people know and love C#, means that any time you run into problems, you've got a lot of places to go for help. And the .NET Framework supports almost any type of development, from applications to web development to Windows services and everything in between. For the most part it's blazing fast, especially if you know what you're doing. The biggest advantage of all, though, is that anyone can get the Express Edition IDE for free, and work in what amounts to the foremost professional grade development environment in the world. Combined with XNA, it's a great way to make games.

Python's a great language in a lot of ways. It's developed a fairly active community that has produced a lot of good information and libraries. Since it's been used heavily in the commercial sector, it's a mature language that is known to be usable for real life work. Learning the basics is a rather simple task, though it includes plenty of advanced functionality. Many people have learned from Python, and many people use it to great effect. There's even a completely free book online called Dive Into Python that you can use to learn. And the presence of an REPL makes experimenting with Python coding very easy. When you're reading to do games, you can move smoothly into PyGame and hit the ground running.

Both languages seem great, because they are great. So the question is, why do I have such serious misgivings about letting beginners loose in either?

C# throws a lot of information at a beginner. Consider what a beginner will typically deal with in C#:
using System;namespace App{    class Program    {        public static void Main(string[] args)        {            Console.WriteLine( "Woot!" );        }    }}

That is a lot of things going on for someone who's never seen coding. That snip has 7 reserved keywords in it, and a number of them are somewhat difficult to explain. And asking a newbie to simply ignore bits of the code as magic really bothers me. They did it to me when I learned C++, and I used things like using namespace std; blindly for months. And once you start getting involved with WinForms, or really any part of the Framework, things get much more noisy and complex. Everything is great once you get over that hill and are basically familiar with the principles at play (classes mainly), but in the meantime, C# code is a confusing mix of simple statements and total nonsense.

So maybe you're thinking at this point, Python doesn't suffer that problem. The equivalent Python program is a single line:
print "Woot!"
Nothing more. The use of "print" is historic and maybe a little strange to someone new to coding, but it's a minor detail and other than that, this code is dead simple. There are a few different problems with Python though. First, although having an REPL is nice, you don't write regular code in that thing, and the actual Python IDEs suck very badly. The end result is that developing an application purely in Python can be kind of a pain, unless you're particularly fond of the Emacs or Vim environments. Second, the Python syntax is completely foreign from anything else. It won't help you understand Java, C#, or C++, which means that learning those languages eventually will involve a bit more work.

However, my deepest reservation with Python is the type system, which is dynamic typed and duck typed. I feel that the biggest pain in programming is learning that computers deal with very strict rules, and I tend to think it's better to start from more rules and then eventually relax some of them. That way, since you're more used to the restrictive rules, you tend not to outright abuse the relaxed rules. For example, arbitrarily changing the type of a variable and using it for some other purpose than when you started really bothers me. Python and most dynamic languages take the line that variable types are locked, and you're simply redirecting the name assigned to a variable. I don't buy that. While it's technically and theoretically accurate, it's a completely worthless perspective to take in terms of actually coding software. All it does in reality is confuse people about what a given variable is being used for. In general, Python is very, very lax about rules, and that tends to result in some rather grievous code being turned out by people who mainly learned to code in Python.

So at the end of it all, I don't know what to say to newbies about which one to select. I personally started in VB6, which involved a lot of behind the scenes magic, but turned out fairly simple code. And VB6 really had very relaxed rules indeed, and is a lot like Python in that regard. I had an intuition early on that this kind of behavior was "bad", and so my VB code never involved variants being thrown around or any of that stuff. (I did use duck typing, but inheritance was seriously broken so there weren't many options.) A lot of people learning VB6 turned out really horrendous code, and I expect the same exact thing to happen with people who learn with Python. That's why I usually side with C# at the end of it all, but I can't say I'm happy with it.
0 likes 7 comments

Comments

_the_phantom_
If you remove all the dynamic stuff from Python we basically end up back at BASIC; not VB or even QBasic but normal, 'pure' BASIC ala Speccy and the BBC era.

I guess the problem with any language which is simple enough to teach the coding basics is that it doesn't enforce structure all that well, and once you add structure you start drawing away from the programming end of things some more.

Bah, I'm just glad I don't need to learn to code again [smile]

July 18, 2007 07:27 PM
Ravuya
Python still has type coercion; it's just that most Python programmers don't use it.

IMNSHO, Smalltalk would be an absolutely fantastic language to start newbie programmers out with. It's a pity that modern implementations are tied down to Squeak and the whole heavyweight UI stuff.
July 18, 2007 07:49 PM
HopeDagger
Pascal and/or Delphi are really neat options for the beginner that don't see much daylight. This is justified, however. In terms of the language itself, it tends to be much more lax on keywords and forced-fed OOP like C#, but yet has strong typing and enforces a (somewhat) clean program style that keeps code organized:


program HelloWorld;

uses crt;

begin
  WriteLn('Hello world!');
end.



This is rather intuitive to understand, as this was what was used in my highschool's introductory CS courses. When they tried shoving Java down students' throats in Grade 11, it was like the C# ballgame above with 'magic' happening left and right.

Back to Pascal though, although I think it's a great language for beginners, it suffers from some nasty external quirks. For one, there's not really a 'standard' anymore. You can take up the flavour Delphi put together, or FreePascal's smorgasboard of extensions. However, while Delphi is a fantastic development tool, it's a little tricky to acquire nowadays. Borland is offering a free 'Turbo Delphi' IDE, but it's crippled so that new VCL components cannot be installed. FreePascal is free, as the name implies, but the DOS-based IDE is terrible. Besides Delphi, there really isn't any Windows-based IDE that even approaches a commercial level of quality to make *real* Pascal game development feasible. Still, it serves it's purpose well as a stepping stone into deeper waters for the beginner. Not to mention surviving communities like PGD that keep the gamedev scene alive with Pascal.
July 18, 2007 08:32 PM
jollyjeffers
Quote:Massive support from Microsoft, combined with the fact that a lot of people know and love C#, means that any time you run into problems, you've got a lot of places to go for help.
This is absolutely crucial IMHO.

It takes a lot of perseverance and existing skill/knowledge to go off the beaten path. Even if it's not such a good choice in the long-term, sticking with the norm to begin with can be a good idea.

Quote: personally started in VB6, which involved a lot of behind the scenes magic, but turned out fairly simple code.
Further proof that all the best people started in VB [lol]

I learnt in VB and I think the fact I was focussing on high level programming paradigms ("what is a method call?" "what does scope and visibility mean?"..) long before messing with low-level implementation details is why I got so good at programming so quickly.

The VB6 gaming community used to be bigger, and you very quickly found out that variant's were evil and you should specify types where possible.

Jack
July 19, 2007 05:51 AM
JTippetts
And yet, people still manage to learn to program, despite all the seemingly insurmountable problems that every language seems to have as far as beginners go. Funny, yeah?

If someone wants to learn and is capable of learning, they'll learn. Eventually, they'll learn to be good, and will overcome whatever bad habits they pick up along the way. Or maybe they won't, but why should that be the language designer's responsibility?
July 19, 2007 04:53 PM
Oluseyi
Quote:First, although having an REPL is nice, you don't write regular code in that thing, and the actual Python IDEs suck very badly. The end result is that developing an application purely in Python can be kind of a pain, unless you're particularly fond of the Emacs or Vim environments.

Komodo. Komodo Edit is free.

Quote:However, my deepest reservation with Python is the type system, which is dynamic typed and duck typed. I feel that the biggest pain in programming is learning that computers deal with very strict rules, and I tend to think it's better to start from more rules and then eventually relax some of them.

I feel the opposite, naturally. I feel that many of the rules computers deal with are not important to end users or applications developers, and slavish adherence to them is a waste of my time. We can instrument interpreters and compilers to take care of that.

Quote:That way, since you're more used to the restrictive rules, you tend not to outright abuse the relaxed rules.

You tend also not to take advantage of their expressive power for a long time.

Quote:For example, arbitrarily changing the type of a variable and using it for some other purpose than when you started really bothers me. Python and most dynamic languages take the line that variable types are locked, and you're simply redirecting the name assigned to a variable.

Stop.

Variables are not values. In Python, a variable is just that - a local means of referencing a variable object. The value, however, is strongly typed and can not be trivially coerced (there is no casting in Python). I find that fans of statically typed languages tend to make too much of this, which is fine for them but not fine for beginners. To a beginner's mind, static typing is wholly unintuitive, and if a language like Python can demonstrate that it is unnecessary for large problem domains, why saddle them with it at the beginning?

Quote:While it's technically and theoretically accurate, it's a completely worthless perspective to take in terms of actually coding software.

That's wholly subjective, and probably domain-specific. I write code for a living in a dynamic language (Perl), and there is a lower incidence of trivial typing bugs than there is in C++, where you expend quite some effort lining all the ducks up just right, pre-declaring that types are inheritable and can be dynamically dispatched (virtual), obtaining interfaces differently if you plan to dynamically dispatch, working around the inherent inability to create collections of objects of arbitrary type (boost::any)... all of which are irrelevant to what the product actually does.

By moving all that plumbing upstream, the resulting code can be more compact and more expressive. People forget, code exists to communicate between programmers, really, not between programmer and machine. If communicating to the machine were all that mattered, assembly would be ideal, perhaps with a few mnemonics. However, because code must be maintained and refactored and altered by other programmers, it requires less "comprehension friction".

Quote:In general, Python is very, very lax about rules...

I disagree, so I'd like to see some elaboration. I think Python is lax about the rules that Python fans consider inconsequential, like type declarations and access restrictions, but there are valid arguments on both sides of such issues.
July 23, 2007 05:09 PM
Spoonbender
Quote:Second, the Python syntax is completely foreign from anything else. It won't help you understand Java, C#, or C++, which means that learning those languages eventually will involve a bit more work.

I don't think that in itself is such a bad thing. On the contrary, I'd say that if a beginner starts out with something different from the "common" mainstream languages (let's face it, if you're going to be a programmer, you'll end up spending a lot of time in the C/C++/C#/Java family of languages)

I think it's a good thing to learn from day one that this isn't all there is to programming. You don't have to think in classes and objects, the entry point doesn't have to be called main, and functions don't have to be as anemic as they are in the C-family of languages.

I have the same misgivings as you do about the dynamic typing bit though. I started out with a functional language (ML), so static typing (and type inference), recursion and higher-order functions don't seem exotic or foreign to me (I'm not as good as functional programming as I'd like, but my point is it's not something far removed from "regular" programming. It's where I started)

One thing I like about Python is that functional programming comes more naturally there, as opposed to, say, C#, where the first rule you learn is "Object-oriented is God!"
You have to be a pretty advanced programmer (preferably knowing a few other languages too), to even start thinking about the functional features they've started adding into the language. (Even delegates take *a lot* of getting used to if the only languages you know are C#/C++/Java.)
When you're starting out in C#, all you see is the dogma that "OOP is the answer. You don't need to look to other solutions, you don't need to know that other paradigms exist".
I think if you start out with Python, you might end up more open to different paradigms.

Of course, since I don't have, say, 50 beginners to test all this on, it's nothing more than a hunch... [grin]
August 08, 2007 07:15 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement