Python and "Performance"

Anthropoid

Grognard fantome
Joined
Jan 14, 2004
Messages
821
Location
USA
For the sake of a graduate program in "data science" I'm trying to get into, I am just embarking on learning some Python, which will be my first object-oriented language . . . though actually IS it object-oriented? I can recall seeing it referred to as a "scripting language."

As a newcomer to it, I was intrigued to read in Kael's guide to Civ V modding that python's negative impact on performance in Civ IV was a part of why the decision was made to switch to Lua for Civ V. While I'm in no position to dispute that, I find it strange given that Python is used in so many seemingly "high performance" contexts: Mount&Blade and EVE Online being games I know of; google and Youtube are also based in python, no?

Just curious to hear what any of your thoughts are on Python.

ADDIT: maybe I should've put this in an "off-topic" forum? If so my apologies, and hope it isn't a problem for a mod to move the thread.
 
Thanks Browd :) yeah I'd have never guessed where best to put it.
 
Well, even BASIC would be fast enough depending on what you want to do with it. And C++ can be painfully slow if you program something badly.

I don't know what those other games use Python for, but Civ5 uses Lua strictly for UI purposes (not counting scenarios and mods). Really, speed isn't needed for this kind of UI functionality. And from looking at Civ5 UI code, it's painfully clear that the coders were new to Lua and did not understand how to get any performance advantage out of it (by localizing variables, reusing tables, etc).

So, although I think the Lua speed advantage is real, I'd be very surprised if Civ5 performed noticeably different from using it rather than Python.

However, after using a variety of different "scripting" languages (mostly Python and PERL), I have to say that Lua is more elegant and more fun to program in than any others. The table implementation is brilliant. Still, each of these languages has its own peculiarities and advantages/disadvantages.

I won't answer the Object Oriented question because I'm afraid my answer won't be precisely correct.
 
I disliked Python for its "meaningful whitespace". Not that I like Lua that much - I really prefer languages where you declare a type for a variable before using it, it makes error checking much easier. And variables being global by default is just crazy ;)

As for performance, I agree that it doesn't matter much in case of Civ5 Lua usage, perhaps except mods that make extensive use of it by doing things like scanning the entire map every turn.

About object-oriented programming, here is a quote from this page:

Python - dictates a specific model for object-oriented programming. Python has rich OO capabilities, including metaclasses, multiple inheritance, and so on.

Lua - does not dictate any particular OO system. Instead you can build your own (using meta-methods) and tailor it to your needs.
 
Is it inherently OO? IMHO the answer is "No"
Can it be made to behave with certain OO characteristics? "Yes"

For examples of pseudo-OO code, see River Connections and Follow Me (self-aware units)
 
Top Bottom