In the year 2014, this is crazy talk. Python doesn't even need to be object oriented, if you... (•_•) ( •_•)>⌐■-■ (⌐■_■) object to that.
It depends. If you want to write a GUI program or directly access the Windows API, C is probably easier than Python (yes, Python has GUI libraries and some access to the Windows API, but it doesn't offer the entire API).
No, I am not writing heavily concurrent programs for home use.
Also, I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
I know I said I use C and not C++ but on further reflection I use C++ because that it was what my compiler and the windows API requires. I use about 5% of what C++ adds to C and I only the C++ conventions that are required to make the code compile (declaring functions ahead of time for example).
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Why did I write this? Online RPG gaming. When did I write this? 1999 or so.
This allowed me to DM games over the internet with a log of all dice rolls to check for cheating.
No, I am not writing heavily concurrent programs for home use.
Also, I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
I know I said I use C and not C++ but on further reflection I use C++ because that it was what my compiler and the windows API requires. I use about 5% of what C++ adds to C and I only the C++ conventions that are required to make the code compile (declaring functions ahead of time for example).
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Why did I write this? Online RPG gaming. When did I write this? 1999 or so.
This allowed me to DM games over the internet with a log of all dice rolls to check for cheating.
I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Why did I write this? Online RPG gaming. When did I write this? 1999 or so.
This allowed me to DM games over the internet with a log of all dice rolls to check for cheating.
Well, if it works for you, can't argue too much with it. But! Modern languages have a lot of nice features.
For starters (and these aren't limited to python by the way), automatic memory management. No pointer arithmetic. Built-in randomization libraries. Built-in list types. Write to a file? f = open('file.txt', 'w') f.write('stuff') f.close()
This is a big one: Pypi. That's python only, but there are analogs for other languages too. Need a server? `pip install flask`. Now you don't have to write Frankenstein multithreaded dice rolling server, you just need to write dice rolling function. Much easier to write, debug, deploy, and maintain.
It depends. If you want to write a GUI program [...] C is probably easier than Python
Doubt it, man. Automatic memory management alone buys you so much!
Yeah, but Python doesn't ship with GUI libraries out of the box. Of course, this is mitigated somewhat if you're coding on Linux, in which case PyGTK and PyQt are both available in most mainstream distributions' repositories.
However, if you're doing GUI programs on Windows, you may as well use C# and get the best of both good GUI APIs and tooling and automatic memory management.
I'm going to hazard a guess that Steve isn't writing exclusively heavily-concurrent applications. Probably true. :P Also, I should clarify that only CPython, which is the canonical Python implementation, sucks for multithreaded code. If you use IronPython (AKA Python on .NET) or Jython (Python on the Java VM), they actually do manage to get threading working right. Python's threading issues are inherent to the implementation and not the language itself.
Also, I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
It's all about saving development time for smaller apps that don't need C's performance or low-level access.
I first learned Python about 10 years ago when I had to write a new build system for my company's product. This system had to remote log in to half a dozen different flavors of Unix, run 'make' on them, and then run whatever packaging tools to create a native installer for each flavor (RPMs for Linux, whatever Sun's package format was for Solaris, similar for AIX, etc.). I already knew C and C++ at the time, but the amount of time it took me to learn Python (which, frankly, is one of the easiest languages out there to learn) and implement the build system was far less than it would've taken me to do the same thing in C. This goes back to my earlier post about Python being a really good "Swiss Army Knife" scripting language.
Python also offers a lot that C doesn't, such as automatically memory management (no more worries about pairing malloc() and free(), or keeping track which obscure functions require you to free data returned from them, etc.) and superior string handling. Oh, and no need to wait for the whole compile/link/execute cycle to complete every time you modify the code.
I know I said I use C and not C++ but on further reflection I use C++ because that it was what my compiler and the windows API requires. I use about 5% of what C++ adds to C and I only the C++ conventions that are required to make the code compile (declaring functions ahead of time for example).
That doesn't quite count as C++, given how pre-declaration is also valid C (even if it's not required -- it's still a freaking good idea to do so). If you at least used classes or a few of the features of the C++ standard library (containers, the string class, etc.), then you'd be talking using a bit of C++.
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Ignoring the threading issues (and it probably wouldn't matter too much for this particular app), this is probably a perfect example of a time where you probably would want to use Python (or a similar language) instead of C. It's not a high-performance app, doesn't even seem to use a GUI, etc.
Now, if you already had some C code lying around that did most of this work, as you apparently did, then you probably wouldn't have bought much by doing it in another language. If you had to do it from scratch though, well, automatic memory management, not having to deal with C's annoying as hell string processing routines, no fear of buffer overruns, etc., all make it worth it.
That said, I did come across a scenario here at work a while back where I had to write a tool to cleanup some tables in a database. My first thought was to write it in Python (I had just written a bunch of testing scripts in Python, so it was on my brain), but then a co-worker mentioned that we already had C++ libraries used by our main product that did a lot of the database crap for me automatically. Instead of re-inventing the wheel in Python, I wrote the tool in C++ and that saved a ton of time, similar to what you did with your dice app. This shows that, as with many things, YMMV.
I did mess around with wxwidgets at one point because I wanted a java like write once environment but I didn't explore it too far.
The dice app did use a GUI client with a few boxes to enter dice sides, modifiers, player id and a memo. The server side just spit everything into a text file that I loaded up in a web browser with a refresh every five seconds. Other than that nothing I write requires multi threading and the only reason that one did is because it was already in place due to it being based on a file server.
Comments
(•_•)
( •_•)>⌐■-■
(⌐■_■)
object to that.
Also, Python sucks for multithreaded code.
Also, I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
I know I said I use C and not C++ but on further reflection I use C++ because that it was what my compiler and the windows API requires. I use about 5% of what C++ adds to C and I only the C++ conventions that are required to make the code compile (declaring functions ahead of time for example).
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Why did I write this? Online RPG gaming. When did I write this? 1999 or so.
This allowed me to DM games over the internet with a log of all dice rolls to check for cheating.
Also, I already know C, how much benefit would I receive from taking the time to learn python? Is there anything that python can do for me that C can not?
I know I said I use C and not C++ but on further reflection I use C++ because that it was what my compiler and the windows API requires. I use about 5% of what C++ adds to C and I only the C++ conventions that are required to make the code compile (declaring functions ahead of time for example).
An example program I wrote was a multi threaded server for rolling dice. Because it was for my personal use I cobbled it together using source code designed for a basic file server and modified it to roll dice rather than serve files. I also wrote a small client app that would connect to it. The server also appended all dice results to a text file.
Why did I write this? Online RPG gaming. When did I write this? 1999 or so.
This allowed me to DM games over the internet with a log of all dice rolls to check for cheating.
For starters (and these aren't limited to python by the way), automatic memory management. No pointer arithmetic. Built-in randomization libraries. Built-in list types. Write to a file?
f = open('file.txt', 'w')
f.write('stuff')
f.close()
This is a big one: Pypi. That's python only, but there are analogs for other languages too. Need a server? `pip install flask`. Now you don't have to write Frankenstein multithreaded dice rolling server, you just need to write dice rolling function. Much easier to write, debug, deploy, and maintain.
However, if you're doing GUI programs on Windows, you may as well use C# and get the best of both good GUI APIs and tooling and automatic memory management. Yeah maybe, but I'm going to hazard a guess that Steve isn't writing exclusively heavily-concurrent applications.
Probably true. :P Also, I should clarify that only CPython, which is the canonical Python implementation, sucks for multithreaded code. If you use IronPython (AKA Python on .NET) or Jython (Python on the Java VM), they actually do manage to get threading working right. Python's threading issues are inherent to the implementation and not the language itself. Umm, but later you mention one multithreaded server (although this probably wouldn't matter that much even with Python's iffy threading). It's all about saving development time for smaller apps that don't need C's performance or low-level access.
I first learned Python about 10 years ago when I had to write a new build system for my company's product. This system had to remote log in to half a dozen different flavors of Unix, run 'make' on them, and then run whatever packaging tools to create a native installer for each flavor (RPMs for Linux, whatever Sun's package format was for Solaris, similar for AIX, etc.). I already knew C and C++ at the time, but the amount of time it took me to learn Python (which, frankly, is one of the easiest languages out there to learn) and implement the build system was far less than it would've taken me to do the same thing in C. This goes back to my earlier post about Python being a really good "Swiss Army Knife" scripting language.
Python also offers a lot that C doesn't, such as automatically memory management (no more worries about pairing malloc() and free(), or keeping track which obscure functions require you to free data returned from them, etc.) and superior string handling. Oh, and no need to wait for the whole compile/link/execute cycle to complete every time you modify the code. That doesn't quite count as C++, given how pre-declaration is also valid C (even if it's not required -- it's still a freaking good idea to do so). If you at least used classes or a few of the features of the C++ standard library (containers, the string class, etc.), then you'd be talking using a bit of C++. Ignoring the threading issues (and it probably wouldn't matter too much for this particular app), this is probably a perfect example of a time where you probably would want to use Python (or a similar language) instead of C. It's not a high-performance app, doesn't even seem to use a GUI, etc.
Now, if you already had some C code lying around that did most of this work, as you apparently did, then you probably wouldn't have bought much by doing it in another language. If you had to do it from scratch though, well, automatic memory management, not having to deal with C's annoying as hell string processing routines, no fear of buffer overruns, etc., all make it worth it.
That said, I did come across a scenario here at work a while back where I had to write a tool to cleanup some tables in a database. My first thought was to write it in Python (I had just written a bunch of testing scripts in Python, so it was on my brain), but then a co-worker mentioned that we already had C++ libraries used by our main product that did a lot of the database crap for me automatically. Instead of re-inventing the wheel in Python, I wrote the tool in C++ and that saved a ton of time, similar to what you did with your dice app. This shows that, as with many things, YMMV.
The dice app did use a GUI client with a few boxes to enter dice sides, modifiers, player id and a memo. The server side just spit everything into a text file that I loaded up in a web browser with a refresh every five seconds. Other than that nothing I write requires multi threading and the only reason that one did is because it was already in place due to it being based on a file server.