Readit News logoReadit News
tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
jsmo · 8 hours ago
Nice, thanks for the write-up! Any pros/cons that jump out to you for someone whose been trying to pick up Elixir on the side?
tymscar · 8 hours ago
Thank you! I have not played around with Elixir just yet, sadly, so I can't help there, I'm afraid.
tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
mjmas · 8 hours ago
double space before each line for code formatting
tymscar · 8 hours ago
Thank you! TIL
tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
titanomachy · 9 hours ago
I don’t know gleam, but surely

    list.map(fn(line) { line |> calculate_instruction })
Could be written

   list.map(calculate_instruction)

?

tymscar · 8 hours ago
You're right, but loads of times I just left that there because I probably did something more involved in the map that I ended up deleting later without realising.
tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
WJW · 9 hours ago
There are (some) guards available though? You could rewrite your example as:

    case x {
      n if x < 0 -> ...
      n if x > 10 -> ...
      n if x <= 10 -> ...
    }
Guards are a bit limited in that they cannot contain function calls, but that's a problem of the BEAM and not something Gleam could control.

tymscar · 9 hours ago
You most likely asked an AI for this. They always think there is an `if` keyword in case statements in Gleam. There isn't one, sadly.

EDIT: I am wrong. Apparently there are, but it's a bit of a strange thing where they can only be used as clauses in `if` statements, and without doing any calculations.

tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
WJW · 9 hours ago
Gleam is really quite a nice language. I did AoC in it this year as well and came away with the following: (incomplete list for both positive and negative, these are mainly things that come to mind immediately)

Positive:

- It can be pretty performant if you do it right. For example, with some thought I got many days down to double digit microseconds. That said, you do need to be careful how you write it and many patterns that work well in other languages fall flat in Gleam.

- The language server is incredibly good. It autoformats, autocompletes even with functions from not-yet-imported-but-known-to-the-compiler packages, shows hints with regarding to code style and can autofix many of these, autofills missing patterns in pattern matches, automatically imports new packages when you start using them and much much more. It has definitely redefined my view of what an LSP can do for a language.

- The language is generally a joy to work with. The core team has put a lot of effort into devex and it shows. The pipe operator is nice as always, the type system is no haskell but is expressive enough, and in general it has a lot of well-thought out interactions that you only notice after using it for a while.

Negative:

- The autoformatter can be a bit overly aggressive in rewriting (for example) a single line function call with many arguments to a function call with each argument on a different line. I get that not using "too much" horizontal space is important, but using up all my vertical space instead is not always better.

- The language (on purpose) focuses a lot on simplicity over terseness, but sometimes it gets a little bit much. Having to type `list.map` instead of `map` or `dict.Dict` instead `Dict` a hundred times does add up over the course of a few weeks, and does not really add a lot of extra readability. OTOH, I have also seen people who really really like this part of Gleam so YMMV.

- Sometimes the libraries are a bit lacking. There are no matrix libraries as far as I could find. One memoisation library had a mid-AoC update to fix it after the v1.0 release had broken it but nobody noticed for months. The maintainer did push out a fix within a day of realizing it was broken though. The ones that exist and are maintained are great though.

tymscar · 9 hours ago
I was also pretty surprised about the performance. It's not C, but it's so much faster than I'd guessed.

I do agree the language server is great. And it works in basically any IDE, which is another huge bonus.

With regards to having to type `list.map`, you actually don't need to! You can do this:

  import gleam/list.{range, map}
  import gleam/int

  pub fn main() {
    range(0,10) |> map(int.to_string) |> echo
  }
Some libraries just aren't there, and I do wonder how hard it would be to port C libraries over. Something I want to play with!

tymscar commented on I tried Gleam for Advent of Code   blog.tymscar.com/posts/gl... · Posted by u/tymscar
periodjet · 9 hours ago
Ruined by ligatures. Use them in your own private coding time, not when trying to communicate with others. It obfuscates rather than clarifies.
tymscar · 9 hours ago
I actually agree. I don’t even use them in my private code. I will look into removing them from my blog!
tymscar commented on Imgur geo-blocked the UK, so I geo-unblocked my network   blog.tymscar.com/posts/im... · Posted by u/tymscar
iLoveOncall · 14 days ago
This took me a good 4 hours uninterupted to setup as I had not a single item in the stack setup yet (PiHole, Traefik, etc.) but do have Docker running on my NAS, but the end result is satisfying.

To anyone that wants to follow this article, it's more general guidance than an actual tutorial, there's a lot of holes to figure out.

It also doesn't work when directly accessing imgur, even if you add rules for the domain and the other subdomains they use, which is annoying.

tymscar · 14 days ago
Hey. I’m glad you got it working. I didn’t intend it to be a step-by-step tutorial, more like a “hey, this is how I solved it”, with some details like the configs in case you want to follow along. And yes, the website itself still does not work, no matter what URLs you try to fix; it’s just the images, which, for me, are good enough.
tymscar commented on Imgur geo-blocked the UK, so I geo-unblocked my network   blog.tymscar.com/posts/im... · Posted by u/tymscar
perching_aix · 14 days ago
> Back when Reddit embedded everything on Imgur, maybe fifteen years ago, it was genuinely useful.

This is true, and I learned to hate every bit of this fact. It taught me to despise hotlinking with passion.

All of those links are now down the train, and you have to pray that someone not only backed up the specific image you're looking for, but that they did so in a discoverable way.

tymscar · 14 days ago
I guess at the end of the day it was a tradeoff we had to take for the lack of a better alternative back then
tymscar commented on Imgur geo-blocked the UK, so I geo-unblocked my network   blog.tymscar.com/posts/im... · Posted by u/tymscar
tymscar · 15 days ago
Oh, I guarantee you that this has not been touched by any AI. I used to use emdashes all the time, then people thought those were AI telltale signs, so I stopped. I loved making lists. Same thing.

Now I’m not allowed to say “key detail”??

u/tymscar

KarmaCake day675February 12, 2015
About
[ my public key: https://keybase.io/tymscar; my proof: https://keybase.io/tymscar/sigs/hNW8A9dk5jXMaIZN45Xydc9piAVVYVpb9M9KroqKHMk ]
View Original