#Noob-surveying-the-language question

1 messages · Page 1 of 1 (latest)

elfin kayak
#

Hi, I'll just append (📌) the background/context to this question because it's probably not overly relevant to the answer.

I'd be interested to know how realistic the following setup is in Gleam (from "it's not possible with the language in principle and never will be" on one end of the spectrum, and "we do this all the time already, no big deal" on the other).

I'd like to have my Gleam app running on a traditional Linux server. Let's say its a simple web server with five major functions. If I make a change to one of the functions that respects the shape of its interfaces to the rest of the program, I'd like to build and test those changes locally, then run some command in my terminal from the project directory like gleam-cli deploy my-gleam-app and the changes are pushed to my server and any activity ongoing in the changed function is watched until there's like a break in traffic, then the code running that function is hotswapped to the latest changes and the app doesn't even stutter.

Is anything like this reasonable to configure? Would love to know whether this is crazy or already easy, or something I could help contribute to on a reasonable timescale.

#

📌 I've been developing software for about 12 years, but I started as a mechanical engineer so most of that time it's been as a spaghetti coder and I'm still kind of haunted constantly with the anxiety that I'm doing things incorrectly. I worked in Python as the only language I could really handle for a while, then learned JavaScript to do web stuff, and I wrote some trivial things in engineering languages like Modelica and Maple.

Then a few years ago I got a job in the public sector and got to take some time to learn and implement apps in whatever language I wanted and I chose Rust! And it was amazing. I have never really written anything that needs the performance, but I came to really rely on the completeness of strictly-typed code, and the borrow-checker is just a pattern to deal with and hasn't given me too many problems, and more recently, I've really started to see the light on Hindley-Milner type systems and modeling a lot of the business logic there instead of inside functions. At that job, we had one of those nightmare scenarios where a major deliverable was due in 24 hours, and the systems we were connected to were making code and schema changes to handle a large volume of incoming data, so we basically had to make changes in response in our app and commit to production. And it actually worked! The changes to our schema in response to the sibling systems made cascading changes in our app, but we chugged until the compiler gave us the green light and we pushed and everything was fine!

#

📌 So I'm kinda glued to strict types for a few different reasons. I'm never written a lick of Gleam nor Erlang nor Elixir (but I have a brother-in-law who's built some really successful products in Elixir over the last decade, so I've talked to him a lot about it and the BEAM and I read some stuff about Elixir with GenServers). I'm really happy with the completeness of the systems I write in Rust (mostly web servers and frontends using templates and a little HTMX) and something about it (especially when I'm writing matches on Results and Options or building out behavior in types) makes me itch to develop as much as I can in it every day. And Gleam's features there, potentially combined with the convenience of running continuously in the BEAM, feel sort of like the "next step" in this style of development. But I'm not a very talented developer and it's much easier for me to write a small blog post about what I'm interested in than possibly taking time to mess up my muscle memory learning a new syntax or read docs or anything like that.

#

📌 And I know that an easy button kind of thing at the point of code commit is possible with like a whole Kubernetes config, but seeing if I could achieve something like that with gleam-live-manager or something installed on my server and client so I have this live, hotswapping system with what feels to me to be two moving parts.

hushed cypress
#

Erlang does have hot swapping, so technically it is possible. But there's no tooling for it as of yet in Gleam.

Also how do you handle static types with hot swapping? Your program is type checked as a whole, but as modules are swapped, you'll be momentarily running partially new and partially old code. Meaning you'll have to have additional context on top of the type system to avoid errors.

elfin kayak
# hushed cypress Erlang does have hot swapping, so technically it is possible. But there's no too...

Yeah, the Erlang hotswapping (which I've never implemented) was the use case that led me to ask. I wondered if some characteristic of Gleam, like types, would preclude it from ever being hotswappable. I figured that in Elixir, you still have the problem of switching instantly from one set of behaviors to another, and assumed that being untyped didn't solve the problem of the instant switch. But I honestly don't know enough about how it works in the Erlang/Elixir case to know what makes it possible there. Pretty lazy question, figured I'd just lay out my dream scenario and hear if and why or why not.

hushed cypress
#

Since Gleam compiles to Erlang, it's technically possible. The type system may just give you confidence that some thing cannot happen when it does due to an older version of the code running. So you have to be extra careful.

fast cypress
#

If it is web traffic you could use Caddy as a reverse proxy in front of your application, start a new instance on a different TCP port, and programmatically use Caddy's API to switch from the old instance to the new one.

quiet roost
#

In "micro services" these 5 functions are often s/thing indepently runing. With the Beam they're smaller (gleam: actors), so you may just replace them altogether.

It takes effort in Erlang to prepare an upgrade path in a running system. The Beam provides the possibiliy, but it is still quite an investment.

quick obsidian
#

You can hot upgrade, and you wouldn’t need to wait for a break in traffic to do so. The upgrade system is sophisticated enough for that not to be needed

#

The thing you need to do is thoroughly test the upgrade to make sure all the interfaces and data structure definitions are compatible. This in practice is a lot of work, it is like doing a database migration for every little bit of code in your app, only you don’t have a schema checking tool that tells you if you got it right or not

#

Companies that use hot upgrade may spend more time testing their upgrades than actually writing and testing features

#

If you are not in a very resource constrained embedded situation it’s likely easier and more practical to use the conventional deployment strategy Shimaore outlined

quick obsidian
elfin kayak
#

@hushed cypress, @fast cypress, @quiet roost, @quick obsidian thanks very much for the responses. I was very wrong about the out-of-the-box, configless nature of hswap in Erlang and am definitely barking up the wrong tree. will probably pursue further familiarity with general deployment tools for now! thanks again!