Echoes from 308 logo

Echoes from 308

Subscribe
Archives
November 8, 2020

A Return to Programming

This past week was a bit of a blur. With the exception of the obvious (the US Presidential Elections), things were pretty quiet. As courses ramp up and project due dates begin to approach on the horizon, I of course did the responsible thing and put some things off to do some open source.


A hobby of mine when things were a bit slow at work was browsing GitHub. I worked at a shop where Scala was lingua franca so naturally I would try to find Scala projects to contribute to. The issue with this is that finding projects that I could work on was a bit of a challenge. Most projects fell into the following two categories:

  • Scala written by Java developers
    • vars everywhere instead of vals
    • misuse (or no use at all) of some of the best parts of Scala, e.g. calling .get on Option[T] types, no use of algebraic data types/pattern matching.... (I could go on)
    • tl;dr This code would actually be better in Java
  • Scala written by Haskell developers
    • I unfortunately do not know what a Semigroupal[F[_]] is
    • tl;dr Dude, I just want to program; I also haven't taken a class in category theory

I'd say that there's nothing wrong about the two types of Scala projects I've described above. They're just very different from how I write my code. Maybe one day I'll finally dive deep into category theory and my code will fall into the category of Scala code written by Haskell developers.


With some luck, I've actually managed to become a contributor to http4s, a Scala interface for HTTP. With the help of some incredibly patient developers on the project, I've implemented encoders/decoders for request query parameters, and squashed some small bugs. Last week I picked up a ticket to help the project cross-compile to dotty (the next version of Scala). Although it was a bit less complex than some of the other things I've done, I felt like it was a good use of my time, especially considering I had other schoolwork to do.


Starting with Scala 3 (dotty), the language isn't allowing untyped parenthesized lambda parameters. What that means is code like this

def extractNames[A <: Student](students: List[A]): List[String] =
  students.map { (s) =>
    s.maybeName.fold("Missing name!")(name => name)
  }

no longer compiles due to the lack of a type annotation for (s) => .... We'd have to re-write anything of this form into something like

def extractNames[A <: Student](students: List[A]): List[String] =
  students.map { (s: Student) =>
    s.maybeName.fold("Missing name!")(name => name)
  }

Not a really mentally challenging task, but an incredibly annoying one considering how common lambda functions are in Scala. Luckily, one of the maintainers recommended using a tool that would automatically re-write these types of expressions into their Scala 3-compatible forms. Unfortunately, I couldn't get it to work for our project so I had to use the following regex monstrosity: \{ .*:.*=>

Regex has never been a tool in my arsenal that I enjoy breaking out (or even looking at), so I'm excited to see how this work is gonna unfold. I probably missed a few places if I'm being honest.


In terms of what's happening in school, a student who came to office hours other day asked me: "Why do you enjoy programming?" I think that was honestly one of the most difficult questions I've been asked as a TA in a long time.

I was going to talk about that in this week's newsletter/blog post/whatever you call this thing, but I realized that I don't really have a good answer for that question. Rather, I feel like it's not something I can easily express. I'll probably save it for a future post.

Don't miss what's next. Subscribe to Echoes from 308:
Powered by Buttondown, the easiest way to start and grow your newsletter.