5 ms·
Python has one giant plus over pretty much every other popular language: The syntax I was reluctant to to meaningful whitespace for a long time. But after
by TekMol 5y ago
Python has one giant plus over pretty much every other popular language:
The syntax
I was reluctant to to meaningful whitespace for a long time. But after doing some projects in Python I have to admit the code looks so much better than C style languages with all the {, } and ;s
And it has one giant plus over PHP:
The module system
PHP went down the wrong road (of insanity) by deciding that the way to avoid naming conflicts is to use longer classnames. Because that is what namespaces in PHP are. Comfort tools to make your class names longer.
There is still one giant benefit of PHP over Python:
Performance
Currently, PHP is about 6x faster than Python.
Let's hope that the Python devs will focus on performance so we get the best of all worlds at one point!
- Bostonian 5y agoYou can avoid curly braces and semicolons and also not have indentation determine the control flow. Julia, Fortran, Visual Basic, and other languages do this.
- TekMol 5y agoNone of these 3 is in the top 10. Personally, I would only consider languages very close in popularity to the leading one when deciding on the language for a new project.
- Bostonian 5y agoVisual Basic and Classic Visual Basic are in spots 6 and 11. I am not against Python's use of indentation, but I don't think it's better than having keywords such as endif or next terminate blocks.
- TekMol 5y agoWow, you are right. Still, I don't think I would choose Visual Basic to build the next big thing though :)
- Zababa 5y agoYes, and they use keywords, wich is basically another flavor of curly braces.
- IshKebab 5y agoI don't know, I think the syntax is ok but it definitely has significant downsides, like making lambda functions stupidly hard. Python's competition isn't PHP; it's Typescript.
- slightwinder 5y agoWhy do people care about so much lambda? If you want a function, use a real one. Python makes it easy to create throwaways everywhere. The only thing it enforces is proper indentation. What advantage should a lambda give you?
- IshKebab 5y agoIt lets you do functional style programming easily. This sort of thing: [1, 2, 3, 4].map(x => x * x).filter(x => x < 10) Python's lambdas and list comprehensions are quite restrictive in comparison to functional style.
- TekMol 5y agoI think this would be the Python equivalent: x = [1, 2, 3, 4] x = map(lambda x: x*x, x) x = filter(lambda x: x < 10, x) x = list(x) Or is there a more elegant way?
- slightwinder 5y agoYou can write this as a oneliner too. But the problem here is not lambda, but the lack of map/filter-methods on list. Disputable whether this is good or bad.
- kangalioo 5y agoThis, maybe ```py x = [xx for x in [1, 2, 3, 4] if xx < 10] ```
- williamstein 5y ago
- zerocrates 5y agoHmm, PHP developers were already making long class names prior to namespaces existing, for example the "PSR-0" underscore-delimited naming convention. The namespace feature is more of a comfort tool to make those long names shorter.
- CodeGlitch 5y agoThe only negative is that type annotations aren't part of the core language. You have to run a separate tool (mypy) to check your types. Feels like it should be a flag on CPython or something.
- Alex3917 5y ago> Currently, PHP is about 6x faster than Python. In a 100KLOC codebase, 99% of the performance issues are going to come down to 5 or 10 lines of code. Don't get me wrong, I'm extremely happy that MS is funding a multi-year project to improve Python performance, and I think it will confer enormous benefits to the ecosystem. And frankly I think that it's absolutely needed. But for me it would also be weird to choose languages based on some notion of average performance. Like sure, a line of Go might be faster than a line of Python on average, but if the entire bottleneck of your codebase revolves around one line of regex then what is doing a rewrite actually going to accomplish?
- TekMol 5y agoI don't think that holds true. 80/20 rule? Probably. Then 80% of CPU time is spent in 20K lines of code. But 1%? I don't think so. A web project of 100KLOC will be a shit ton of features and CPU time will be spent in hundreds of different places. Another issue is what I would call "code depth". Even if you find a few lines deep down in a framework or library that makes your specific use case slow - what can you do? Patch the framework? That comes with a ton of issues on its own.