(This might be a duplicate of another question but all of its answers were vague nonanswers, and I can't find it again, so here goes...)
I like python3 and I'm quite good at it; it's rather verbose so when I make long scripts I have a tool script I import that contains lots of shortenings and predefinitions. As long as I don't answer existing questions with it, and as long as I make it freely available (on git?), can I do this and only have the from g import*
counted towards my code-golf score? or would I be implored to include the bytes of library just cause I wrote it?
It almost feels boring but to say it is, is to call Golfscript and Pyth boring and uninteresting, with which I disagree.
4 Answers
Yes, and it does not necessarily have to be a separate language.
There's no problem with using your own library as long as it doesn't violate the standard loopholes. In answers where you use it, you should put "Python 3 + <name> library" in the header.
If you go for the library route, you do need to count the import in any answers with it.
-
3\$\begingroup\$ This makes the most sense: why treat a library different from a language? \$\endgroup\$– YpnypnCommented Oct 22, 2015 at 21:53
-
2\$\begingroup\$ A estabilished example is "<some shell language> + coreutils",
coreutils
isn't included in the byte count. \$\endgroup\$– KroltanCommented Nov 2, 2015 at 23:28 -
\$\begingroup\$ Why include the import statement? It's trivial to compile foo-with-bar-language to foo-language + bar-lib - are we required to publish such a compiler in order to be eligible for this deduction? \$\endgroup\$ Commented Jul 8, 2017 at 0:27
-
\$\begingroup\$ @JanDvorak Yes (that would be a quite Meta-Golfscripty thing to allow). \$\endgroup\$– feersumCommented Jul 8, 2017 at 2:27
-
\$\begingroup\$ @feersum Hm... is there an established naming scheme for these languages? \$\endgroup\$ Commented Jul 8, 2017 at 6:55
Yes. But:
According to what I see from the comments and previous relevant questions, the consensus is that you may, however, you must do the following things:
- Define it as not a clean copy.
- This means declaring it as "<Original Language> + <Library Name (with link)>"
- Provide a link to the library.
- This is common sense.
- Explain thouroughly
- Also common sense - if you show up with a library no one has ever seen, nobody's going to know what it actually does.
- The Library cannot be updated after the question exists!
- This is a general loophole, and must be abided to.
-
\$\begingroup\$ Wait, so I have to call it Gython rather than Python with my G library? \$\endgroup\$– catCommented Oct 21, 2015 at 23:48
-
2\$\begingroup\$ I would agree with calling it the latter - you just can't say that it's normal Python with a normal import. \$\endgroup\$ Commented Oct 21, 2015 at 23:48
-
\$\begingroup\$ Additionally, in the case of Java, Oracle don't much like people messing with their stuff. Does this only apply to languages with permissive licences? \$\endgroup\$– catCommented Oct 21, 2015 at 23:49
-
2\$\begingroup\$ If you can't find it on an unaltered version of whatever your language your writing the library for, it must be identified as said language with a custom library. It's just not the same language anymore. \$\endgroup\$ Commented Oct 21, 2015 at 23:50
-
\$\begingroup\$ And just for final Clojure: the bytes counted are
from g import*
or the length of g.py? \$\endgroup\$– catCommented Oct 21, 2015 at 23:58 -
1\$\begingroup\$ I'd say the former, but I don't have the full right to say that. I'd suggest an opinion from a moderator for that. \$\endgroup\$ Commented Oct 22, 2015 at 0:05
-
7\$\begingroup\$ RE "The library cannot be updated after the question exists". I disagree. The library cannot be updated to easily solve the question, but new versions of the library can always be created (in which case one might need to specify which version of the library is being used) \$\endgroup\$– JustinCommented Oct 22, 2015 at 4:12
-
3\$\begingroup\$ I agree with @Justin. It seems silly to freeze development of a golfing library once it gets used for the first time. The solution of specifying "Original Language + Library Name + Version (with link)" as the "language" of the post, with the "Version" being one that existed prior to the creation of the question, seems like a good one. (...and it just now occurs to me that I haven't even posted on this site so why should anyone listen to me? But the argument seems solid, anyway.) \$\endgroup\$– David ZCommented Oct 26, 2015 at 7:51
Yes, but make a language not a library
Writing a library might be acceptable but we definitely allow the creation of custom languages.
To achieve your goal you could make up a language called "Mython" (or whatever you want to call it) and write this compiler for it:
p = print
q = input
def runMython(code):
exec(code)
So if you wanted to run the Mython code
x = "dog"
p(q() + x)
You could just do
runMython("""
x = "dog"
p(q() + x)
""")
This is better than a library because you don't even need the import.
As always, languages are (usually) only valid in challenges that were posted after the language was invented.
-
\$\begingroup\$ Hmm. Perhaps I'll just get to work on an interpreter for the actual, non-pathetic language I'm actually designing from actual scratch. \$\endgroup\$– catCommented Oct 22, 2015 at 0:02
-
3\$\begingroup\$ This is better. The Library route would be good, but using this would both reduce byte count and de-clutter answer headers. +1 \$\endgroup\$ Commented Oct 22, 2015 at 0:16
-
4\$\begingroup\$ -1. This works for Python, but making a Mjava compiler would be a huge pain involving complex file manipulations. \$\endgroup\$– YpnypnCommented Oct 22, 2015 at 21:52
-
\$\begingroup\$ -1. Didn't golf the Mython interpreter. :P \$\endgroup\$– mbomb007Commented Oct 30, 2015 at 15:03
Yes, but make it runnable on its own
You don't necessarily need a compiler, as long as you can run mython myscript.my
(or whatever your language is called) from the command line.
One way of achieving this would be to make a small shell script that somehow ran Python with the right flags and parameters so that your library is loaded at startup. I don't know for Python, but this option exists for other languages such as Ruby and Perl. I know because I have very similar plans to yours :)
g.py
which turnsprint()
intop()
andinput()
intoq()
, which I then import withfrom g import*
: is this OK and how are bytes counted? \$\endgroup\$import g
and havingg.py
shove stuff into builtins \$\endgroup\$(i+5).a
prints the input plus five. \$\endgroup\$