Gleam v1.12

(github.com)

156 points | by Alupis 18 hours ago

6 comments

  • Alupis 18 hours ago
    Some highlights from this release are listed here[1].

    The best part of Gleam in my opinion is the language's design. It's just so elegant to read and write. Take this example code snippet from the release notes:

        pub fn find_book() -> Result(Book, LibraryError) {
          case ask_for_isbn() {
            Error(error) -> Error(error)
            Ok(isbn) -> load_book(isbn)
          }
        }
    
    
    It's a trivial code snippet, but I'm finding this kind of "first class" pattern matching produces very readable, elegant-looking, well organized code.

    There was a discussion the other day about the pipe operator being added to PHP 8.x. Gleam was my first language which included a pipe operator. Now, having used it a bit, I feel every language should have something like it.

        pub fn hello_test() {
          telephone.ring()
          |> should.equal("Hello, Joe!")
        }
    
    The pipe skips so much boilerplate and clearly communicates intent. Absolutely love it.

    [1] https://gleam.run/news/no-more-dependency-management-headach...

    • ZpJuUuNaQ5 17 hours ago
      >It's just so elegant to read and write.

      Interesting. I was just about to write the opposite. I tried Gleam to solve last year's Advent of Code, and it felt like a weird mix between Rust and Elixir. You can't write code as elegantly as you'd do in Elixir, which was somewhat disappointing. I switched back to Elixir after a couple of days. I think the biggest advantage of Gleam is static type system.

      • lpil 17 hours ago
        If you've examples of code you have in Elixir that you could not express well in Gleam I would be very happy to help you out with that.

        The two languages are almost the same at the value level, so code should translate across well.

      • Alupis 17 hours ago
        Depending when this was, it was likely pre-1.x days? Things moved very quickly there for a while - it's worth checking back in again.

        Gleam seems to have a lot of obvious influences from Rust, and the creator is a rust dev.

        While the Gleam ecosystem is vastly less mature than Elixir's or Rust's (because it's literally younger), the language itself, I've found, is vastly more pleasant to read/write. YMMV of course.

        • lpil 17 hours ago
          > Gleam seems to have a lot of obvious influences from Rust, and the creator is a rust dev.

          Hi! That's me!

          Gleam the language doesn't have any Rust influence really. It's a happy accident that some of the syntax ended up looking the same, but that's likely due to both being inspired by similar languages such as OCaml and the C family. Most the syntax and the semantics predate Gleam's compiler being rewritten in Rust.

          The build tool is a rip-off of Cargo for sure though.

          • Alupis 17 hours ago
            > The build tool is a rip-off of Cargo for sure though.

            Hey, great artists steal, as the saying goes...

            It's all shaped up really nice. I'm a big fan of Gleam and your work in general.

            • lpil 15 hours ago
              Thank you, very kind.
        • zem 17 hours ago
          more like both gleam and rust have a strong ML influence (gleam might actually consider itself an ML? not sure about that, but it's definitely a descendant)
      • innocentoldguy 15 hours ago
        I prefer Elixir's syntax over Gleam's, but my main issue with Gleam is architectural. Specifically, Gleam had to bastardize BEAM and OTP to implement static typing. To me, static typing vs. dynamic typing is like having a shelf with a doily vs. one without a doily (the shelf works fine either way), so messing up a solid Actor Model implementation, for instance, for the sake of static typing seems like the wrong thing to do.
        • chamomeal 14 hours ago
          How does it bastardize the beam? Like are there things you can do in elixir/erlang that you couldn’t with gleam?
          • Alupis 13 hours ago
            I'm curious to know what the parent meant, as well. My understanding, which is incomplete admittedly, is that Gleam's type system lives in Gleam and isn't carried over into the produced Erlang/BEAM code, since BEAM has no concept of types, etc.

            Gleam also has an OTP implementation[1] available, which includes Actors and the like. My understanding is that every BEAM language must implement OTP themselves, so there's nothing unusual here.

            [1] https://hexdocs.pm/gleam_otp/

    • giacomocava 17 hours ago
      Omg yes, pattern matching is such an amazing feature I miss it dearly in languages that don't have it!
    • steve_adams_86 18 hours ago
      I'm so envious of this. In TypeScript I use ts-pattern and Effect Schema, and while they make this logic way nicer, it's insanely verbose and doesn't offer any of the niceties of being first class.
      • Alupis 17 hours ago
        I have not used it at all, but Gleam does have a javascript target in it's compiler/build-tool. So in theory, you can write Gleam (strongly typed, etc) and produce js.

        I've exclusively used the BEAM/Erlang target so far - but the js community within Gleam seems quite interesting.

        • steve_adams_86 17 hours ago
          I've been considering trying this, but my team already struggles to properly adopt TypeScript so I'm fairly sure introducing Gleam would cause a few people to throw me out a window.
          • giraffe_lady 15 hours ago
            Gleam is so much smaller and easier than typescript and the type system works harder for what it is. TS gets you because it is similar to javascript in some ways that make it easier to start the transition. But a complete js -> ts transition is about as big a deal as it would be from js to any other language, except you can use the same external libraries.
            • anon3459 10 hours ago
              No just no
              • giraffe_lady 10 hours ago
                Sorry but yes. Pure structural typing is a dead end hindley milner is the future.
    • thijsvandien 17 hours ago
      Error(error) -> Error(error) has strong if err != nil { return err; } vibes, and I don't consider that a good thing.
      • bmacho 15 hours ago
        No, it doesn't have strong if err != nil { return err; } vibes.

        Pattern matching on Ok/Error is one of the best known error handling, while go error handling is one of the worst. They are about as far from each other as possible.

        • smithcoin 15 hours ago
          Interesting, I find myself thinking the exact opposite.
      • debugnik 16 hours ago
        That's what Gleam's use expressions[1] are for (the last example is exactly this case). Most languages with the same heritage as Gleam have grown a similar syntactical feature, such as OCaml's binding operators or F#'s computation expressions. Although I appreciate how simple Gleam's is while having similar power.

        [1]: https://gleam.run/news/v0.25-introducing-use-expressions/

      • Alupis 17 hours ago
        This is a trivial snippet. Often you will transform/map your error into another type (or deal with it in some way), so it's not so much `if err != nil { return err; }` vibes like you're thinking here.

        The beauty here is being compelled to handle both the happy and sad paths. You cannot just pretend the sad path doesn't exist.

    • no_wizard 15 hours ago
      snake case convention is the only thing that always feels odd to me.

      Perhaps its because I deal in TypeScript all day, every day, but it never stuck with me.

      That said, small price to pay for a very nice runtime!

      • __jonas 14 hours ago
        I come from js/ts as well and I find snake case much more readable than camel after using it in other languages for a bit. There are even js/ts projects that use snake case despite the camel case convention, for readability

        https://github.com/sveltejs/svelte/issues/3479#issuecomment-...

        • plainOldText 14 hours ago
          Yeah, CamelCase for modules, snake_case for functions and variables.

          Your brain can instantly tell what entity you’re dealing with.

      • Alupis 15 hours ago
        I come from a background where everything is camelCase. Naturally I wrote my JSON this way as well, among other things.

        Switching to snake_case was challenging at first - I kept writing things in camelCase. Now, I've become pretty fond of snake_case and have a tough time going back into environments that require camelCase - funny thing, that is.

        Thankfully Gleam's build tool/language server has a fairly strongly opinionated formatter built in, so it will let you know pretty quickly and help you fix it.

        • zelphirkalt 48 minutes ago
          One thing I disliked is black, the Python formatter, with its utterly naive rules, that treat all code the same. It required me to workaround in many places, like always using a trailing comma for any list or tuple, to keep the items on separate lines, instead of black fumbling around and putting them on the same line. It was utterly annoying. This made me very vary of "opinionated" (read: inflexible unconfigurable pieces of software) formatters. Hopefully Gleam's formatter isn't as stupid as black is.
  • okkdev 16 hours ago
    The link should probably point to the excellent 1.12.0 post on the website: https://gleam.run/news/no-more-dependency-management-headach...
  • mistahchris 16 hours ago
    I really like gleam. I have a few unfinished side projects in gleam with about 10k lines of code, so I've had enough of a taste to know I like it. I can't wait to see how it matures. I plan to write more gleam in the future. I am particularly excited about the possibilities of sharing more code between webapp frontends and backends. Gleam has so much potential and is already quite productive.

    I am not that online of a person. But I joined the discord to say hi and ask a few questions and I have to say the community really does have great vibes. If I were spending more time online, I would likely bias to spending it in the gleam community. They're a bunch of very friendly, and smart people working on a wide variety of interesting projects.

  • brightball 17 hours ago
    Great talk on Gleam from August last year.

    https://youtu.be/vyEWc0-kbkw

  • ninetyninenine 14 hours ago
    I tried to make a c-compiler in gleam. One thing I really didn't like is the lack of interfaces/type-classes and lack of composition operator.
    • Alupis 13 hours ago
      Gleam has a note regarding type-classes on their website[1]. The language itself seems to aim to remain simple - which is a pretty good thing in my opinion.

      [1] https://gleam.run/frequently-asked-questions/#will-gleam-hav...

      • ninetyninenine 12 hours ago
        I don’t like it. Makes it feel like golang it’s like they want to keep it simple so they remove something fundamental. Golang says the same shit in their faq and there’s a whole slew of people who gave golang so much shit for it. Especially the fp community.

        Golang for the longest time had no generics. Now it doesn’t have sum types.

        When you try to build something truly complex like a compiler, you’ll see the abstractions start to screw up because can’t use interfaces in gleam.

  • ASalazarMX 17 hours ago
    The official website has an interesting footer

    > As a community, we want to be friendly too. People from around the world, of all backgrounds, genders, and experience levels are welcome and respected equally. See our community code of conduct for more. Black lives matter. Trans rights are human rights. No nazi bullsh*t.

    On one hand I applaud that their community standards are inclusive, but on the other hand, it shouldn't be that blatantly ideological from the get go. It's just another programming language, not a political platform.

    • steve_adams_86 17 hours ago
      I used to be on the fence with this, finding the ideology-forward attitude fairly abrasive. I've since decided that while I don't love it, I see the perceived necessity of it that some people have. I enjoy the privilege of living somewhere and being a person who no one cares to cause problems for. Some people don't have that experience, and are targeted routinely and unfairly. I see it like they put up these barriers and deterrences because they need to, not just that they want to. People who support them participate in that endeavour because it matters enough.

      For guys like me, it seems like a needless distraction from what matters. Unless I consider living a life in which there are people who don't want me to exist, or something. Then yeah, I might throw up a few "please fuck off" signs, I don't know.

      • AnEro 16 hours ago
        I used to think it was kinda pander-y, but then after participating in some of these communities it was just obnoxious when it wasn't stated, the cultural wedge between people. Where randomly there was drama from someone posting an unrelated yet offensive meme/joke, then it was a huge discussion on if it was ban worthy, if it was okay to joke about, or xyz. When really I just wanted to be nerdy with others.
        • steve_adams_86 16 hours ago
          I get that. You can put up the signs, but it doesn't need to be a regular, loud topic in the community. In fact, the signs should serve to prevent the need to discuss it in the community and make moderation cleaner and easier.
          • ModernMech 13 hours ago
            I like what Rust does: they make the LGBTQ+ flag the background of the discord icon. Nuff said.
      • zdragnar 16 hours ago
        I dunno, it seems like everyone should have learned lessons from the sordid scala and node drama incidents, but instead they're just forgotten.

        Don't make in groups and out groups. Just have a "be nice" rule and leave it at that.

        • steve_adams_86 16 hours ago
          The trouble is that nazis think it's very nice to get rid of the untouchables. Life is messy, you've got to set some boundaries and stick to them or jerks gum up the works.
    • SwiftyBug 17 hours ago
      The Gleam community has been the best, most welcoming community I've ever seen on the internet. And I've been a around for a while. I attribute this in part to their clear stance.
      • steve_adams_86 17 hours ago
        I was welcomed too, and strongly encouraged to contribute. It was really nice. Though the signals might appear abrasive to some, it doesn't represent an abrasive group of people at all.
        • Alupis 17 hours ago
          Joining their Discord and getting greeted by the language creator himself within a few minutes was pretty cool. Most other languages, their creators/maintainers seem so unapproachable and distant. You can talk directly with the core team on there, ask questions, etc. Louis really has built a pretty fun community around Gleam.
        • batisteo 15 hours ago
          The good thing is, you don't have to be tolerant with the intolerant. And that's exactly what they are advertising. It let the nice people flow in, as you experienced.
    • tuttigachimuchi 17 hours ago
      Programming languages aren’t math—they are cultural products that have the right to express their values and objectives
    • alain_gilbert 11 hours ago
      The most ironic thing is that if you search for "nazi programming language" you'll find gleam.
    • arrowsmith 14 hours ago
      I've never used Gleam and really don't care either way about the creator's politics, but it would be nice to see Gleam hit the HN front page for once without this same tedious conversation getting repeated every time.

      Isn't there something more interesting we can talk about?

    • akkad33 16 hours ago
      But this is not very relevant to the release announcement?
      • buzzerbetrayed 15 hours ago
        When you put distracting things on your homepage, don't be surprised when they're distracting
    • lpil 17 hours ago
      > It shouldn't be that blatantly ideological from the get go. It's just another programming language, not a political platform.

      It's first and foremost a community, and it's important for communities to have clear a code of conduct and moderation of that code.

      There are lots of languages without community, Gleam is not one of those.

      • giraffe_lady 15 hours ago
        Gleam is an incredible technical achievement and the community an amazing social one. You should be proud of both, thank you for your clear vision and commitment on this issue despite so much consistent external pushback.
        • lpil 15 hours ago
          Thank you, you are very kind. I am extremely proud of the community, they are wonderful lot.
    • ForceBru 16 hours ago
      > Shouldn't be that blatantly ideological, it's not a political platform

      Yeah! This always stands out like a sore thumb on the website. Like _yeah_, all of it should go without saying! You're a freely available programming language, of course everyone can use it! Of course everyone is welcome! Does a hammer care about your gender or race? No, anyone can use it! It's also very weird and a little childish to specifically include "no nazi bullshit". Isn't it obvious that "nazi bullshit" isn't welcome? Like a no-brainer? Why does a programming language feel the need to say this? Are prominent nazis actively showing interest in Gleam and trying to promote their "bullshit" with it?

      Also, the phrase "nazi bullshit" is severely downplaying the problem with the nazis. "Bullshit" is usually something mildly inconvenient, somewhat unfair, kinda infuriating, but it usually doesn't threaten anybody and doesn't fuel world wars.

      • atomfinger 16 hours ago
        > Isn't it obvious that "nazi bullshit" isn't welcome? Like a no-brainer?

        Unfortunately, not in this day and age.

        > Why does a programming language feel the need to say this?

        It's less about "the language saying it" and more about the standards of the community that surrounds the language.

        For a language to thrive, it needs a community of people contributing to it. If it doesn't, it'll eventually die unused. As such, there's more than "just the language"; it is also a community-building effort.

        > Also, the phrase "nazi bullshit" is severely...

        IMHO, you're reading too much into the word "bullshit".

      • samdoesnothing 15 hours ago
        [flagged]
        • re 13 hours ago
          > I'm just sharing what I've observed

          Can you be more specific? I'm curious about the types of "slightly right leaning" things that you think are reasonable to say in a programming language community, but that would be controversial or forbidden in a "highly politicised"/"no nazi bullshit" community.

          • samdoesnothing 12 hours ago
            Any praise of capitalism, any outward support of right leaning parties, any criticisms of immigration policy, etc.
        • giraffe_lady 15 hours ago
          HN itself has quite a lot of "nazi bullshit." You don't usually, regularly see people being virulent about it but people frequently endorse policies that would absolutely have fit cleanly into the historical nazi party's platform. Things like race science and eliminationist policies against the homeless, anti-immigration stances, homo- and transphobia are particularly popular. People here are normally "polite" about it and we seem to all have decided that means it doesn't count. It does count.
          • samdoesnothing 13 hours ago
            [flagged]
            • giraffe_lady 12 hours ago
              • samdoesnothing 12 hours ago
                The latter I see.
                • giraffe_lady 12 hours ago
                  As I said, several of these would fit cleanly into the historical nazi party's platform. A pretty narrow claim that I would certainly not accept about a site I was moderating.
                  • imtringued 3 hours ago
                    Ok, but if you read the "wolf in sheeps clothing" party program of the nazi party and put it in the context of the aftermath of what the party actually did, you'd realize that they don't actually care about their program and only ever used it as a wedge to blame outgroups for the ills of society.

                    What I'm trying to say here is that the nazis were outwardly role playing socialists to appease workers, but when it was time to punish the "capitalists" they didn't seem to care whether they were actually capitalists and were more interested in whether a person was part of the ingroup (=white christian Germans) or not. In other words, if capitalism or market economies are rigged, then they only care about whether the economic system is rigged in favor of the ingroup.

                    The reason why I'm responding to you is that the barrier to a nazi accusation is essentially zero these days and most anti-fascists I've encountered are essentially the spitting mirror image of fascism. They declare an outgroup, but call it nazi this time. Then the anti-fascist logic allows the justification of infinite retaliation. Any shred of being principled is completely thrown out the window.

                    Because nazis controlled all of Germany for a time, they've done a lot of things that can be attributed to them, which means there are a lot of things you can take about any ordinary person and create a very loose nazi association through motivated reasoning.

                    Note that in a mirror image, left and right are swapped. They're not the same, but they are eerily similar.

                    Yep, these days you can be fed Youtube shorts of people arguing the Green Party in Germany are Nazis, while there is an actual party (AfD) that puts hidden hitler moustaches on Alice Weidel in their official fliers. That same party claims Adolf Hitler was a leftist and leftism is bad, which is good, because they're not leftists, but they also happen to like Adolf Hitler.

    • ModernMech 16 hours ago
      Trans people are over represented in compilers communities. You don’t get programming languages without the hard work of people in the trans community. In a world where they are constantly under attack, it’s important to make them feel safe and welcome. Trans people are welcome in our dev communities and that needs to be explicitly stated these days, because trans inclusion is not implied in our bigoted society.
    • AnEro 17 hours ago
      > It's just another programming language, not a political platform

      Politics is baked into everything we do, like the lack of any political messaging is still a political message. With this approach, it weeds out those that don't align with the core community which is ideal for an organization that only thrives with volunteer involvement.

    • terminatornet 10 hours ago
      Counterpoint: it's actually good to be vocally against nazi bullshit
    • turnsout 17 hours ago
      Being anti-nazi is not ideological.
      • ribelo 16 hours ago
        Of course it is. You can't be against anything without an idea, without it you wouldn't be opposed, you'd just not give a shit. Not caring isn't ideological just like not believing in god isn't, but being anti-god? That's pure ideology.
        • timeon 14 hours ago
          Sure but 'not giving a shit' means accepting Nazism.
          • ribelo 12 hours ago
            Yeah, like not spending your every penny on poor is accepting a misery.

            In The Good Place, a brilliant show, there’s a great scene where we find out why people stopped getting into the "Good Place" after they died. Life used to be simple before: if you bought your wife a flower, it was a straightforward good deed. Now every action is tainted, because the CEO of the flower company employs child labor, cheats on his wife, and murders bees with pesticides. Ah, and he is an nazi.

            No, that’s not how it is at all. Nobody is obligated to give a damn. Not fighting isn’t the same as supporting, and that’s the biggest lie that has thoroughly fucked this world. It’s the exact opposite: only not giving a shit can still save it.

          • Alupis 13 hours ago
            > Sure but 'not giving a shit' means accepting Nazism.

            This is some "critical theory" nonsense. The real world isn't divided into two camps, "those actively for" and "those actively against". You can, and should, just go about your life.

            You'll live a happier, more mentally-healthy life by just ignoring the noise and not getting pulled into some sort of "if you're not with us, you're against us" thing.

            Gleam is a language, and just like all languages - be it English, Spanish, C++, Python, musical notes, and more - both agreeable and disagreeable people will use it. It's impossible to prevent people who you disagree with from using a language. There's no point in even trying - all you succeed in doing is giving yourself mental grief, anxiety and hardship.

            Just do your thing...

            • lowboy 12 hours ago
              > It's impossible to prevent people who you disagree with from using a language

              True, but the message on the website starts with "As a community...", and speaks to participation in the Gleam community, not the usage of Gleam as a language. And participation within a community _can_ be prevented by its stewards.

              • Alupis 12 hours ago
                I just want to point out, this conversation has been had over and over, on HN, in the Gleam Discord, and I'm sure in many other places as well - always spurred by the same statement on the Gleam website.

                So instead of discussing one of the most beautiful programming languages ever created, we're discussing politics, virtues, and wannabe Nazis. Because of a single sentence on the website...

                I don't care either way, but it is notable how distracting that seemingly innocuous statement has become.

                Could the community goals not be accomplished in a possibly less divisive way? The first part of the community statement seems entirely sufficient to me.

                So, while I don't care and will continue to use Gleam regardless, it does seem to me that greeting curious potential new users with any particular brand of politics (righteous or not) is possibly antithetical to the goals of the language.

                • lowboy 9 hours ago
                  I haven't seen any of the previous iterations of the conversation, nor have I had a chance to try Gleam (though it is on my short list!).

                  > greeting curious potential new users with any particular brand of politics (righteous or not) is possibly antithetical to the goals of the language

                  But it might be an important goal for the community.

            • zdragnar 13 hours ago
              But how will you control people if you haven't put them in little boxes first?
            • turnsout 13 hours ago
              I think it's valuable for the leaders of a community to make it clear what kind of a community they're trying to build. If you think being anti-Nazi is like, "woke nonsense," then you know that the Gleam community is not going to be for you.

              Does that prevent a Nazi from using Gleam? No. But the actual objective is to set the tone.