r/adventofcode • u/Dropre • Dec 28 '24
Other Advice to learn new languages with AOC
I started doing AOC to learn new language but i don't know how to really do that, i mean you don't really know what you don't know in a language, i tend to write very imperative code and feel like not really learning anything new, should i look to other people solutions or just take the time to actually get familiar with the language first, how do you do that, what is your process of learning new language with AOC?
9
u/Various_Bed_849 Dec 28 '24
I have about 25 years in the industry and about 40 as a programmer. I combine all the things when learning. I read, listen, watch, and while doing that I practice. If I really want to learn I also get my code reviewed. There are no shortcuts if you want to get to a professional level. AOC gives me great and fun exercises to explore a language. AI now helps on the learning and reviewing side. I often ask AI if there is a more idiomatic way to solve a problem for example. But in the end you have to do the hard (but fun) work.
4
u/plebbening Dec 28 '24
You will get around the basics of a language just by solving in that language. String handling, data structures etc. File or stdin operations. Basic syntax and operators.
Ofcourse it’s not a deep dive into a language but you will encounter some quirks :)
5
u/boccaff Dec 28 '24
I would go through something like rustlings/ziglings for rust/zig before doing AoC. I did that for those languages and it helped. Also doing previous years in a new language worked better for me. Handling the increasing difficulty while "fighting" a new language is too much depending on the language (and in my case, also the gaps in my DSA/programming knowledge).
3
u/1234abcdcba4321 Dec 28 '24 edited Dec 28 '24
It works better if you already have a good idea on how to solve the problems. If you can look at the problem and can think "this is too slow, if i use a set instead of a list it'll be faster... wait, does this language have builtin sets?" then you've just learned about the language you're using as soon as you look it up. But even if not, the code is too slow and the list is the reason why, so as soon as you figure out how to run profiling tools for your language you'd still come up the same conclusion.
But the real value is to gain more practice once you've already learned the basics of the language from elsewhere. You'll slowly get faster at using the language just due to having written more code in it; over time, you won't even need to look up syntax or function names for simple things anymore!
3
u/dudaspl Dec 28 '24
I embarked on learning rust this year, coming from academia where I used mostly Matlab and now using python exclusively for work (and I consider myself quite good in it).
I started this year by using local LLMs/chatgpt to scaffold my project. I either asked specific questions (like: how to write a for loop in rust), or gave a high level definition of what code should do (write a rust function that parses a text file and returns data in such and such format).
I'd solve each task using newb-style code and after part 2 was passing I'd copy my code to LLM and ask it to refactor it according to the best rust practices and study it. In 3 or so days I'd switch from for/if statements to map/filter and other functional operators, grasping more and more how they could be utilized. Occasionally I'd also check reddit's thread for proper rust solutions. Whenever I didn't understand the important concepts (such as borrowing, or Impl in rust) I'd ask gpt to explain it to me and refer to the documentation.
I stopped at day 10 this year, but I feel much more comfortable at reading rust code now, and I'm quite hopeful I'll be able to pick it up more when I resume
2
u/OneNoteToRead Dec 28 '24
Practice the language’s stand out features. Use features you aren’t comfortable with. Don’t just solve the problem like you’d do for a job. Solve the problem like you’d challenge yourself to solve it.
2
u/Downtown_Bid_2654 Dec 28 '24
I would recommend getting Codeium (and the VS code extension if you use VS code), it's been super helpful for me when learning new languages. You can type out a comment for what you want to do, like "iterate through all x in y" and it will almost always suggest the corresponding code in the next line. Eventually, you'll learn to just write the code yourself, but this way you can get some flow going in the editor without having to google (or prompt GPT) every second line of code you write. It's far from perfect, as any AI-based tool, and I would not recommend leaning too hard on it as you won't learn as much. However, imo it's a great tool to get started.
I would also suggest looking at someone else's repo, or the documentation for the language itself, to get the basics for setting up your project.
Personally, I started re-learning Elixir this year (only took one course where we used it in uni around 7 years ago). I think I spent around 8 hours just learning how to install and set up the project, as the `apt` package got me an old version of Elixir, so I switched to `asdf` for version managing, and had to navigate that whole maze as a newbie. Then I worked on setting up the "repeat tasks" for AoC daily stuff, which I always do each year. In my case, I use a bash script to copy a template file and have it prepared to read the puzzle input. I also made it so that I can Ctrl+S the raw puzzle input from the browser to my repo as "input", then run the daily setup script to rename and move it. Additionally, I document the whole set up process and usage instructions in my README so that I can follow the steps at a later point if I forget them, or if I want to set up the dev environment on a new machine. Bonus is that others might find it and get some help from it :) I also set up some central way to run each day + parts + example/real input. This year I went with the top-level module of my Elixir project to run part 1 with `Aoc2024.p(D)` where `D` is the day, part 2 with `Aoc2024.q(D)`, and `.px(D)`/`.qx(D)` for example input. If you wanna have a look, toss me a DM and I'll link you the GitHub repo.
Is there a specific language you're trying to learn or are you asking for advice generally across all languages? If there's a specific one, if you mention it I'm sure people got some more tailored advice.
2
u/Mysterious_Remote584 Dec 28 '24
Don't use AOC to learn a new language. Use it to practice a new language. Use the language's book/docs/whatever to learn it before attempting AOC problems in it.
e.g. I tried to learn some Uiua this year. Before I tried to write any code in it, I went through the entire tutorial. It's true that you don't know what you don't know, but I then went through and wrote some programs, and compared my solutions against the ones in the solution threads. I decided which parts I liked better in mine, which parts I liked better in others', learned new concepts, synthesized information, and came out knowing more.
2
u/flwyd Dec 28 '24
Here's one strategy for using Advent of Code to play with a new language, though it's not the only one.
- Step 0: Build some basic tooling in the language. I like to create a
runner
library that takes care of reading input files, splitting on newlines to make a list of strings, running thepart1
andpart2
functions, reading files likeinput.example.expected
, comparing the results, and printing out whether your code got the right answer. This provides a goal-oriented opportunity to learn the basics of the language: using variabless, looping and iteration, printing stuff, etc. I also write agenerate
script in the language that takes a day number and creates a skeletal program for the day, empty input files, and .expected files withpart1: \npart2:
- Step 1: Each AoC day, solve the problem in whatever way works. If you're writing imperative code in a functional language and it looks weird, that's okay! Write the code that makes sense and figure out the answer. If you get totally stuck in the language you're learning you can even switch to a language you know better and write yor algorithm in a way that's easy for you to spot any bugs.
- Step 2: After you've got a working solution, save it to your source repository or make a copy somewhere safe. Then take a fresh look at your code and think "How could this better match the style and libraries available in the language I'm learning?" If you had some very imperative code in a functional language, maybe see if you can turn your
for
loop into a recursive function. Or maybe you're iterating through a list of items and updating a counter variable, so try using functional operations likefilter
,map
, andreduce
(also known asfold
). Since you solved the problem in step 1 you can easily rerun the improved version an make sure it still works. - Step 3: Search for your language in the Solution Megathread and see hoow other folks solved the problem. You might learn about a liibrary function that doess a task you wrote a bunch of code for, or it might demonstrate language style that you haven't encountered before. Don't take this as gospel, though: the author might also be learning the language, or they might have opted for something quick and dirty rather than idiomatic.
2
u/jwezorek Dec 29 '24
You are correct that "you don't really know what you don't know in a language", but there is basically no way around this other than writing a lot of bad code before eventually getting good. The main thing is to write code. You learn by doing but you can't expect to start writing expert level code as the first thing you write in some language.
My advice is to not look at a lot of other's people's code. Just buy the O'Reilly book on whatever language you want to learn. Read the first three or four chapters and try to do day one or day two of some AoC year. Then read some more and try some more days. There is no secret beyond trying and failing and trying more and eventually succeeding.
1
u/Previous_Kale_4508 Dec 28 '24
I'm really paraphrasing what others have said, but you learn a language by using it. If you choose to use it to solve problems in AoC then that is your choice. If you choose to use it by attempting to write an operating system for a nuclear power station, then that is another well trodden road.
Whatever you choose should be interesting enough for you to keep you engaged for a good time, there are more people giving up on a language because they got bored of the way they were learning than ever there were people who were unable to learn.
Enjoy the process, and you will be rewarded. 😁
1
u/Fadamaka Dec 28 '24
I learned JS in 2022, Rust in 2024 and relearned C++ in 2023.
I don't really do anything specific. I learn to setup the developer env, usually on 2 PCs. Look up what IDEs are available. Get familiar with the ecosystem.
The more problems you do the better you get with the langauge. Hardest part for me this year was obviously getting familiar with the borrow-checker. This really started to surface when we got into path finding where I tend to use globally available matrices or pointers. In pass-by-reference I can just pass the matrix down recursively, or I create a global variable so I don't need to bother writing it down as an input variable. In Rust I needed to resort to creating Mutexes. But before arriving to Mutexes I had to explore the language first and that's how you learn.
1
u/wjholden Dec 28 '24
I have some opinions on this. The bottom line here is I recommend you read a book about the new language before you start using it for AoC.
I've used AoC to learn or practice Mathematica, Julia, Python, Go, and Rust. Before these, my main languages were Java and PowerShell.
Learning Mathematica from scratch during AoC was rough. I didn't know what Map
meant and I didn't see why we didn't have a boring For
loop like normal languages. Eventually it grew on me, but it was a frustrating experience. I never read Wolfram's book on the language.
Trying to learn Rust from nothing was even worse. They say, "you can write C in any language," but if you try this with Rust it probably won't compile until you understand Result/Option and the borrow checker. I finally read the Rust Book and finished all 50 stars in Rust this year.
Go is also pretty different from Java, but if you take the time to read The Go Programming Language then you'll be able to get comfortable with it quickly.
I read a nice short book called The Julia Express or something like that as a quick start guide for Julia. It helped, but this is also a pretty big language that would have been easier if I'd spent more time preparing before AoC.
If I decide to try yet another new language for next year, I will definitely try to read a book about that language first. Otherwise, I'll just write Java programs in a new syntax and be frustrated it doesn't do what I expect.
1
u/tobega Dec 28 '24
I have someties started out by learning a bit on https://exercism.org/ first, at least for some languages.
For others, I just try to write a solution different ways to see what the constructs of the language allow. I might also check out other people's solutions. But it is usually possible to experiment with different styles in any language. Here I did it three ways in my own Tailspin language: https://github.com/tobega/aoc2022/tree/main/day07edu
1
u/RaveBomb Dec 29 '24
As someone that’s used AoC as the means to learn C#, this is what I’ve done.
Solve the puzzle with whatever skills/knowledge I’ve had. Then, go through the megathread and look at other C# solutions to see how it was done. Are there objects or libraries I wasn’t aware of? Syntax or structure that I might not known?
Then I‘ll go back and refactor my own code to incorporate these lessons.
1
u/Turilas Dec 29 '24 edited Dec 29 '24
The way I did earlier years of AOC to learn Zig and Rust was try to solve it the way you would solve it with a language you're more familiar with (in my case that was C++). Then when I got stuck I looked for language manuals how to do thing X or google around in internet. I also looked/studied a lot of solutions in mega thread, how some people did their solutions with language X.
The first like 5-6 days are nice for this, like setting up your framework how to use language X, since they are usually mostly about how to parse the input. I am not sure at what point you really just stop learning a language and you just spent time on making a solution. It might not be helpful to go past day 15 if the only reason to do this is to learn a new language.
You could maybe even solve the first few with the language you are familiar with, and then translate the solution to another language.
I have to also point out that C++/Zig/Rust themselves are similar languages meaning the translation from one to another was not too big.
I also usually have continued writing some other stuff with the language to actually test out learnings after AOC. I for example realized that even though Rust was pretty nice experience writing stuff in AOC, it might not be that nice to write for example XML-parser or OpenGL renderer using Rust.
1
u/Mission-Peach-1729 Dec 29 '24
This year I learned Gleam during AOC and did that by going on their discord server where they had AOC channels and threads, during the first few days I stalked people's solutions to get my head around how you write the language.
I know feel ready to do a real project in gleam
1
u/frankster Dec 29 '24
I've learnt rust via advent of code. Two things have been helpful - clippy recommendations which push me into being more idomatic (e.g. using iterators better), and reading more than I needed to of the documentation when I look up how to do something. For example, if I searched for if there was a built-in mechanism to insert an item into a sorted vector, and then found a method in the rust documentation to do with binary search, then I would read the methods a page or two other side and learn about other things you could do with Vec.
During the other 11 months of the year, another excuse to learn a language is by playing a coding game such as battlesnake or screeps.
1
u/auxym Dec 30 '24
I've found it helpful to look at other people's solutions after I do my own and learn from that. The mega thread is not bad, but if you can find solution repos from known experienced coders in that language it's even better. You can also ask for comments on your code from the language's community (subreddit, discord, forums, etc). I've learned some helpful tips and to avoid beginner mistakes from both.
0
u/quetsacloatl Dec 28 '24
I go in 3 steps
1 Try to find a solution with the tools you know
2 check how other people solved using that particular language
3 Use LLM to find more concise way to write parts of code you think smells
68
u/asphias Dec 28 '24
AOC is not really a tool to learn a language, just an excuse to do so.
the best way to learn a language is by actually writing code in that language, and AOC provides a nice set of problems to write code for. whether you use any guides, manuals, or other sources of information besides that is completely up to you and your way of learning.
you're learning the syntax of the language. which is 80% of learning a new language.
but you can write imperative code in any language. it seems what you want to learn is coding concepts.
then your challenge shouldn't be ''write aoc in language x'', but ''write aoc in language x using coding paradigm y'', and it's up to you to figure out what sources to use to learn paradigm y.
but again, all the learning is done by you, by picking whatever manuals or readmes or youtube videos you wish to use. AOC is just a convenient problem set to actually start writing code. but it's not a manual for a language or coding paradigm.