27
\$\begingroup\$

I've never done code golf before, but it looks fun. I have some questions though. Should I learn some golfing languages, or just try some challenges out with the languages I know? (I know C# and Python) Are there any types of challenges I should try first, or should avoid until I'm better? Are there any things that are generally known to be disallowed? Is there anything I should keep in mind while golfing? Are there any general tips for golfing? Answers to any or all of these questions would be greatly appreciated, along with anything else I should know.

\$\endgroup\$
  • 2
    \$\begingroup\$ Do whatever sounds fun. In any language, on any challenge. If you're looking for tips, try the tips tag. \$\endgroup\$ – Nathan Merrill Jun 13 '17 at 21:43
  • \$\begingroup\$ In general, Python is a fairly good language for golfing in. I'd start out in Python and then, if you feel like it, try learning something like Jelly or CJam etc. \$\endgroup\$ – Beta Decay Jun 13 '17 at 21:49
  • 1
    \$\begingroup\$ @BetaDecay I am always amazed at how complicated golfed python solutions can become. I think there is a pretty big learning curve in python, which makes it a nice language to start with :) \$\endgroup\$ – JAD Jun 14 '17 at 14:40
  • \$\begingroup\$ Reading through the topics linked in the Community FAQ covers some of your questions. \$\endgroup\$ – Laikoni Jun 14 '17 at 16:36
  • \$\begingroup\$ @cairdcoinheringaahing notifications using @username only work if that person has already commented on the same post. You can use Code Golf Chat to contact someone about a post they haven't yet commented on, or you can flag for moderator attention if appropriate (which is not just for negative things, just things that need a mod). \$\endgroup\$ – trichoplax Jun 27 '17 at 19:05
22
\$\begingroup\$

I don't really know what's best specifically for you but I'll share my short experience over the past year here.

I started out golfing in Java, probably the worst possible language to golf in. However, despite never having won a single challenge in Java, people almost always commented on my answers, offering support and suggestions. So, the key thing to take away from this part of my experience is: "The more common the language, the more people can appreciate the cool tricks you've learned in your experience." Say you've been golfing in python and C# for 5 years, you may actually teach some users here a few neat tricks they're not seen before. I find that rewarding on its own.

After golfing and losing for a few months in Java, I started using Groovy and a few other langauges I wanted to learn more but never did. In the course of about a month my Groovy skills had sharpened to the point of knowing Groovy on Grails and I started web development! Pretty fun to golf in a new language then apply that knowledge to a career advancement or personal skill advancement. Maybe start golfing in C# to hone your ASP.NET skills and learn to become an Enterprise website developer! Kinda what I did.

Lastly, and most recently, I've been messing with a langauge named 05AB1E. I feel like this is a great way to ease into understanding esolangs. When I first looked at Jelly I was a little overwhelmed by all the monads and dyads. I still am overwhelmed by them. But I'm slowly learning by paying attention to the masters. However, 05AB1E uses a fairly straightforward command system and a stack-based memory system. You can write a program simply by looking at this:

https://github.com/Adriandmen/05AB1E/blob/master/docs/info.txt

You basically pick the tiny building blocks you want and go from there. Sure, understanding what it's actually doing will take you some time. However, I've never picked up a language easier than I have 05AB1E. If you have any questions feel free to hit me up or join the 05AB1E Oasis chatroom. Adnan is the original creator of the langauge and Emigna has some of the best (and FGITW) answers I've ever seen.

The main takeaway from all that crap would be: Read other people's work, enjoy the effort they've taken and always learn something new; you don't need to be the best to compete.

P.S. Use this link if you have a specific language in mind to get language specific tips and tricks:

https://codegolf.stackexchange.com/search?q=tips+for+golfing

\$\endgroup\$
19
\$\begingroup\$

A few thoughts, from a fairly-newbie:

  • Use whatever language you like. Personally, I see every language as competing in its own space. I compete against other JavaScript entries, and to a very small extent against Ruby and Python. Competing against Brainfuck is silly. Competing against CJam or Jelly or whatever is sillier.
  • Collaborate with others: help them improve their solutions, and incorporate their suggestions about your own.
  • Don't submit ungolfed solutions - make a reasonable effort before you post.
  • Don't copy other people's solutions without attributing them.
  • If you have an idea for a new challenge, post it to the sandbox for feedback first.
  • Read other people's solutions to learn from them. Personally, I prefer to attempt the challenge first before I do this.
\$\endgroup\$
  • 3
    \$\begingroup\$ +1 for "each language competing in its own space". \$\endgroup\$ – BradC Jun 16 '17 at 14:39
  • 2
    \$\begingroup\$ Competition between, for example, Jelly and 05AB1E is always fun to watch :P \$\endgroup\$ – Stephen Jun 20 '17 at 20:02
10
\$\begingroup\$
  1. Golf for fun, not to win!

  2. Post your answer even if someone else has already posted a shorter answer in the same language!


Yes, you can learn from other people's answers, but learning by doing is in my experience much more effective.

It's likely that other's will have posted submissions in your language before you are finished writing yours. And it's likely that their submissions are shorter than what you managed to write. Post your solution anyway! People will likely give you advise based on what you have done, and you'll learn.

Examples:

Post: "Hey, I'm new to this, and it works!", even if something much better has already been posted.

Have a look at what happened with this Java-submission by a new golfer ("not for the win but for the fun :)"). The user has about 500 Java-answers on SO (so the user has written quite a bit of Java-code), but got help from 4 different users to golf his/her score quite a lot.

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

Sometimes a win is getting your code about the same length as everyone else's.

I recently started golfing in Swift, which is probably one of the worst languages to use because the strict typing causes you answer to be about twice as long as everyone else's.

Unless there is a limitation that breaks your code online, post a link so people can test it.

When you post a solution, the OP will most likely want to test it him/herself. You can find online playgrounds fairly easily, but TIO is most commonly used around here.

Learn what your language does well and what it is terrible at.

Pick a language you want to use, and start learning its loop-holes, pitfalls (Swift still doesn't have a 'by-the-power-of' operator, AKA **), built-ins, and strengths. You can easily gain this knowledge over time as you try to solve challenges:

Hmmm, I should be able to make this shorter.

*Googling...*

Ah, never knew about that language feature!

*Lose 10 bytes from your solution.*

What if your language doesn't cut it but you love the syntax?

If you want to get crazy, write a new language or a transpiler and open-source it, then use that to write your solutions.

\$\endgroup\$
  • 6
    \$\begingroup\$ What if your language doesn't cut it but you love the syntax? Golf in it anyway. Just because Java will never win against other langs, doesn't mean it doesn't have it's own set of tricks to make golfing its code an intresting challenge. \$\endgroup\$ – Pavel Jun 19 '17 at 3:55
0
\$\begingroup\$

First of all: Welcome to Programming Puzzles & Code Golf!

The vast majority of challenges here are , and the golfers are very welcoming and supportive. There are various other challenge types here too:

You are not expected to know everything before you start, so just go ahead and jump in, and people will link to any applicable rules on Meta as they come up. If you want a head start on this, start from the FAQ page and browse through whatever sections are relevant. Many of the rules will only come up rarely, so don't worry about memorising them all up front. You'll pick them up as you go (and no doubt contribute to proposing new ones/changing old ones in time).

As long as you are aware that there are rules out there, and take it as a positive thing when people point them out to you, all should be well. The fact that you are asking this question suggests you already have the right attitude...

\$\endgroup\$

You must log in to answer this question.

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