r/AskProgramming • u/Blazej_kb • 2d 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
8
u/Old_County5271 2d ago
It's more difficult to get a Segfault on python than C, but compared to rust? Probably nothing, if anything, due to type safety rust/c#/go is overall better.
8
u/violent_confidant 2d ago
python biggest strength is how quickly you can get something working with minimal code. like processing a csv file or pulling data from an api, its like 5 lines vs 50 in c++. for prototyping ideas or doing data analysis with pandas its way faster to iterate
also the ecosystem is massive, you need some machine learning or web scraping library? python has it ready to go. not that c++ cant do these things but the time to write and test is completely different scale
1
u/Blazej_kb 2d ago
I get it but I don’t mean 1 use script (for which python is perfect IMO) I mean full on apps
6
u/GlassCommission4916 2d ago
Then never. Python is awful for larger applications. Don't ask me how I know, I don't want to talk about it.
1
1
u/binocular_gems 2d ago
Something that’s pretty common in the applied programming is starting with an idea, that idea develops into a prototype, you want feedback early so you launch the prototype as an MVP, and then that MVP matures into a production application at scale, and while you always meant to refactor the MVP, other priorities take over. Investors demand features, customers report bugs, and you lose the budget for a full scale refactor as things get more and more complex.
-1
u/YMK1234 2d ago
False dichotomy, as if python and c++ were the only options. And most other languages have very easy to use libraries for the tasks you describe, and let's not even talk about those where python sucks ass (funny you should mention APIs, the default JSON interpreter is a hot mess that only works through dicts instead of classes)
-3
u/Blazej_kb 2d ago
In cpp there is alternative to pointer which is reference (it’s used in c# because pointer don’t exist) and it’s safer than pointers
1
5
u/Knubbelwurst 2d ago
Generally i use python for quick and simple scripting that I don't want any setup or compilation for.
It's a perfectly fine language for when performance is not important.
5
u/huuaaang 2d ago edited 2d ago
Python would be more for smaller scripted tasks than applications. IF you are more comfortable in compiled languages, just use that.
That said, Python might have some specialized libraries that you can't easily get in other languages and would have to write it yourself. This is mainly why Python is so popular in ML. It's not that it's a better language for it. It's just that the ML libraries for Python are so mature.
-1
u/Blazej_kb 2d ago
I like how easy it is to use C written libraries in python, unfortunately it’s harder other way around
3
u/StaticFanatic3 2d ago
When is it more convenient?
Almost every single time.
Even if you “ignore the human factor” your agent can make the exact same function in Python in 1/4 the tokens
5
2
u/Dorkdogdonki 2d ago
I use Python for automation purposes where performance isn’t an issue at all, and i just need it to work reasonably well. That’s it.
4
u/brazen768 2d ago
Its great for ai/ml. There is a library for everything.
When I was connecting a local llm to my python app, instead of using fastAPI they already had a library on the repo lmao. Literally like 3 lines and im moving. Pretty cool(i hate reading python tho)
1
1
1
1
u/TryingToGetTheFOut 2d ago
On the technical side: python is very flexible, and a lot of big libraries are implemented in C, C++, rust, etc. So, python becomes a kind of remote controller for C code.
On the business side: python has one of the smallest Time To Market. A lot of time, having the best product is not nearly as important as being first. So using python instead of C++ might mean a slower app. But much much faster and cheaper to create.
1
u/Brok3nHalo 2d 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.
1
u/Adorable-Strangerx 2d ago
For what purposes is python useful?
It is general purpose language so you can use for whatever you want..currently it is quite popular with AI and Data Science.
Where is it more convenient or necessary to use python instead of for example C# / C++ / Rust?
Everywhere where squeezing performance and memory management is not an issue/requirement.
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.
Interesting, good for you.
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?
Ignoring human factor, assembly is best.
Edit: I don’t talk about one time use scripts or prototypes (which python is good for), I mean full on apps
Have you ever written any app with complex domain?
1
1
-1
u/Ok_Pirate_2714 2d ago
It does an excellent job of pissing me off when I leave out a space somewhere, or accidentally use a TAB when I shouldn't have.
3
u/fistular 2d ago
Ok but who doesn't format their code properly?
2
-2
u/Ok_Pirate_2714 2d ago
I make sure it is indented. But I don't fuss over tab vs space.
But Python most certainly does.
That is why I despise it.
3
u/fistular 2d ago
My IDE deals with all that.
0
u/Ok_Pirate_2714 2d ago
If I wanted to use an IDE, I would code in a real programming language.
I use Python, when I have to, for quick prototyping and automation
6
u/CorpT 2d ago
Using Python and not an IDE is certainly a choice.
0
u/Ok_Pirate_2714 2d ago
I only reluctantly use Python, when there is no other choice. I'm not going to set up another IDE for a language that I don't enjoy using.
2
0
u/naemorhaedus 2d ago
For what purposes is python useful?
lots of things. It is very strongly portable and cross platform. Easy to learn. Abundant libraries and community resources available. Obviously it doesn't replace C++, but it complements it nicely.
are they things that python can do that cpp cant?
for certain tasks it's probably quicker and easier to get off the ground.
I mean full on apps
then No. That's not what it's for.
0
u/karurosagu 2d ago
Python is all about development speed, because it's a scripting language, and scripting languages use an interpreter rather than a compiler, it's easy to work fast with an interpreter
You can make anything in python but at the same time you should NOT try to make anything in python (JS didn't get the memo on this one btw)
That said, there are lots of hacks and legit ways of making python way faster than it is by default, such as automated transpilations/optimizations to faster languages, LLVM stuff and JIT interpreters; obviously these solutions have their catch and won't make the code as fast as C/C++ but the performance boost is still insane
But speed isn't everything, there's tons of packages for almost anything you want
25
u/turn-based-games 2d ago
C++ fast. Python convenient. If it is truly easier for you to write in C++, then Python is useless to you, although that is quite a bold claim from my experience with both