# How to count bytes in languages with autoformatters [duplicate]

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.

• Related: scoring in Vim. – DLosc Oct 7 '16 at 20:17
• I don't really see how that's related... – James Oct 7 '16 at 20:20
• @DJMcMayhem This question essentially asks, "Are keystrokes directly comparable to bytes," like the Vim question does. – DLosc Oct 7 '16 at 20:26
• Its really related to this – Nathan Merrill Oct 7 '16 at 20:27
• 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? – Geobits Oct 7 '16 at 20:31
• @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. – DLosc Oct 7 '16 at 20:47
• @Geobits According to at least one source, QBasic 1.1 for DOS was not a sane IDE. – DLosc Oct 10 '16 at 4:18
• @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. – Geobits Oct 10 '16 at 4:21
• @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 – mbomb007 Oct 10 '16 at 18:53
• "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. – coredump Oct 13 '16 at 11:08

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

• 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. – Nathan Merrill Oct 10 '16 at 15:32
• Oh good I don't have to go back and change all of my AppleScript answers to correctly format their bytecount. relieved – Addison Crump Oct 11 '16 at 7:59

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

• 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. – DLosc Oct 10 '16 at 4:29
• ... 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. – DLosc Oct 10 '16 at 4:34
• What do you mean here? Do you mean that we need to count after autoformatting? – Erik the Outgolfer Oct 12 '16 at 15:44
• 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 – Taylor Scott Dec 28 '16 at 20:02