r/learnpython • • Jun 28 '20

Can anyone explain why we use Python

I keep reading people say things like ‘because Python is built on C’ and ‘Python is much slower than C++ or Go’, ‘Thats why those languages are used to make most popular games’. I also see people refer to Python as a ‘machine’ language, etc etc. So... why use python then if you can do things faster with another language? And why is Python so popular if this is the case? Seems like python is easier to understand for me at least and much easier to read, but is there some other benefit I’m not understanding? Sorry if this had been asked before, I can’t find any direct comparison information between Python and other languages.

EDIT: Thanks everyone! I feel a much better understanding of why python is fast in a different way from other languages, saving programming time rather than computing time. Definitely got the answers I was looking for.

Another edit: Great insights all around. Thanks to everyone taking the time to answer! Looks like I need to do some more research on Cython as I see a few people mentioning it for when speed is required.

336 Upvotes

120 comments sorted by

View all comments

Show parent comments

15

u/[deleted] Jun 29 '20

Wondering if you might be able to share your feedback. I still don't understand the concept of building a web app with python. I know PHP quite well, I can put html right into a php file and run it right on the browser with dynamic variables OR use php to output json for a vue app.

Python can't seem to do either of these, it's straight up a command line/server language? How do you actually output html or web apps? People always talk about it being fast but it has no output that can be read by a browser?

17

u/oefd Jun 29 '20

I can put html right into a php file

PHP's behaviour outside of the tags html goes here<?php this_is_code(); ?>more html is effectively the same as

echo 'html goes here';
this_is_code();
echo 'more html';

PHP is unlike basically all other languages in that it has a 'magical' auto-printing mechanism outside of the <?php ; ?> tags, but that's just a difference in how it's written. It's the same behaviour as just printing output using php facilities like echo

In python your http framework like flask effectively just use print() and other facilities for writing output to write things to the socket which connects you to the client's browser. That's the same as what PHP does with your stuff outside of <?php ; ?> tags .

4

u/[deleted] Jun 29 '20

Right but it just seems so insanely easier. I guess I just need to understand python better but I see PHP much faster for rapid development. I've built apps that have generated a lot of money with just PHP/html, it just seems so clear to have your html right in front of you with loops and variables. Python I am assuming you have to print all of your html using a print statement and then concenate everything? Seems like it would be hard to read and write.

Although I am new, I am likely missing something. Just explaining why I have resisted Python so long. I was the same way with using jquery but once I learned VUE I was like "how did I live before this" lol

3

u/thblckjkr Jun 29 '20

Writing html inside php is easier at first. But, it doesn't scale well.

When you have a couple of forms with bootstrap and some MySQL database is ok'ish.

But when you need, let's say vue, and templates or something like that, it makes writing code extremely difficult,and maintaining it is really painful as well.

So, at the end you end up using some framework (Django, Laravel, Symphony, etc) that abstracts most of the code and you end up writing basically the same code in every language, with some just tweaks to take full potential of what a specific language offers.