At this point I'm open to try anything that will give me access to the python ecosystem without having to code in Python.
From the FAQ it looks like Erg code gets transpiled to python bytecode.
Oh, man, have I got a treat for you: go checkout hylang.org -
Hy is a lisp that (ab)uses the python AST to give you access to the entirety of python, but gives you a pretty lisp syntax.
I've always been super interested in Hy but couldn't ever get it working. Any suggestions for forums or good installation instructions or tutorials? I live Clojure and also have to deal with a lot of Python at work so would be awesome to use lispy syntax to write my Python stuff
Slightly related question: why do people love Python so much? Or, any dynamically typed language? There's almost nothing that has frustrated me more in a professional setting than trying to figure out what some dynamically typed code is doing and ensuring I don't break anything by making changes.
I don't see how it can though - at least it can't do it in a statically typed way because half of the Python ecosystem hasn't bothered with static types and the semantics of the type hints that do exist isn't defined.
So you'll end up with everything you import being `any` which is not really any better than just using Python.
Erg looks fun for small programs. Though Erg's syntax choices seem less Pythonic than I'd expected. Interesting though, some of the idioms seem handy.
Though Nim definitely can be described as a statically typed Python-compatible language! I haven't used them but https://github.com/Pebaz/nimporterhttps://github.com/yglukhov/nimpy both seem great. Nimporter in particular looks fantastic for writing fast python libraries.
Actually come to think of it that might be the easiest way to write fast KiCad 6 plugins.. I really want to try making a native KiCad autorouter. But I don't want to figure out the C++ plugin setup and since KiCad 6 the Python APIs seem better documented and supported anyways. Problem is that Python would likely be too slow. Nimporter could be perfect. It looks really simple to setup.
> I really want to try making a native KiCad autorouter. But I don't want to figure out the C++ plugin setup and since KiCad 6 the Python APIs seem better documented and supported anyways.
So I find this to be super interesting, particularly when it comes to parts with lots of pads that one has to route.
Python would let you iterate the algorithm quickly. It's far easier to optimize the big O notation of your autorouter than in C++, say. Once you're happy with the algorithm, then you can try to optimize the slow bits in C/C++. But even things like dicts in python are still going to be super fast.
As far as speed up goes, there's PyPy, Nuitka, and Cython, which are all interesting. There's also a restricted version of python called RPython which PyPy uses to compile everything to C.
If it's me in 2022, I'd probably go with Cython. A lot of packages uses it. It's well known, and it's (mostly) python -- mostly because it would be easier to go back and forth in python rather than switching mental contexts between Nim and C and Python.
This is what is putting me off the most of this, the syntax feels very unreadable for something that is meant for python, which has a very readable and open syntax, even typescript's sometimes messy typing is for the most part more readable than this
To provide some rationale, the '!' syntax distinguishes declarations from imperative constructs or effectful statements. You will see similar syntactic sugar in Haskell (do notation), F# (computation expressions), and probably others - they are often abstractions for specific monad-wrangling patterns, and won't look out of place for many in a more functional-style language.
It would be nice if someone created a typescript for python. Something that allows us to wrangle control and sanity over reams of legacy untyped python madness.
I think both `erg` and statically typed Python are both attempts at doing exactly that.
May be what you mean is a static typing solution for Python whose syntax is a superset of Python syntax (which I don't think `erg` is), but isn't identical to Python's syntax( ie, it is a strict superset, which statically typed Python's syntax isn't). Typescript is exactly that for JS.
In that case, I agree with you that such an attempt would indeed be very interesting because it would allow for more aggressive exploration of ergonomic typing constructs while maintaining that any valid Python would be valid in that new language as well (just like TS).
As others have mentioned, one can get some types in python through its own typing module and use a combination of tools for type enforcing and editor intellisense (mypy, pylance, etc.).
However what I’m missing is having more advanced type constructs. For example mapped types, lookup types, etc [1].
That said, it seems like python devs keep adding features over time. For example a couple of years ago it wasn’t possible to specify which fields of a dictionary are required and not required (it required putting required fields in one TypedDict and then subclassing it into another one that had the non required ones with total=False), nor it was possible to “spread” a TypedDict to declare the kwarg types in a function.
And while they're at it, can they unify the pip, egg, conda, miniconda, apt-get dependency management madness? If we're putting in requests for miracles, that's mine.
Also note that while this repo might look like a third party bolton (it started that way), the type hinting syntax is nowadays actually integrated in the language.
The only thing you need to do is add appropriate type hints at function definitions and then run mypy in your build and CI and you got something that checks basically as strict as Java.
For those saying it’s optional so can’t be trusted, consider that compiling C++ with -Wall -Werror is also optional… adding it is simply part of standard project hygiene.
This is exactly the sort of thing I've been looking for. Not sure how production-grade it is* but definitely gonna use it for some scripts and data processing. I love python, most of all its ecosystem, and use types extensively, but it still misses some things I wish it had better support for. Namely: immutability, and explicit side effects, which are both prominent features of Erg. So this is super exciting.
Does anyone know if Erg code can be (ergonomically) called from python? I think that'd be the real killer feature, being able to write erg modules and pull it into the greater python ecosystem as easily as native python.
* looks like the project is nary a few weeks old? Can't really dig into the git history on mobile, it freezes my browser
Not sure why I'd want to use this, presuming I was already happy with python. Especially now that python's type hinting is more mature. Looking through the feature set the main thing it seems to provide is a type system, but with a syntax I don't like as much as python's type hinting.
This is sort of speculation on my part: The fact that static typing PEPs can't easily introduce syntactic changes to the language (I don't think there has been a syntactic change introduced because of static typing ever since Python 3.5) will really hold back Python's static typing from being ergonomic at least, and "fully capable" at the worst.
I think that limitation of statically typed Python alone is enough to give this new language a chance.
It's also looks like the type inference of erg will be better than the current Python checkers.
I was just playing around with Python 3.10 for the first time today. I made an algebraic/sum-type (dataclasses + typing.Union), then did some structural pattern matching on a value of that type (match statement), and Mypy could tell me statically when the pattern matching wasn't exhaustive!
I think it's pretty damn amazing how well Python has been able to evolve into the realm of static typing. And no unofficial superset syntax required!
As someone coming from FP and having to use Python at work, I have the opposite perspective: I am constantly frustrated at how bad the type hinting is, and how few "guardrails" there are generally. :(
I don't know if this is what I'm looking for, but I think there's a ton of room for innovation and improvement in the python world. I welcome this language and I think it's quite interesting!
a link: https://fable.io/blog/2022/2022-06-06-Snake_Island_alpha.htm...
In order for this to succeed, python libraries would have to be rewritten without the C API in the dialect/subset of python supported.
I wonder if erg could strive to use a subset of python mostly and innovate narrowly in just a couple of places to make python more functional.
* Download and just run doesn't work. (e.g. Node, dotnet, cargo do this well). Hell, I've generally had more success with C++ in this regard.
* The syntax can be used in an extremely terse way, and that terseness seems to be idiomatic.
So you'll end up with everything you import being `any` which is not really any better than just using Python.
[1]: https://github.com/gilch/hissp
Though Nim definitely can be described as a statically typed Python-compatible language! I haven't used them but https://github.com/Pebaz/nimporter https://github.com/yglukhov/nimpy both seem great. Nimporter in particular looks fantastic for writing fast python libraries.
Actually come to think of it that might be the easiest way to write fast KiCad 6 plugins.. I really want to try making a native KiCad autorouter. But I don't want to figure out the C++ plugin setup and since KiCad 6 the Python APIs seem better documented and supported anyways. Problem is that Python would likely be too slow. Nimporter could be perfect. It looks really simple to setup.
So I find this to be super interesting, particularly when it comes to parts with lots of pads that one has to route.
Python would let you iterate the algorithm quickly. It's far easier to optimize the big O notation of your autorouter than in C++, say. Once you're happy with the algorithm, then you can try to optimize the slow bits in C/C++. But even things like dicts in python are still going to be super fast.
As far as speed up goes, there's PyPy, Nuitka, and Cython, which are all interesting. There's also a restricted version of python called RPython which PyPy uses to compile everything to C.
If it's me in 2022, I'd probably go with Cython. A lot of packages uses it. It's well known, and it's (mostly) python -- mostly because it would be easier to go back and forth in python rather than switching mental contexts between Nim and C and Python.
See here for the examples.
https://cython.readthedocs.io/en/latest/src/tutorial/cython_...
Good luck with the project!
> 2.times! do!:
May be what you mean is a static typing solution for Python whose syntax is a superset of Python syntax (which I don't think `erg` is), but isn't identical to Python's syntax( ie, it is a strict superset, which statically typed Python's syntax isn't). Typescript is exactly that for JS.
In that case, I agree with you that such an attempt would indeed be very interesting because it would allow for more aggressive exploration of ergonomic typing constructs while maintaining that any valid Python would be valid in that new language as well (just like TS).
However what I’m missing is having more advanced type constructs. For example mapped types, lookup types, etc [1].
That said, it seems like python devs keep adding features over time. For example a couple of years ago it wasn’t possible to specify which fields of a dictionary are required and not required (it required putting required fields in one TypedDict and then subclassing it into another one that had the non required ones with total=False), nor it was possible to “spread” a TypedDict to declare the kwarg types in a function.
[1]: https://www.typescriptlang.org/docs/handbook/release-notes/t...
https://github.com/python/mypy
The only thing you need to do is add appropriate type hints at function definitions and then run mypy in your build and CI and you got something that checks basically as strict as Java.
For those saying it’s optional so can’t be trusted, consider that compiling C++ with -Wall -Werror is also optional… adding it is simply part of standard project hygiene.
Deleted Comment
[1] http://mtshiba.me/TheErgBook/
Does anyone know if Erg code can be (ergonomically) called from python? I think that'd be the real killer feature, being able to write erg modules and pull it into the greater python ecosystem as easily as native python.
* looks like the project is nary a few weeks old? Can't really dig into the git history on mobile, it freezes my browser
1: https://en.m.wikipedia.org/wiki/Ambigram
I think that limitation of statically typed Python alone is enough to give this new language a chance.
It's also looks like the type inference of erg will be better than the current Python checkers.
I think it's pretty damn amazing how well Python has been able to evolve into the realm of static typing. And no unofficial superset syntax required!
https://peps.python.org/pep-0646/#grammar-changes
The other case that I remember off the top of my head is Python 3.6 adding annotations for variables that aren't created via function definitions:
https://peps.python.org/pep-0526/
I don't know if this is what I'm looking for, but I think there's a ton of room for innovation and improvement in the python world. I welcome this language and I think it's quite interesting!
Deleted Comment