TIGSource Forums

Developer => Technical => Topic started by: Feral_P on December 24, 2010, 07:32:57 AM



Title: From C++ to Python?
Post by: Feral_P on December 24, 2010, 07:32:57 AM
I've searched through the few language threads I found here, but none of them really answered my (fairly unusual) question.

After working with C++ for at least a year now (on and off), I'd consider myself reasonably competent at the language and at programming in general. I doubt I'm the best judge of that, but unless you're going to set a test for me - you're welcome to - you won't be getting a second opinion :P. I don't have any real difficulty with it; the low level-ness and lack of automatic garbage collection seem fine to me - possibly because it's the only language I've used. I've been using SDL and OpenGL for input and (simple) graphics. But the problem is, I've never finished a game with it. Development always seems to be really slow.

To cut to the chase, I was wondering whether it was worth learning Python to make games with instead. I find the whole Python philosophy kind of... seductive. It feels like admitting defeat after spending so long learning C++, but I doubt I'll need the extra speed it affords me and if Python could increase my development speed I think it would definitely be worth changing.

So really I want to know whether using Python could make development (most likely of simple turn based strategy games) quicker for me, or if it's just my poor programming that's stopping me.

Any kind of discussion of the pros/cons of either language or, possibly, alternate suggestions are fine as well.


Title: Re: From C++ to Python?
Post by: Draknek on December 24, 2010, 07:54:33 AM
My suggestion: AS3 development using FlashPunk or Flixel. Excellent for rapid prototyping, lots of useful code already there, and you get a browser-embeddable SWF at the end.

I think part of your problem is probably using C++ rather than something like AS3 or Python, and part of it is probably using SDL/OpenGL rather than something which provides useful game stuff like FlashPunk/Flixel.


Title: Re: From C++ to Python?
Post by: speeder on December 24, 2010, 08:00:56 AM
I suggest Lua, it is widely used in the industry, and widely I mean WIDELY.

And you can use it with several engines that allow you to make games fast, like Novashell for 2D games, Spring for 3D RTS...


Title: Re: From C++ to Python?
Post by: flavio on December 24, 2010, 08:03:22 AM
It feels like admitting defeat after spending so long learning C++

It's never wasted time learning a language! You carry your knowledge on other languages, and you understand other languages deeper. So, don't worry, your time with C++ is worth.

There are studies that show that in order to solve a given problem you need less time and code with scripting languages. So, knowing a scripting language will make the dev time more short.

But, in the real world, you need to know both. Scripting languages are used to develop the gameplay mechanics and so on, but you could find some aspects which you need to face with a lower level language (for example, for performance reason).

An example with Panda 3D: you can develop your game with Python entirely, but if you need to modify something at low level (or you need to improve the performance of a Python module that you've written) you should modify the core of the engine - which is in C++ (or you have to rewrite your Python module in C++).

So, yes, it should surely be useful learning Python, but don't detach from C++, you'll need it many times again!


Title: Re: From C++ to Python?
Post by: increpare on December 24, 2010, 08:16:55 AM
So, yes, it should surely be useful learning Python, but don't detach from C++, you'll need it many times again!
I haven't used it for indie work in over a year.  Most of the knowledge is transferrable, so it's not a big deal.  I wouldn't recommend python, because of the horrors of allowing other people to play games made with it (it's not impossible, but it's a royal pain).  So I'd second Draknek's recommendation [as someone who's made cross-platform games in plenty of languages (except python, though I've tried running other people's python games and have heard their shrieks of horror when they finally finish their games and try to get them working on other people's machines)].

Don't let programming anxiety stop you making games.  Lots of people can make games with very little programming knowledge.

The only python-based games engine I'd recommend is renpy (http://www.renpy.org), because it automatically builds binaries for all PC platforms (regardless of which one you're on), which is mucho handy :)

Used as embedded scripting languages, python and lua can both be super handy, and definitely can speed things up (I've only ever embedded lua myself, which I definitely like).  But if you're having trouble finishing anything with C++, it might be worth a break from it and going to a ready-made engine for a bit (no shame in that at all).


Title: Re: From C++ to Python?
Post by: Taiko on December 24, 2010, 09:29:05 AM
So, yes, it should surely be useful learning Python, but don't detach from C++, you'll need it many times again!
I haven't used it for indie work in over a year.  Most of the knowledge is transferrable, so it's not a big deal.  I wouldn't recommend python, because of the horrors of allowing other people to play games made with it (it's not impossible, but it's a royal pain).  So I'd second Draknek's recommendation [as someone who's made cross-platform games in plenty of languages (except python, though I've tried running other people's python games and have heard their shrieks of horror when they finally finish their games and try to get them working on other people's machines)].

Don't let programming anxiety stop you making games.  Lots of people can make games with very little programming knowledge.

The only python-based games engine I'd recommend is renpy (http://www.renpy.org), because it automatically builds binaries for all PC platforms (regardless of which one you're on), which is mucho handy :)

Used as embedded scripting languages, python and lua can both be super handy, and definitely can speed things up (I've only ever embedded lua myself, which I definitely like).  But if you're having trouble finishing anything with C++, it might be worth a break from it and going to a ready-made engine for a bit (no shame in that at all).

Porting games from Python source to executables really isn't as bad as everyone says.  Download the py2exe package and then write a script to make the binaries.  Once you make the script for one game, changing it to work for other games is trivial.

Plenty of companies use Python - especially for cinematic scripting (Blizzard and Maya are probably the most notable).

As far as moving from C++ to Python, you'll find that the syntax is pretty easy to pick up.  Python isn't as close to C++ as, say, Java, but Guido built the original code using C so obviously there are plenty of similarities.

I'd advise you to try Python and see how you like it.  If you are used to programming it shouldn't take more than a weekend to pick up.  Pygame is a great SDL cover to use when making simple games.


Title: Re: From C++ to Python?
Post by: eclectocrat on December 24, 2010, 01:04:30 PM
Yeah, but, hum, well... er..

I mean, I love python, it's lot's of fun, very nice to use, buuuuuut... In this day and age we don't need to limit ourselves to writing "computer" games anymore. Now we have gone back to the good ol' days of (for lack of a better term) video games. Go ahead and write your game in python, it'll work great and be a lot of fun, but you WILL come up against some serious roadblocks if you want to run it on, say, an Android phone, or a Symbian phone, or a Casio electronic dictionary, or a RIM blackberry pad, or one of the myriad devices that are popping up every season. So, in light of that I'm going to give a big hearty endorsement for Lua. It's TINY, fast, can be embedded in almost anything (I have my Lua engine running on Win, Mac, Linux, Symbian, Android, iPhone, Nintendo DS (almost!)), plus as mentioned above, it's ubiquitous in the industry.

So, if you can reach a bigger audience, why not? If you KNOW you want to write COMPUTER games, things that won't translate well to other devices then pick whatever gives you a hard on.


Title: Re: From C++ to Python?
Post by: Triplefox on December 24, 2010, 03:13:21 PM
I went from "Python as gamedev language" in the early-mid 00's to "Python as misc. script language, AS3/haXe for gamedev" now. Never really needed C++, but it still has its purposes, especially if you're targeting consoles/mobile and need the extra resource control.

If I needed to build to a hardware platform today, I would look towards Lua and consider learning enough C++ to maintain/extend whatever engine I built on. But the undercurrent is towards the browser/Flash/JS, and the massive productivity/usability/distribution boost implicit in that option is hard to resist, even if a lot of the available tech is still rough and not up to par.

It's still worth using one of Python, Perl or Ruby because they each have a gazillion libraries that one can use to facilitate out-of-engine tasks - tools, scripts, build processes, DSL compilers...


Title: Re: From C++ to Python?
Post by: Feral_P on December 25, 2010, 03:45:58 AM
Thanks, everyone, for your comments :)

Python portability could be a problem and I'll check out Lua, since it seems learning one of these would be a good choice.

Something like AS3 that you could run in a browser could be useful as well.

I'm not really considering making anything for a platform besides computers, although I guess the option is always nice. I do want portability between PC/Mac/Linux, though.

Thanks again, and keep the suggestions coming!


Title: Re: From C++ to Python?
Post by: Musenik on December 25, 2010, 12:49:48 PM
Here's a different suggestion. I've made three commercial games with Python. (okay, 'arcada mia' has a few months before it ships...) They run on Mac and Windows, and I'm sure it would be trivial to get them working on Unix. But as mentioned, the mobile space is growing, and it has lots of opportunity for indies, but Python isn't ready for mobile. Also, the Python language is in a weird transition, headed in a direction I don't care for.

I just found CoffeeScript, which is an interesting wrapper on JavaScript. Haven't committed yet, but it looks like two good things. A clean replacement for Python language, and a potential way to pick up JavaScript. JavaScript JITs blow Lua out of the water, and JavaScript is EVERYWHERE.

CoffeeScript Site (http://jashkenas.github.com/coffee-script/?section=top#top) (barebones but very informative)



Title: Re: From C++ to Python?
Post by: BorisTheBrave on December 25, 2010, 04:37:31 PM
Also, the Python language is in a weird transition, headed in a direction I don't care for.
Really? Like what?


Title: Re: From C++ to Python?
Post by: Musenik on December 25, 2010, 09:54:06 PM
Also, the Python language is headed in a direction I don't care for.
Really? Like what?
One man's wrong way is another's path to nirvana. Like two ships in the night, I bumped into Python when it was headed where I was going, but that was never its destination. So no specific criticism from me.


Title: Re: From C++ to Python?
Post by: moi on December 25, 2010, 10:02:54 PM
Also, the Python language is headed in a direction I don't care for.
Really? Like what?
One man's wrong way is another's path to nirvana. Like two ships in the night, I bumped into Python when it was headed where I was going, but that was never its destination. So no specific criticism from me.
It's a sad tale of tears and intrigue, a lady in white waiting on a the shore of a colonial port in africa. Some mail in a cargo that might not reach desination, sealing the destinies of two countries.


Title: Re: From C++ to Python?
Post by: Musenik on December 25, 2010, 11:15:46 PM
One man's wrong way is another's path to nirvana. Like two ships in the night, I bumped into Python when it was headed where I was going, but that was never its destination. So no specific criticism from me.
It's a sad tale of tears and intrigue, a lady in white waiting on a the shore of a colonial port in africa. Some mail in a cargo that might not reach desination, sealing the destinies of two countries.
The captain had orders to rendezvous with the French colonial steamer, but those orders revealed too much. He swore by the salt in his blood, this underwater boat was the future of Germany. The plot to kill a Austrian prince was merely a spark compared to the beaming glory of Kaiser Wilhelm. The future rule of all Europe steamed into his periscope's sights.


Title: Re: From C++ to Python?
Post by: ink.inc on December 26, 2010, 10:38:10 AM
I love you guys.


Title: Re: From C++ to Python?
Post by: mcc on December 26, 2010, 11:48:24 AM
Python and C++ are good at different things and I view them as highly complementary. It's also possible to write a single piece of software with parts written in each language.

I can't speak to whether python is any good for games though. And count me with the people saying python will be a huge source of frustration to deploy, either on PC or any other platform. If you don't want to spend time learning extra languages then JavaScript or Lua might be a better thing to attack first.

(Just curious, Increpare, have you tried cx_Freeze?)


Title: Re: From C++ to Python?
Post by: increpare on December 26, 2010, 12:07:00 PM
(Just curious, Increpare, have you tried cx_Freeze?)
Yes, for some pyqt stuff, though trauma has claimed all memory of any python games packaging-related efforts.

(http://www.examiner.com/images/blog/EXID15135/images/dexter.jpg)


Title: Re: From C++ to Python?
Post by: Darren_D_Daley on December 29, 2010, 03:55:44 PM
Have you considered using XNA ? it uses C# (pretty similar to c++) and DirectX and provides a pretty decent template to start off with and there is loads of information and examples showing you how to do things with it.


Title: Re: From C++ to Python?
Post by: simono on December 30, 2010, 06:36:53 AM
I just found CoffeeScript, which is an interesting wrapper on JavaScript. Haven't committed yet, but it looks like two good things. A clean replacement for Python language, and a potential way to pick up JavaScript. JavaScript JITs blow Lua out of the water, and JavaScript is EVERYWHERE.

JavaScript +1

But be careful with CoffeeScript - I would recommend against using it too early. It is high level and will hide problems you will run into nonetheless later on. First: know your JavaScript (and by that I mean: EcmaScript), then use additional class helpers if you feel comfortable writing them yourself and then maybe use something extensive like CoffeeScript if you really think you need it.

Try http://gamejs.org (my lib :))or something even simpler like https://github.com/batiste/sprite.js


Title: Re: From C++ to Python?
Post by: increpare on December 30, 2010, 06:54:23 AM
But be careful with CoffeeScript - I would recommend against using it too early. It is high level and will hide problems you will run into nonetheless later on.
Like what?  (Surely hiding problems is the duty of any high level language ;) ). 


Title: Re: From C++ to Python?
Post by: Feral_P on December 30, 2010, 06:54:46 AM
I decided to use Python/Pygame. I also got Py2exe and I managed to make a 'hello world!' exe, so that part doesn't seem like too much of a problem.

Thanks for all the advice :)


Title: Re: From C++ to Python?
Post by: simono on December 30, 2010, 07:23:33 AM
But be careful with CoffeeScript - I would recommend against using it too early. It is high level and will hide problems you will run into nonetheless later on.
Like what?  (Surely hiding problems is the duty of any high level language ;) ).  

I was thinking of JS scoping, especially closures. Function scope is a pitfall for newcomers and CoffeeScript or MooTools change the way that works. they don't really change it, but they make it *look* like classical, object-oriented programming.

I shouldn't have said "hide problems" more like "change problems" ;)


Title: Re: From C++ to Python?
Post by: simono on December 30, 2010, 07:24:19 AM
I decided to use Python/Pygame. I also got Py2exe and I managed to make a 'hello world!' exe, so that part doesn't seem like too much of a problem.

Thanks for all the advice :)

Congrats! Python/pygame is also a good combo :)


Title: Re: From C++ to Python?
Post by: eclectocrat on December 30, 2010, 07:50:26 AM
JavaScript JITs blow Lua out of the water ...

Really? Since when? I haven't checked for a year or so, but LuaJIT was on the top of the heap not long ago, and by a good margin.


Title: Re: From C++ to Python?
Post by: simono on December 30, 2010, 08:10:12 AM
JavaScript JITs blow Lua out of the water ...

Really? Since when? I haven't checked for a year or so, but LuaJIT was on the top of the heap not long ago, and by a good margin.


Uh... I'm a JS fan. But it depends on the JS interpreter. V8 is super fast. Rhino is Java (so great JIT but terrible startup time). Spidermonkey / Tracemonkey somewhere in between.


Title: Re: From C++ to Python?
Post by: st33d on December 30, 2010, 08:27:19 AM
I'd second the Lua suggestion.

It seems like a good addition to your C++.

The Eufloria guys reckoned it made developing their game a lot more pleasant and it's used in the industry (an employable skill).

If you just want to make sketch games, then AS3 is good for rapid prototyping, but there's quite a lot of gotchas on the way (most of them from ECMAScript, which bestows terrible god-like powers upon n00bs).