Ask HN: Projects for learning a language?
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 ] threadThere 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)
https://golang.org/pkg/net/http/ https://golang.org/pkg/encoding/json/
https://adventofcode.com/
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...?
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.
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.
[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...
I think building non-web GUIs may have become harder since 2006, depending on platform/language.
https://cryptopals.com/
I always turn to Cryptopals when kicking the tyres on a new language.
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.
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 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 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?)
- 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!
[0] https://manpages.debian.org/stretch/bsdgames/index.html
https://www.reddit.com/r/learnprogramming/comments/g98sn4/sp...
- 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.
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.
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.
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/