Hacker News new | ask | show | jobs
by juanbyrge 1246 days ago
Python is great for small scripts or explorations. You can't use it for anything serious that needs to scale due to the lack of concurrency and significant memory overhead. If you need something to scale you use something like C++, Java, Go, Rust, etc.
3 comments

Yet it's good enough to scale Pinterest, Instagram, and Youtube.
>You can't use it for anything serious that needs to scale due to the lack of concurrency and significant memory overhead.

Please actually think about what you are saying instead of just parroting off stuff you read on blogs.

Python has concurrency. Its called multiprocessing. Of course, there is startup overhead, but it achieves the same functionality. Furthermore, processes that are most commonly threaded (like fanning out network requests) are well suited to async, which has less overhead than threads.

Also, memory considerations are relevant only for embedded systems, for which you would never use Python. Memory is dirt cheap these days.

> Python is great for small scripts or explorations.

I've used Python on program with >30000 LOC without any problems.

Typically large code bases have problems that are more intrinsic to organization than what language its in. Huge code cases in any language are usually fine if discipline is exercised.

And concurrency issues and memory overhead problem are from not knowing the right way to do it. Although I will concede that naive approach to both of those is sub-optimal.

> Although I will concede that naive approach to both of those is sub-optimal.

Paradoxically, this can actually lead to a better understanding of how to write performant code. When I first learned some of the be implementation details of python, I couldn't believe it was performant enough to work for anything ... after optimizing enough of it, I understand better what actually matters

Also people seem to forget the rule of premature optimization. Worry about performance when performance starts to be a problem. You identify the area with performance is lacking and optimize that. Compute is cheap, manpower is expensive.
Do you really have no problems? I find the lack of proper type support and proper variable scoping to be a huge issue.
Python has types now (though it didn't when I wrote the 36kLOC program I had in mind).

What problems are there with python variable scoping -- you can have global and local variables, shouldn't that be enough?

> though it didn't when I wrote the 36kLOC program I had in mind).

Yeah, that was my assumption. Still, typing in Python feels very clunky compared to TypeScript. And even though it is much better after 3.8 and 3.9 updates, the adoption of typing in various useful libraries was relatively low as far as I remember.

> What problems are there with python variable scoping -- you can have global and local variables, shouldn't that be enough?

Maybe it is just me, but the scoping rules feel weird: blocks like "with"-statement or for-loops don't create scopes. There is no distinction between declaration and assignment. Sometimes you have to use those weird "nonlocal" and "global".

The scoping is bad, they should have copied Perl's "every block is a new scope" and added an explicit "let" keyword to define variables instead of overloading assignment. The "nonlocal" and "global" and stuff like "lambda x=x" is a big giveaway that their approach was wrong, but I guess it was too late to change it.

The typing has been great in my experience. Most of my deps have types and if they don't I can autogenerate them. The powerful typing of TypeScript is mostly not needed if you're not interacting with JS code.

> Yeah, that was my assumption. Still, typing in Python feels very clunky compared to TypeScript.

I used comments in the code to say what the types were, e.g.:

    def processNotesForm(d):
        """ process the notes form
        @param d::{str:str} = the form data
        """
Of course in modern Python one would simply say:

    def processNotesForm(d: Dict[str,str]):
Lack of typing support is a major advantage. If you don't have types you don't need interfaces, generics, etc. The resulting code is shorter and less bug prone.
You still need all of that. You just have to store that information in documentation and do analysis in your head instead of relying on a static analyzer.
No, you really don't. Static typing is very complex and error prone compared to dynamic typing.

There is a lot less stuff that needs remembering.

Languages like Python and TypeScript support 'any' as a type, so you can always opt out of strong typing if you want. Most of the time generics are preferable to things randomly dying at runtime though.
Things don't die very often due to typing issues. The unit tests always pick up typing problems.

Testing the code's behavior implies testing the code's typing. And if you are not testing the code's behavior then the code isn't really tested at all.

Does your code check every single variable is not null before using it? That every function argument is of the expected type? That every attribute exists before it is accessed? And do you have unit tests for all of this too?

If so - then you're writing a whole lot of manual checking that a strongly typed language would perform for you, at compile time. If not - well then you're doing less testing than a strongly typed language would.

I agree that these issues are rare, and there is evidence that strongly typed languages have a similar number of bugs to dynamic ones. But suggesting that because you have unit tests, you don't need strong types, is a bit naive to me.