News for hackers. Stuff that matters.
Re:A high-performance, zero-overhead, extensible Python comp... by haberman on Wednesday September 18, 2024 @03:04PM (#41584104)
> Non-goals: Drop-in replacement for CPython: Codon is not a drop-in replacement for CPython. There are some aspects of Python that are not suitable for static compilation — we don't support these in Codon.

This is targeting a Python subset, not Python itself.

For example, something as simple as this will not compile, because lists cannot mix types in Codon (https://docs.exaloop.io/codon/language/collections#strong-ty...):

    l = [1, 's']
It's confusing to call this a "Python compiler" when the constraints it imposes pretty fundamentally change the nature of the language.
Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @04:19PM (#41584969)
Who is out here mixing types in a list anyway?
Re:A high-performance, zero-overhead, extensible Python comp... by dathinab on Wednesday September 18, 2024 @06:46PM (#41586457)
parsing json is roughly of the type:

type Json = None | bool | float | str | dict[str, Json] | list[Json]

you might have similar situations for configs e.g. float | str for time in seconds or a human readable time string like "30s" etc.

given how fundamental such things are I'm not sure if there will be any larger projects (especially wrt. web servers and similar) which are compatible with this

also many commonly used features for libraries/classes etc. are not very likely to work (but idk. for sure, they just are very dynamic in nature)

so IMHO this seems to be more like a python-like language you can use for idk. some since computations and similar then a general purpose faster python

Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @06:55PM (#41586536)
Agreed, I was just joking. I understand heterogenous lists are possible with Python, but with the use of static type checking I feel like its pretty rare for me to have heterogenous lists unless its duck typing.
Re:A high-performance, zero-overhead, extensible Python comp... by JonChesterfield on Wednesday September 18, 2024 @11:18PM (#41588159)
If your language obstructs heterogeneous lists your programs will tend to lack them. Look for classes containing multiple hashtables from the same strings to different object types as a hint that they're missed.

Whether that's a feature is hard to say. Your language stopped you thinking in those terms, and stopped your colleagues from doing so. Did it force clarity of thought or awkward contortions in the implementation? Tends to depend on the domain.

Re:A high-performance, zero-overhead, extensible Python comp... by bobbylarrybobby on Thursday September 19, 2024 @03:10PM (#41595254)
Heterogeneity is easily achieved in statically typed languages via sum types.
Re:A high-performance, zero-overhead, extensible Python comp... by orf on Wednesday September 18, 2024 @04:28PM (#41585057)
It’s common to have a list of objects with different types, but which implement the same interface. Duck typing of this kind is core to Python.
Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @06:53PM (#41586521)
Good point.
Re:A high-performance, zero-overhead, extensible Python comp... by itishappy on Wednesday September 18, 2024 @04:45PM (#41585248)
The json module returns heterogenous dicts.

https://docs.python.org/3/library/json.html

Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @06:53PM (#41586526)
Yeah, just because it can do that doesn't mean that it is good design.
Re:A high-performance, zero-overhead, extensible Python comp... by gpderetta on Thursday September 19, 2024 @08:51AM (#41591334)
how would you represent an arbitrary JSON array in python then? A potentially heterogeneous list seems the obvious solution.
Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Thursday September 19, 2024 @02:42PM (#41594981)
Why would I want to do that? I'm rarely ingesting arbitrary JSON. Rather I'm designing my data structures in a sensible way and then maybe serializing them to JSON. Just because JSON can represent heterogenous lists doesn't mean it is a good idea to use heterogenous lists in my programs.
Re:A high-performance, zero-overhead, extensible Python comp... by gpderetta on Friday September 20, 2024 @04:37AM (#41599993)
The JSON spec does not require a schema. If you want to write a library that can support any valid JSON you have little options. That's useful if you are implementing something like jq just to give an example.
Re:A high-performance, zero-overhead, extensible Python comp... by gwking on Thursday September 19, 2024 @09:54AM (#41591854)
It is the design of JSON! Which is a reflection of the same dynamic typing choice made in the original design of Javascript.
Re:A high-performance, zero-overhead, extensible Python comp... by mrguyorama on Thursday September 19, 2024 @01:31PM (#41594220)
They, uh, still aren't wrong hah.

Tell me again why we somehow standardized on sending the equivalent of JSObject.toString() for everything? Especially when "standardized" isn't

Re:A high-performance, zero-overhead, extensible Python comp... by CaptainNegative on Wednesday September 18, 2024 @04:29PM (#41585071)
I often find myself mixing Nones into lists containing built-in types when the former would indicate some kind of error. I could wrap them all into a nullable-style type, but why shouldn't the interpreter implicitly handle that for me?
Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @06:53PM (#41586519)
Yeah, that seems fair.
Re:A high-performance, zero-overhead, extensible Python comp... by nicce on Wednesday September 18, 2024 @04:32PM (#41585110)
Everyone who chooses the Python in the first hand.
Re:A high-performance, zero-overhead, extensible Python comp... by bpshaver on Wednesday September 18, 2024 @06:52PM (#41586511)
Well, I'm one of those people, and I feel that I rarely do this. Except if I have a list of different objects that implement the same interface, as another commenter mentioned.
Re:A high-performance, zero-overhead, extensible Python comp... by RogerL on Wednesday September 18, 2024 @07:02PM (#41586577)
return [key, value]
Re:A high-performance, zero-overhead, extensible Python comp... by ghxst on Wednesday September 18, 2024 @09:39PM (#41587613)
Why would you do this over `return key, value` which produces a tuple? Just curious.
Re:A high-performance, zero-overhead, extensible Python comp... by dgan on Thursday September 19, 2024 @01:31AM (#41588829)
Not the parent, but i return heterogeneous lists of the same length to the excel to be used by xlwings. The first row being the headers, but every row below is obviously heterogeneous
Re:A high-performance, zero-overhead, extensible Python comp... by 0xDEADFED5 on Thursday September 19, 2024 @04:52AM (#41589897)
javascript refugee?
Re:A high-performance, zero-overhead, extensible Python comp... by slightwinder on Thursday September 19, 2024 @08:23AM (#41591069)
To quote the Zen of Python:

    Explicit is better than implicit.
    Readability counts.
Re:A high-performance, zero-overhead, extensible Python comp... by ErikBjare on Thursday September 19, 2024 @02:20PM (#41594736)
How does that apply in this case?
Re:A high-performance, zero-overhead, extensible Python comp... by slightwinder on Friday September 20, 2024 @07:40AM (#41600990)
"return key, value" is implicit. While "return [key, value]" is explicitly telling the full return-value. And it's (for me) more readable than "return (key, value)".
Re:A high-performance, zero-overhead, extensible Python comp... by Nab443 on Saturday September 21, 2024 @01:16AM (#41607670)
I don't see how "return (key, value)" is less readable than it's list counterpart. Now, why using a list that can grow, and so takes more space and maybe less efficient, for something that should not?
Re:A high-performance, zero-overhead, extensible Python comp... by slightwinder on Tuesday September 24, 2024 @08:38AM (#41635857)
"return (key, value)" can be read as a function-call. Especially as space after the function-name is allowed in python. And performance on that level is no serious topic in python anyway. But this is mainly just a personal preference.
Re:A high-performance, zero-overhead, extensible Python comp... by ghxst on Sunday September 22, 2024 @02:24PM (#41618891)
A list and tuple are not the same thing. There could be reasons to require a list explicitly but I couldn't really think of any obvious ones which is why I asked.
Re:A high-performance, zero-overhead, extensible Python comp... by Myrmornis on Thursday September 19, 2024 @08:05AM (#41590916)
You should use a tuple there: it's a collection of fixed size where each slot has an identity. (There's a common confusion in Python circles that the main point of tuples is immutability; that's not so).
Re:A high-performance, zero-overhead, extensible Python comp... by __mharrison__ on Wednesday September 18, 2024 @08:37PM (#41587210)
Someone who is using Python the wrong way.
Re:A high-performance, zero-overhead, extensible Python comp... by dekhn on Wednesday September 18, 2024 @09:25PM (#41587532)
I've been mixing types in Python lists for several decades now. Why wouldn't you? it's a list of PyObjects.
Re:A high-performance, zero-overhead, extensible Python comp... by gwking on Thursday September 19, 2024 @10:32AM (#41592324)
An example related to JSON content is HTML content. I have a Python library that represents all of the standard HTML tags as a family of classes. It is like a lightweight DOM on the server side, and has resulted in a web server that does not use string based templating at all. It lets me construct trees of HTML completely in Python and then render them out with everything correctly escaped. I can also parse HTML into trees and manipulate them as I please (for e.g. scraping tasks and document transforms). It is all strongly typed using mypy and I adhere to the strictest generic typing I can manage.

Each node has a list of children, and the element type is `str|HtmlNode`. I find this vastly easier to use than the LXML ETree api, where nodes have `text` and `tail` attributes to represent interleaved text.

Interestingly, the LXML docs promote their design as follows: > he two properties .text and .tail are enough to represent any text content in an XML document. This way, the ElementTree API does not require any special text nodes in addition to the Element class, that tend to get in the way fairly often (as you might know from classic DOM APIs). https://lxml.de/tutorial.html#elements-contain-text

It could be a simple matter of taste! But I suspect that the difference between what they are describing as "classic DOM" vs what I am doing is that they are referring to experience with C/C++/Java libraries circa 2009 that had much less convenient dynamic type introspection. The "get in the way fairly often" reminds me of how verbose it is to deal with heterogenous data in C/C++/ObjC. In ObjC for example, you could have an array mixing NSString with other NSObject subclasses, but you had to do work to type it correctly. If you wanted numbers in there you had to use NSNumber which is an annoying box type that you never otherwise use. And ObjC was considered very dynamic in its day!

I have long felt that the root of much evil was the overbearing distinction between primitive and object types in C++/Java/Objective-C.

All of this is a long way of saying, I think "how to deal with heterogenous lists of stuff" is a huge question in language design, library design, and the daily work of programming. Modern languages have by no means converged on a single way to represent varying types of elements. If you want to create trees of stuff, at some level that is "mixing types in a list" no matter how you might try to encode it. Just food for thought!

Re:A high-performance, zero-overhead, extensible Python comp... by quotemstr on Wednesday September 18, 2024 @03:15PM (#41584219)
It's not even a subset. They break foundational contracts of the Python language without technical necessity. For example,

> Dictionaries: Codon's dictionary type does not preserve insertion order, unlike Python's as of 3.6.

That's a gratuitous break. Nothing about preserving insertion order interferes with compilation, AOT or otherwise. The authors of Codon broke dict ordering because they felt like it, not because they had to.

At least Mojo merely claims to be Python-like. Unlike Codon, it doesn't claim to be Python then note in the fine print that it doesn't uphold Python contractual language semantics.

Re:A high-performance, zero-overhead, extensible Python comp... by orf on Wednesday September 18, 2024 @04:31PM (#41585092)
Try not to throw around statements like “they broke duct ordering because they felt like it”.

Obviously they didn’t do that. There are trade-offs when preserving dictionary ordering.

Re:A high-performance, zero-overhead, extensible Python comp... by actionfromafar on Wednesday September 18, 2024 @05:33PM (#41585814)
The trade-off is a bit of speed.
Re:A high-performance, zero-overhead, extensible Python comp... by cjbillington on Wednesday September 18, 2024 @06:44PM (#41586438)
This might be what you meant, but the ordered dicts are faster, no? I believe ordering was initially an implementation detail that arose as part of performance optimisations, and only later declared officially part of the spec.
Re:A high-performance, zero-overhead, extensible Python comp... by Someone on Thursday September 19, 2024 @02:28AM (#41589143)
> but the ordered dicts are faster, no?

They may be in the current implementations, but removing an implementation constraint can only increase the solution space, so it cannot make the best implementation slower.

As a trivial example, the current implementation that guarantees iteration happens in insertion order also is a valid implementation for a spec that does not require that guarantee.

Re:A high-performance, zero-overhead, extensible Python comp... by dathinab on Wednesday September 18, 2024 @06:56PM (#41586542)
if you claim

> high-performance Python implementation

then no this aren't trade-offs but breaking the standard without it truly being necessary

most important this will break code in a subtle and potentially very surprising way

they could just claim they are python like and then no one would hold them for not keeping to the standard

but if you are misleading about your product people will find offense even if it isn't intentionally

Re:A high-performance, zero-overhead, extensible Python comp... by baq on Thursday September 19, 2024 @03:20AM (#41589401)
dicts ordering keys in insertion order isn't an implementation detail anymore and hasn't been for years.
Re:A high-performance, zero-overhead, extensible Python comp... by nick238 on Thursday September 19, 2024 @03:21PM (#41595368)
I get that all dicts are now effectively an `collections.OrderedDict`, but I've never seen practical code that uses the insertion order. You can't do much with that info (no `.pop()`, can't sort a dict without recreating it) beyond maybe helping readability when you print or serialize it.
Re:A high-performance, zero-overhead, extensible Python comp... by funny_falcon on Friday September 20, 2024 @04:06PM (#41605136)
Readability, reproducibility, and simple LRU.

Reproducibility matters for tests, they become simpler. Some other algorithms become simpler as well.

LRU is just a dict with preserving order: on access just delete and insert again.

Re:A high-performance, zero-overhead, extensible Python comp... by adammarples on Wednesday September 18, 2024 @05:03PM (#41585454)
Well would you claim that Python 3.5 isn't python?
Re:A high-performance, zero-overhead, extensible Python comp... by stoperaticless on Wednesday September 18, 2024 @05:52PM (#41585974)
All versions of python are python.

If lang is not compatible with any of python versions, then the lang isn’t python.

False advertising is not nice. (even if the fineprint clarifies)

Re:A high-performance, zero-overhead, extensible Python comp... by thesz on Thursday September 19, 2024 @01:44AM (#41588895)
> If lang is not compatible with any of python versions, then the lang isn’t python.

Python versions are not compatible between themselves, as python does not preserve backward compatibility, ergo python is not python.

Re:A high-performance, zero-overhead, extensible Python comp... by KeplerBoy on Thursday September 19, 2024 @02:40AM (#41589204)
The words "any" and "all" have a different meaning.
Re:A high-performance, zero-overhead, extensible Python comp... by skeledrew on Thursday September 19, 2024 @10:33PM (#41598279)
Interestingly I recently had to run a script I wrote for 3.11 on an old system that has 3.6, and the only thing I had to remove were a few type hints (which of course don't affect function). Seems pretty backwards compatible to me.
Re:A high-performance, zero-overhead, extensible Python comp... by stoperaticless on Sunday September 29, 2024 @05:39AM (#41686125)
Pretty compatible != compatible.

(I can edit my own script, I would hate if installation instructions for “django” would include “just remove the type hints from the scripts”)

Re:A high-performance, zero-overhead, extensible Python comp... by odo1242 on Wednesday September 18, 2024 @03:08PM (#41584140)
Yeah, it feels closer to something like Cython without the python part.
Re:A high-performance, zero-overhead, extensible Python comp... by jjk7 on Wednesday September 18, 2024 @03:16PM (#41584227)
The differences seem relatively minor. Your specific example can be worked around by using a tuple; which in most cases does what you want.
Re:A high-performance, zero-overhead, extensible Python comp... by itishappy on Wednesday September 18, 2024 @03:46PM (#41584584)
Altering python's core datatypes is not what I'd call minor.

They don't even mention the changes to `list`.

> Integers: Codon's int is a 64-bit signed integer, whereas Python's (after version 3) can be arbitrarily large. However Codon does support larger integers via Int[N] where N is the bit width.

> Strings: Codon currently uses ASCII strings unlike Python's unicode strings.

> Dictionaries: Codon's dictionary type does not preserve insertion order, unlike Python's as of 3.6.

> Tuples: Since tuples compile down to structs, tuple lengths must be known at compile time, meaning you can't convert an arbitrarily-sized list to a tuple, for instance.

https://docs.exaloop.io/codon/general/differences

Pretty sure this means the following doesn't work either:

    config = { "name": "John Doe", "age": 32 }
Note: It looks like you can get around this via Python interop, but that further supports the point that this isn't really Python.
Re:A high-performance, zero-overhead, extensible Python comp... by dathinab on Wednesday September 18, 2024 @07:03PM (#41586584)
> Strings: Codon currently uses ASCII strings unlike Python's unicode strings.

wtf this is a supper big issue making this basically unusable for anything handling text (and potentially even just fixed indents, if you aren't limited to EU+US having non us-ascii idents in code or text is common, i.e. while EU companies most times code in english this is much less likely in Asia, especially China and Japan.

it isn't even really a performance benefit compared to utf-8 as utf-8 only using us-ascii letters _is_ us-ascii and you don't have to use unicode aware string operations

Re:A high-performance, zero-overhead, extensible Python comp... by robjwells on Thursday September 19, 2024 @05:19AM (#41590012)
Yeah this is a baffling decision. I’d like to know what the motivation is. ASCII doesn’t even contain € or £.
Re:A high-performance, zero-overhead, extensible Python comp... by gpderetta on Thursday September 19, 2024 @08:53AM (#41591366)
In fact most EU languages are not representable in ASCII.
Re:A high-performance, zero-overhead, extensible Python comp... by BiteCode_dev on Thursday September 19, 2024 @04:27AM (#41589752)
For a real compiler try nuitka.
Re:A high-performance, zero-overhead, extensible Python comp... by wpietri on Thursday September 19, 2024 @08:52AM (#41591353)
Yeah, this right here would kill it for me:

> Strings: Codon currently uses ASCII strings unlike Python's unicode strings.

That rules out almost anything web-ish for me.

The use case I could imagine is places where you have a bunch of python programmers who don't really want to learn another language but you have modest amounts of very speed-sensitive work.

E.g., you're a financial trading company who has hired a lot of PhDs with data science experience. In that context, I could imagine saying, "Ok, quants, all of your production code has to work in Codon". It's not like they're programming masters anyhow, and having it be pretty Python-ish will be good enough for them.

Re:A high-performance, zero-overhead, extensible Python comp... by Retr0id on Thursday September 19, 2024 @09:05AM (#41591467)
>> Strings: Codon currently uses ASCII strings unlike Python's unicode strings.

Yikes. These days I wouldn't even call those strings, just bytes. I can live with static/strong typing (I prefer it, even), but not having support for actual strings is a huge blow.

Re:A high-performance, zero-overhead, extensible Python comp... by wpietri on Thursday September 19, 2024 @09:01AM (#41591430)
Ah, looking further, I find this about the company: "Their focus lies in bridging the gap between these two aspects across various domains, with a particular emphasis on life sciences and bioinformatics."

That makes sense as a sales pitch. "Hey, company with a lot of money! Want your nerds to go faster and need less expensive hardware? Pay us for magic speed-ups!" So it's less a product for programmers than it is for executives.