10
\$\begingroup\$

In QBasic, VBA, AppleScript, etc., there is an autoformatter that adds spaces and expands some syntactic sugar. For example, if I type this code:

?x*2

QBasic will expand it to

PRINT x * 2

Should I count this code as 4 bytes or 11?


Edit: Nathan Merrill brings up How to count bytes in macro heavy languages as a closely related question. I agree that it's related, but I don't think it's a duplicate. The reason why I asked this question is because the normal usage of these programming languages adds spaces automatically. It's not something that happens when the programmer chooses to expand macros--it's something that happens without any action on the programmer's part. It would be easy to conclude that the fully spaced version is the correct syntax of the language, and therefore that the condensed version is illegal for code golf submissions.

Here's a link to the answer that prompted me to ask this question. Also pertinent is this comment on my QBasic quine, which suggests that a quine using condensed syntax isn't valid because "the autoformatter can't be turned off" in QBasic 1.1.

\$\endgroup\$
10
  • \$\begingroup\$ Related: scoring in Vim. \$\endgroup\$
    – DLosc
    Oct 7, 2016 at 20:17
  • \$\begingroup\$ I don't really see how that's related... \$\endgroup\$
    – DJMcMayhem
    Oct 7, 2016 at 20:20
  • \$\begingroup\$ @DJMcMayhem This question essentially asks, "Are keystrokes directly comparable to bytes," like the Vim question does. \$\endgroup\$
    – DLosc
    Oct 7, 2016 at 20:26
  • 8
    \$\begingroup\$ Its really related to this \$\endgroup\$ Oct 7, 2016 at 20:27
  • 1
    \$\begingroup\$ It's been a long time since I've used Basic variants, but can't you turn off the auto formatting in any sane IDE? \$\endgroup\$
    – Geobits
    Oct 7, 2016 at 20:31
  • \$\begingroup\$ @Geobits Hm, that's an interesting question. I know you can in QB64, and I just found where you can in VBA. I don't recall such an option in DOS QBasic, but I may not have ever looked in the right menu. \$\endgroup\$
    – DLosc
    Oct 7, 2016 at 20:47
  • \$\begingroup\$ @Geobits According to at least one source, QBasic 1.1 for DOS was not a sane IDE. \$\endgroup\$
    – DLosc
    Oct 10, 2016 at 4:18
  • \$\begingroup\$ @DLosc Hmm. IIRC you can run directly from the command line, something like qbasic /run mything.bas. Now I wonder if that works with "unformatted" code. If so, I'd say it's still pretty obvious that it should count that way. \$\endgroup\$
    – Geobits
    Oct 10, 2016 at 4:21
  • \$\begingroup\$ @Geobits Idk how to do it in Visual Studio, and it autoformats .NET code. Edit: A short look shows you can. stackoverflow.com/a/5493003/2415524 \$\endgroup\$
    – mbomb007
    Oct 10, 2016 at 18:53
  • \$\begingroup\$ "It's not something that happens when the programmer chooses to expand macros--it's something that happens without any action on the programmer's part." Just to clarify: macros in Lisp are automatically expanded too. In fact it makes no sense to evaluate a form without performing macroexpansion first. The user can call macroexpand to control when it happens, but that's all. \$\endgroup\$
    – coredump
    Oct 13, 2016 at 11:08

2 Answers 2

24
\$\begingroup\$

Count code size before autoformatting

Rationale: You can type or paste unformatted code into the interpreter, hit run, and it works. The fact that the interpreter adds whitespace or expands shortcuts is irrelevant. If you typed 4 bytes, the size of your program is 4 bytes.

Rationale 2: Geobits points out that many IDEs have an option to turn autoformatting off. In this case, it's even clearer that the unformatted code is legitimate code that the interpreter can run directly.

\$\endgroup\$
2
  • \$\begingroup\$ Even if the code is dependent on the IDE, you can still count it that way, but the technical "language" would then be the IDE+interpreter. \$\endgroup\$ Oct 10, 2016 at 15:32
  • 1
    \$\begingroup\$ Oh good I don't have to go back and change all of my AppleScript answers to correctly format their bytecount. relieved \$\endgroup\$ Oct 11, 2016 at 7:59
0
\$\begingroup\$

Count file size

Why not use the original scoring mechanism and just use the byte count of the source file?

This can be quite effective due to the fact that BASIC languages often use tokenisation, shortening the length of the file.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ QBasic-based response, may apply to other languages too: This could work as long as you write the file in a text editor other than the QBasic IDE. (I've done this once.) Otherwise, the autoformatter kicks in before you can save the file, meaning the source file will have all the extra spaces in it. And even in QB64 with the autoformatter turned off, the file will always have a trailing newline, which I'm not in the habit of counting in my submissions. \$\endgroup\$
    – DLosc
    Oct 10, 2016 at 4:29
  • \$\begingroup\$ ... This not to mention the Windows \r\n newline convention, which I'm also not in the habit of counting in my submissions. You can get 1 byte per newline by counting keystrokes OR by writing the code in Notepad++ with Unix-style newlines. I've successfully run such code files in QB64. However, I haven't been able to test this approach against DOS QBasic. \$\endgroup\$
    – DLosc
    Oct 10, 2016 at 4:34
  • \$\begingroup\$ What do you mean here? Do you mean that we need to count after autoformatting? \$\endgroup\$ Oct 12, 2016 at 15:44
  • 3
    \$\begingroup\$ This would effectively kill VBA for code-golf - a blank .xlsm file called a.xlsm with one worksheet and one VBE code module has a file size of 10,970 bytes \$\endgroup\$ Dec 28, 2016 at 20:02

Not the answer you're looking for? Browse other questions tagged .