Live data from Hacker News

Learning Rust via Advent of Code

forrestthewoods.com

11–20 of 85 posts

Re: Learning Rust via Advent of Code

#11
post #2

What is HN-users view of learning a programming language through this kind of problem-solving? Is it limiting? Should this be used as a complement to a larger toy project?

It depends on your style of learning tbh. I enjoy going through a language's basics in docs (Golang playground and Rust's docs are fantastic) and then solving a problem.

My first "app" in Golang was a discord bot. I have to do maintenance on it occasionally and it's been a great learning experience.

Re: Learning Rust via Advent of Code

#12
I used this years AoC to learn rust and had similar issues with input parsing. I found a fairly simple parsing crate (https://docs.rs/scan-rules/0.2.0/scan_rules/) which helped a lot with the simpler inputs (day 24 was still a pain). It pretty much exactly matches the format you described.

Re: Learning Rust via Advent of Code

#14
post #3

Some comments having flown through the article > Helper Lambdas > I like lambdas in C++11. I use them regularly for small helpers that exist solely within a function. `move` lambdas might work better? The default tries to infer based on usage but often fails. A `move` lambda lets you do something similar to C++'s capture lists (though more verbose / cumbersome). > BinaryHeap > The standard library provides a max-heap…

The #[rustc_layout_scalar_valid_range_start(...)] and #[rustc_layout_scalar_valid_range_end(...)] attribute allows you to specify a niche, so you can build a Non255U8 if you want. For example:

#[rustc_layout_scalar_valid_range_end(254)] struct Non255U8(u8);

Re: Learning Rust via Advent of Code

#15
I do appreciate the rule set that Rust forces the programmer into, however I keep coming back to it felt to me that I was being asked to conform to the language. Maybe I'm looking at it all wrong. When I was also learning other languages it felt to me some of them conformed to me more than others, and therefore were easier to write logic towards. Is low level safe systems programming the main/only use case or is there a reason to use Rust in other domains?

Re: Learning Rust via Advent of Code

#16
post #2

What is HN-users view of learning a programming language through this kind of problem-solving? Is it limiting? Should this be used as a complement to a larger toy project?

I think this kind of learning is great. One of the benefits of this type of exercise is that tackle certain types of problems that are not that common in day-to-day coding, and you do it over and over, so you become quite comfortable with areas that you might otherwise not use frequently.

Building larger projects is of course also a great way to learn!

Re: Learning Rust via Advent of Code

#17
post #13

@forrestthewoods You have an incorrect link under the "Advent of Code" section. The first link reads https://www.forrestthewoods.com/blog/learning-rust-via-advent-of-code/(https://adventofcode.com/ It should just be https://adventofcode.com/

Fixed!

Re: Learning Rust via Advent of Code

#18
Hey, I did the same thing this year! At least I tried to do AoC in Rust until I reached the problem which required using doubly-linked lists... Turns out it's not quite as easy as a Rust newbie would think.

Regarding input parsing, I pretty quickly converged to using regexes and never looked back. I guess it's an acquired taste, but rubular.com is my best friend when it comes to it.

Re: Learning Rust via Advent of Code

#19
If you decide to learn Rust using AoC 2018, I highly recommend comparing your work with that of BurntSushi, who is known to write high quality code.

https://github.com/BurntSushi/advent-of-code

You develop Rust skills by writing your own and then hone your skills by learning from idiomatic Rust.

Re: Learning Rust via Advent of Code

#20
"Learning a new language via Advent of Code turned out to be a great idea. I highly recommend it."

I'll second this: Using a set of progressive problems is an excellent way to get used to actually writing code in a language.

"My first stumbling block was parsing. Almost every AoC problem starts with parsing lines of text from an input file."

Scheme. Guile. The PEG parsing module. (There's no kill like overkill.)

Post reply on HN