Ask HN: What is the coding exercise you use to explore a new language?
What is a good sample program or project to work on to explore the primary aspects of a programming language? Something that can be worked on for a couple hours or days. Something that will give exposure to most of the basics of a particular language. Would love to know how people go about trying out a new language in this way.
72 comments
[ 4.2 ms ] story [ 130 ms ] threadShould note I often work on 2d tile based games.
As for the practical aspect of picking up a new language (for a purpose), I'd shamelessly look into an already existing projects along with following whatever language textbook.
Learning syntax is likely a simplest step, picking up an idiom is more involved and is often specific to objectives.
But before that I prefer to get a book and work my way through all the examples, otherwise I'm just making up what "idiomatic" means.
http://pleac.sourceforge.net
It tests quality of libraries, resource safety, concurrency, performance etc.
There's a pretty causal relationship between starting my unfinished side projects and me trying a new language or library.
I use advent of code to really dig deep into a programming language I sort of know but want to learn to use more. I plan on learning modern C# this way this year, it's been almost a decade since I taught myself the language at this point.
- Is in C++
- Focuses on spheres
[1]Raytracer Challenge:
- Is Written in pseudocode
- You will be able to render objects composed of polygons not just spheres
[1] https://www.youtube.com/watch?v=MFjmpjPwFEM
I used to work on a fork of https://github.com/jackpal/Taipei-Torrent with custom features, I found its code to be easy enough to understand
Gives me a chance to learn the new language with a project that's decent in size, without it being debilitating. Plus, it is fun writing an interpreter.
It can also be fun, if your sense of humor responds to funny names, and if you choose the right inputs.
If you wanted smaller exercises, you could take some of the leetcode exercises and grind through them on your own (outside of the leetcode framework if your language isn't represented there; if it is represented there, the Leetcode easy and medium are pretty good and there's loads of them).
I also recommend this same exercise to others through the book "The Ray Tracer Challenge" [1] by Jamis Buck, because it describes an entire implementation of a raytracer in pseudocode. Beginners mostly just need to plug-in their language of choice & still end up with a satisfying visual result. Experienced programmers can extend it by adding the ability to load non-trivial .obj models, which will necessarily motivate adding concurrency, bounding volumes, & other general performance improvements.
I'm planning on tackling it again in Elixir soon, which should be fun & interesting.
EDIT: Almost forgot to mention the free bonus chapters [2] that get you started on bounding volumes (AABB), soft area lights, and texture mapping.
[1] https://pragprog.com/titles/jbtracer/the-ray-tracer-challeng...
[2] http://www.raytracerchallenge.com/#bonus
[1] http://www.raytracerchallenge.com/#bonus
[2] https://raytracing.github.io/
[3] https://pbr-book.org/3ed-2018/contents
[4] https://github.com/mmp/pbrt-v3
[1] https://youtube.com/playlist?list=PLy68GuC77sUTyOUvDhVboQoOl...
I second the advice of loading .obj, it's a good exercise.
Implementing Octrees is another good one that will speed up your code while exploring tree structures in that language.
It covers sockets, string handling, and byte handling.
Python has been stuff like Pi hats with sensors, or using Pandas to analyze VAERS or Kaggle data. I assume this is similar for other scripting or backend languages/projects.
UI could be something like using Angular to build a simple site, or Android to build a simple app.
Basically find something that's simple and functionally similar to what you think you want to achieve with the language. At least for me, I want to learn a language to use it on a project, not just learn it for the sake of learning it.
This way I can see how to input data, display it and how I can operate with the database.
It's simple.
Sadly for Rust and MongoDB I tried that 5 times and never got to the point that it compiles. It just wasn't intuitive and the error messages didn't make sense. For Rust also I went through the tutorial, because I really wanted to like it and switch to it, but compared to Go it was just too complicated. I didn't understand the game, boxes ownership move unpack... it all didn't make sense . I digress but yeah, a guestbook is usually my 1st application.
- Simple scope, easily expendable. - Stack as a simple data model. - State machine for number entry.