Why Python?

J_Period

gone :(
Joined
Feb 8, 2006
Messages
385
Location
Denver, CO, USA
I'm curious: why is Python the language that was used with Civ IV? For a good object-oriented language that can be compiled on the fly, I'd much rather they had used Java. I just find that python looks worse, is harder to read and very frustrating overall!
How does everyone else feel about it? (especially those of you with some programming experience outside of Python)
 
Python is the current "Hip" "Trendy" language. No other reason that I can see (and several reasons I can see why it was a bad choice).
 
Because Java's not a scripting language (yes, I know about JavaScript, that's not relevant here). Python can easily be integrated into C++ projects (which Civ4 is an example of), there is a ready-made package to do so very easily (boost.python). Such packages do not exist for many other languages, especially not 'full-flegded' programming languages like Java. Of course, Python is not the only language that has this option either, but it's one of the most widely used ones for this purpose. I don't really have any first-hand experience with this so I don't really know the reasons for Python's popularity, but apparently it's very easy to implement and of coures Python is an extremely powerful language, which many other scripting languages aren't.
 
zyphyr said:
Python is the current "Hip" "Trendy" language. No other reason that I can see (and several reasons I can see why it was a bad choice).

Um... I think Ruby is the current "hip and trendy" language. Dare I even add how sexy it is? [Seriously, it's sooooo sexy.]
 
Ah, my personal experience with Python. Yes, I definitely agree that the syntax is very frustrating, I truely despise this language for it. I don't agree it's hard to read though, quite the opposite, it's very easy to read. It's hard to write: one stupid typo can completely change the meaning of your code without generating an error. Any language where whitespace has syntactic meaning or where variables need not be declared is inherently evil :mad: Dynamic typing makes you very suspicious as well. And Python has all of these! :mad: :mad: :mad: I can't even remember how much time I lost tracking down bugs that boiled down to a typo in a variable name or an accidental tab too many or too few (I repressed it!).

Then again, I absolutely adore the functional elements in the language (list comprehension, yay!), even if the implementation is annoying. Python is truely a multi-paradigm language. Also, it's fast to run and fast to write code for (but not fast to debug, see above :(), it's powerful, the introspection rocks your socks off, it has a wealth of native data structures and you can write very beautiful and elegant code for it (Java forces you to be much more by-the-book).

So my feelings are mixed. If they'd fix up the darn syntax it would be a fantastic language, but as it is I have a love-hate relationship with it.
 
Locutus said:
Ah, my personal experience with Python. Yes, I definitely agree that the syntax is very frustrating, I truely despise this language for it. I don't agree it's hard to read though, quite the opposite, it's very easy to read. It's hard to write: one stupid typo can completely change the meaning of your code without generating an error. Any language where whitespace has syntactic meaning or where variables need not be declared is inherently evil :mad: Dynamic typing makes you very suspicious as well. And Python has all of these! :mad: :mad: :mad: I can't even remember how much time I lost tracking down bugs that boiled down to a typo in a variable name or an accidental tab too many or too few (I repressed it!).
I find the tabbing comes naturally. Never had any problems with it at all. Also never had any problems with typos in variable names - I try to keep them distincitve though.

It's the synatax of C I don't like. What is with all those accursed semicolons? And curly brackets? Who needs them when you're going to indent it so you can read it anyway?

Pah!
 
I find the tabbing comes naturally. Never had any problems with it at all. Also never had any problems with typos in variable names - I try to keep them distincitve though.

It's the synatax of C I don't like. What is with all those accursed semicolons? And curly brackets? Who needs them when you're going to indent it so you can read it anyway?

Pah!

Wow, That exactly my opinion as well. I know many programing languages and python is one of my favorites as it is so easy to follow and write code in. I have been programing with visaul basic in excel recently and that language droves me nuts after I getting used to programming in python.
 
The Great Apple said:
It's the synatax of C I don't like. What is with all those accursed semicolons? And curly brackets? Who needs them when you're going to indent it so you can read it anyway?
Ah, but those semicolons and curly brackets are what avoids having to give syntactic meaning to white space ;). C is by far not the only language to use semicolons not line breaks as end of statement markers, and the advantage of not doing so is that you can then use line breaks merely to avoid rediculously long lines and generally make things look neater (generally happens with involved conditionals, function calls with lots of arguments or function calls where several of the arguments you are passing are nested quite deaply in a structure/class). "Curly brackets" allow any amount of statements to be treated as a single statement, anywhere. You can do some quite funky things with C if statements due to that. Nicer development enviroments auto indent anyway, and I'd rather not have the tab counts themselves be meaningful when moving chunks of code around (just hit it with a format selection afterwards, and if then doesn't look right it means you messed up the bracketing ;)).
 
tabs are a major flaw.

one, it forces you to use good editors or development environments. what if you need to indent a huge section? it's a chore on Notepad. with brackets, it's as easy as putting it here and there.

second, copying and pasting from websites may not work so well if the page doesn't keep the formatting.
 
Seven reasons why giving syntactic meaning to whitespace is bad:

1) When coding I can type 200-300 characters/minute, at that speed typos are easily made and hard to notice (for the same reason implicit declaration is bad as well).

2) It's inconsistent. At the start of a line it matters how you use whitespace, at any other point it doesn't: you can put as much space as you want between tokens inside a statement without changing the meaning. If you start moving code around, that's asking for trouble.

3) When combining code from different sources, or when multiple programmers work on the same file, you get clashing layouts and clashing use of whitespace styles. This should never ever ever change the meaning of the code!

4) Whitespace is invisible, you can't see whether you're looking at a tab or a (bunch of) space(s). How can give meaning to something that's invisble?!

5) In editors that use proportional fonts it's plain impossible to keep track of whitespace.

6) Whitespace is inherently and intuitively meaningless. Giving meaning to something inherently meaningless is just wrong!

7) Whitespace is very useful for making code readable, but don't force it on me and certainly don't force a particular style on me, even if it's a good one! The whole philosophy of Python is to not force certain conventions on programmers, even if they're good ones (hence the crappy OO implementation for example -- no information hiding allowed). Combining that with the whitespace issue just doesn't compute...

Semicolons are command seperators, they add structure to your code and make it more readable. In languages with a C-like syntax, it's instantly obvious where a statement starts and ends, you can put several commands on the same line, you can spread commands over multiple lines and it's always obvious where the statements start and end. Python is really inconsistent in this. Sometimes you can spread a command over multiple lines no problem, sometimes you need to use a backslash. The use of the semicolon for combining commands is optional and inconsistent in Python. In Python the seperation of statements is obscured by the syntax. IMO command seperators are not the most important element of a language -- I can live with Python's lack of them -- but it would be preferable to have it.
 
Chinese American said:
tabs are a major flaw.

one, it forces you to use good editors or development environments. what if you need to indent a huge section? it's a chore on Notepad. with brackets, it's as easy as putting it here and there.
So it makes it a pain to use Notepad, I personally don't mind ;). I simply cannot stand anything without some syntax coloring, a decent find/replace, and the ability to block indent/dedent anyway. There are editors out there which are better in every way than Notepad - I use SciTE, which loads just as fast, supports multiple documents open at once in tabs, and all of the above. There are plenty of others that are similar.
second, copying and pasting from websites may not work so well if the page doesn't keep the formatting.
True, but thats why most forums (like this one) have code tags, and html has the <pre> tag. You are right though, it can make it harder on newbies especially.

I don't mind whitespace as much as the lack of static typing - while you can do really nice stuff with that lack, it can make it a pain to figure out what a call actually does. This doesn't tend to matter as much here as it would in a program written entirely in python, but it still can be annoying. I also dislike the forced use of "self" - I get tired of it very fast.

The native lists/tuples, dictionaries, functions that are easily passable and other native features are really nice though. While I wouldn't want to write a big program in python (mostly because of the no static type checking), I find it works nicely for scripting. Just my 2 cents.
 
talchas said:
I also dislike the forced use of "self" - I get tired of it very fast.

Ah, yes, another major pet peeve. It's utterly inconsistent and counter-intuitive and adds no functionality whatsoever, it's just syntax clutter.
 
I wanted to throw in my $0.02. During my 24 years of programming, I have to say that python is not at the bottom, but pretty close. Especially when you consider that scoping is dependant on spacing. This problem is made worse when different systems treat characters like tabs differently, some see them as 4 spaces vs a tab character, etc.

Anyways, that's my $0.02
 
Choice of Python as scripting language in Civ4 has good point and bad point.
But I understands that it is kind of compromise and practical choice.
In practical sense, there are not many languges to choose from for game development or modding.

C++: It's implementation lanuage. :) So if Python is not chosen, this will be second choice with illusive SDK.
Java,C# : It is not going along well with C++ used in Civ4. Beautiful but rather rigid. Not scripted.
PowerBuilder, Delpai, VisualBasic : they are commercial product.

So viable choices would be: Python, Perl, Lua, Ruby, Tcl.
Among these, Perl is most popular but rather old and it is rather oriented toward text processing and shell scripting.
Not so good for complex game development. This applys to Tcl, too.
In game development, Lua and Ruby are most popular.
Lua is extensively used in game development including Sims2/SimCity by Maxis, Bioiware and many others.
It work vey simlesslyl with C++. But it is less known to other general programers.
Luby is used in Japanese game mostly. It has beautiful features but less known to programmer outside of Japan.
Quite limited development environment and library. Not so mature yet.
So This leaves Python as a middle ground or practicl compromise between popularity, functionality, sutablility to game development.
Ruby is beautiful than Python. Lua workes better with C++ than Python. They are very good OOP languages.
But, in popularity, maturity, environment, and available library and knowlege base, Python is much better than both.
So it's good choice out of practical consideration.
I, too, dislike Python. But even if I was in position to choose language for modding in Firaxis, I, too, would have chosen Python.
Lua would be second best, Ruby as third.
 
Im actually curious to see how many extensive mods use python 6 months after the SDK comes out. Given the fact that you have to use C++ for extensive mods why use 2 languages? Anything you can do in Python you can do in C++ and it will run faster if its done in C++.

The only thing you lose is fact that other people won't be able to mod it. Which, for most extensive mods isn't a big deal.
 
NP300 said:
Besides, Java is slow and I've heard that it's hard to learn.

Java is easy to learn, too easy probably which is why alot of university Computer Science programs teach it as a first language.
 
Rabbit_Alex said:
Java is easy to learn, too easy probably which is why alot of university Computer Science programs teach it as a first language.

too easy? just because something is well formed doesn't make it too easy :lol:
Then there's VB which really is too easy and doesn't teach you much about real programming
 
Programming language has something in common with real lauguage or religion. The native speaker/religious follower argues that their lanuage/religion is better than that of others.
C++, Java, VB, python all has many followers and haters and dominant domain. They are best programming lanuage in their own application domains. So you can not say Java is better than VB or vice versa without specifying application domain. Who will write PC FPS game in Java?
And for VB haters, VB is not too easy.
All computer language is just a tool that is used to let your work done.
VB or python takes much less time and effort to write and debug than, say, C++ or Java. If speed/efficency is not an issue, but development time/cost is an issue, then lanuage like VB/Delpi/Python is better languge in such application area.
 
Back
Top Bottom