Text of discuss.python.org › t › basic-syntax-layer-and-syntax-transformation › 102071 as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Basic Syntax Layer and Syntax Transformation - Ideas - Discussions on Python.org

Basic Syntax Layer and Syntax Transformation Ideas tzengshinfu (tzengshinfu) August 12, 2025, 6:00am 1 Hi, folks: Recently, I came across a couple of posts: PEP 802: Display Syntax for the Empty Set Introduce funnel operator i.e. |> to allow for generator pipelines It made me realize that a truly developer-friendly and vibrant programming language— especially one with a long history— naturally attracts people from many different backgrounds: we have OOP developers, FP developers, mathematicians, AI experts, newcomers, and even developers coming from other languages.

As more and more people join in, adding a new feature becomes a process of finding a solution that everyone can accept. (Well… most of the time, the OOP camp wins. I’m one of them too.) This reminded me of when I switched roles and had to work on systems originally developed in Java. Java, being a long-standing language, takes backward compatibility very seriously. While it has added (and simplified) syntax in recent years to attract new developers, some aspects cannot be changed due to compatibility concerns— like renovating an entire building but keeping certain old doors and windows because people are used to them.

For example, JEP 512: Compact Source Files and Instance Main Methods reduces boilerplate code and lowers the cognitive load for beginners (though from the opposite perspective, it actually increases the cognitive load for experienced developers). Yet newcomers still ask me questions like: Why can’t we compare strings with string1 == string2 and must use string1.equals(string2) ? But why is it okay to concatenate strings with string1 + string2 ?

Why? Because there are many considerations. Some decisions were made long ago and couldn’t be changed in time— like missing the highway exit and having to keep going. The later an enhancement proposal comes, the less likely it is to bring major syntax changes or optimizations. After all, introducing new syntax is always a trade-off— we must consider backward compatibility and weigh the pros and cons of adopting it universally.

My compromise is to introduce an IDE plugin that automatically transforms syntax without altering the actual code. On top of that, I added shortcut inputs— now, typing == will call .equals and perform local folding, so the code looks like string1 == string2 , but after committing to version control, it’s still string1.equals(string2) . Back to this topic—without relying on IDEs or other external tools, could we make it easier to introduce new syntax into existing structures?

Could we even allow developers with different design paradigms to work in the same codebase? I think it might be possible to establish a basic syntax layer , where all new features are built on top of it, with syntax transformation done via flags (e.g., --profile=math ) or mapper files (e.g., set() = ∅ ). The basic layer would represent the current, widely accepted, stable version— developers could then choose a profile for syntax transformation.

For example, a mathematician could have all empty sets displayed as the familiar symbol ∅ . Other collaborators, if using --profile=general , would see them as set() . A mapper file could even allow custom symbols, like set() = {/} . I apologize for not thinking this through in great detail— I’m neither a compiler expert nor a language syntax expert, but I’m aware of the complexity involved. I just wanted to share some personal thoughts, hoping Python can be even more appealing to developers from all sorts of backgrounds.

Thanks to all of you—without you, we wouldn’t have this amazing language and ecosystem. 1 Like roundabout (roundabout) August 12, 2025, 6:25am 2 I would say a more viable approach would be a preprocessor, every developer has a non-versioned directory with the sources in the custom representation, before doing anything they would sync it with the master code and then generate the master code again. aroberge (André Roberge) August 12, 2025, 8:28am 3 Like “roundabout-host” wrote, this could be done with a pre-processor.

Python as it exists is so flexible that it is already possible to do so and have written a library with many examples: Ideas: making it easier to extend Python’s syntax — ideas 0.0.38 documentation . That being said, I think that the way you describe it would be a terrible idea for Python itself, not to mention how much more work it would be for the core developers to support various variants of the syntax. What would happen if you’d want to use libraries from two different, and incompatible variants?

1 Like matthewyu0311 (Matthew) August 12, 2025, 5:46pm 4 There exist many third-party code and AST transformers. The main downside is that they are not forward-compatible. Whenever upstream Python introduces a new syntax, these third-party tools need to be updated. There have been over the years many calls for first-class language support (not just import hooks) for syntactic transformers, syntactic macros and so on. There is even a PEP 638 .

None of the proposals have gained any traction beyond ideas and drafts. What actually would need to be implemented first-class? Most likely, at least the lexer – parser → AST → compiler → bytecode pathway will consist of additional intermediate steps which do the transformation. This can’t happen without a major redesign and rewrite of the execution model and import machinery. The amount of work needed isn’t justified by the purported benefits these proposals bring, and given the concerns over the proliferation of DSLs further fragmenting the ecosystem.

1 Like skirpichev (Sergey B Kirpichev) August 13, 2025, 3:47am 5 I would say it’s terrible only assuming emphasized condition. But I don’t think it’s too bad if we will just support, say, AST transformations in the REPL. This is something standard in various enhanced alternatives for the builtin REPL (like IPython). Paddy3118 (Paddy3118) August 13, 2025, 8:55am 6 Wouldn’t this negatively affect readability as one would have to be conversant with multiple flags and different flags could make the same change in different ways leading to confusion : a maths module using ∅, another using {,} and the “standard” using set() for example.

4 Likes sirosen (Stephen Rosen) August 13, 2025, 4:41pm 7 There’s an obvious comparison any macro proposal draws with Lisp. Lisp produces wildly divergent codebases, and that is an accepted and well understood characteristic of the language. The question isn’t “can we make Python more like Lisp?” but “should we?” Macros have tremendous expressive power. The cost of that power is the evolution of dialects. This type of change requires acceptance of an ideological stance of “yes, we want the language to evolve in this direction.” As useful as macros are, I think it’s too big of a change to contemplate at present.

Maybe in the next 5 or 10 years of language evolution I’ll change my mind, I’m not ruling that out. But personally, I don’t see it as a good idea right now. 2 Likes tzengshinfu (tzengshinfu) May 29, 2026, 2:59am 8 Let me share a pessimistic and unpleasant personal opinion: After using AI for assisted programming for a while, looking back, discussing syntax seems less important than before. No matter how English-like or mathematically friendly the syntax may be, in the AI era, it’s better to write actual English and actual mathematical equations.

English becomes source code, and the AI output will prioritize: Smaller compiled binary file size Faster initial startup speed Memory safety Cross-platform compatibility (e.g., WASM). My friends who use AI have started writing Rust in AI (many functions are rewritten in Rust = RIIR), but they never look at the generated source code (Rust). (The role is equivalent to the machine code.) (Personally, I don’t want that.) Looking back at this issue, since source code is a shared convention among all developers

The rest of this page is on the live site.