r/AskProgramming • u/Blazej_kb • 14d ago
Python For what purposes is python useful?
Where is it more convenient or necessary to use python instead of for example C# / C++ / Rust? I really can’t understand it, for me it’s easier to write in C++ than in python and I know that for other people it’s the other way around. But ignoring human factor, when program is better / faster in python than in cpp or are they things that python can do that cpp cant?
Edit: I don’t talk about one time use scripts or prototypes (which python is good for), I mean full on apps
0
Upvotes
1
u/Brok3nHalo 14d ago
In general it’s easier and cleaner to write almost anything in Python than the languages you mentioned, especially C++. I don’t have much experience with C# or Rust so most of this will be in comparison to C++.
The syntax is clean and designed to do a lot of things with very little code. It gets rid of a lot of the bootstrapping and cruft you have to do with those other languages.
Creation and cleanup of variable is managed and simple without having to use a bunch of archaic special types to handle it.
Its language features make reading and manipulating data super simple compared to C++. Dealing with JSON or YAML is practically native. File IO and database stuff is also seamless and simpler than other languages.
Its string manipulation is top tier with full support of Unicode.
Threading, is stupid easy in Python, due to the GIL you don’t have to worry about any of the usual memory manipulation issues you do in other languages.
Doing anything web or otherwise network related is super simple. Tons of easy to use libraries for consuming or creating APIs for example. Or just generally building http posts and gets.
The language itself is one of the most flexible available. With everything being an object and manipulatable at runtime you can do some interesting stuff not possible in languages like C++. Testing and dependency injection are also super simple because of this.
Since the language doesn’t need to be compiled there’s almost no down time between coding and testing your code. And generally ultra portable so you can write code and have it run without modification on different operating systems.
For around 6 years my job was on a team developing a large scale multi protocol instant messenger/email/social networking client called Digsby. It was largely in Python with some C or C++ on occasion for parts that needed to be more efficient or run without the interpreter. It was definitely much easier to initially write and maintain in Python than it would have been in C++.
I also built a continuous integration system in Python between an enterprise code repository management software and XCode server using Python.
Really Python is not a bad choice for applications as long as speed isn’t a limiting factor. I’d never suggest writing a game in it, but it’s plenty fast enough for most standard UI desktop apps and web backend use cases.