It would be great to have an option in answers to add metadata. (This would be most useful for questions tagged , but maybe also other tags?) You would be able to put in the language, the golfed code, current byte count, and old byte counts. Then the data could be used to sort answers by "best score", or even to make graphs of language usage and score. Those graphs could tell us surprising things (and not-so-surprising things, like that Java would be in a certain corner and J in the other.)

Here is some HTML for it (put this after the <h2 class="space">Your Answer</h2>):

<div id="metadata">
    <label>Language: <input id="metadata-byte-count" list = "langs"></label>
<datalist id="langs">
<option value="JavaScript">
<option value="JavaScript (ES6)">
<option value="Java">
<option value="C">
<option value="C++">
<option value="C#">
<option value="J">
<option value="GolfScript">
<option value="Japt">
<option value="F# ">
<option value="Batch">
<option value="Python">
<option value="05AB1E">
<option value="Ruby">
<option value="V">
<option value="MATL">
<option value="PHP">
<option value="PowerShell">
<option value="Swift">
<option value="Convex">
<option value="05AB1E">
<option value="Mathematica">
<option value="Excel">
<option value="R">
<option value="Jelly">
</datalist>
<label style="
    display: block;
">Golfed code: 
  <textarea style="
    padding: 2px;
    display: block;
    width: 300px;
"></textarea></label>
  <label>Current byte count: <input type="number" id="metadata-byte-count" style="
    font-size: 13px;
    padding: 2px;
">
bytes</label>
<a href="https://codegolf.meta.stackexchange.com/questions/10145/how-to-count-bytes-faq" style="
    display: block;
">Need help counting bytes?</a>
  <h3 style="
    font-size: larger;
    display: inline-block;
    padding-right: 20px;
" class="space">Old byte counts</h3>
  <input type="button" id="metadata-add-old-byte-count" value="Add old byte count">
  <div id="metadata-old-byte-counts">
  <label><input value = "x" type = "button" style="
    padding: 0.14em 0.5em;
    font-size: smaller;
    margin-right: 2px;
"><input type="number" class="old-byte-count" style="
    padding: 0;
  "> bytes</label>
  </div>
  </div>

Wanna try it out?

body,html{/*Fix a SE style issue that causes lots of vertical scroll*/min-width: 100% !important;}h2{font-weight: 400; }
<link href=https://cdn.sstatic.net/Sites/codegolf/all.css rel=stylesheet><h2 class=space>Your answer here</h2><div id="metadata"> <label>Language: <input id="metadata-byte-count" list="langs"></label> <datalist id="langs"> <option value="JavaScript"> <option value="JavaScript (ES6)"> <option value="Java"> <option value="C"> <option value="C++"> <option value="C#"> <option value="J"> <option value="GolfScript"> <option value="Japt"> <option value="F# "> <option value="Batch"> <option value="Python"> <option value="05AB1E"> <option value="JS "> <option value="Ruby"> <option value="V"> <option value="MATL"> <option value="PHP"> <option value="PowerShell">  <option value="Swift"> <option value="Convex"> <option value="05AB1E"> <option value="Mathematica"> <option value="Excel"> <option value="R"> <option value="Jelly"> </datalist> <label style=" display: block; ">Golfed code: <textarea style=" padding: 2px; display: block; width: 300px; "></textarea></label> <label>Current byte count: <input type="number" id="metadata-byte-count" style=" font-size: 13px; padding: 2px; "> bytes</label> <a href="https://codegolf.meta.stackexchange.com/questions/10145/how-to-count-bytes-faq" style=" display: block; ">Need help counting bytes?</a> <h3 style=" font-size: larger; display: inline-block; padding-right: 20px; " class="space">Old byte counts</h3> <input type="button" id="metadata-add-old-byte-count" value="Add old byte count"> <div id="metadata-old-byte-counts"> <label><input value="x" type="button" style=" padding: 0.14em 0.5em; font-size: smaller; margin-right: 2px; "><input type="number" class="old-byte-count" style=" padding: 0; "> bytes</label> </div></div>

Of course, this data would be available via the API and maybe even under /tools (>=2k rep only).

Maybe a UTF-8 byte counter embedded in? Or better yet, a byte counter that recognizes the language specified and picks it from there?

Note that this contains a dropdown / input that prevents us from getting 'dirty' language data (eg. "JS", "Javascript", "Java Script", "JavaScript", etc.) but still allow for obscure languages.

Any questions, ideas, comments, or waffles? Comment or answer below!

  • 1
    Interestingly, the sidebar shows How to count bytes FAQ in the sidebar, even though it is only in the snippet. – programmer5000 Apr 18 '17 at 17:24
  • This should be part of the userscript – dkudriavtsev Apr 18 '17 at 17:37
  • @Mendeleev maybe, but then it can't connect with the SE backend. – programmer5000 Apr 18 '17 at 17:39
  • I wonder if having the leaderboard by default would make more people use the header format – jrtapsell Feb 1 at 16:51

Interesting idea, but not worth inclusion

For starters, as-is, this would be adding something like 2KiB of stuff to each answer. Not only does that cause less room for the meat of the answer (which is already limited to 30,000 characters), it also causes additional download for users on mobile or other data-limited plans.

Second, and more important, answering a challenge here is already hard enough for new users to get right. This is something that has been complained about time and time again (Martin has a good summary of links at the top of this post specifically regarding golfing languages, in addition to the literally dozens of other Meta posts by new users). Adding an additional hurdle beyond all the already-existing FAQs, header styling, byte counting, etc., is just going to lead to additional frustration for new users, the exact opposite of what we want.


(NB - If this is something that could be implemented at the site level automatically, sure, it could be an interesting addition. However, given our beta-not-a-beta graduated-but-not-quite-fully status, and that the parent site is kind as to allow us to exist even though we don't really fit their model for the rest of their sites, I don't see SE developer resources being allocated to this.)

I may be missing something, but it seems to me that the snippet adds a little form to the answer but doesn't store the data anywhere. Does it really add metadata to the answer?

A better way of adding language metadata would be to use the prettify tags <!-- language: lang-java --> etc. The problem there is that support is lacking for most languages used on this site. But trying to add support for those languages might be the most practical way of pushing this issue forward, if you feel strongly enough about it to invest the considerable amounts of time that would be required.

  • The snippet was just an example of how the front-end experience might look like. – programmer5000 Apr 18 '17 at 21:22
  • I am not allowed to modify the backend, so I can't implement that. – programmer5000 Apr 19 '17 at 17:26
up vote 0 down vote accepted

Might make things easier for us, not harder.

Problems (current and future):

Hard for new users to understand formatting

Instead of having special code formatting, the # Language, bytes <s>old bytes</s> header, etc. this could be an opportunity to make things easier for new users. Basically, you enter code in the code box, your language in the language box, and the explanation where they currently put the whole post.

Results in answers that take up more storage space

To the argument of this taking up more storage space, it could be encoded like this:

{
  "lang": "yourlanguage",
  "bytes": 4,
  "oldbytes": [444, 44],
  "postBody": "Blah blah explination"
}

Crossed out 44 is still 44

Minifyed and using small property keys:

{"l":"yourlanguage","b":4,"o":[44,444],"p":"Blah blah explanation"}

Compared to a standard answer:

# yourlanguage, 4 <s>44</s> <s>444</s> bytes
Blah blah explanation

Byte count: 66 to 67. We could use a terser data format than JSON and come out ahead. I think 7 bytes longer answers shouldn't impact our answer limit too much.

Hard for new users to understand golfing

When the code box gets full or has a lot of whitespace, we could show a message telling the user to remove whitespace and otherwise lower their byte count (with lots of links to meta posts.) The current explanation is confusing; at least one user thought they were supposed to optimize their code to make it run faster. When the code entered in the box matches the regex [\s\S]{300,}|([^\t]+\t){5,}|([^ ]+ ){10,}, we can show them a warning:

Can you try to reduce the byte count of your submission? You might be interested in some tips.

Note that the tips link goes to .

The code box could show a (UTF-8) byte counter for a set of languages known to use UTF-8, like JS, Java, C/++/#, Python, and not show it for others.

We don't get the current formatting / this will break the leaderboard snippet!

The generated Markdown from the metadata and the explanation would be what is currently suggested for answers. It might look like this:

# yourlanguage, 4 <s>44</s> <s>444</s> bytes

    Your code here

Blah blah explanation

Same thing. Just with a better user experience, and metadata on the backend that we could use to get cool graphs of how bad Java does, popular language submissions, average scores per tag, average scores per user, and how often people outgolf Dennis.

  • This definitely makes things harder for us. Code sometimes contains unprintable ASCII, or characters that would have to be HTML-escaped. It could probably create security vulnerabilities, too. – mbomb007 Apr 19 '17 at 18:35
  • @mbomb007 why security? How would it be more vulnerable? And how is unprintables more of a problem with this than now? And it would need to be HTML-escaped, but the Markdown parser would do that, just like for the current code blocks. – programmer5000 Apr 20 '17 at 16:48
  • I was talking about if it was done on the back end, for that part. Sort of referencing PeterTaylor's answer. – mbomb007 Apr 20 '17 at 16:50
  • Could be useful, at the moment the best option is to parse the html to try to infer the metadata using SEDE, and you can't use regex for that... – jrtapsell Jan 30 at 12:17
  • This shows that there are a lot of headerless answers (5724 at the moment) – jrtapsell Jan 30 at 12:38

For new answers

It might be possible to recommend having a header at the top of an answer something like this, maybe with a UI like the one @programmer500 suggested:

<!-- CG{"lang":"Kotlin", "size":[100,99,98]} -->

The idea of it being that it is JSON, so parsing it in the dump should be easy, and if more metadata wants to be added it can be while keeping backwards compatibility, the CG tag should make it easy to reduce the number of false positives being found.

For old answers

It would seem that headers at the moment are quite mixed, based on analysis of the current dump data the breakdown of first tags in looks like this:

  • h1=67904
  • h2=20315
  • p=3144
  • h3=983
  • pre=68
  • blockquote=15
  • ol=13
  • ul=11
  • hr=4
  • strike=1

This may prevent all of the answers being automatically changed over, but as most of the answers follow a standard format it should mean that the rest can be dealt with manually.

Using a version of the leaderboard regex that allows a few more separators I am working on finding all the posts with no header, the gist I will update is here.

  • I'm curious: how'd you get that dump of first tags? – Riker Jan 31 at 19:20
  • 1) Download Dump, 2) Filter only posts whose parent has the tag code-golf, 3) Take the first line and get the first tag with Jsoup (All in Kotlin) – jrtapsell Jan 31 at 19:33

You must log in to answer this question.

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