Hacker News new | ask | show | jobs
by LudwigNagasena 1246 days ago
> 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".

2 comments

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]):