I\'m currenetly struggling with choosing how to proceed as a programmer. I mainl
ID: 654625 • Letter: I
Question
I'm currenetly struggling with choosing how to proceed as a programmer. I mainly programmed games and would like to continue. And for about 5 years or so I just used C++ and OpenGL, so I spent a lot of time on infrastructure, strange bugs, and mostly getting basic things to work.
A friend of mine then recommended python and after initially being aversed by it being not as explicit and formal as I was used to I was shocked by how much more productive I could be and how much progress I could actually make in a very small amount of time.
So currently I'm working on a multiplayer-shooter and repeatedly I find myself struggling with python being not as fast I might want it to be. I know that that I have to approach writing efficient code in python very differently now, but even with a little help from friends that are more experienced with python there is just too much going on sometimes (and extrapolating this, I know that I will end up stuck).
There are a lot of things I really like about my "home-language" C++, but after knowing how many hours I could be wasting I don't really want to go back.
What language can you recommend which offers high-productivy, is memory-safe (I really hated this) and as high-performance as I can get, but is still mature enough to be used for kind of serious projects (games-related) and maybe even mature enough to have people already having spent some time on OpenGL-Bindings or various libraries for Sound and similar (alternatively easy access to shared libraries written in C). Easy cross-plattform is a big plus! So no .NET please. Is this even possible?
Explanation / Answer
I would say stick with Python and use some of the advanced features it provides. Specifically I am talking about the extensions. If you look at how things work today there are some very fast things in Python and those things are all done in C/C++ as extensions.
You can create C/C++ extensions to speed up the slow parts of Python. Additionally a good intermediary position would be to use Cython to get some decent speedups.
Cython This provides a way to tweak Python code to make it run faster. The basic idea here is to realize that one of the very slowest things in Python is typing as well as one of the most powerful. Cython gives you the ability to specify the typing of variables in order to speed things up. Here is a great example: Cython Example
Extensions The next step if Cython doesn't speed things up enough is to create a straight C/C++ extension. What this means is that you can create a custom function that will greatly speed things up. Look for the most CPU intensive parts and implement them in C++ while keeping the other abilities of Python.
My Personal Experience I created this IO tool to test asynchronous IO in Python that was very powerful. It could do all sorts of things including data integrity checks. This meant that I could write data out and then later verify it. My problem was that Python allowed me to very quickly create this program but because of Python the data integrity section was very slow. It was so slow that it would consume all of the CPU and bring the system to a crawl. In order to solve this and make the program usable I thought about recreating the program in C++. My problem was that every time I looked at what I would need to do the problem looked staggering and not worth the effort. After some time I looked around and found Cython. It was a good intermediary solution. I implemented the slow Python code in Cython and found that I got some large performance improvements. After a while I still ran into the problem where things were slow so I created a C extension. This extension then allowed me to realize my dream.
PyPy I have heard, although never tried, that PyPy is a much faster implementation of Python which might give you the performance you desire while still using Python.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.