Hacker News new | ask | show | jobs
Ask HN: Projects for learning a language?
76 points by drywater2 1832 days ago
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.

35 comments

The best strategy in my opinion is to build something that aligns with some of your hobbies or favourite things. Do not attempt to "solve a problem" or "do generic exercises", build something that ties up with something you already enjoy.

For example, if you're into some kind of sports, build a software that helps you keep track of it. If you like cooking, build a recipe tracker. You know the gist.

By building something that helps you with some of your passions, you'll feel more connected to it and more engaged with the project.

This does not need to be a product, or something you'd try to sell or market. Build it for you. Share it with those people you like, if you feel like doing it, but build it for you.

What if anything I can come up with that aligns with my hobbies has already been done?
You almost certainly will never do something novel while also learning a new language. And even beyond the learning phase: I've found that getting past this mental barrier of "whatever I build has to be useful" is essential to getting enjoyment out of side projects. Find it in yourself to enjoy the process for its own sake.
But it hasn't been done by you, in that language, right? Yoy are doing it mainly for learning.

Also, you will find you end up with a somewhat different feature set, get to fix what annoys you.

This is potentially a source of inspiration! Two simple options for example: your goal is to exactly reproduce the existing thing; or there are parts of it you don't like and want to improve on.
It doesn't really matter if it has already been done. It is actually good because then you can compare and try different things, or add the same features to learn how hard it is.
> What if anything I can come up with that aligns with my hobbies has already been done?

That depends on what your goal is. If your aim is to learn the programming language, code up that program/task/tool even if someone else has already done it.

Why is it relevant if it's already been done?
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!

There is a debian package called 'bsdgames'[0] that contains several simple text-based games for people looking for some ideas.

[0] https://manpages.debian.org/stretch/bsdgames/index.html

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.

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/

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.

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.

+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...?

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.

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?)

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 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

I made a Flash game way back in 2004 called Proximity[1] that was fairly popular. Whenever I want to learn a new language/platform, I tend to port a new version of that game to that language.

I don't always release it publicly, but it's a 'solved' program that I don't have to spend time reworking how the core of it works (needs a hex grid with number tiles, mouse or keyboard input, a menu system, computer opponents, etc), although I might rework some things or add new features to it.

I've done this to learn C# (and XNA), Java (and J2ME), Objective-C (and OpenGL ES), Swift (and SpriteKit), and LUA (with Pico-8).

I've also made versions in Python (text console), for Kindle, and the original was in Flash, but I knew the tech ahead of time.

I recommend it. Can be anything relatively simple. Make a blackjack game, a version of tetris, a Todo app, a Sudoku solver, a web service, whatever seems interesting to you.

[1]: https://www.newgrounds.com/portal/view/183428

Hey, cool game! It's rare for me to like new games (new for me, of course), but I like your's and been playing it for the last couple of hours..
Thanks! I made a sequel and released it on Xbox 360 and iPhone a long time ago, but let the code atrophy for a while. I finally resurrected it and started cleaning it up and improving it a couple of years ago, but at one point decided to do the 2D->3D conversion and ended up rebuilding it again.

Trying to figure out a way so potentially hundreds of viewers on Twitch can play along with a Twitch streamer, essentially joining a team and voting for where to place their tile, or just play like normal. Had to take a break working on it recently (job hunting), but I hope to jump back into it after I get settled at a new job.

I need to do a newer update video (you can play a full game now, more focused on adding menus and streamer support right now), but you can see kind of what I'm doing with the third game here, if you're curious. There's videos of Proximity 2 in action on my channel as well:

https://www.youtube.com/watch?v=0IAx9fsBuus

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.

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)

I'm not sure whether you're looking for just an idea for a project or an actual walkthrough. But either way this index of "Build your own X" writeups should be useful: https://github.com/danistefanovic/build-your-own-x

Ideas include building a Git, shell, search engine, and of course compiler/programming language.

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/

Cryptopals is loads of fun

https://cryptopals.com/

+1

I always turn to Cryptopals when kicking the tyres on a new language.

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 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.
Checkout 7GUIs, is an interesting gym for an environment that provide a GUI.

https://eugenkiss.github.io/7guis/tasks/

If you are looking for inspiration try '500 Lines or Less' [0]. It includes in-depth analysis of projects at hand and implementation. These are manageable project with a clear goal so you will complete them for sure.

[0] https://aosabook.org/en/index.html https://github.com/aosabook/500lines

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.
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/

If it is helpful in anyway, I found this answer very interesting

https://www.reddit.com/r/learnprogramming/comments/g98sn4/sp...

Build something that solves a problem you have right now. Even if it's a trivial problem and nobody else will be able to use the solution except you.

That forces you to think real world usability etc

I see this recommendation rather often, but it's rather unhelpful. I certainly can't think of any such problem that I have.
Well it doesn’t have to be that hard, you just have to come up with a problem that is not actually a problem for you, making it very trivial. An example: right now it is sunny outside, so what if I could build a service that notifies me of the time for sunset every day.

It doesn’t have to be a problem with actual value to anyone, but once you start thinking about it, you will probably find it engaging to solve.

Feel free to make a more helpful suggestion!
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.
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.
Some famous programmer or another uses Conway's Game of Life as an exercise for learning a new language.
It's been a few years, but every time I learn a new language, I like to try and make an IRC client or IRC bot in that language.

It gives you an idea of what the language can do and how to handle network connections with it.

A raytracer was a good early Rust project I did. I've also done a Lisp interpreter, a partial jq reimplementation, and Conway's Game of Life. Go would probably also lend itself to these projects.
I almost always start with a few of the first eulers problems, followed by flappy bird and/or a sudoku solver, and then a super simple interpreter
Build something for a friend’s problem. You then have a customer that is not you, and external motivation.
There’s nothing like creating a programming language to throw yourself in the deep end!
I’ve found Advent of Code to be great for learn a new language projects.
A roguelike game.
A raytracer is simple enough and fun.
i often did try to implement the minimax algorithm on tic-tac-toe. Its not too complicated.