8 ms·
Python’s Preprocessor
- __MatrixMan__ 2y agoPart 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 2y agoGrowing old is mandatory; growing up is optional.
- pryelluw 2y agoYou’ve managed to sum my whole approach to life in one beautiful sentence. Thank you.
- gradschoolfail 2y agoThank you for connecting 2 sayings of Murakami Haruki :) 1.痛みは避けがたいが、苦しみはオプショナル (https://archive.ph/Ca9rE 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 2y agoLiterally: it's difficult to avoid pain, but suffering is optional
- pokler 2y ago“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 2y ago> 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 https://en.wikipedia.org/wiki/Layla_and_Majnun Lagniappe: https://www.youtube.com/watch?v=EZ8magpNo10&t=93s https://www.youtube.com/watch?v=EZ8magpNo10&t=93s
- gradschoolfail 2y agoBeautiful 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 :)
- 082349872349872 2y agoNote 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 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 https://www.youtube.com/watch?v=ImOYx9j0kIA , a soft Dio interpretation, and https://www.youtube.com/watch?v=zo3pfnldlD0 https://www.youtube.com/watch?v=zo3pfnldlD0 , a hard Andersson, Fältskog, Lyngstad, and Ulvaeus interpretation)
- gradschoolfail 2y agoWhenceforth came the margin on which K,Y thrived :)
- 082349872349872 2y agohmm... 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 https://arxiv.org/pdf/cs/0204037 (the description in the abstract of the structure function sounds suspiciously like a galois connection)
- throwaway894345 2y agoPython 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 2y agoBatteries are included. Nannies are optional.
- extraduder_ire 2y agoIf you stopped people from doing this the easy/obvious way, they'd attempt it in a worse and more hacky way.
- IshKebab 2y agoHaha great hack. Something tells me I'll run across someone seriously using this in like 10 years...
- btown 2y ago>>> 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/ad3d3f2f3f19833f59fd7e9ec59e1714e0986e08#diff-dd2b2c4b437189e677979328b2325d2c184b26d1e0c903be6d14458f5c02ee17R34-R36 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 2y agoReminds me of `break rust;` causing the Rust compiler to emit an internal compiler error. I wonder which other languages have similar easter eggs.
- bch 2y agoTcl really became “Enterprise-ready”[0] at this time. [0] https://stackoverflow.com/a/1026619 https://stackoverflow.com/a/1026619
- shakna 2y ago> 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
- hsfzxjy 2y ago> `break rust;` causing the Rust compiler to emit an internal compiler error Is this real?
- photonthug 2y agoI 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 2y agoMake sure you enforce use of curly braces like all good languages
- nerdponx 2y agoNow 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://hylang.org/ https://github.com/gilch/hissp https://github.com/gilch/hissp http://coconut-lang.org/ http://coconut-lang.org/
- dang 2y ago[stub for offtopicness]
- mdanger007 2y agoTied with Coq for best name
- surfingdino 2y agoLet's not forget this fine contribution to the Python's nest. https://github.com/ajalt/fuckitpy https://github.com/ajalt/fuckitpy
- seanw444 2y agoAnd this: https://github.com/Roger/escrotum https://github.com/Roger/escrotum
- wiseowise 2y agoLet’s not forget https://web.archive.org/web/20210308033218/https://github.com/deeppomf/DeepCreamPy https://web.archive.org/web/20210308033218/https://github.co....
- sli 2y agoThere 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.
- isoprophlex 2y ago> 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
- 2y ago
- ppierald 2y ago[flagged]
- metadat 2y agoAre 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.)
- Tsche 2y agoI'm glad y'all like it, more to come soon :)
- skeledrew 2y agoFor 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...
- Abismith 2y ago[dead]
- est 2y agobest use case I've found so far is pyxl, inspired by jsx https://github.com/dropbox/pyxl https://github.com/dropbox/pyxl. You can write code like # coding: pyxl print <html><body>Hello World!</body></html>
- 0xbadcafebee 2y ago> 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)
- Leynos 2y agohttps://pyinstaller.org/en/stable/ https://pyinstaller.org/en/stable/
- 0xbadcafebee 2y agoYep, that proves my point, thank you
- BiteCode_dev 2y agoTangential, 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 http://nedbatchelder.com/code/cog#h_what_does_it_do
- rbarrois 2y agoThat'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 2y agoIt 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
- zxexz 2y agoHuh, 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.
- buildbot 2y agoSuper 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 :)
- deleted 2y ago[deleted]