Live data from Hacker News

Ask HN: What is the coding exercise you use to explore a new language?

news.ycombinator.com

41–50 of 73 posts

Re: Ask HN: What is the coding exercise you use to explore a new language?

#42
Depends on the concept I'm trying to learn.

My "go to" for anything UI related is Connect 4.

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.

Re: Ask HN: What is the coding exercise you use to explore a new language?

#43
post #11

If one knows C++ then Peter Shirley's https://raytracing.github.io/books/RayTracingInOneWeekend.ht... is a pretty nice raytracer one can type in any language.

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

Re: Ask HN: What is the coding exercise you use to explore a new language?

#44

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…

+1 for rustlings, which also inspired "ziglings" [1]. Both of these were great resources for quickly & easily learning the basics of their respective languages.

[1] https://github.com/ratfactor/ziglings

Re: Ask HN: What is the coding exercise you use to explore a new language?

#45
Something that speaks to the language's strengths and the ecosystems' interests. The problem has to feel more than a simple exercise.

Functional -- writing an interpreter for a toy language,

Scripting -- Sudoku/Wordle solver with UI

Systems language with low-level hardware access -- OpenCV integration, driving I/O pins, web server.

For all of them, I also test access to native C/C++ libraries.

Re: Ask HN: What is the coding exercise you use to explore a new language?

#46
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.

Re: Ask HN: What is the coding exercise you use to explore a new language?

#47
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).

Re: Ask HN: What is the coding exercise you use to explore a new language?

#48
post #23

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…

I'm currently going through this book and it's amazing. Any tips on where to go once I finish it?

Re: Ask HN: What is the coding exercise you use to explore a new language?

#49
post #48
post #23

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…

I'm currently going through this book and it's amazing. Any tips on where to go once I finish it?

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!

[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

Re: Ask HN: What is the coding exercise you use to explore a new language?

#50
post #12

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.

This seems interesting. Any resources you can recommend for understanding the protocol? And any examples of simple clients in various languages?

I typically only use the spec (https://www.bittorrent.org/beps/bep_0003.html) because it's simple enough, but in case of doubt I guess a third party resource is good. I found https://blog.jse.li/posts/torrent/ to be quite informative about it.

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

Post reply on HN