8
\$\begingroup\$

I've noticed something while looking at code golf challenges that seems troubling, I'm going to use answers taken from

Fast, Cheap, and Good - Choose any Two

But I have seen this on other questions as well.

Looking through the answers, the answers that use script languages all appear to be cheating! Take a look at this answer provided by @Matt

b="input",a="<input type=checkbox>",c=":checked";$("body").html("SELECT ANY TWO"+a+"FAST"+a+"GOOD"+a+"CHEAP").click(function(){$(b).not(c).attr("disabled",!!$(b+c)[1])})

While this is all well and good, this snippet of code is not complete, in order for this to run (at the very least) you would have to include the jquery library either from a CDN or from a local resource and then wrap your code in a script tag.

<script src="somelocation/jquery.js"></script>
<script>
  //code
</script>

None of this is included in this total, but all the compiled languages include everything required to make the program actually run (including import statements)

https://codegolf.stackexchange.com/a/26803/21210
https://codegolf.stackexchange.com/a/26853/21210

This is not limited to jquery only, here is a similar answer using angular: https://codegolf.stackexchange.com/a/26851/21210

Seems to me in a battle to get the lowest amount of characters in source code, that all languages should be held to the same standard.

\$\endgroup\$
9
\$\begingroup\$

The issue is this snippet from the tag wiki's listed requirements:

How should the answer be presented – should a bare function be acceptable, or it must include full input/output code?

This is not always included. If this is supposed to be a requirement, then the problem is the question, not the answers.

In the example linked question, the task is:

You should render a set of three check boxes...

Where it could say:

Write a program that will render...

Write a function that will render...

A simple change is all it takes to make it clear what an answer should consist of. You'd also have much better grounds for a complaint against an answer that doesn't meet it. As it stands, you cannot blame people (much) for taking advantage of ambiguity. From what I've seen, that's par for the course here (pun very much intended).


That said, if the question is specified as a complete program, I think you have a valid point. It may be hard coming up with perfect rules for every language, though.

\$\endgroup\$
  • \$\begingroup\$ This certainly seems like the most reasonable solution. \$\endgroup\$ – iamkrillin May 10 '14 at 13:26
6
\$\begingroup\$

I agree with you in part.

While this is all well and good, this snippet of code is not complete, in order for this to run (at the very least) you would have to include the jquery library either from a CDN or from a local resource and then wrap your code in a script tag.

<script src="somelocation/jquery.js"></script>
<script>
  //code
</script>

The part I agree with is that using jQuery should not be free unless the question says that libraries may be imported for free. While there will always be some unfairness because different languages have different standard libraries, it's not reasonable to argue that jQuery is a part of JavaScript. There's probably a minified URL for it which is about as long as http://u.rl/123456, so a character count for <script src="//u.rl/123456"></script> is probably reasonable. (I can also see an argument for a much longer piece of code to insert the script tag into the document from JS). Downvote answers which try to cheat here, and if you want to draw more attention to them you could mention them in chat.

But I don't agree that we should count a script tag to wrap the code. When counting bytes for a compiled language, we don't count the compiler invocation (except for non-standard flags which are required to make that particular program work correctly) or the program invocation from the shell. We count the size of the source file. Similarly, <script src="myProgram.js"></script> should be free.

\$\endgroup\$
0
\$\begingroup\$

I'll weigh in here since I asked the Fast, Cheap, and Good - Choose any Two question.

All the answers depend to some degree on a framework. The main stipulation was to "use the checkbox control in the language of your choice". In jQuery or JavaScript, this would of course be a standard HTML checkbox input element.

But I think the bigger issue is that it sorts itself out. Consider that one of the points of allowing multiple languages or execution contexts is that there could be multiple winners. If we are comparing apples to apples, then it makes no difference if all jQuery answers are required to include the script tag - they simply all get longer by the same amount.

I can see awarding a 300b c++ answer over a 150b jQuery answer. Many times it will depend on the background of the asker. If he sees more cleverness in the c++ answer, then by all means give that one the nod.

Having said all this, I can definitely understand why jQuery without the include statement ruffles some feathers. If we consider the browser the context, then JavaScript is free, but jQuery would not be. So I would award a pure JavaScript answer higher.

I think there's also an issue that relates to the appropriateness of the tool for the task. Whether it's fair or not, some questions will by their very nature favor one language over another.

\$\endgroup\$
  • \$\begingroup\$ I see what your going for here, but if you consider the browser the context, the awarded answer would not run at all. Instead, the source code would simply be displayed on the screen (hence why I asked this question here) \$\endgroup\$ – iamkrillin May 10 '14 at 17:50
0
\$\begingroup\$

if we consider that the import of a jQuery interpreter or CoffeeScript compiler be included on the count, shouldn't we also add the import of the GolfScript? (as in ruby g.rb for 10 chars)

I can execute jQuery code in a lot of web contexts without need of importing it (such as stackexchange.com itself)

On the other hand, the argument that it is an import like in C, C#, Java or Python seems valid. Maybe we can provide a standard script tag with a minified URL that could be used by all jQuery answers so they don't compite to see who has the shorter tag.


About being some snippet of javascript being a complete program, I think it depends on the needed context.

If the code just calculates a numerical value, it can be a program by itself, since I can pass it to node, rhino or whatever standalone engine and it will give me a result.

But if the code needs an HTML context, such as modifying/accesing DOM (in the example $("body") or using alert/prompt, the minimun code needed for a document to be interpreted as HTML+js (even if it doesn't use jQuery) is

<script>[code]</script>

that implicitly declares a <html> root, with an implied <head> with a single <script> child and and empty body. Otherwhise, a standalone engine would fail since there is no document, and a browser would treat it as plain text

\$\endgroup\$
  • 1
    \$\begingroup\$ jQuery is a library for javascript rather than an interpreter for another language. It's not the same as the relationship between GolfScript and Ruby. \$\endgroup\$ – Gareth May 12 '14 at 18:55
0
\$\begingroup\$

I've only used jQuery in that answer, as it was mentioned in the original question, and not specifically referred to as not allowed or requiring extra points added to the score, etc. I agree that answers with jQuery should be treated differently (JS or JS+jQuery, etc.) as it's an external library, but I think that's up to the OP and it should be clarified per question, if not mentioned.

\$\endgroup\$

You must log in to answer this question.

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