1. 17

So, I’ve just read Software Technique, and one of the things the author talks about is doing life studies in programming, and about the general process of learning via timeboxed, open ended code exercises.

Do you have any problems or recommendations for coding exercises?

  1.  

  2. 6

    There’s a book, Programming Pearls by Jon Bently that has a lot of really good programming problems for practice, and it gets you thinking.

    Beyond that I would recommend doing Advent of Code - the problems are presented in plain English, and while the problems are fictional, it’s good practice for when you’re given plain English specifications and you need to make a program that matches them. It’s also good because they’re presented in two parts, where the second part is sometimes a twist or change in specifications - another thing that comes up very often in real life programming.

      1. 4

        I think porting code from one language to another is underrated … you learn about someone else’s code and you also learn more about the source and target languages.

        Here’s a tiny example I did with some explanation of the process:

        https://github.com/andychu/javascript-vs-c

        Fixing other people’s code is probably one of the hardest / latest skills I learned.

        I also find that refactoring existing code is one of the fastest ways to learn a domain. I usually write my own tests for the code first, and then aggressively minimize / simplify / re-organize it. Many times some natural optimizations will fall out.

        I run the tests 1-10 times per minute, so I get lots of feedback on every change. The breakages give me a natural path to learning the code, rather than trying to read it all up front.

        I recently reduced this Python JSON binding from ~1500 lines to ~800 lines, which was pretty effective

        https://github.com/oilshell/py-yajl/commits/master

        Here’s another one inspired by lobste.rs last year, which had a lot of code reductions and modernization too:

        https://github.com/oilshell/blog-code/tree/master/ddmin

        1. 4
          Mathematical General Crypto $$$ Commercial

          Ranked according to personal preference. I might have forgotten some. But these (especially the first three and the crypto things) are amongst my personal recommendations.

          1. 2
            Bioinformatics
            1. 1

              I second this!

              Also any exercise dealing with genomics is a good practice! Lets you explore a completely new world of data structures and algorithms.

          2. 3

            I have a handful of project ideas I like to use when learning a new language, or trying a new technique:

            • Interpreted emulator: Something small like a CHIP-8 or Gameboy. It touches a lot of areas (IO, graphics, tests etc), but the domain is straightforward (essentially implementing a well understood spec) so you can concentrate on your code.
            • Ray tracer. Easy to get something started, and can make it as complex as you want from there.
            • Parsing a small toy language.
            • Clone of https://httpbin.org/
            1. 2

              If you want to go beyond parsing, reimplementing TCL is a manageable task. Look at picol. 500 lines of C.

            2. 2

              If you want to dabble with algorithms try leetcode and if you want to learn how to build projects then think of idea and implement it. Both has its pros and cons but I would go for project orientated approach since you learn so much and it’s really valuable to see the end results but as far as leetcode is concerned I think they are great if you want to land an interview at faang

              1. 2

                I’ve heard good things about Exercism, and I’ve recently spent some time very slowly working my way through one of their tracks. They seem fairly well thought-out, and taking a look at other people’s solutions after submitting my own tends to be enlightening. The exercises also range from fairly trivial (fizzbuzz) to fairly complex (implementing a parser/interpreter).

                1. 2

                  I know everything about coding exercises — adventofcode is the best. The only beast created by humans to humans.

                  1. 1

                    When I started out programming writing a command line options parser in C was a rite of passage. Next was a linked list library. I wrote one of those too. Can’t remember what came next, but eventually JSON came along and everyone and their dogs wrote JSON parsers, including yours truly. SBJson lucked out and got popular, and is now in its fifth major version. I dare not calculate how much time I’ve sunk in maintaining it, and I never even wrote anything that actually used it :-) I learnt a lot though, and there’s some gems in there I’m pretty proud of.