1. 32
    1. 20

      I always thought that (after the empty file) the most boring python quine was:

        File "/tmp/quine.py", line 3
          File "/tmp/quine.py", line 3
      IndentationError: unexpected indent
      
      1. 4

        That’s a pretty cool one!

    2. 10

      Surely the most boring quine is the empty python file?

      1. 9

        My favourite quine, which is almost as boring, is:

        #!/bin/cat
        
      2. 3

        Empty shell script, don’t even need shebang

      3. 2

        The navel gazing thing (that disqualifies what I wrote as well) is that you do want to reproduce a shebang for it to be really really a quine. Though what’s “really a quine” for things that aren’t like… compiled binaries is very much in the eye of the beholder

        1. 2

          You don’t need one if it’s invoked as python empty_file.py.

    3. 6

      Languages where you can embed arbitrary files have very boring Quines. :-) Here’s a very boring Go one:

      package main
      
      import (
      	_ "embed"
      	"fmt"
      )
      
      //go:embed main.go
      var self string
      
      func main() {
      	fmt.Println(self)
      }
      

      Zig comptime would probably be the best elaborate but boring Quine maker.

      1. 1

        Very clever!

      2. 1

        Does this rely on you writing the output out to a file called main.go? I’m curious but not curious enough to try it out

        1. 3

          main.go is the traditional filename for single file Go programs.

        2. 1

          The source file needs to be named main.go, but the executable can be named anything.

    4. 6

      According to Douglas Hofstadter, who first introduced the idea of a quine program in “Godel, Escher, Bach”, a quine program reproduces itself using indirect self reference, named after an idea first described by logician W.V.O.Quine. The whole point of the exercise is to demonstrate and illuminate Quine’s idea of self reference.

      By this original definition, an empty shell script or python script is not a quine, because there is no self reference.

      Here is Hofstadter’s original quine program, written in a made-up language:

      DEFINE PROCEDURE "ENIUQ" [TEMPLATE]: PRINT [TEMPLATE, LEFT-BRACKET, QUOTE-MARK, TEMPLATE, QUOTE-MARK, TEMPLATE, QUOTE-MARK, RIGHT-BRACKET, PERIOD].
      ENIUQ['DEFINE PROCEDURE "ENIUQ" [TEMPLATE]: PRINT [TEMPLATE, LEFT-BRACKET, QUOTE-MARK, TEMPLATE, QUOTE-MARK, TEMPLATE, QUOTE-MARK, RIGHT-BRACKET, PERIOD].
      ENIUQ'].
      

      The “self reference” is achieved by the template string that is passed as the argument to the ENIUQ procedure.

      @rtpg’s solution:

      t = 't = %r\nprint(t %% t)'
      print(t % t)
      

      is similar to Hofstadter’s original, with some differences:

      • Instead of defining a function with a template parameter, the template string is stored in a variable t. In both cases, the parameter or variable is referenced twice.
      • The Python %r substitution eliminates the verbosity required by the original.
    5. 3

      Wow, Spoilers!

      I would encourage anyone who hasn’t to take a hand at writing a quine themselves before reading this article. The key insight produced by the quine exercise relates to the concept of “code as data”, not how boring a quine is in a given implementation or the steps you had to take to get there.

      1. 4

        So… I wrote this partly because I read the first article on Quines that comes up in a DDG search (that I linked to in the beginning of the article). It goes super into “code as data”, but I find it kind of funny that the “code” that is being embedded is not C code nor Python code, but print/printf format syntax code!

        Like there is nothing about this exercise where I am treating Python code as data. I have code, and then I also am just reproducing it in the template. But I am treating a template string as code.

        In a way this is revealing the unfortunate truth that while we’re not really cheating with Python tooling, we are just using Python as a way of calling a “print string compiler” and then printing out the source text.