3 ms·
I usually do AoC in Common Lisp, but this year I'm giving Swift a chance. It's not half bad at this kind of twiddling for being a statically typed mainstream l
by codr7 2y ago
I usually do AoC in Common Lisp, but this year I'm giving Swift a chance.
It's not half bad at this kind of twiddling for being a statically typed mainstream language.
https://github.com/codr7/aoc24/tree/main/swift/Sources/aoc https://github.com/codr7/aoc24/tree/main/swift/Sources/aoc
This year is a tiny bit weird, I was just getting ramped up organizing the event at a new job; because I think it's very useful for devs to learn some real problem solving, as opposed to stitching frameworks.
And then I had to leave because my new boss turned out to be someone I couldn't imagine working with.
Guess it'll be just me and Emacs as usual.
- usmannk 2y agodont you find all the string parsing and manipulation to be quite painful in Swift? I tried to do AoC in Swift before and that put me off a lot. I liked doing little functional one liners but a week from now the parsing burden will be too high.
- codr7 2y agoNah, the String type is fine as far as basic functionality goes, I like adding my own convenience stuff in extensions. The language has been moving pretty fast though, I have a feeling a lot of features I find useful are relatively new.
- tarentel 2y agoI program everyday in Swift. I attempted AoC for the first time in Swift last year and gave up after about a week or so for this exact reason and switched to python for the remainder. I don't want to struggle with the awkward string API to do things other languages can do in a line.
- codr7 2y agoI'm curious, any specific examples you can remember?
- mattdw 2y agoI found the Scanner API (1) to be pretty handy for the more complex parsing in past years. It’s Foundation so hopefully also on Linux/Windows, but if not there’s also one on GitHub called SwiftScanner. 1: https://developer.apple.com/documentation/foundation/scanner https://developer.apple.com/documentation/foundation/scanner
- tomtom1337 2y agoI enjoyed reading your solutions! I’m surprised how terse they are!
- codr7 2y agoLovely! I try to strive for readability first and foremost, which is a challenge in itself.
- timsneath 2y agoExcellent! Come and join the Swift leaderboard here https://forums.swift.org/t/advent-of-code-2024 https://forums.swift.org/t/advent-of-code-2024 if you haven't already -- it's super interesting to compare different solutions.
- clearing 2y agoAre you writing the solutions / compiling / running all with Emacs? I wanted to try Swift this year as well but feels sort of silly spinning up XCode for this.
- codr7 2y agoYep, on Linux, or WSL to be exact, I just use the internal shell though.
- spaenleh 2y agoYou can use VSCode with a swift project created with the SwiftPackageManager (SPM). I find the experience to be good, with a good LSP support. I just have to sometimes trigger the build task for it to find newly defined objects. That is if you have nothing against using VSCode.