Why Python?

Kael said:
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.

Python is much easier to write and you don't have to worry about memory management, which is a huge concern in C++ (just look at the unpatched Civ4...) For the most part what you win in performance just doesn't weigh up against the increased 'cost' (in time, complexity) of development. Are there actually non-buggy Python scripts that have a noticable impact on the game's performance? I haven't seen them yet...

I've had access to the SDK for going on two years but haven't really done major modding in it yet. If I can avoid it, I will. If I will use it at all in the next year or so, it will probably be to extend the power of Python rather than to actually implement new features. The one exception might be AI modding. Since very little of it is exposed to Python it's probably easier to just do that in C++ entirely.

So I think we'll continue to see plenty of Python coding going on after the SDK is released, if only from the people who aren't quite experienced enough to handle C++.
 
And one more thing...
If you write a MOD in C++.. It becomes much harder to merge multiple modes., I guess.
The C++ mod will produce a single DLL that will be dynamic-linked and called by main Civ4 executable.
For many python mods, non-programmer player can simply merge or just drop in mod files in some folder and do relatively simple job with nothing more than text-editor to merge python mod files.
To merge multiple C++ mode you should merge all the source code of individual mod DLL and recompile and link to produce single DLL. It is much harder than intepreted python (which does no needs compile or link).
This job requires quite a knowlege of C++ and work.
Merging makefile is also troblesome for many non-programmer players.
( assuming that SDK uses free version of Visual C++ ( VC++ Express?)
It is much harder than intepreted python which does no needs compile or link.
As a result, most player will be unable to use more than single C++ mod at a time.
 
J_Period said:
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

:lol: Haha you got that right. Clicking through menus and wizards does not a programmer make.
 
Well... C and C++ are sytems language. C was developed to develop Unix and it's used in many heavy application and systems, like Adobe Photoshop, Corel Draw and Windows. It's a hig-level language that can goes low-level when it's necessary. But it's power comes with complexity and to speed up stuff, many developers imbed a scripting language (interpreted and not compiled) in their frameworks. A good example is Unreal that is mainly programmed in C/C++ but has it's own scripting language to solve some taks as AI, Map Definition, &.c. Other games use Lua -- a very popular scripting language for games developed in Brazil.

CIV4 for decided to use Python but they could be using Perl, Ruby, Lua and, even, JavaScript -- a scripting language used in extended forms in Flash (i.e. ActionScript) and Photoshop (i.e. ExtendedScript). It seems to me that the decision was a matter of personal taste as Python is very trendy today, although Ruby is becoming quite popular nowadays. And I don't think the developers did it with the modders community in mind... It's just a common practice today...

Java could never be used as a scripting language, because it's compliled to bytecode and runs in a virtual machine. Although it could be implemented in a game, it wouldn't be practical. Java entered the scene as a C++ competitor due to it's portability and -- in a distant past -- better productivity. Got hyped because of the internet boom and found it's niche in the enterprise environment, though it never replaced C/C++ in system and huge software development -- Java is an application language. It could be used, though, to develop such thing as a CIV for mobile phones!
 
Have to say I love Python, I originaly learned C/C++ and then took classes in Java, Java was easy to use because of the way it copies C syntax and its API was very well documented. Overall though Java wasn't anyware near as impressive or slick as Python. I can understand how people become very acustomed to that C syntax, I found Python hard to pickup at first but once your over that its a breeze. I have never had problems with white space as I had already developed a habit of Tab only when working in C.

I think a lot of the syntax complaints come from people who arn't codeing in a "Pythonic" mannor, for example you should realy never have a problem with long lines of code if you pack your arguments in tuples.
 
Python is a neat little language that is appropriate for some thing and not appropriate for others. Just like any programming language has its strengths and weaknesses.

I have to say the Civ IV developers made a solid choice in Python. It is a very powerful language that allows you to do quite a lot in only a few lines of syntax. Its lax syntax and variable typing are troublesome, but that is the tradeoff with it.

On the other hand, using Java for Civ IV would be totally inappropriate. Java works best on the server side in larger enterprise and web apps. On the desktop, it is simply too big and too clunky for its own good. Heck, just to run a Java app on my windows machine takes 35 megs of HD space.

Furthermore, as pointed out earlier, C++ integrates much better with Python than it does with Java, namely because the Python interpreter is written in C. Thus the developers smartly chose C++ for the things that make sense in C++, namely hosting the application, managing the graphics and rendering, and the core engine. The non-essential elements were extracted into Python to maximize that languages strengths.
 
Java works best on the server side in larger enterprise and web apps. On the desktop, it is simply too big and too clunky for its own good. Heck, just to run a Java app on my windows machine takes 35 megs of HD space.
I beg to disagree. Java is intially an imbedded software language (back when it was named oak). The server side stuff made in java could generally be done in C++ too. It's possible to make java programs that are not that big. I have to point this one: http://clash.apolyton.net, since it's an alternative civ, it's kind of relevant here, and since I code it, I couldn't help here.
Java can also be used as a scripted language, through itss use of reflextion, but the problems with that are: -it would be awfully slow, -the syntax of java is far too complex for scripting.
I wrote my tectonics.py script by porting it from java code (and adapting to Civ IV api obviously). The result was a smaller code, which is easier to read, and much easier to tweak as I don't have to recompile everytime (in java, I's use a text file as an input in order not to recompile, whereas python doesn't need that).

As for other languages, I don't know lua but I dislike ruby. I found Ruby hard to read (not as much as perl though) because it lets you write the same thing in essentially many many different ways whereas python keeps things simple by generally providing one construct to do one thing rather than several.
Overall, even though python can cause problems with sometimes weird syntax (I keep forgetting the colon after if's), it's quite fast to code and fast to run. And I'd rather debug a typo than some memory corruptions you can get easily in C++.

I'll finally add that the SDK will probably never produce mods that can get integrated by the casual player, so it will have very limited use (Kael and other will certainly be able to do great stuff with it in their own mods, but it'll be really mod specific everytime).
 
Java isn't even a competitor for Python - they're completely different languages in all respects.

In addition, Java is FAR too slow to be used in any modern game. Java's managed memory is a complete hog and would randomly slow any game to a crawl, since the programmer has no real control over it.

Debate Python's merits all you want, but don't confuse the facts by trying to say Java would do the job better.
 
Zurai said:
Java isn't even a competitor for Python - they're completely different languages in all respects.
True, Java isn't a scripting language and shouldn't be used as one.
In addition, Java is FAR too slow to be used in any modern game. Java's managed memory is a complete hog and would randomly slow any game to a crawl, since the programmer has no real control over it.
Not entirely true, at least depending on your definition of modern. These people managed to write a FPS in it. Games with graphics as good as the latest C/C++ games, however...
 
Zurai said:
In addition, Java is FAR too slow to be used in any modern game. Java's managed memory is a complete hog and would randomly slow any game to a crawl, since the programmer has no real control over it.

Debate Python's merits all you want, but don't confuse the facts by trying to say Java would do the job better.

Java is a lot faster than python, however, so clearly it could be used as a substitute for python in any speed sensitive situation. The reason it isn't terribly appropriate to civiv is not speed, but rather the dynamic aspect (much more work involved in unloading/recompiling/reloading/reexecuting a java program than a python script).

Java is mostly fast enough these days, even for games, the main reason for it not being used in any modern game is actually more due to factors of familiarity among the existing developers, and lack of strong bindings to direct3d. Given that most games are GPU rather than CPU bound these days, the direct3d binding is a bigger issue than the performance. The garbage collector is quite easy to control these days, so that isn't much of an issue either.
 
Java can't be as fast as C because it cannot access low-level programming. In modern games with loads of 3D processing, Java would never match it. C can imbed assembler code when necessary.

Of course Java is faster than scripting languages because it's pre-compiled, but it would be necessary to implement a virtual machine in the game that's written in... C! So why not use the original one and it's OO variant -- C++?

Java stands in the middle of the way... not purely compiled as C/C++ nor purely interpreted as Python/Ruby/Perl/&c. What was the winner factor for Java -- mainly in the enterprise ecosystem -- it is its own limitation: the virtual machine.
 
dellamotta said:
Java can't be as fast as C because it cannot access low-level programming. In modern games with loads of 3D processing, Java would never match it. C can imbed assembler code when necessary.
Depends on the application. In long-running processes Java can perform optimisation based on profiling the code as it runs and can therefore do optimisations that are based on the actual code paths taken rather than the best-guess a C compiler can do. In some cases (not most though!), this can make Java faster than C...

dellamotta said:
Of course Java is faster than scripting languages because it's pre-compiled, but it would be necessary to implement a virtual machine in the game that's written in... C! So why not use the original one and it's OO variant -- C++?
Python is also compiled to bytecode and run on a virtual machine like Java you know :)

Locutus said:
Ah, yes, another major pet peeve. It's utterly inconsistent and counter-intuitive and adds no functionality whatsoever, it's just syntax clutter.
It makes sesnse, because methods are bound to the class not the instance. So the following are identical

x = Foo()

x.dosomething()
Foo.dosomething(x)

where the latter is handy for calling methods on things like base classes.
 
spiralx said:
Depends on the application. In long-running processes Java can perform optimisation based on profiling the code as it runs and can therefore do optimisations that are based on the actual code paths taken rather than the best-guess a C compiler can do. In some cases (not most though!), this can make Java faster than C...

Exactly, Sun's new HotSpot JVM does some pretty complicated optimizations on the fly whereas C++ is only optimized at compile time. Thus long running Java apps can and will outperform their C++ counterparts.

spiralx said:
Python is also compiled to bytecode and run on a virtual machine like Java you know :)

Well only Jython does that regular Python obviously does not.
 
Anyway, in general these type of discussions end up going no where as everyone has opinions about which language is better for which task. I think the overall point is that the developers chose Python for their own reasons. I do not think that Java would have been an applicable languge in this context and that C++ / Python was a very nice choice.
 
Back
Top Bottom