return to table of content

Python’s Preprocessor

dang
28 replies
20h30m

[stub for offtopicness]

mdanger007
14 replies
1d

Tied with Coq for best name

sli
0 replies
22h25m

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.

photonthug
1 replies
22h9m

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.

isoprophlex
0 replies
23h11m

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

spapas82
5 replies
23h24m

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 :)

jghn
2 replies
22h40m

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'

riffraff
0 replies
21h5m

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

__MatrixMan__
0 replies
21h7m

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

exe34
0 replies
22h4m

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

peterleiser
0 replies
21h51m

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

jedberg
11 replies
23h47m

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

giancarlostoro
2 replies
23h46m

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

Tsche
1 replies
19h9m

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 :)

giancarlostoro
0 replies
4h4m

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

BeetleB
2 replies
23h2m

Dong is a very common name in some countries.

kuroguro
1 replies
22h30m

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

sitkack
0 replies
21h23m

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 …”

lysace
1 replies
22h15m

Not a prude but this name just reeks of immaturity.

Tsche
0 replies
18h40m

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

nomdep
0 replies
21h4m

* 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

carom
0 replies
23h30m

Pydong is the blog name.

AlanYx
0 replies
21h59m

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

ziml77
0 replies
22h58m

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.

btown
18 replies
23h11m

    >>> 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!

SkiFire13
9 replies
21h27m

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

hsfzxjy
3 replies
14h27m

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

Is this real?

pjmlp
0 replies
11h58m

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.

shakna
0 replies
8h6m

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
TheMatten
1 replies
10h6m

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

``` import Data.Function

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

notpushkin
0 replies
7h42m

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

  import Data.Function

  main = do
    let it = fix error
    print it

sans_souse
0 replies
7h21m

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

throw-the-towel
2 replies
17h48m

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.

lhmadk
1 replies
8h35m

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.

jszymborski
0 replies
2h36m

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.

JodieBenitez
0 replies
15h42m

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

bonoboTP
1 replies
7h6m

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.

dylanfw
0 replies
28m

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

brcmthrowaway
0 replies
21h21m

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

__MatrixMan__
9 replies
23h53m

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.

082349872349872
5 replies
23h22m

Growing old is mandatory; growing up is optional.

gradschoolfail
3 replies
17h22m

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”)

sdrothrock
1 replies
15h5m

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

pokler
0 replies
36m

“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

082349872349872
0 replies
8h50m

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

pryelluw
0 replies
23h2m

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

throwaway894345
1 replies
21h23m

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. :)

rbanffy
0 replies
15h38m

Batteries are included. Nannies are optional.

extraduder_ire
0 replies
6h19m

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

zxexz
2 replies
7h25m

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.

sgarland
1 replies
5h31m

mutating strings in place

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

zxexz
0 replies
1h45m

Yep!

IshKebab
2 replies
23h23m

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

raminf
0 replies
17m

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.

kevindamm
0 replies
5h48m

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

0xbadcafebee
2 replies
14h46m

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)

0xbadcafebee
0 replies
3h29m

Yep, that proves my point, thank you

rbarrois
1 replies
10h32m

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!

dgoldstein0
0 replies
10h20m

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

photonthug
1 replies
22h42m

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.

ImaCake
0 replies
19h26m

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

skeledrew
0 replies
17h2m

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...

metadat
0 replies
19h30m

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.)

est
0 replies
15h13m

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>

buildbot
0 replies
2h49m

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 :)

Tsche
0 replies
19h22m

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

BiteCode_dev
0 replies
10h53m

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