Python advice

Chris Angelico rosuav at gmail.com
Mon Sep 22 20:55:00 EDT 2014


On Tue, Sep 23, 2014 at 5:00 AM, Chris Kaynor <ckaynor at zindagigames.com> wrote:
> As a rule-of-thumb I'd recommend sticking to one or two high-level languages
> until you are reasonably comfortable with them, then possibly branching to
> other languages. As you've already started with Python, I'd continue on it
> for a while. Possibly throw in Javascript/HTML/CSS for web-development - for
> server-side code you could look in the to various Python web frameworks, or
> learn PHP for those.

Let's start with application programming languages... pick up the
other languages separately. I'd strengthen the recommendation: As
you've already started with Python, and as Python is an excellent
language, I'd recommend continuing with it for a good while. Don't
bother with PHP.

> A few languages and their major strengths:
>
> Python is pretty good base-line language. It is really good as a glue
> language to piece together other components, or for IO-bound or user-bound
> code, but will not preform well enough for many other applications such as
> games. It is good for short parts of games, but a full next-gen engine would
> be much too slow if written in pure Python, however Civilization 5 uses
> Python as its scripting language. There are also libraries available that
> can provide enough performance to do basic games in Python.

Agreed (with the minor correction re Civ 4/5 and Lua, per other
posts); but you'd be amazed how much can be done in the "slow
language". There are two common models for mixing Python and some
lower-level, higher performance language: either you use the high
performance language as the main program and then script a few parts
in Python to make them customizable, or you use Python as the main
program and use the other language to do the heavy lifting via
well-defined API calls. The latter is extremely well-suited to
heavy-duty mathematical computation - you can do enormous amounts of
work with numpy, and all the grunt-work is done in Fortran, even
though you just write pure Python code.

> C# is another good base-line language, although its much more limited to
> Windows (there are ways to run it on Mac and Linux, but not as easily). The
> main benefit it has is that, if you have Visual Studio, you get a nice UI
> designer built-in. Overall, this is a decent option for Windows-only GUI
> applications, and can be expanded with other libraries to other platforms,
> including many mobile platforms. Some web-servers can also run it as a
> server-side language.

I haven't used it extensively, but I'm given to believe that mono
means C# is reasonably viable on Mac/Linux these days. You'd have to
find an expert to be sure, though.

Personally, I don't think C# has anything above other languages, if
you're writing for desktop OSes. But mobile is a completely different
story, and if you can write one codebase that runs on Windows, Mac,
Linux, and whatever phone you're targeting, that's a huge win.
Otherwise, though, don't bother learning C#, at least for now.

> Javascript is basically a necessity for web-based applications, as it is the
> only language that is commonly runnable across all browsers. There are,
> however, compilers that can (with some success) convert other languages to
> Javascript. (note: Javascript runs in the browser, primarily)

JavaScript/ECMAScript is the One Obvious Way to script a web page.
It's also one of the easiest languages to sandbox as a means of
allowing untrusted people to script your program. (It shares this with
Lua, which is a much less powerful language.) Sadly, it's stuck in
UTF-16 land, and that's never going to change (for reasons of backward
compatibility). Learn JS if you want to do anything even slightly
fancy with web pages.

> PHP is another commonly used web language, and is widely supported by
> servers. Anymore, there are also good Python libraries available for
> server-side webpages, although whether you can use them will depend on the
> server you are using. For some of the free servers, even PHP may not be
> supported, and you will only be able to do static sites (no server-side
> code).

A few years ago, PHP was the *only* way to write server-side code for
cheap web hosting. That's changing, but given how terrible a language
PHP is, I would say you're far FAR better off filtering web hosts down
to those that let you run Python code (even if that means paying a
little more) rather than learning PHP. Don't learn PHP unless you have
a really REALLY compelling use-case... maybe there's some existing PHP
framework that does 99.995% of what you want, and the remaining .005%
just requires a tiny bit of your own PHP code. And even then, keep
your eyes open for the possibility of outgrowing that framework.

> C/C++ are both low level, and therefore generally harder to learn but
> provides much better performance than many other languages. I'd recommend
> putting these off until you are more comfortable with other, higher-level
> languages.

Agreed. The primary job of C is to write high level languages in. :)
Secondarily, it's occasionally used for other boring jobs like C
compilers, OS kernels, device drivers, and other stuff that early
programmers can completely ignore. Eventually, you'll need to learn C,
if only to understand why certain things are the way they are at the
CPU level (for instance, do you know why 2**31 is such a common
limit?), but the more you can avoid actually coding in C, the happier
you'll be. C++ has its place, but not all that much of it... or maybe
too much of it, I'm not sure which. It's trying to stretch upward into
the domain of high level languages, and stretch downward into "C but
with a few more features", and I'm not convinced it's doing a good job
of balancing the two.domains.

> LUA is a commonly used scripting language for games. You'll find many
> engines have LUA support, as it tends to be very light-weight. I'd only
> recommend LUA if you want to program in one of those engines. World of
> Warcraft is one game I know of that has public support for LUA when making
> UI mods.

Lua is a much simpler language than ECMAScript, incredibly
light-weight, and easily sandboxed. It doesn't work with Unicode (I
think its string type is eight-bit, so you have to work with encoded
bytes), which is a serious downside in my opinion. Learn Lua if you
want to work with something that embeds it. Otherwise, don't bother
for now.

> Objective-C is one of the main languages used for IOS (Apple) development.
>
> Java is a commonly used language for Andoid development.

Learn these if you want to develop for their corresponding phones.
Java has other roles, too, but IMO nothing you can't do with Python.
And thanks to Jython, you can even use Python to call on Java-specific
libraries.

So, that's application languages. What about other types of language?

* SQL is the one and only database query language you should ever need
to bother with. (You might skip SQL too, if you use something like
SQLAlchemy, but you certainly won't need any other query language -
not in 2014.) It's well worth getting to know SQL at some point;
whether you use Python, Pike, C, or any other language for the
application, your SQL code will be the same.

* HTML5 is the one obvious way to build web pages, these days. Don't
bother with XHTML, older versions of the HTML standard, or any of the
other tweaks; just put "<!doctype html>" at the top of your file and
follow the HTML5 standard. Yes, it's not fully stable yet, but the
core isn't changing, so you're safe.

* bash scripting and bash command lines are the One Obvious Way to
execute lots of commands, on any sort of POSIX system. Get to know the
shell ecosystem - the nature of bash pipelines and so on, plus the
standard POSIX tools. Combining 'find' with some other program is one
of the easiest ways to do sweeping changes to a subset of files on
your system.

* English. Yes, really. It's not a programming language, but your code
looks better if all your text strings, comments, variable names, etc
are correctly spelled. (Particularly so if they end up as part of a
communication standard. I'm looking at you, Referer!)

Not every language will be important to every programmer, but I'd say
the above four are going to be the most useful to someone who already
knows Python.

ChrisA



More information about the Python-list mailing list