Hacker News new | past | comments | ask | show | jobs | submit login
Python’s Preprocessor (pydong.org)
402 points by rbanffy 40 days ago | hide | past | favorite | 98 comments



    >>> from __future__ import braces
      File "<stdin>", line 1
    SyntaxError: not a chance
For those interested in how this (hilarious) error text came to be, it's been hardcoded in cpython since 2001!

https://github.com/python/cpython/commit/ad3d3f2f3f19833f59f...

The author, Jeremy Hylton, is now a Principal Engineer at Google working on AI search quality. It's quite remarkable that in 24 years, a single person's career has gone from a tongue-in-cheek memorialization of certain syntax being forbidden, to working on ubiquitous query systems that don't require dedicated syntax at all!


Reminds me of `break rust;` causing the Rust compiler to emit an internal compiler error. I wonder which other languages have similar easter eggs.


Tcl really became “Enterprise-ready”[0] at this time.

[0] https://stackoverflow.com/a/1026619


> The Stardate time format had nothing to do with Sun. I added it to Tcl while working at Scriptics, as an easter egg for the then-upcoming Tcl2K Conference. One of the conference events was a competition to implement a standard-to-stardate conversion utility, using an arcane formula. Only one guy entered the event. He spent a couple hours agonizing over the implementation (as he was looking for a job at Scriptics, he was eager to impress) only to have the easter egg revealed afterwards. Of course he won the competition anyway. And he got the job, too. – Eric Melski


> `break rust;` causing the Rust compiler to emit an internal compiler error

Is this real?



> error: internal compiler error: It looks like you're trying to break rust; would you like some ICE?

Lovely, and the word game is just great.


https://play.rust-lang.org/?version=stable&mode=debug&editio...

> error: internal compiler error: It looks like you're trying to break rust; would you like some ICE?

> --> src/main.rs:2:5

> |

> 2 | break rust;

> | ^^^^^^^^^^

> |

> = note: the compiler expectedly panicked. this is a feature.

> = note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-...


This one in Haskell is coincidental, but used as a joke:

``` import Data.Function

main = do let it = fix error print it ```


On HN, you can add code blocks by indenting with 2 spaces:

  import Data.Function

  main = do
    let it = fix error
    print it


If NLP counts, try xyzzy in gemini.google.com


How is it remarkable? Random people didn't get to add stuff to Python in 2001. It was a niche thing and someone who was contributing to it was likely to be a smart and dedicated person who would naturally have an impactful career ahead of them.

It's a misconception that the informal playful hobby hacking things are their separate world from real professional development.


I think OP is commenting more so on the reversal of the developer’s relationship with rules of syntax than their personal capabilities.


Totally right, my mistake. I guess the order of information as presented in that comment misled me.


No worries. I was working at PythonLabs at the time, so I guess you could say that adding Easter eggs to Python was part of my day job.


Innocent times. Perhaps Hylton could join the "vote of no confidence" motion in order to get justice for Tim Peters:

https://news.ycombinator.com/item?id=41314393


And just like that, I'm down the drama rabbit hole.


It's always so cool to see this kind of Easter eggs. So sad that they're not as common as they used to be.


There are all sorts of easter eggs and jokes in Python, for example a joke about blind people that GvR prevented from being reverted:

https://marc.info/?l=python-dev&m=130991276326041&w=2

In 2024 suddenly everyone is grown up and corporate and has never done anything wrong.


> In 2024 suddenly everyone is grown up and corporate and has never done anything wrong.

Trying to be considerate of others, even when they are different from ourselves, is indeed kind and good and does come with maturity. You needn't be corporate or have never done wrong to be considerate.


20 years at google, now thats some F-U money!


I thought getting cute with import-hooks was probably the most creative possible way to get fired, but I see now that this was naive. My only regret is that the codec regex probably prevents using stuff like "μtf8" to really troll people properly, so now I'm going to have to use import hooks, preprocessors, and sys.settrace to monkey-patch every function to the previously called one, while swapping stdout and stderr every 17 minutes.


Make sure you enforce use of curly braces like all good languages


Part of me says that python has not gone out of its way to expose preprocessor hooks for good reason, and reasonable adults should stay away from it.

The other part wants nothing to do with reasonable adults anyhow. Such fun could be had.


Growing old is mandatory; growing up is optional.


Thank you for connecting 2 sayings of Murakami Haruki :)

1.痛みは避けがたいが、苦しみはオプショナル

(https://archive.ph/Ca9rE)

Now, I don’t know how representative this book is of Murakami’s novelistic style, but I wonder: Is this low-maintenance, attention-deficit prose part of Murakami’s attraction, especially among the young? Do people enjoy reading him for the same reason they persist in listening to music as blandly familiar as Clapton’s? If Martin Amis is engaged in a “war against cliché” — a phrase in danger of becoming a cliché itself — then Murakami, on the evidence of this book, is a serial appeaser. How much does his thigh hurt? “Like crazy.” How do we know the weather is nice? Because — as he tells us (twice) — there’s “not a cloud in the sky.”

  self-styled zero-percenter and book reviewer in the above 
2.^_^?

(Norwegian Wood)

(Roughly, “growth is pain, nongrowth is unfortunate”)


> as blandly familiar as Clapton’s

If it hadn't been for Clapton, I probably never would've heard of Laylā bint Mahdī bin Saʿd bin Muzahim bin ʿAds bin Rabīʿah bin Jaʿdah bin Ka'b bin Rabīʿah bin Hawāzin bin Mansūr bin ʿAkramah bin Khaṣfah bin Qays ʿAylān bin Muḍar bin Nizār bin Maʿad bin ʿAdnan.

https://en.wikipedia.org/wiki/Layla_and_Majnun

Lagniappe: https://www.youtube.com/watch?v=EZ8magpNo10&t=93s


Beautiful song… I start to see where the … uh … tradition of responding to rejection with physical selfdestruction in that part of the world comes from…

As for Clapton, something tells me that wouldnt make a good snowclone :)


Note that Yaghmaei exercised the Kolmogorov Option and, unlike Ramesh, stayed in the IRI after the revolution.

For Clapton snowclones, I enjoyed a comment on https://www.youtube.com/watch?v=u7jV7IkHdqk :

> Eryczek wrote this when he was secretly in love with Patrycja; at that time Patrycja was the girlfriend of the famous Jurek Harrison!

(if you have time, while we're here there's a great yin/yang thing going on between https://www.youtube.com/watch?v=ImOYx9j0kIA , a soft Dio interpretation, and https://www.youtube.com/watch?v=zo3pfnldlD0 , a hard Andersson, Fältskog, Lyngstad, and Ulvaeus interpretation)


Whenceforth came the margin on which K,Y thrived :)


hmm... AK and margin lead me to Vereshchagin and Vitanyi, Kolmogorov’s Structure Functions and Model Selection (ca. 2002) — might this be something you have opinions on, or should I ask Hutter instead?

https://arxiv.org/pdf/cs/0204037

(the description in the abstract of the structure function sounds suspiciously like a galois connection)


You may not agree that facts are better than opinions, but here is one: Aaronson-Carroll’s paper on sophistication, downstream of your link,

is now 10 years’ in the making..

If you manage to access Hutter, let me know if I already know your public key ;)


Marcus and Jürgen introduced me to the notion that the limes marks a node (corresponding to the second eigenvector?) on the Chladni plate of germany; on the southern side, the dot product (with this "barbarianism" eigenvector) has a negative value.

Lagniappe: Grund(Bläbst), Feuer am Limes (1987)

  Das große Graph war viel zu weit,
  für unsre Schnitte zu wenig Zeit.
  Versuchen wir es wieder,
  solang' man Spektren noch rechnen kann.


Not doubting that the confoederati were always destined to become Men of Culture!

Just observing that cultural boundaries might be interesting, even if the interiors might not be[0]

Should we close the Rao-Gelman thread then, or are you still working on it?

[0] no time or battery to source out a citation, there was an american (californian?) accusation that the helvetics are only capable of inventing cuckoo clocks

Edit: https://skeptics.stackexchange.com/questions/2587/did-the-sw...

Edit edit: you have to admit M. Kowalski was abit trigger-happy in casting aspersions on Mr Quid? Otoh a flatlander might be blunt but also in their own way circumspect?


Being innocent of the ways of MO, I'm not going to judge sig. Quid either way.

For flatlanders, after reading https://blogs.ethz.ch/kowalski/2015/04/11/worms-brains-and-g... I now worry that procrustean restriction to planarity could be detrimental to their neural networks.

(the 1D graphs, aka the total orders, have no expanders, but on the flip side, that's probably why prime ideals and ultrafilters are so effective?)

EDIT: On Silver's River, a few footnotes on Ez.47:

47:10 In a groysn taykh khapt men groyse fish.

47:22 anticipating Ruth/רוּת?


Yes


They might have discovered that taykh-optimizing the sisyphean is itself sisyphean..


taykh? (Q. what do you call a strawberry from Bretagne? A. Une freizh)

Right now I'm going down the rabbit hole of expander graphs (aha, these also have a spectral gap?), but soon I shall have some bandwidth for coarse-graining coffee automata.

(I doubt you have my public key, but I fear that were you to take the inference closure of our convos and some gumshoe work, you could easily have 33 bits worth of identity)

Lagniappe: https://blogs.ethz.ch/kowalski/zazie-au-pot-de-these/ (I hope Zazie's ultimate commentary has not given her uncle a complex)


Taykh = river, as in Yez 47,12/nathaniel silber (shtetl = … )

Tonton = pork (osaka slang)

So, an algebraic exercise for me, a geometric one for you, and a quantum for both?


Geometric, or even philosophical?

Do I understand correctly that if we were to attempt to explain Kolmogorov Sophistication to Aristotle, we would say "the sophistication of `x` is the smallest essence over all proper[0] descriptions of x by, first[1] its essence, and then[2] its specific accidents"?

Intuitively, this would make sense, because as glass bead game players we are drawn to (beads whose cane was also formed from)* beads. As Körner would say, the height of distinction for a mathematician is to have, not an eponymous theorem, but an eponymous lemma.

[0] I don't understand what constitutes a proper description here yet, but am currently assuming it has to do with lying on a subsumption frontier, otherwise the trivial model would always be minimal.

[1] I think this has to be noncommutative, for otherwise we'd waste description bits on labelling the accidents? Compare canonical Huffman. (.a Lojban)

[2] see also Linnaeus


[0] not sure what you (or I, even) mean here, would the earlier bead of ultrafilters (& ultrametrics) be relevant in dispelling your discomfort?

[1] yes

[2] Linnaeus?


[2] Nomenclature binomiale

(compare the "biped, featherless — with broad nails")


Literally: it's difficult to avoid pain, but suffering is optional


“You can hold yourself back from the sufferings of the world, that is something you are free to do and it accords with your nature, but perhaps this very holding back is the one suffering you could avoid.” - Franz Kafka


You’ve managed to sum my whole approach to life in one beautiful sentence. Thank you.


Python has a whole bit about how it is for "consenting adults" and that's why it lacks public/private visibility modifiers and presumably why it exposes all other manner of metaprogramming magic. If they were worried about "reasonable adults", these other design decisions would be curious. :)


Batteries are included. Nannies are optional.


If you stopped people from doing this the easy/obvious way, they'd attempt it in a worse and more hacky way.


Huh, that’s convenient and really useful. When I do ridiculous import hacks, i usually just do it be importing a module, that trades the ast module to rewrite code, exec it and shim in an exit(). A preprocessor would be so much more ergonomic.

I used the ast rewriting stuff mostly before dicts were all ordered - replacing fist literals with an ordered dict call, which was actually useful.

I love how flexible python is. Most cursed thing I ever did was mutating strings in place, which led me eventually abusing mmap as well to write scripts that mutated themselves. Now I feel need to write lisp interpreter as a producer.


> mutating strings in place

They’re immutable. Were you directly writing to the memory location with ctypes or something?


Yep!


best use case I've found so far is pyxl, inspired by jsx https://github.com/dropbox/pyxl.

You can write code like

  # coding: pyxl
  print <html><body>Hello World!</body></html>


For the first time in a very, very long time I'm running into something that totally blows my mind and sets off lightbulbs like this is...


That's quite interesting.

Now, I'm left to wonder if this could have been used to better handle the Python 2-to-3 transition, e.g '# coding: six.python2' would adjust Python2 code to be valid Python3, or '# coding: six.python3' would adjust Python3 code to run under Python2 - e.g adding/removing the b"..." or u"..." prefixes!


It could help, but the parts it would help with are the easy parts. The challenges of py2 to py3 were the runtime behavior change: a Unicode and regular string containing ASCII were the same string in py2, as in you could use them as keys of a dict and they'd key the same entry. In py3 a bytes and str of the same ASCII would identify different entries in the same dict.

Some more nasty changes: various built ins like .keys() and .values() return lists in py2 but iterators in py3. Code gets very verbose if you use the six utilities or other workarounds to translate code safely - most times those are called they are used once, but every once in a while they are used twice.

Imo if you have such a tool that can rewrite at import time you should just commit the transformed code, and clean it up incrementally. The hard parts are the behavior changes that can cross long distances like the str v bytes behaving so different than py2 Unicode v str


Are the dependencies introduced via this coding hook strategy picked up by `pip freeze' or uv?

Otherwise, ..have fun with that :). Probably easier to rewrite any library rather than fight such dragons (because if someone put this in, what other traps await? Seems almost guaranteed.)


I'm glad y'all like it, more to come soon :)


Super cool! It would be kinda funny to make a pseudocode python that get’s “decoded” by an llm. Obviously it would be hideous but probably somewhat fun :)


Tangential, but if all you want is inline code generation from Python and not a full preprocessor, you can use the excellent cog from Ned Batchelder:

http://nedbatchelder.com/code/cog#h_what_does_it_do


Haha great hack. Something tells me I'll run across someone seriously using this in like 10 years...


I'm assuming you've written 10 in binary.


It won't take that long (I already have two use-cases for it).

The only concern is how brittle it might be vs. future Python releases.


Now that I know this is possible, it seems like it would be a fun addition to the Hy, Hissp, and Coconut projects: https://hylang.org/ https://github.com/gilch/hissp http://coconut-lang.org/


> the Python developers have strong opinions

except when it comes to downloading, installing, or running anything Python related. maybe by 2124 we can give users a python app and let them run it without 20 steps. (oh who am i kidding, by then we'll rewrite everything in whatever comes after Rust)



Yep, that proves my point, thank you


[stub for offtopicness]


I think the title of this needs to be changed as it implies that this is a preprocessor project named Pydong. As far as I can tell that's simply the name of this blog and this post is about how python has a preprocessor built-in if you abuse the right mechanisms.


Tied with Coq for best name


I remember that I wanted to implement a python module that would improve upon the builtin Django groups. So following a tradition of adding ex to the end of the existing name, I named my module "groupsex".

After taking a peek at it I decided to rename it to groups2 instead :)


Not python but literally yesterday I had do a double take when I saw https://github.com/janestreet/sexplib


I was introduced to S-Expressions a few decades ago yet it is still the case that 100% of the time I pronounce 'SEXP' as 'SEX-P'


Ah the traditional lispish naming for predicate functions, applied to questions of an amorous nature!


I occasionally run across something called K8-Sexecutor, or at least that's how I pronounce it.


the children's exchange dot com drops the s, just in case.


Let's not forget this fine contribution to the Python's nest. https://github.com/ajalt/fuckitpy


> https://github.com/ajalt/fuckitpy

10 years ago this was just a joke, but today, now that we're finally agile enough so that any disorganized jumble of completely unreviewed and unversioned notebooks might suddenly become a production pipeline? Why let a little thing like critical errors halt the execution of that perfect nightmare you've been working on! The only problem is that the database still won't let you shove a string into an integer slot, but data-science is looking forward to switching over to spreadsheets completely as soon as we can migrate the data from redshift.


I'm sure this tiny inconvenience can be taken care of with the help ofhttps://github.com/ostafen/viperdb or, if we want to stick to the juvenile innuendo, https://pythonhosted.org/pickleDB/


> The web devs tell me that fuckit's versioning scheme is confusing, and that I should use "Semitic Versioning" instead. So starting with fuckit version ה.ג.א, package versions will use Hebrew Numerals.

Big lol



There are also seeeeeveral LOVE2D libraries with overtly sexual names. The most egregious example that comes to mind is the (now defunct compat library) "AnAL." There's also HUMP, Pölygamy, Swingers, Adult Lib (debatable but close enough), Gspöt, Möan.lua, fLUIds (also debatable, but there's a clear theme here), and yaoui.



You can always ask the folks at Experts Exchange for guidance on naming things.


[flagged]


confused why coc is okay, dong is not okay.


You Sir are a genius! This will be my pronunciation of "coc" from now on.

Serious answers are flagged, so it shall remain a mystery.


oh no


As a community we really couldn't come up with a better name, eh?


Pydong is the blog name.


* As you can see by opening the link, "pydong" is the name of the blog, not the Python preprocessor

* I'm glad that we are not ants. Deciding everything "as a community" would be hell


Dong is a very common name in some countries.


I think it's the name of Vietnam's currency.


Also a common name as is Phuc.

I had a partner that was a translation coordinator and they would play me this VM from one of the Vietnamese translators, every time he called he would say, “Hi this Phuc, ha ha that is funny to you, anyway …”


Not a prude but this name just reeks of immaturity.


To me it was always just a silly way of pronouncing "Python", especially in reference to terrible shenanigans like the ones the post talks about :P


Isn’t it a play on words/reference to Pudong in China? It’s a nice central part of Shanghai.


PrePy could have worked... I guess lol maybe it was taken, cause Pydong... yeah.


I had actually considered PrePy and variations thereof for the magic_codec project (which is the example implementation showcased in that post), unfortunately all of these had been used by other projects before. Pydong is the name of the blog :)


Ah I did not realize this. Whoops. Thanks for clarifying!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: