13
\$\begingroup\$

I've been lurking for quite a while and have realized (after a technical interview) that I'm really out of practice solving problems like what is here. Is there a language that you recommend I start with? I'm a Python enthusiast (and I know Java and PowerShell) and I plan to try and golf with it, but I'd like to learn some golfing languages too, because I love learning stuff.

What would be a good one to start with?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Thanks everyone! I'm looking forward to participating! I've been working through problems posted, just not golfing them yet. Going to get started though! \$\endgroup\$ Commented Feb 26, 2018 at 0:14
  • 2
    \$\begingroup\$ In addition to learning golfing languages, it can also be interesting to attempt to learn new general-purpose languages through golfing, or even some non-golfing-oriented esoteric languages. \$\endgroup\$
    – Steadybox
    Commented Feb 26, 2018 at 1:30
  • 1
    \$\begingroup\$ Somewhat related. \$\endgroup\$ Commented Feb 26, 2018 at 11:38
  • 1
    \$\begingroup\$ PowerShell is great and does all things. Golf in that. (I may be biased). \$\endgroup\$ Commented Feb 26, 2018 at 20:55
  • \$\begingroup\$ @AdmBorkBork I probably will. I need to extend my PowerShell skills. While Python's my favorite language, I find myself using PS in my job fairly often. \$\endgroup\$ Commented Feb 27, 2018 at 2:42
  • \$\begingroup\$ NOTE: Due to some of the new rule changes, making your own language to golf with is potentially something you can do. \$\endgroup\$ Commented Mar 9, 2018 at 20:43

5 Answers 5

12
\$\begingroup\$

Start with your familiar language

You'll find that if you start off with learning a new golfing language right away, you'll find it rather difficult to create competitive solutions. That's completely normal; since you're new to Code Golf, your mindset is still set to practical uses. Instead of learning a new language right away, I would recommend that you start by looking for golfing tips in your own familiar language. That way, you're working with a language you've known for a while, and you can focus on learning the code golf mindset. It will also be interesting to see what can be done in the languages you know that you've never seen before.

Then, learn some more intuitive languages

Then, after you've become somewhat experienced with golfing in your own language and you're starting to get the hang of golfing ideas and thought processes, you can start learning a language. For a beginner at golfing languages, I would recommend you start by learning something like 05AB1E or Seriously/Actually, which are two stack-based golfing languages that have relatively simple syntax.

Each golfing language has its own mindset and structure. Different languages often have shorter ways to solve tasks, such as Jelly and Python. Getting the Nth triangular number in Python could be lambda n:n*~-n but in Jelly would be RS, as in sum(range(n)). Different languages also use different memory structures (i.e. tapes vs stacks) and specialize in different things. For example, Charcoal specializes in ASCII art, compared to 05AB1E for sequences. You may not always win a challenge with a given language, but it can be quite fun to puzzle how to even solve it.

Finally, learn some more powerful and less intuitive languages

Then, after you get the hang of that, you could start learning a more difficult language like Jelly. Jelly isn't stack-based so the command flow isn't as intuitive to begin with, but it's a very powerful golfing language because of its tacit command structure (which is also what makes it confusing at times!).

Hope you enjoy your time here!

Welcome to PPCG! I look forward to seeing your contributions to this community, and all the best to your golfing adventures! If you ever have any questions about how we operate, make sure you check out the help center, and if you ever want to ask for tips for golfing in basically every language you can think of or just hang out with fellow golfers, be sure to check out our chat room!

\$\endgroup\$
2
  • \$\begingroup\$ Why are people keep thinking that Jelly is non-intuitive? That's my first and only golfing language I know of. \$\endgroup\$
    – user202729
    Commented Feb 25, 2018 at 3:39
  • 1
    \$\begingroup\$ @user202729 maybe intuitive isn't the right wording (though just because you learned it first doesn't mean it's not non-intuitive, you might just have an easier time learning certain things). at least, its command structure is less easy to understand when learning it than a stack-based language \$\endgroup\$
    – hyperneutrino Mod
    Commented Feb 25, 2018 at 5:37
5
\$\begingroup\$

Welcome to Programming Puzzles & Code Golf! I am speaking from experience, and I'll have to warn you that mastering takes time. Here are my tips for you, and for any beginner in general.

First try to golf in a language you already know

Getting used to golfing in a "practical" language that you are already familiar helps a lot. Make sure to read the appropriate questions that suit your language (e.g. Tips for golfing in Python).

  • At first, you might not be able to produce the shortest submissions in that language, and some other user might post something shorter. Don't let that discourage you! But rather, try to analyse the other (shorter) programs, discover what tricks they use, figure out how it works, etc. If you don't understand the algorithm they used at all, you can always ask the OP to add an explanation. By understanding how other entries in a language you use work, you'll see more and more interesting tricks that you will eventually get to use on a regular basis.

  • Others are there to help – (Usually) if we see some piece of code that can be improved, or if your solution would benefit from some kind of rearrangement, we'll most likely comment to express our suggestions. Analyse the "golfs" thoroughly and feel free to edit your answer accordingly (of course, giving credit to those that helped you shorten your solution). This also gives you the benefit of learning new tricks by looking at how others modified your code.

  • Some of the skills you earn by learning a practical language can also be used in golfing languages. There are actually some tips that apply to a vast majority of languages.

Then, try to learn a (easier) golfing language

After having learned some of techniques in your language of choice, you should be able to go ahead and learn a golfing language. I wouldn't use something too confusing at first, but rather an esolang that makes it easier to get rid of the "practical / imperative" mindset (of course, only when golfing!). Here are my suggestions:

  • 05AB1E – A stack-based language with lots of built-ins, some which are hardly ever used, but when chained properly, yield some unbelievably terse code.

  • Pyke – Another stack-based esolang, whose usage dropped in the last couple of months. It has its own online interpreter with includes a list of commands you can search pretty easily. Note that you'll most likely not win with Pyke, but I think it is worth learning.

  • If you are interested in challenges, then Charcoal is an awesome tool to use. It's like drawing on a Canvas using... well, code. There are some other interesting languages made for this purpose (and also for ), namely SOGL and Canvas, both stack-based, but I believe they are a bit more confusing, since the docs aren't very clear yet.

  • Gaia – Although you won't see Gaia win very often, it's an easy-to-learn stack-based language, which pretty much opens the path towards Jelly – Like the aforementioned, Gaia's functions lie on separate lines, and can be accessed using various syntax features. You can read more about Gaia's structure here.

Then try to dive deeper – learn something harder1

There are many very confusing languages out there, but some of them are particularly competitive at code-golf contests:

  • Jelly – A tacit golfing language, which is a lot more confusing then everything I mentioned before. However, if you get to understand its concepts, you'll be amazed by how terse it can be. In Jelly's case, learning by doing is definitely the way to go. If you need help, feel free to ask for it in Jelly's official chatroom or join us in Jelly HyperTraining (the latter has been very effective for me).

  • Husk – It uses prefix notation, and it's a functional language based-off Haskell, which excels at challenges due to its very neat feature (among many others), support for infinite lists. I also recommend reading Language Comparison, from Husk's wiki page.

  • Brachylog – A declarative programming language based off Prolog, which is extremely useful and concise for .

Other languages you might want to learn over time

  • Pyth – A prefix-notation golfing language, which used to be very competitive back in the day. It's based off Python and it has some structures that somewhat resemble Python programs. The Pyth online interpreter also offers a great feature called "Debug", which essentially outputs a pseudo-code that helps you see what you're doing wrong, or what you have to add to make it work properly. Its "higher-order functions" use their own variables, and every built-in has a fixed arity, so there are usually no syntactic ambiguities, unless that function is overloaded. You can read more about Pyth at its awesome documentation.

  • Japt – A language that is transpiled to Javascript. Its documentation can be found along with the online interpreter, which offers some nice features, similar to Pyth's "Debug" section.

  • If you like regular expressions and string manipulation, I recommend Retina or V.

  • CJam — An esolang that was very trendy back in the day, but nowadays, you’ll likely not win with it. It only has a handful of commands, and is stack-based, but when those features are put together smartly, it won’t let you down. Like Pyth, CJam is an ASCII-only language.

  • Also make sure to check out some of the less-used esolangs around here such as Ohm, Pyt, Stax.

Final notes

If you have any question regarding any golfing language, want to improve one of your existing answers or are looking for suggestions, don't hesitate to visit The Nineteenth Byte (aka TNB), our official chatroom. Regardless of what path you choose to take, good luck golfing!

1: Of course, if you wish to do so.

\$\endgroup\$
5
  • \$\begingroup\$ CJam is the best. Objectively. There is no language better than CJam. Stop acknowledging the existence of these obviously inferior languages. /s \$\endgroup\$ Commented Feb 26, 2018 at 3:01
  • \$\begingroup\$ Thanks for pointing me to TNB... I got some good help there. \$\endgroup\$ Commented Feb 26, 2018 at 3:29
  • \$\begingroup\$ Is CJam (126 users, about 2000 answers) really a "less-used esolang"?! \$\endgroup\$ Commented Feb 26, 2018 at 8:22
  • \$\begingroup\$ How far back does "the aforementioned" go? Brachylog has 12 users and under 400 answers. \$\endgroup\$ Commented Feb 26, 2018 at 8:35
  • \$\begingroup\$ @PeterTaylor I've edited the answer, hopefully addressing your concerns. \$\endgroup\$
    – Mr. Xcoder
    Commented Feb 26, 2018 at 8:46
4
\$\begingroup\$

Welcome to Programming Puzzles & Code Golf!

We're very happy to have gained another new golfer! HyperNeutrino covered in their answer a lot of what I was going to say, so I'll focus on the various golfing languages.

First off, let me point out that there are dozens of golfing languages to choose from. I'll try to narrow it down to the most commonly used langs:

  • 05AB1E is a stack-based language, the type which is usually easiest to understand—all values are contained in a master array/list, or "stack", and each command takes a few values from the end of this array, does something with them, and puts the results back at the end of the array. 05AB1E is fairly recent, is still being updated, and has a fairly active community, making it a good candidate.

  • Actually is a stack-based language similar to 05AB1E. Someone who's more familiar with the two could probably point out the differences in detail.

  • Pyth is a prefix-based language, which can be slightly harder to get the hang of. It's also as old as CJam, although it is actively being maintained. If you want a Python-based golfing language, it's definitely one to look into.

  • Jelly is a tacit language—even trickier to understand than Pyth. However, it's been known as one of the top golfing languages, beating all other languages in most challenges it enters. It's written in Python, which may give it a slight advantage in your case.

  • Husk is a relatively new Jelly challenger. It's a functional language, being based on Haskell; coming from Python, it may or may not be easier to understand than Jelly.

  • MATL is another stack-based language, based on MATLAB. It tends to be really good at mathematical operations, especially those involving matrices.

  • Charcoal is prefix-based, but unique in that it specializes in creating ASCII art.

  • Japt is a shortened version of JavaScript—which might not sound very enticing, but you never know ;-)

  • Brachylog is an interesting declarative language, where programs often consist of, quite literally, "the output should have this relation to the input, find it for me".


All in all, there's no "right" golfing language for you to learn—but there's certainly no "wrong" language either. It is generally better to choose a language that has an active community, because there will be more experienced users to encourage you and give you tips on golfing your answers. But whichever language(s) you choose, I hope you enjoy your time golfing :-)

\$\endgroup\$
4
  • 2
    \$\begingroup\$ The main differences between 05AB1E and Actually is that 05AB1E was actually designed, as opposed to Actually, which is the result of a series of bad design decisions I made :P \$\endgroup\$
    – user45941
    Commented Feb 25, 2018 at 3:46
  • \$\begingroup\$ I'd recommend adding SOGL, given that it can be surprisingly short in KC and ascii art challenges \$\endgroup\$ Commented Feb 25, 2018 at 10:44
  • \$\begingroup\$ @cairdcoinheringaahing *Canvas \$\endgroup\$
    – ASCII-only
    Commented Mar 8, 2018 at 0:40
  • \$\begingroup\$ IMO you can think of prefix-based as "everything is a function" (well at least that's basically how Charcoal's verbose mode works) \$\endgroup\$
    – ASCII-only
    Commented Mar 8, 2018 at 0:41
2
\$\begingroup\$

Welcome to PPCG! I started golfing a little less than a year ago, and here's how I progressed from enthusiast programmer to serious golfer:

Start with a language you know fairly well

  • That means in your case python. python has the advantage that it's more "encouraging" than other languages -- it's already short and easy to write, so there are lots of golfers who are always giving new users pointers. I am a proud R golfer, and there's a few of us who I'm always happy to see comment on my answers.
  • Don't be discouraged when your answer isn't the first or the shortest. I posted a few 300+ byte solutions that I'm now proud of but at the time I didn't enjoy golfing at all -- I was upset about golfing languages and how much better at processing strings other languages were. I can't remember what challenge I first read that said "shortest answer in each language wins" (emphasis added) but that flipped a switch for me, and I really started enjoying golfing, not just for all the interesting problems to solve, but for the sake of golfing.
  • Post your answer, ask for comments, and as somebody else said, go dissect what the shorter answers did, ask them for an explanation (in chat or in comments). The only way to get good at anything is to practice the crap out of it, and somebody else (usually) has more experience than you.
  • Eventually, you'll get a nice short answer or golf down somebody else's answer a lot and you'll know you're contributing to the community, which is always nice.
  • Rep exist to make the Q&A sites a game, and it's nice to have a lot to unlock privileges, but don't just go chasing reputation. Otherwise it gets really depressing and you'll probably quit. PPCG is not a good fit for that style, because every golfing problem is a challenge where you are competing against yourself to find a shorter approach than your previous one. Squeezing another 2 bytes out of your approach feels way better than getting 200 rep, because now you know a good trick for next time.

Go with a language that's (super) different

I was an R golfer and I know MATLAB decently well (I'm not Luis Mendo but I'm not terrible), so I was comfortable enough with matrix languages. MATL would have been a natural fit, but I really wanted to get out of my comfort zone, so I picked a random esolang, and settled on Cubix.

I found Cubix was super helpful because

  • the syntax is extremely simple. It's stack-based, only has integer arithmetic, but besides managing the stack, you have to worry about which way the instruction pointer is going, because the code runs on the surface of a cube.
  • So you also have to manage code size, or else the cube will change sizes and all the code you've written doesn't work.
  • Because it's easiest (but still quite difficult) to write simple programs, it requires you to break down problems into really small parts, which is very helpful for the more general problem-solving.
  • You don't have to go for a weird language like Cubix, even a more practical language that's got a different syntax and/or built-in data structures than Python is good, just to get you to think about problems differently.
  • Next I switched to MATL because like I said, I was comfortable with MATLAB and the stack-based syntax was a natural fit after doing some Cubix. There was still a pretty steep learning curve but it's been a fun language that I will keep writing answers in.

Go pick whatever language you want

  • Keep golfing in your "comfort zone" languages (there are definitely still language features you don't know about), and learn new languages whenever one seems interesting to you! You should have enough experience that you should be able to pick up a language and learn enough to answer a simple challenge, then dive deeper if it piques your interest from there. Or if you see somebody else post an answer in a language, go try to write an answer on another challenge! People are always creating new languages for golf, and you being a "free beta tester" will help the language grow in golfiness.
  • Golfing is sometimes just about finding the right language for the job, just like any programming challenge. If it calls for ASCII-art, maybe think about learning Charcoal. For pattern matching, look at Retina. For anything else, pick Jelly/SOGL/MATL/J/CJam/whatever. If it's a trivially easy challenge, go learn the basic syntax of a new language just to answer it.
    • To keep things fun, I find myself writing answers in SNOBOL which is an ancient language that predates the use of regular expressions in programming languages. some funky features: it has a PATTERN type, strange whitespace requirements, and handles control flow by GOTOs and SUCCESS or FAILURE of a line. Because it's so strange, nobody else uses it and I've had to figure most golfs out for myself, with the help of the various tutorials that exist online.
\$\endgroup\$
1
\$\begingroup\$

How I started

Unlike many here, I actually started by posting a challenge. In fact, I posted 4 different challenges before I posted my first golf. And my first golf was actually a self-answer on that fourth challenge.

Since then, I've abused Python 2, Python 3, Z, CJam, Brainfuck, Underload (and Betaload), ///, ><>, Check, Headsecks, Bash, Foam, Jelly, J, Dreaderef, Pip, MiLambda, Ternary, Golunar, Glass, Momema, Felix, and Haskell.

I almost never use a language that's already been used before on a challenge, because I am more interested in getting a solution working in an obscure esolang than in the competitive aspect. If you feel similarly (or if you're bad at golfing, as I am), here's my process:

  • Write some challenges.
  • Make some esolangs and golf in them.

Since you're the creator (and in my case, usually the only user) of your esolangs, you're probably the one who knows them best. To me, the best esolangs are always ones where golfing is very tricky.

\$\endgroup\$

You must log in to answer this question.

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