4
\$\begingroup\$

While C and similar languages provide beautiful and entertaining (and very hard) possibilities for golfing and obfuscation, most code-golf problems on this site have a golfscript solution, or a solution using the unix shell or some scripting language. This is frequently due to the overheads present in structured languages (variable declaration, library imports, "int main(){}", etc.)

This quest to find a problem where Java wins gave me the idea:

Write a code golf problem, where C-like or otherwise structured languages have an advantage against scripting languages. (and against esoteric languages, regular expressions, etc.)

The languages which have an advantage must have variable declarations, and must provide at least structural programming, or better yet, OOP. The more "C-like", the better (C, C++, Java, C#, etc.)

The problem should generally favor these languages, not just be a problem where one specific language with one specific compiler wins due to generating a unique error message long enough to be infeasible to be implemented with a shorter code in any other language.

As the criteria are highly subjective (language choice, what defines a "scripting language", what the advantage should be, etc.), the winner will be solely decided by votes.

The answer with the highest vote count will be selected as winner, not sooner than 10 days after the first answer gets a higher than zero score.

An example would be a code-golf problem, where a C and a Pascal program would fare better than golfscript or a shell script. I don't even know if it is possible, but there are a lot of smart people out there.

EDIT: Ultimately the voters decide, but if you think you can outsmart the rules, you can do it, if you believe the voters would like it. However, to limit the number of trivial answers, it would be better if the answers would feature programs which really did something useful, so: they should have input and they should have output depending on it. This is a recommendation, not a hard rule, so if you think you can convince your voters, it's your choice...

\$\endgroup\$
  • \$\begingroup\$ Should this be on meta rather than main? \$\endgroup\$ – Peter Taylor Sep 9 '12 at 7:23
  • 1
    \$\begingroup\$ @PeterTaylor that was my first thought too. But IMO it is an interesting open-ended problem, so I figured “why not?” \$\endgroup\$ – J B Sep 9 '12 at 9:35
  • \$\begingroup\$ Pretty difficult. There are compilers such as tcc that make it possible to use C code like a scripting language, which blurs the line between "compiled" and "scripting" languages. Should I call Python a compiled language because there exists PyPy? \$\endgroup\$ – FUZxxl Sep 9 '12 at 14:26
  • 2
    \$\begingroup\$ "answer with the highest votes" is not an objective winning criteria within the meaning of the FAQ. \$\endgroup\$ – dmckee Sep 10 '12 at 23:34
  • \$\begingroup\$ Migrated. Question killed. \$\endgroup\$ – J B Sep 11 '12 at 19:06
  • \$\begingroup\$ Perl and JavaScript have optional variable declarations (mandatory with use strict) and OOP. \$\endgroup\$ – Konrad Borowski Oct 22 '12 at 13:59
  • \$\begingroup\$ Sounds very code-ist ;) \$\endgroup\$ – WallyWest Feb 3 '14 at 3:02
5
\$\begingroup\$

In programming competitions, the way that you avoid people using scripting languages (which in this case, I'd define to be any language that runs primarily in an interpreted mode) is to make runtime a factor.

\$\endgroup\$
  • \$\begingroup\$ Perhaps measure the maximum memory allocation of the process? \$\endgroup\$ – luser droog Nov 22 '12 at 6:31
3
\$\begingroup\$

Play on things high-level languages don't have, or hide pretty deep.

First thing that comes to mind would be to ask for the shortest program to segfault, playing on many languages' proud lack of pointers.

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

Just go the opposite way!

Invent an interpreter, which accepts C like syntax, but works without main and has popular headers pre included. Make it available publicly, and use it for your solutions.

Hm. Aren't PHP or Lua pretty much such languages?

\$\endgroup\$
  • \$\begingroup\$ Or define a problem in, say lexial analysis and use lex (which is basically exactly what you have described specialized for lexical analysis). \$\endgroup\$ – dmckee Dec 20 '12 at 3:57
1
\$\begingroup\$

Copy an arbitrary number of bytes from the stack to the heap.

\$\endgroup\$
  • 2
    \$\begingroup\$ Define stack and define heap. Even in a scripting language, one could design, for example, a LIFO data structure and call it stack. But ultimately, the voters decide. \$\endgroup\$ – vsz Sep 8 '12 at 21:17
  • \$\begingroup\$ @vsz why does that matter? If you've got to implement your own, your code will be longer than the C program. Is that not a disadvantage? \$\endgroup\$ – Griffin Sep 9 '12 at 10:16
  • 2
    \$\begingroup\$ Arguably, []{+}@*:x; solves this challenge in GolfScript. (It takes a number n on the stack and moves the n values below it on the stack into the array variable x.) \$\endgroup\$ – Ilmari Karonen Sep 18 '12 at 1:08
1
\$\begingroup\$

I'm pretty much going with you can not invent such a problem. Scripting languages is a broad category and many of them have different advantages and disadvantages. Programming languages like perl, python, ruby and many more may have started as a scripting language but evolved to actual general purpose programming languages and it is therefore up to debate whether you still want to count them as scripting languages or not. If you are referring to application-specific script languages (like some audio or video processing tools have) then there certainly are problem which can not be solved comfortably in such languages. (Also many of those tools switched to actual general purpose programming languages like those mention before or lisp dialects and many more). Also I highly doubt that you can create a golf problem where esoteric programming languages are at a disadvantage since various esoteric programming languages have been created solely for the purpose of being fit for golfing. Especially since languages with a big standard library are usually at an advantage because you have much more functionality available at lower costs. If Haskells prelude would also import Data.List, Data.Ord, Data.Function ... it would be at a much more advantage at golfing. You certainly can design problems where your favorite language is at an advantage (because there is already a builtin function which does the job (this is what eso languages usually do)) but that's it.

\$\endgroup\$
  • 2
    \$\begingroup\$ Also keep in mind that stuff like "copy n bytes from the stack to the heap" can not be really considered a golfing problem. The canonical golfing is about producing the required output for a given input. \$\endgroup\$ – mroman Sep 12 '12 at 11:34
1
\$\begingroup\$

How about a code golf where the measurement being golfed is the compiled assembly, rather than the characters used? Obviously one could write in assembly, but for a complex enough problem, it would be more accessible to those using compilers. Most scripting languages would be out.

\$\endgroup\$
  • \$\begingroup\$ You'd have to post the assembly anyway, because otherwise duplicating the exact output could be tricky. And you get into complicated platform limitations - it's not only which architecture but which executable format, which libc, ... \$\endgroup\$ – Peter Taylor Nov 20 '12 at 23:01
  • 1
    \$\begingroup\$ This does give compiled languages an advantage, that's true, but the advantage it gives them is that interpreted languages can't compete at all. \$\endgroup\$ – Wayne Conrad Jan 4 '14 at 10:11
  • \$\begingroup\$ @WayneConrad, some interpreted languages can be compiled as well \$\endgroup\$ – zzzzBov Jan 4 '14 at 18:10
1
\$\begingroup\$

Create a picture, like in this challenge :-)

Make a PNG image with "Hello World!" with programming APIs, in the shortest code possible

Generally anything that is related to the fact that obscure languages are not used in real practice and thus don't have support for more complex practical tasks.

\$\endgroup\$
  • \$\begingroup\$ Some obscure languages have access to fairly feature-complete libraries, but a question for which there are DSLs is likely to be won by one of them. \$\endgroup\$ – Peter Taylor Feb 1 '14 at 22:08
  • \$\begingroup\$ Bash one that one. \$\endgroup\$ – PyRulez Apr 12 '14 at 17:52
0
\$\begingroup\$

As someone who fondly remembers the days of optimized ASM graphics demos, simply require the program to be under 'n' bytes, where 'n' is smaller than the text of the script required to define the problem but greater than the number of compiled bytes from a language like C.

PERL sometimes still managed to squeeze large algorithms into tiny spaces however, so a semi-complex problem would be required.

\$\endgroup\$
  • 4
    \$\begingroup\$ The canonical codegolf definition we use around here counts source code size. An ASM submission expecting its size to be counted as assembled would really be considered as (non-human-readable) binary machine language, not assembly langugae. Kind of frowned upon. \$\endgroup\$ – J B Sep 9 '12 at 9:37
0
\$\begingroup\$

Make sure the input is easily parsed by scanf!


Make the criteria the (one with the least) maximum memory footprint of the running process (including language run-time). Scrpting languages use heaps more memory, usually.

\$\endgroup\$
  • \$\begingroup\$ Max memory would keep out Java, C# while allowing Lua etc. \$\endgroup\$ – Johannes Kuhn Apr 19 '13 at 9:08

You must log in to answer this question.

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