frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Elliptical Python Programming

https://susam.net/elliptical-python-programming.html
184•sebg•11mo ago

Comments

benob•11mo ago
TIL that in python, 1--2==3
seplox•11mo ago
It's not a python thing. 1-(-2), distribute the negative.
qsort•11mo ago
In most C-like languages that would be a syntax error. E.g. in C and C++ as a rule you tokenize "greedily", "1--2" would be tokenized as "1", "unary decrement operator", "2", which is illegal because you're trying to decerment an rvalue.

Python doesn't have "--", which allows the tokenizer to do something else.

nyrikki•11mo ago
In C, that is really because Unary minus (negation) has precedence over binary operations.

    +a - b; // equivalent to (+a) - b, NOT +(a - b)
    -c + d; // equivalent to (-c) + d, NOT -(c + d)

https://en.cppreference.com/w/cpp/language/operator_arithmet...

    +-e; // equivalent to +(-e), the unary + is a no-op if “e” is a built-in type
     // because any possible promotion is performed during negation already
The same doesn't apply to, !! Which is applied as iterated binary operations (IIRC)

I am pretty sure the decriment operator came around well after that quirk was established.

seanhunter•11mo ago
Peter van der Linden’s book “Expert C Programming” (which is awesome btw) says that one of them (Kernighan, Richie or maybe Ken Thompson I forget) realised early on that the c compiler had the wrong operator precedence for bit twiddling and unary and boolean operators but “at that stage we had a few thousand lines of C code and thought it would be too disruptive to change it”
j2kun•11mo ago
Also worth noting that `1 - -2` works and produces 3 in C because the space breaks the operator.
plus•11mo ago
For those who are curious, `...` is a placeholder value in Python called Ellipsis. I don't believe it serves any real purpose other than being a placeholder. But it is an object and it implements `__eq__`, and is considered equal to itself. So `...==...` evaluates to `True`. When you prefix a `True` with `-`, it is interpreted as a prefix negation operator and implicitly converts the `True` to a `1`, so `-(...==...)` is equal to `-1`. Then, you add another prefix `-` to turn the `-1` back into `1`.

`--(...==...)--(...==...)` evaluates to `2` because the first block evaluates to 1, as previously mentioned, and then the next `-` is interpreted as an infix subtraction operator. The second `-(...==...)` evaluates to `-1`, so you get `1 - -1` or `2`.

When chaining multiple together, you can leave off the initial `--`, because booleans will be implicitly converted to integers if inserted into an arithmetic expression, e.g. `True - -1` -> `1 - -1` -> `2`.

> There should be one-- and preferably only one --obvious way to do it.

This article is obviously completely tongue-in-cheek, but I feel the need to point out that this sentence is not meant to be a complete inversion of the Perl philosophy of TIMTOWTDI. The word "obvious" is crucial here - there can be more than one way, but ideally only one of the ways is obvious.

pletnes•11mo ago
Numpy actively uses … to make slicing multidimensional arrays less verbose. There are also uses in FastAPI along the lines of «go with the default».
abuckenheimer•11mo ago
excellent explanation, to add to this since I was curious about the composition, '%c' is an integer presentation type that tells python to format numbers as their corresponding unicode characters[1] so

'%c' * (length_of_string_to_format) % (number, number, ..., length_of_string_to_format_numbers_later)

is the expression being evaluated here after you collapse all of the 1s + math formatting each number in the tuple as a unicode char for each '%c' escape in the string corresponding to its place in the tuple.

[1] https://docs.python.org/3/library/string.html#format-specifi...

nomel•11mo ago
Expanding on this a little, I will be replacing all occurrences of 2 with two blobs fighting, with shields:

    >>> 0^((...==...)--++--(...==...))^0
    2
rmah•11mo ago
>> There should be one-- and preferably only one --obvious way to do it.

Except for package management, of course. There, we need lots and lots of ways.

blooalien•11mo ago
And apparently string formatting which should have an ever growing number of ways to handle it. :shrug:
elijahbenizzy•11mo ago
Ok do this but for JavaScript
voidUpdate•11mo ago
https://en.wikipedia.org/wiki/JSFuck
mariocesar•11mo ago
If you're curious, the code in ellipsis results in executing:

    print('hello, world')
mturmon•11mo ago
Thank you!

I noticed some ** and * in the thing sent to eval(), which (given that the building blocks are small integers) seemed related to prime factorizations.

The initial %c is duplicated 21 times (3*7, if I read correctly), and then string-interpolated (%c%c%c...) against a long tuple of integers. These integers themselves are composed of products of factors combined using * and **.

There is also one tuple "multiplication" embedded within that long tuple of integers -- (a,b)*2 = (a,b,a,b). That is for the 'l' 'l' in "hello".

It's all very clever and amusingly mathy, with a winking allusion to the construction of natural numbers using sets. It made me Godel.

callamdelaney•11mo ago
I think we're really starting to over crowd pythons syntax and I'm not a fan.
noddleah•11mo ago
you're telling me you never program in python elliptically??
acbart•11mo ago
Pretty sure this would have been possible in Python 2.6. The Ellipsis object has been around for a very long time.
MadVikingGod•11mo ago
This behavior can be replicated with any class that has two special methods: __neg__ that returns -1 and __sub__ that accepts ints and returns 1-other.

For example if you make this class:

  class _:
       def __neg__(self):
           return -1
       def __sub__(self, other):
           return 1-other
You get similar behavior:

  >>> --_()
  1
  >>> _()--_()
  2
Fun python for everyone.
maxloh•11mo ago
You can do this on JavaScript too.

  alert(1)
  // equals to:
  [][(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[+!+[]]]+[+!+[]]+([]+[]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[!+[]+!+[]]])()
https://jsfuck.com/

Cockpit is a web-based graphical interface for servers

https://github.com/cockpit-project/cockpit
146•modinfo•3h ago•87 comments

Astral to Join OpenAI

https://astral.sh/blog/openai
1180•ibraheemdev•10h ago•727 comments

Google details new 24-hour process to sideload unverified Android apps

https://arstechnica.com/gadgets/2026/03/google-details-new-24-hour-process-to-sideload-unverified...
425•0xedb•6h ago•504 comments

Bombarding gamblers with offers greatly increases betting and gambling harm

https://www.bristol.ac.uk/news/2026/march/bombarding-gamblers-with-offers-greatly-increases-betti...
22•hhs•1h ago•18 comments

How the Turner twins are mythbusting modern technical apparel

https://www.carryology.com/insights/how-the-turner-twins-are-mythbusting-modern-gear/
87•greedo•2d ago•44 comments

Return of the Obra Dinn: spherical mapped dithering for a 1bpp first-person game

https://forums.tigsource.com/index.php?topic=40832.msg1363742#msg1363742
222•PaulHoule•3d ago•31 comments

Show HN: Three new Kitten TTS models – smallest less than 25MB

https://github.com/KittenML/KittenTTS
294•rohan_joshi•8h ago•97 comments

EsoLang-Bench: Evaluating Genuine Reasoning in LLMs via Esoteric Languages

https://esolang-bench.vercel.app/
52•matt_d•3h ago•18 comments

Noq: n0's new QUIC implementation in Rust

https://www.iroh.computer/blog/noq-announcement
135•od0•5h ago•17 comments

Waymo Safety Impact

https://waymo.com/safety/impact/
184•xnx•3h ago•164 comments

Clockwise acquired by Salesforce and shutting down next week

https://www.getclockwise.com
61•nigelgutzmann•4h ago•37 comments

Be intentional about how AI changes your codebase

https://aicode.swerdlow.dev
55•benswerd•2h ago•23 comments

From Oscilloscope to Wireshark: A UDP Story (2022)

https://www.mattkeeter.com/blog/2022-08-11-udp/
70•ofrzeta•4h ago•12 comments

4Chan mocks £520k fine for UK online safety breaches

https://www.bbc.com/news/articles/c624330lg1ko
233•mosura•9h ago•374 comments

NanoGPT Slowrun: 10x Data Efficiency with Infinite Compute

https://qlabs.sh/10x
89•sdpmas•5h ago•14 comments

“Your frustration is the product”

https://daringfireball.net/2026/03/your_frustration_is_the_product
397•llm_nerd•12h ago•236 comments

Launch HN: Voltair (YC W26) – Drone and charging network for power utilities

45•wweissbluth•7h ago•23 comments

Scaling Karpathy's Autoresearch: What Happens When the Agent Gets a GPU Cluster

https://blog.skypilot.co/scaling-autoresearch/
112•hopechong•7h ago•55 comments

OpenBSD: PF queues break the 4 Gbps barrier

https://undeadly.org/cgi?action=article;sid=20260319125859
176•defrost•10h ago•54 comments

Juggalo makeup blocks facial recognition technology (2019)

https://consequence.net/2019/07/juggalo-makeup-facial-recognition/
220•speckx•10h ago•139 comments

Minecraft Source Code Is Interesting

https://www.karanjanthe.me/posts/minecraft-source/
18•KMJ-007•1h ago•6 comments

My Random Forest Was Mostly Learning Time-to-Expiry Noise

https://illya.sh/threads/out-of-sample-permutation-feature-importance-for-random
7•iluxonchik•3d ago•0 comments

An update on Steam / GOG changes for OpenTTD

https://www.openttd.org/news/2026/03/19/steam-changes-update
252•jandeboevrie•6h ago•180 comments

The Need for an Independent AI Grid

https://amppublic.com/
16•olalonde•2h ago•2 comments

Xiaomi launches next-gen SU7 with 902 km range and Lidar, still undercuts Tesla

https://electrek.co/2026/03/19/xiaomi-launches-next-gen-su7-902-km-range-undercuts-tesla/
62•breve•2h ago•27 comments

Tesla: Failure of the FSD's degradation detection system [pdf]

https://static.nhtsa.gov/odi/inv/2026/INOA-EA26002-10023.pdf
152•doener•3h ago•78 comments

Connecticut and the 1 Kilometer Effect

https://alearningaday.blog/2026/03/19/connecticut-and-the-1-kilometer-effect/
38•speckx•6h ago•25 comments

Android developer verification: Balancing openness and choice with safety

https://android-developers.googleblog.com/2026/03/android-developer-verification.html
22•WalterSobchak•3h ago•9 comments

The Shape of Inequalities

https://www.andreinc.net/2026/03/16/the-shape-of-inequalities/
90•nomemory•9h ago•14 comments

macOS 26 breaks custom DNS settings including .internal

https://gist.github.com/adamamyl/81b78eced40feae50eae7c4f3bec1f5a
308•adamamyl•8h ago•157 comments