Turn Your Mac Into a Space Heater with Two Lines of Swift
Description
A screenshot of a tweet from Paul Hudson (@twostraws). The tweet humorously suggests that adding two lines of Swift code to an Xcode project can heat up a room. The code snippet shows two classes, A and B, inheriting from each other (`class A: B {}` and `class B: A {}`), creating a circular inheritance dependency. This is a classic computer science joke that plays on the idea of causing a compiler or runtime to get stuck in an infinite loop, consuming maximum CPU resources and generating significant heat. The joke is particularly relevant to developers working with compiled languages like Swift, who understand that the compiler's attempt to resolve this logical impossibility will lead to a system freeze or crash, effectively turning the CPU into a heating element
Comments
21Comment deleted
This is the most elegant way to trigger thermal throttling I've ever seen. It's not a bug, it's a feature for cold winter mornings during sprint planning
Facilities cut the heating budget, so I spun up a Swift project with `class A: B` and `class B: A`. Nothing warms the room faster than a type checker stuck topologically sorting a graph that isn’t a DAG
The real genius of Swift's type system: it doubles as a distributed heating solution for open-plan offices. Just deploy this pattern across your CI/CD pipeline during winter months and watch your AWS bill compete with your heating costs
Ah yes, the classic 'turn your MacBook Pro into a space heater' optimization technique. This circular generic constraint is essentially a type-checker DoS attack - the Swift compiler enters an infinite loop trying to resolve whether A inherits from B or B inherits from A, maxing out CPU cores while your laptop's fans achieve liftoff velocity. It's the compiler equivalent of 'this statement is false,' except instead of a philosophical paradox, you get thermal throttling and a $3000 hand warmer. Senior engineers know this is why we have compilation time budgets and why that innocent-looking two-line 'refactor' can turn your build time from 30 seconds to 'heat death of the universe.'
Swift type checker: proving circular dependencies scale perfectly - to 100% CPU and room-temp nirvana
Mutual inheritance: the design pattern that converts reference cycles into thermal cycles - Swift’s type checker goes O(heater) while your architecture goes O(facepalm)
Pro tip: declare class A: B and class B: A in Swift; the type checker will hunt for a least fixed point while your Mac demonstrates the Space Heater pattern
damn Comment deleted
same Comment deleted
This post is 2 years old, so it has already been fixed Comment deleted
So no more free heating, so sad Comment deleted
Trick the compiler Comment deleted
Just take an old version to use this heating Comment deleted
+ Comment deleted
yeah that's true Comment deleted
Or bruh:for(;;){goto bruh;} Comment deleted
Circular dependency, it's impossible Comment deleted
error: B is not declared in this scope 😎 Comment deleted
I used to do that, now I just turn on couple of dozens gpus to mine dogecoin 24/7 Comment deleted
my room is hotter than outside in july😂 Comment deleted
Too old. 2019 Comment deleted