Ask HN: Projects for learning a language?

76 points by drywater2 ↗ HN
Hello HN.

I've read a few books for a couple of programming languages (go, rust), but I still need some kind of project to really see the big picture and think deeply.

What kind of project (besides some CHIP-8 emulator) would you recommend?

Thank you and I'm more than curious about your answers.

60 comments

[ 3.0 ms ] story [ 117 ms ] thread
Some famous programmer or another uses Conway's Game of Life as an exercise for learning a new language.
I always thought of Make A Lisp (MaL) as a great way to learn two languages at the same time. And some of what you learn about Lisp in the process will rub off on your use of the language you are working with. Ie: It might trick you into being a better programmer than you expected.

There are a lot of MaL examples written in Lisp even, which initially sounds redundant, but gets new Lisp programmers to learn Lisp's internals by writing them in the same language.

This is similar to the "old days" when people used to write a BASIC interpreter or C compiler to learn a new language (writing a compiler teaches you ASM programming, so it's a good comparison with the dual nature of MaL)

Depends on your skill level, the trick to a good practice project is that is big enough that you are learning the concepts about the language that will push your abilities forward. However, it also should be small enough that you don’t waste your time solving problems you don’t really care about and that are not increasing your skills. For me I am usually learning a language to take advantage of some feature that language has. I know Go makes it really easy to create and test web servers so if that is why you picked it up trying making and testing a simple API. Maybe one that just queries two other existing APIs on the internet and aggregates the results. Making an API in Go would be good because you will need to unmarshal the json from the other two public APIs and combine the object then marshal the object to json and return it to the user. Be sure to write unit tests.

https://golang.org/pkg/net/http/ https://golang.org/pkg/encoding/json/

Advent of code is an interesting set of challenges, with a generally rising set of complexity. There are 6 years worth of 25 challenges.

https://adventofcode.com/

+1

In the past I have made a point of doing AOC in a language I didn't know or was planning to learn. Maybe rust this year...?

Another voice for AoC.

It should make you have go into text and file processing (including regexps) and basic data structures (lists/arrays, hashmaps, trees, graphs). Maybe GUIs or image processing: it's never essential, but sometimes it helps in debugging a puzzle, or it's just fun to make a visualization of the solution. Even simple parsers.

However, typically you wouldn't touch things like async, networking or writing a server. Though you could try writing an HTTP API client that automates downloading inputs, many people do it.

I'd still recommend it mostly because it's very fun, in my experience, which keeps you motivated.

Another +1. These can be great ways to learn new languages. The later stages can be quite difficult but there’s so many years worth of challenges to mine from I can guarantee you won’t get bored even with the more basic problems.

If you get stuck on a solution chances are someone else has already solved it in your language of choice which can also be great for learning.

I like Larry O'Brien's three-part series, "15 Exercises to Know a Programming Language," [1][2][3] mostly for the overall philosophy ("should be tough enough to require problem solving: try to embrace the language's idioms") and for the rationale that comes with each exercise (e.g. implement this to learn that about your chosen language). Note: the internal links between parts of the series are broken, so here are all three parts:

[1] https://knowing.net/posts/2006/06/15-exercises-to-know-a-pro...

[2] https://knowing.net/posts/2006/06/15-exercises-to-know-a-pro...

[3] https://knowing.net/posts/2006/06/15-exercises-to-know-a-pro...

That is an interesting problem set, but with some serious difficulty spikes due to specific problem domains. I use C++ and Go professionally and think I'm pretty competent at both, but I've never had to write a GUI, and wouldn't really know where to start, other than to go read the docs for Qt, try to put together a build script, and then cry a lot - but if I had to do it with a gun to my head, what I'd probably do is write a web server and let the browser be my GUI engine. And then the whole third set... HTTP server/client are both scalably difficult depending on how much library support you lean on (raw sockets to HTTP is approachable, but I'd rather use Boost), but I'd have absolutely no idea where to begin with the email client.
Yes, although this is revealing in itself as to which languages are suited to which problem domains. Also shows up which platforms are suited to what; if I were building a C++ GUI I'd fire up Visual Studio, unless you told me it had to be cross-platform or not-Windows at which point I'd go back to "cry a lot". (Yes, Xamarin, QT, it's still a lot of work)

I think building non-web GUIs may have become harder since 2006, depending on platform/language.

I don't know if I would recommend it, but I've noticed that in the past, whenever I moved to a different type of computer/OS (Amiga, MS-DOS, Windows, etc.) or language (Java, Javascript, etc.), I ported my biorhythm program to the new system/language. It starts out simple - just strings, math, file/screen input/output, then progresses to graphical plotting of the biorhythm curves. It's a simple algorithm. Disclaimer, I don't know if I believe in biorhythms, it's just something interesting and a flashback to my childhood in the 70s.

Basically, I would say the easiest way would be to choose something you've already conquered in a language/system you already know. That way, you're only tackling one new thing.

BTW, it wasn't always biorhythms for me - I originally wrote my Mandelbrot program in Pascal, and taught myself C in order to convert it to C so it would run faster.

Mine was sunrise/sunset and phases of the moon. And more graphical: planet orbits, watching for alignments.
Coincidentally, my biorhythm program would tell you various things about yourself (birthstone, zodiac traits, yin/yang, Chinese animal, numerology, but also the phase of the moon the day you were born). Yeah, I threw in everything I could find/calculate.
I have a "standard" project to work on for new languages, which has enough complexity to get me coding things idiomatically by the end, but since it's something I've done before I don't need to worry much about the topic at hand.

The project is a hurricane modelling and visualization program, which is pretty specific to my experiences, but having that to riff on has been my way of learning scala, python, c#, and (soon, in theory) Go.

I've used that approach for both front-end and back-end development as well and it works quite nicely. Its really useful to have something where you don't need to worry about any sort of design/what/how to build and can just focus on the actual language.
Sometimes I’ll write a unit testing library with a terse syntax/DSL to learn a new language. That pushes me to learn how to bootstrap tests to test the testing framework :) It usually helps me get into some of the more advanced language features. After that, most things I do in the language feel relatively easy by comparison.
I always go for a simple lisp interpreter. I think this covers a good range of techniques and gives you a pretty good feel for what is/isn't ergonomic in the language.

I don't generally bother with features like macros etc, I just get enough going to define and evaluate functions in a repl. When you keep the scope small like this it doesn't take very long, and it can be broken up into a few fairly well defined evenings - e.g. lex, parse and eval.

One caveat is that if you haven't written a toy interpreter before then it will take you a bit longer. Once you know a little about the common techniques and patterns it's easy though.

edit: grammar

It's not the best project for your requirements (seeing the big picture and thinking deeply), but my go-to project for general-purpose languages is to implement a Markdown static site generator with a simple plugin system.

It allows me to test a few things I care about: filesystem operations, templating engine, reflection (or lack of), string parsing, testing, build systems. It also gives me a feel on the ecosystem (e.g. how many good quality Markdown parsers? Do I have to write my own).

Also, because I have a few of them I can make something of a comparison between languages for this particular use case (how long did it took me? how fast does it process the sources?)

There’s nothing like creating a programming language to throw yourself in the deep end!
Games of course! Doesn't have to be fancy with graphics at first but the beauty here is graphics/frontend/UI is definitely on the table if you want to pursue it later. In the same spirit, it's very easy to add features/mechanics to it. Get creative!

- Simplest game ever is a number guessing game. Obviously solvable by binary search on the player side. It's like an exciting counterpart for Fibonacci for learning PL flow-control structures. Additional features: limit number of guesses, make players guess floats instead of just ints. Latter will obviously teach you about FP handling in your language of choice.

- Next up, make that two dimensional, so the player is now guessing coordinates instead of numbers. Needs more math, you will definitely implement the distance formula. You can add a backstory if you like (are you bombing enemies in stealth perhaps?) and add mechanics based on that backstory.

- For something more complex---and I think this is your level now---people might suggest a constrained DF/Rogue-like. But me, that always grows more complex than a pedagogical device when I do it. So I stick to boring text games, sometimes inspired by game shows. Quizmaster-types (ala Who Wants to be a Millionaire), hangman-types (ala Wheel of Fortune), would force you to create structures for abstraction, all staying within complexity budget.

Happy hacking!

I usually rewrite software I use at home:

- a monitoring system for my home automation devices, the checks go from generic (is the site up?) to specific (are the water leak sensors up?)

- a program to keep track of the chores my children are supposed to do (a backend with an API, a mobile application and a hook into the home dashboard)

- my note taking program, because the world absolutely needs one more

I use a bus for communication (MQTT) but also APIs, so the rewrite quickly brings me into the technicalities of the language as I do not have th reinvent how the programs work. On the other hand, these rewrites led to plenty of improvements.

I would work backwards from why you want to learn a new language in the first place. Definitely spend some time on that. Usually the reason will lead directly to a project that you want to work on. Otherwise it will be hard to follow through.

Ex: I wanted to learn C, but my reasoning was only that it seemed like "real" programmers knew it. But that's not a good reason. Instead what I really wanted was to get closer to hardware and build software that did low-level operations. So I learned objective C and build audio-processing software for iOS that I actually wanted to work on. So I was able to learn a bit of the language and a bunch of other cool things that I still use today.

For learning Rust I just picked a random, reasonably sized C++ project and spent a few weeks porting it to Rust. Was more than enough to get a grip on the core language features and tools and start receiving interview offers for a Rust position (though I ultimately decided to stay on the JVM track). The project was a face detection library: https://github.com/atomashpolskiy/rustface
Can you talk more about how you evaluated career options for rust vs jvm and what kept you on the latter?
Yeah, it seems like 90% of Rust jobs that are realistically accessible for someone with my background (different servers for the most part) are in crypto space, which I dislike, and there are very few of them as well. Java gives me better and more numerous options to choose from, and recently I even landed a Scala position in a very interesting domain. So it's about variety and job safety after all.

I also would not want to program in Rust for 100% of the time. It's a great tool to have for certain mission-critical types/parts of software where the cost of a mistake is high, but it also can be very frustrating to work with, at least until you become proficient with the idiomatic ways to structure programs and code in Rust. And even then I would not pick it for R&D type of work for instance, where you have to experiment and refactor a lot. Borrow checker is something you have to keep in mind at all times, and as I said already it can be extremely frustrating when you simultaneously have to think about design, execution logic and performance. Doubly so when the parts you're working on are not going to be concurrent in any foreseeable future.

OTOH, I can see how coding something well-defined and to the spec can be rewarding and less expensive in the long run with Rust.

If you've already been programming for a while then a great project is to reimplement the language in itself. You'll reinforce a lot of aspects of the language while you do this (since you'll be looking up what syntax exists and what it means exactly, all the time). Plus, building language implementations is always fun.
For me, there is no single go-to project that fits all languages. Each language has it's own purpose.

Go and Rust are fairly similar in terms of parallelization and performance. Both are general purpose languages and are great at solving system problems. Choosing a toy project that requires these perks will yield the most satisfying results and enables you to get a good grasp of why those languages exist, and where their differences are.

Both languages empower you to build inter-system applications, both languages are highly performant and both let you build safe and tested programs. A distributed ray tracing engine comes to my mind - it would allow you to let both languages collaborate, compare solutions to problems between the languages and get into the nitty gritty details of memory management, allocations, garbage collection etc.

This would probably be my pick, because you can build and improve it for years if you really want to put the effort in it.

Here's a great primer on that topic - it's still actively developed and made me look at modern ray tracing technology in awe.

https://raytracing.github.io/

Build something for a friend’s problem. You then have a customer that is not you, and external motivation.
I don't think there's a good universal project that you can keep reimplementing in different languages and getting a good grip of the language. In your paricular case, go is more of a general purpose language so anything that involves simple filesystem and network operations(cache, databases, apis and all that) would be fine. In theory rust can do the same things but it's a systems language and trust me, it's not suitable for such things at all: poor ecosystem, the help you will get online is not preally great: what you will commonly get when you hit a wall when playing with something like actix is "this is bad practice" responses without an example of good practices. With that said, I've been playing around with robotics in my spare time lately and even for a beginner, I think this could be a great choice: you can pick up a decent robotics kit for 20-ish bucks and a raspbberry pi and you will have tons and tons of fun, even if you've never touched rust before in your life. And even if you have, it's still tons of fun.
I’ve found Advent of Code to be great for learn a new language projects.
A raytracer is simple enough and fun.