Hacker News new | ask | show | jobs
by benrutter 299 days ago
I'm a python developer, and a big fan of the features with gradual typing etc. This article really highlights for me though, how python has very much changed from the language it was even 5 years ago.

Initially, the celebrated feature of python was that it allowed easy and fast development for newcomers. There was a joke a long the lines, "I learned python, it was a great weekend".

As much as I like python's type system (and wouldn't want to see them ever go way!), part of me wonders if moving into a world where hello-world can look like this, is a world where python is no longer the "lean in a weekend" language:

     from typing import Annotated
     import typer
     
     app = typer.Typer()
     
     @app.command()
     def main(
          name: Annotated[str, typer.Option("--name", "-n")],
     ) -> None:
         """Prints out 'HELLO {name}!!' (name upper cased) to the console"""
         print(f"HELLO {name:upper}!!")
     
     if __name__ == "__name__":
         app()
(obviously the example is silly, and I know this is a lot more than you need to do, hopefully you get my point though!)
5 comments

> python is no longer the "learn in a weekend" language

For the last 10 years, Python's evolution has been directed by professional developers working for large software companies, and they've focused on adding features that help them work on million-line Python codebases.

Even if the language was originally intended to be easy to learn and ideal for small programs, that's clearly not a design goal any more.

Is there a language today that’s as easy to understand as the “executable pseudocode” of Python 2.x? I haven’t found one.

Agree but fortunately Python's types are entirely optional!

I'm very familiar with pyright and still I start most of my new projects without types and start sprinkling them in once I have a good base working already. This works so well that every time I pick up a static language I just get turned off by the friction of mandatory types and go back to Python. The only exception is Typescript where I can just Any everything temporarily as well.

All due respect but Typer looks like the kind of library that you want to use after your CLI has enough args that you wouldn't be able to get away with the sort of "Hello World" simplicity that you pine for.

Nobody's stopping you from manually parsing a couple of arguments. I still do it all the time and it's OK. If anything the magic of gradual typing is that you get to use it as necessity arises.

I think your completely fair in pointing out that only a deeply troubled person would write this up as a generic version of "hello world", it's a silly example and I was at least partly going OTT for comic effect.

That said, I think it's true that production python tends to look more like my example, and less `print("hello world")`.

Typer is very convenient. I don't believe anyone manually parses arguments manually in Python where we have argparse in the standard library, and Typer is a step forward from that.
I really want to like typer, and frequently go down the rabbit hole of rewriting all my argparse into typer, but I keep getting put off by it's high import cost and that development seems to be a bit up in the air (see https://github.com/fastapi/typer/issues/678#issuecomment-319...). A shame because otherwise it's a really nice library!
Personally, I would absolutely not mind it if Python made type annotations required.
I use pyright with typeCheckingMode: strict and enforce that via checks in CI. You still have the Any/type: ignore escape hatches when necessary. I haven't written fully dynamic Python in years.
You're going to love the equivalent Haskell example.
You can't leave me hanging and not give it!