The Star Language that will outshine Rust? Gleam

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I found some things in this language that I'm not sure about yet I found some things that I really don't like and the rest of it was basically just like rust I'm kidding it definitely does have some features that I wish rust had and we'll get to those one really cool thing you can do in gleam is pattern match on strings instead of making a few function calls to split the string into tokens like I'd have to do in Rust I can just destructure the first part of the string in one variable the second part of the string in another variable and we've split the string just using a pattern match can't do that in Rust obviously this isn't the main selling point of the Lang anguage just one of the features I found interesting there's something even more interesting about IFL statements return statements mutable variables methods and Loops there aren't any seriously it doesn't have any of those things some people are probably like well what else is there anyway there's a lot of interesting stuff to unpack here so let's dive in gleam actually runs on a virtual machine and unlike rust it's garbage collected so there's no borrow Checker to worry about it is a functional language even though at first glance the syntax looks like rust you could make the case that it's actually more similar to a language like Haskell than rust one of my favorite Parts about rust is its first class support for web assembly in my opinion that makes it a great option for web applications and I've made quite a few videos about that and a course on LinkedIn learning gleam doesn't have the same first class support for web assembly but it does have first class support for compiling to JavaScript so unless you need web assembly specifically it's conceivable that gleam can also serve as an alternative to the JavaScript ecosystem for building web applications one Hallmark design decision in Russ is a lack of autoboxing so if we have a value for which which the size is not known at compile time the rust compiler will force us to use a Smart pointer like box RC and so on these values need to be stored on the Heap instead of the stack so Russ forces us to be ultra explicit about it so we know we're making a performance concession this is really nice for performance critical applications because it forces the developer to be explicit when something needs to be stored on the Heap that might force them to rethink their approach such that the Heap storage isn't needed but the reality is that many applications won't be tangibly affected by this performance hit and in those cases it can make sense to abstract those details away from the developer in some cases that can make the cat a lot cleaner without any downside now let's talk about loops and gleam simply doesn't have them you're forced to use recursion or higher order functions like combinators I actually really like this decision and not because I dislike Loops but because I think it'll help with consistency in other languages there's so many scenarios where you could either use a loop or a combinator like map flatmap filter and so on and the decision winds up being made somewhat arbitrarily by the developer without loops I'd expect to see a bit more consistency and how common things are done okay semicolons gleam doesn't require that statements end with a semicolon I've personally never been a huge fan of semicolons anyway if anyone actually prefers semicolons let me know down in the comments gleam has a lot in common with rust but at times there are some subtle differences the syntax for declaring variables is pretty much identical including the ability to have an explicit type when creating a record basically the equivalent of a struct gleam has you surround the fields with parentheses instead of curly braces but other than that it's pretty much much the same idea modules work mostly the same way they do in Rust but gleam doesn't require the mod statements to define the module hierarchy it takes the route most other languages do and lets the module hierarchy be controlled by the directory tree and the file names tups work mostly the same way as rust but are prefixed with a pound sign gleam has case statements which are basically the same as match statements and rust you also get all the nice pattern matching that you get in Rust D structuring of Records lists and so on and then of course gleam has a bit of extra support for string destructuring that I mentioned in the beginning I mentioned earlier that gleam doesn't have IFL statements at all anywhere you normally use an if else you're going to have to use a case statement instead in Rust we have the assert EQ Macro for verifying things in our tests in gleam there's a package called Glee in it that has a module called should with functions like equal that do the same thing gleam doesn't have any exceptions and its result and option types are pretty much identical to the Russ counterparts as in Rust the idiomatic way to write functions that are fallible is to have them return a result so those are some of the things that I really like about gleam but there's some aspects that I haven't quite formed an opinion on yet things you could argue that are good or bad depending on the situation gleam is like hascal in that everything is immutable if you want to update the field of a record well you can't really you need to create a new record copying over all the fields that you want to retain from the original record that might be surprising to some but it's actually pretty common in functional languages there's a bit of a trade-off here because immutability is amazing for testability and being able to read existing code because you don't have to worry about tracing possible State changes but sometimes it's not so great for efficiency some algorithms just need mutability to be performant okay on to methods gleam doesn't have support for methods either just to be clear what we mean here is that you can't associate a function with a record such that it has direct access to the records Fields I think the idea here is that methods don't have a whole lot of utility when record Fields have to be immutable that makes sense but one thing I find offputting is that for collection combinator functions like list. map you need to call list. map instead of just appending map to the name of the list I don't really have a problem with that in principle I just wish you could prefix the function name with the first argument so it reads more like subject verb instead of verb and then the subject like we see here maybe that's pedantic of me I don't know another massive deviation from rust okay get this types are optional in function signatures you can define a function without specifying any types and this isn't Dynamic typing like python these are still static types they're just inferred at compile time this is actually pretty common in functional languages like hascal and oaml but it might be surprising if you're coming from rust or the object-oriented world the only non-functional language I've seen with this feature is one called Lobster that I made a video about a while ago anyway I'm pretty confident this feature is going to be divisive let me know in the comments if you absolutely can't stand it because I know there's going to be a few of you I'm a little more neutral on this feature than others might be because regardless of whether the types are required by the language you're going to want to be able to visually see the types when you're looking at the function but that's something that the development environment should be able to do for you even if the language isn't forcing you to be explicit about the types for that reason I can be convinced to foro explicit types one thing that's really nice about this though though is that in cases where you'd have to write a function with a generic type it might eliminate the need to be explicit about that generic type in Rust you need to explicitly declare two type parameters one for each of the arguments in gleam you just not specify any types and you'd get the same effect now here's the other interesting thing say you wanted the function to be generic but you want to ensure that A and B are of the same type in Rust instead of having two generic type parameters you'd have just one and you'd apply it to both parameters in gleam if you want to force both parameters and the return value to be all of the same type you can do something pretty similar but notice that we didn't need to declare the generic type Fu up front we just started using it The Gleam compiler knows that our intent is for it to be a generic identifier because it starts with a lowercase letter my initial reaction is that this seems a bit nicer and I don't think it's a detriment to readability GLE functions have something called labeled arguments rust doesn't have them but the concept of name function parameters is pretty common the general idea is that help the developer when calling a function by allowing them to rely on parameter names instead of memorizing the order of the arguments I'm a ambivalent about this as a language feature in general because I think this is something that we should rely on development environments for they can automatically display the parameter names in line in the code as the developer is working on that function but not only does gleam support name parameters it takes things a step further and allows you to give parameters both internal names the names by which you refer to the parameter inside the function body and external names which you refer to at the call site I personally haven't been able to think of a use case for this and on the surface it seems like it might even be a detriment to code readability probably not a huge deal but yeah that's my current stance let me know in the comments what you think okay now this is the aspect of gleam I was a little baffled by gleam doesn't have strs or classes it has what are called custom types and those are roughly equivalent to an enum in Rust so when you define a custom type you need to Define at least one variant of that type and then you can store whatever Fields you like in that variant similar to rust those fields can be named or unnamed so if you don't need any variants you're forced to just have a placeholder variant just to store the fields you need maybe I'm missing something here but the seem like a strange decision that might lead to a lot of boiler plate I think I would have preferred custom types that operate more like a rust struct and then maybe a dedicated enum type like rust has what I did find interesting about this approach is that you can basically use these custom types for polymorphism if all the variants share the same field you can reference that field without caring which variant the value is that might come in handy okay at this point we've run through a bunch of language features but the viability of a language depends heavily on its ecosystem of packages and tooling let's take a look at the basics everything kind of revolves around this gleam executable we can use gleam new project to create a project gleam run to run the project gleam test to run all tests in the test directory pretty straightforward for dependency management there's a file called gam.org to.tl we have in the rest ecosystem it's the same idea except that the Syntax for describing package versions is a little different you can add dependencies directly in this file or you can use The Gleam ad command which adds packages the same way you could with cargo ad in the rust ecosystem in terms of the packages available GLE can use llang and elixir packages which is pretty big because the ecosystem is already pretty mature basically everything you need probably exists already now if you've been following the channel you might know that I'm a huge fan of rust frontend web development Frameworks so I'm really excited that there's already a front end framework for gleam called luster I'd love to dive more deeply into that so let me know in the comments if you're interested and maybe I'll make a video all in all I think gleam has a pretty bright future the syntax is incredible and for me it leaves little to be desired is it going to replace rust though for the most part I don't think so the fact that it depends on garbage collection and a virtual machine already pretty much guarantees that it won't irrespective of whether the syntax is preferable but is it possible that it emerges as a better option than rust in some domains like building user facing applications it's definitely possible can it take a bite out of the market share of other highle languages like go JavaScript and typescript yeah I think so but it's still early so we'll see I'm going off the rails here but if you took gleam took away the garbage collector and virtual machine and replac it with a borrow Checker to me that would be pretty close to a perfect language for most domains maybe for everything but the ultra lowlevel stuff anyway hope you like this video let me know in the comments what you think of gleam is it promising is it vaporware yeah let me know if you like bleeding edge programming languages check out this video I made about Lobster which is a pretty interesting language thanks for watching and we'll see you in the next one
Info
Channel: Code to the Moon
Views: 23,478
Rating: undefined out of 5
Keywords: gleam, rust, garbage collection, functional, functional programming, fp, frontend, rustlang, gleamlang
Id: Zy-eDWVam_Y
Channel Id: undefined
Length: 10min 32sec (632 seconds)
Published: Thu Jun 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.