(Error) quines, hello world, polyglots, oh my!

C, Bash, C++, score 174.5 175

C, 301 bytes - Quine

#include<stdio.h>
int main(){
#ifdef __cplusplus
printf("Hello, World!"
#else
char*c="#include<stdio.h>%cint main(){%c#ifdef __cplusplus%cprintf(%cHello, World!%c%c#else%cchar*c=%c%s%c;printf(c,10,10,10,34,34,10,10,34,c,34,10,10%c#endif%c);}//";printf(c,10,10,10,34,34,10,10,34,c,34,10,10
#endif
);}//

Try it online!

Bash, 48 49 bytes - Error quine

.code.tio: line 1: .code.tio:: command not found

Try it online! (the trailing newline was added, see comments)

C++, 349 350 bytes - Hello, World!

#include<stdio.h>
int main(){
#ifdef __cplusplus
printf("Hello, World!"
#else
char*c="#include<stdio.h>%cint main(){%c#ifdef __cplusplus%cprintf(%cHello, World!%c%c#else%cchar*c=%c%s%c;printf(c,10,10,10,34,34,10,10,34,c,34,10,10%c#endif%c);}//";printf(c,10,10,10,34,34,10,10,34,c,34,10,10
#endif
);}//.code.tio: line 1: .code.tio:: command not found

Try it online!


Explainations and notes

The C quine is inspired by this C quine (the short version), and contains C++ code for the Hello, World!.

The Bash error quine works due to the TIO implementation, but given that error messages are generally implementation defined, it might be hard to print them in some standard way (other than directly outputting to stderr, which is just like a regular quine... how unoriginal would that be). The submitted Bash program may be an invalid Bash program, but it is still a valid error quine in Bash. (Edit: note the trailing newline that is now legal to output.)

The C++ Hello, World! doesn't output a trailing newline, but the challenge doesn't require it. After the preprocessor preprocessing, the only code source left is the main function with a simple printf call.

What was used in this answer are similarities between C and C++, very useful for polyglots (C is not entirely contained by C++, but it is contained enough) (for example: the usage of the C standard library is almost the same in these two languages which allows for a single #include directive, the main function definition is also similar enough to factorize the beginning and end out of the preprocessor-picked variations). The preprocessor and the __cplusplus macro are almost necessary at this point as they allow the C and C++ interpreters (or compilers, whatever) to pick only a specific subset of the program. The trailing line comment // ensures that the concatenation with a TIO Bash error doesn't upsets the C++ parser as it will completely ignore it.

I didn't find a way to to golf it even further. An other approach or a different set of languages are probably to be considered. For example, maybe using Argh! or INTERCAL for the error quine (or any other language in which error output is part of the language specification (these languages are rare, even among esolangs)). It might also be more interesting to use an other strategy than this """polyglot""" that makes each language ignore the code designed for the other languages instead of actually running most of the code.


MathGolf, gnuplot, Underload, score: 33.5

MathGolf, 9 bytes (Quine)

ÿ'ÿ\_'ÿ\_

Try it online.

gnuplot, 58 bytes (Error quine)


(Hello, World!)S
^
".code.tio", line 2: invalid command


With one leading and two trailing newlines.

Try it online.

Underload, 67 bytes (Hello, World!)

ÿ'ÿ\_'ÿ\_
(Hello, World!)S
^
".code.tio", line 2: invalid command


With two trailing newlines.

Try it online.

Explanation:

MathGolf:

ÿ          # Push a string of four characters: 
 'ÿ\_      #  "'ÿ\_"
     'ÿ    # Push character "ÿ"
       \   # Swap the top two values on the stack
        _  # Duplicate the top value on the stack
           # (after which the entire stack joined together is output implicitly)

gnuplot:

I've never used gnuplot before, but I simply tried random languages on TIO that contains (Hello, World!)S for the Underload program, and result in an error quine at the same time, of which gnuplot was one of the few, and the shortest I could find.

It will ignore the leading newline, and then complain about the (Hello, World!)S being invalid on line 2. Everything after that is fortunately enough ignored.

Underload:

Underload will simply print everything between (...)S, which is the intended Hello, World! in this case. It does give an error due to the rest of the program, but we can ignore STDERR and only look at the STDOUT, which is allowed by default.


V (vim), ><>, Help, WarDoq!, score 16

V, 6 bytes (Quine)

H2aH2a

Try it online!

H      # move cursor to first non-blank character (effectively no-op)
 2a    # twice append
   H2a # literal characters

><>, 26 bytes (Error quine)

something smells fishy...

Try it online!

Note the trailing newline. Quoting from Esolangs:

Although there are multiple reasons an error may occur, there is only one error message: something smells fishy...


Help, WarDoq!, 32 bytes (Hello, World!)

H2aH2asomething smells fishy...

Try it online! Link is to an interpreter in CJam identical to the reference implementation described at Esolangs. The code (without the trailing newline, due to technical limitations) can also be run from the CJam interpreter linked at Esolangs, but it unhelpfully combines STDOUT and STDERR into one output field.

H                               # print 'Hello, World!'
 2                              # ignored
  a                             # throws an error: attempts to read two integers from STDIN and XOR them
   H2asomething smells fishy... # (not executed)