1. 13
  1.  

  2. 5

    I find Mypyc to be the single most interesting project in the py-* space.

    I used to love Ruby. I still kinda do, but it’s dwindled. I like that it kinda flows with my thoughts, I like how blocks kinda serve as those units of “oh, and it also needs to do THIS” that I can toss around freely. I’ve written some TERRIBLE ruby, where I’ll have 30-40+ methods chained on File.read, and that’s how I’d process some file. I didn’t think it was terrible at the time, because the job got done. Certainly, that’s preferable to it not getting done at all, but all the same there’s a lesson to be learned.

    Typing. I think the first experience I had with a statically typed language was Scala. I could still do my regular-ol’ “chain until satisfied” approach just like I did in Ruby, with the addition of type safety. I really began to understand some of the benefits when I was changing over some complicated Ruby classes into Scala code, and I’d bang against the guard rails in a much more effective way than with ruby.

    some_object.tap{|o| puts "issue_with_index??? --> #{o} " }
    

    I’ll be honest, I solved almost all my bugs for a long time with some variation of Object#tap.

    Something clicked in my head and I began to understand the benefits of using types to restrict the domain I was in, to try and model the problem not just with my mind, but by the very language constructs I was supposed to be using in the first place!

    Types are such a rich tool for novices or hobbyists like myself, because it forces me to expand my way of thinking. I swear, 90% or more of the 10s of thousands of lines of ruby I’ve written is mostly just cruel abuse of blocks, Enumerable, and some basic understanding of how Ruby does File I/O under the hood.

    All this to say, I’ve been picking up Python lately and I have a little watch script that runs Mypy and checks all my type annotations, runs my build, etc etc. It’s so refreshing to be working dynamically, knowing that when I do get stuck, I can dig into those little dir hidey-holes, and then once I’ve uncovered my way through the tunnel into the light, I have mypy to check my types and make sure everything is up to snuff. Mypyc is such a cool idea because it is doing the maximal thing with having all that type information by feeding it all into a compiler and generating native code. For processing scripts and hopefully some SciPy stuff too, I can see Mypyc bringing Python back into more stable footing in that arena. I’ve had my eyes on Julia since I dug through Jeff’s Femtolisp code, and while it’s a very cool language and a very sensible approach to the structure of technical programs, I don’t think the ease of use is there to really say “Julia is a general-purpose language” without it being tongue in cheek. Multiple dispatch is wonderful for interactive development, but otherwise imo, it’s more cognitively demanding than reading a good ol’ Python class with good SOLID ergonomics. A class does a thing, here’s what it does, here’s what it needs, here’s how to call it, and it’s just that simple. I think Julia should’ve gone with traits.

    Anyhow, this is Python’s chance to say “Hey, we have types, we have a way to generate native code with a typesafe front end, we can compete on some level via performance in a technical computing domain.”

    1. 2

      My dream is that tools like mypy and TypeScript will eventually have ways of communicating type information back to their interpreters, and give our dynamically-typed languages performance boosts. This feels like a great first step in that direction!

      1. 1

        Note that such dream is already achieved in Dart.

        1. 1

          The point isn’t for new languages; it’s to bring performance enhancements to existing dynamically-typed languages.

      2. 1

        This weekend, I was thinking about how it would be possible to compile Python code to a Python C extension and I stumbled upon Mypyc which seems very promising.

        Even if the project is its early stage, it seems quite active:

        Have you ever toyed with Mypyc ? What do you think about it ?

        1. 1

          I haven’t toyed with Mypyc, though I’ve been meaning to.

          If you’re looking to compile Python to extension modules, take a look at Cython - a fairly mature transpiler that does exactly that.

          1. 1

            The downside of Cython is that it came before MyPy so it’s type annotations are more C-like. I’d love to see these projects converge, with a MyPy front end on the Cython compiler.

            1. 1

              Have you seen https://github.com/cython/cython/issues/1672.

              They’ve added some support for the PEP-484 style annotations.