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.
I typically write a raytracer while attempting to stick to a small set of "best-practices" for the language I'm trying to learn. I also use this exercise from time-to-time to test new language features (for example C++20 ranges/coroutines recently).
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.
In that case, you might be interested in this youtube playlist [1]. The uploader claims to be new to Rust and implements the entire book in it. I haven't watched it myself, but had it bookmarked at the recommendation of a friend.
Thank you for this. A while ago I was doing a fair bit of Elixir in my spare time, so this has given me a reason to pick it up again. Going to give it a go myself
Once you finish the main book, there's a few free bonus chapters provided [1] that help you implement soft area lights, bounding boxes (AABB in this case), and texture mapping. Beyond that, you might be interested in the "One Weekend" series [2], which is all C++ but is mostly general enough for other languages. There's also PBRT [3] which is an open source textbook/documentation for the pbrt-v3 renderer [4], but this is beyond the scope of "small exercise" territory. Good luck!
If I'm looking for problems I always like to try Advent of Code problems, it's a good chance to learn basic io, sample the standard library, and learn how to idiomatically handle common problems.
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.
I commonly build a name generator based on travesties or Markov chains. I can write a simple version of it in a few minutes in a familiar language, but it exercises file IO, some simple data structures, string operations, and some randomization. Gives me a good first general idea of what it will be like to work with a new language.
Command line tool that ingests an arbitrary-length (but assumed finite) stream of lines, parses each line to a number, computes the Welford single-pass algorithm for mean and standard deviation, and prints the output nicely to the console.
It's a good introduction to handling input and output, string manipulation, error handling, abstractions for iteration (or lack thereof), and language performance characteristics. All while being a fairly easy task that can be implemented easily but performantly in 60 lines of Python: https://git.sr.ht/~wintershadows/polyglot-benchmarks/tree/ma...
It also lets you play around with different software architectures and abstraction models, introducing enough real-world complexity to prevent you from making too many assumptions, while the logic is simple enough to keep you from getting lost in deep algorithmic implementation.
I have started adding some of these implementations to a Git repo that I will eventually fill out with other "polyglot" comparisons. See here for (currently) Python, Nim, Perl, and (somewhat-overengineered) Common Lisp: https://git.sr.ht/~wintershadows/polyglot-benchmarks/tree/ma...
I have several more implementations that I haven't committed to Git yet, because I've been lazy.
I've learned a lot through this process, not just about individual programming languages, but also about "how things work" in the process of trying to figure out why Python is so much faster than every other language I've tried (on par with Nim, handily beating all others, haven't tried plain C yet).
My very first goal is always to write a “hello, world” program, deploy it to a web server, then uninstall the language, runtime, and other required assets... and do it again. I write up the process, then follow those instructions on a new system. Rinse and repeat until it’s possible for a chimp to replicate.
By far the most trouble I ever have is getting soup-to-nuts deployment happening such that I can concentrate on fixing bugs without being scared shitless I won’t even be able get the damn thing running in production.
Thanks for all the comments. Just to clarify, not really asking how to learn a specific language or how to code. Question is more if one were doing a survey of various languages to understand disadvantages/advantages of each and for a general working knowledge, what's a good relatively quick baseline exercise to do that comparison ?
I usually pick one of the ideas on my low-stakes "side quest" list that I maintain. Something that I won't mind if it never gets finished, or if I have to trash it and start over because of what I learned while building it the first time, now that I know the language better. I'm currently working on a RISC-V cycle-level simulator in Rust.
While I'm picking up Rust, I really like the "rustlings" project that lets you exercise various parts of the language locally, instead of in a browser, so I can use the tools that I like. https://github.com/rust-lang/rustlings
+1 for rustlings, which also inspired "ziglings" [1]. Both of these were great resources for quickly & easily learning the basics of their respective languages.
If it's a game engine, I tend to do a simple port of my Proximity game[1] to it. I don't usually finish it enough to release it, though (I probably could and should in retrospect). I've done that for Flash, C#/XNA (eventually released on Xbox Live Indie Games as "Proximity 2"), J2ME, Java/Kindle, iOS/Objective-C (eventually released, but no longer in the store), Python (just a command line ASCII version), LUA/Pico-8 (nearly done, I just need to force myself to spend a couple weekends and finish it up), PlayDate (functional, mostly a port of my Pico-8 version they are both LUA-based, but it's not pretty and I don't have my PlayDate yet for testing to feel comfortable releasing the game yet), C++ (mostly made this for my portfolio for game dev jobs), and probably a couple others I'm forgetting.
Currently working on a new version in C#/Monogame, and next version after that will probably be Unity so I can make a VR version, something that's on my bucket list. Also at some point I'm going to make a new web version again using Javascript/Phaser (already made another simple game in Phaser, so it shouldn't be too hard, just need to actually do it).
It's been going slow though since I have so much less spare time and energy nowadays, though.
I try to explore a language using different problems every time. If you've already done a project or solved a problem, I think your previous solution will detract from getting a feel for a language's features and conventions by inspiring you to follow a certain pattern.
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.
I have and continue to spend obscene amounts of time orchestrating the entire systems architecture from zero to full tilt in my language of interest. I start with base functionality applied examples needed throughout the systems life cycle; documentation, templates, clis, daemons, logging, cryption, networking, queuing, concurrency, databases and more as these are the teaching tools about the platform of "what, why, how". Such a simple statement does not accurately represent the details or the value however the experience of having founded and exited several technology companies using this model has proven the approach. With each passing new iteration the system's simplicity of understanding has increased while also adding value in many areas of support, new hires, and management. If it ain't broke don't fix it so after five previous complete refactors under multiple companies this sixth iteration is first for enjoyment in problem solving and then to apply this work to yet another startup. Nothing is more important than the foundation!
I generate an n-dimensional just intonation pitch lattice, based on my study of the work of Ben Johnston.
I like it because it’s kind of small, but tests several aspects of working in the language.
* the program needs support for several numeric types: integers, floats and rationals.
* several basic math algorithms are needed, which will either test the std lib, how to use the package manager, or other language constructs as I pipeline implement them
* how easy is it to write/run tests
Here’s one version in Rust, which links to clojure, cl versions. Want to try it with Julia next due to the built-in support for rationals.
I use Advent of Code every year to improve my understanding/facility with some language that isn't a strength of mine. The benefit of doing that is that it's well-paced and interesting to me. The downside is that at least 35% of AoC is algorithmic and once you discover the "trick", redoing that AoC puzzle in a new language is less interesting (though it will still drive understanding of the new language).
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).
Adding to this, a lot of projects these days will rely upon some external libraries and APIs. So a new language in this case is just a sauce to consume the utilities.
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.
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.
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.
Cryptocurrency analysis. Open APIs and a huge flow of data from the exchanges. And I mostly don't care about cryptocurrencies, nor am I holding any in my portfolio.
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.
Meta-answer: I like to pick a project I wouldn't mind doing a 2–3 times in that language. It's hard to learn all the best practices, idioms, etc. of a language in one sweep. Having a project that you can repeatedly do in X language—making it more "X-like" each time—is a good way to learn how to refactor things and structure things "natively" in language X.
If the language isn't well represented yet on rosettacode.org I like to learn about a language by implementing rosettacode examples in it: https://github.com/eterps/odin_rosettacode
Can anyone out there compare this to The Ray Tracer Challenge (https://pragprog.com/titles/jbtracer/the-ray-tracer-challeng...) which has also been mentioned in this thread. They seem to be trying to do very similar things, and it would be interesting to hear how the differ and their pros and cons
May sound boring but usually it's a CRUD web API.
But it really depends on the language. If the language is not particularly suited for this kind of project, first I find a good use case and then I build a simple version of it.
"How quickly can I build 50 different tiny demos that each show one thing"? Small size means you can focus on one thing at a time, before you hit #50 you'll probably already be building off of what you've learned in past demos and combining them as you try new things.
Other than that I try to pick a game that fits the theme. Games are amazing because they have well defined business requirements with sufficient depth to really exercise your critical thinking skills.
I write a bittorrent node. It goes over many topics I'm interested in: potrntially low-level networking, storage, bits and bytes fiddling, concurrency. The protocol is shockingly simple, and the end result is both easily testable and actually useful.
My focus is usually from a game dev standpoint.
I might see how quickly I can put together an A* algorithm on a 2d array.
Or Conway's game of life as a similar, how easily can I process these things.
I always recommend building a calendar app, or something that deals heavily with dates. Knowing how to work with date and time in any language is critical.
I want an official certification of 140 IQ and your comp sci degree from everyone posting here. Otherwise do fizz buzz and go do some easy level problems on code wars. Much more makes little sense when you don't even know the array initialization syntax yet.
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