Skip to content
DevMeme
3110 of 7590
Languages Post #3428 · source on Telegram

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

21
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. Anonymous

    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

  3. Anonymous

    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

  4. Anonymous

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

  5. Anonymous

    Swift type checker: proving circular dependencies scale perfectly - to 100% CPU and room-temp nirvana

  6. Anonymous

    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)

  7. Anonymous

    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

  8. @fuutea 5y

    damn

    1. @VladislavSmolyanoy 5y

      same

    2. @rostopiradv 5y

      This post is 2 years old, so it has already been fixed

      1. @NiKryukov 5y

        So no more free heating, so sad

        1. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

          Trick the compiler

        2. @walkersubterra 5y

          Just take an old version to use this heating

        3. @DTSHNICK 5y

          +

      2. @bekzat_karayev 5y

        yeah that's true

  9. @pyproman 5y

    Or bruh:for(;;){goto bruh;}

  10. @Jeffeek 5y

    Circular dependency, it's impossible

  11. @Vlasoov 5y

    error: B is not declared in this scope 😎

  12. @bekzat_karayev 5y

    I used to do that, now I just turn on couple of dozens gpus to mine dogecoin 24/7

  13. @bekzat_karayev 5y

    my room is hotter than outside in july😂

  14. @ozalexo 5y

    Too old. 2019

Use J and K for navigation