10
\$\begingroup\$

The title pretty much says it all. If I use tabs/spaces for making the code more readable, do I have to count them?

Also, are line breaks counted as one character(\n) or as two (\r\n)?

\$\endgroup\$
3
\$\begingroup\$

Whitespace is only counted when necessary, but unnecessary whitespace should still be avoided in golfed code

I think any whitespace unnecessary for execution may be excluded from the byte count, as long as it is mentioned in the answer and not required by the challenge.

In my opinion the best way to make your submission more readable is to post both

  • the golfed version with anything unnecessary (including whitespace) removed and
  • the (possible) ungolfed version with extra whitespace, readable identifiers, etc. to make understanding the solution easier.

This allows for easy checking of your score, while still giving readers an easier way of understanding your code.

Linebreaks are counted as \n, if possible

If the program works correctly with \n in the file instead or \r\n, then you can claim the byte count of the program with \n's. If, however, your interpreter/compiler requires you to use \r\n, you should switch interpreters count the linebreaks as 2 bytes.

\$\endgroup\$
  • 3
    \$\begingroup\$ I can't decide if I should down- or upvote this. Your leading headline implies that it's completely acceptable to post only an ungolfed version and ignore all unnecessary whitespace when counting. I don't think we should encourage that (and I'm quite sure there's a consensus against that on meta already, I'll search for it later). But then you suggest that a golfed and ungolfed version should be posted separately, which I agree with - but then in that case, there is no unnecessary whitespace to be counted in the golfed version. So what are you actually proposing? \$\endgroup\$ – Martin Ender Sep 4 '15 at 9:41
  • \$\begingroup\$ @MartinBüttner Is it better now? \$\endgroup\$ – PurkkaKoodari Sep 4 '15 at 9:44
  • 4
    \$\begingroup\$ I don't know... I'm still reading "it's not recommended, but totally legitimate to leave unnecessary whitespace in your answer". I might just write up a stricter separate answer later and we can see how people vote. \$\endgroup\$ – Martin Ender Sep 5 '15 at 18:22
31
\$\begingroup\$

(This answer is quite similar to Pietu's but a bit stricter on the first question.)

Count the code as posted. If there is unnecessary whitespace, remove it.

This makes it easier for everyone else to check your score. For someone who doesn't know your language it can be hard to tell which spaces are necessary (and counted) and which not. Furthermore, I think people who post code with unnecessary spaces left in (but who don't count them) often don't test if all the spaces are actually unnecessary. In some languages I've used, I sometimes think I can just strip all spaces at the end, but then it breaks unexpectedly (I'm thinking Ruby and Mathematica, but there are certainly others).

If you want to provide a more readable version with indentation etc., include it in your answer separately, but the counted code should always appear first. As an example, here is one of my Mathematica answers which does this.

Newlines are counted as \n, if possible

On this account I agree with Pietu: unless your code only works with \r\n, count it as a single character (i.e. usually as a single byte, unless you use UTF-16, say).

\$\endgroup\$

You must log in to answer this question.

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