-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
359 additions
and
2 deletions.
There are no files selected for viewing
358 changes: 358 additions & 0 deletions
358
_posts/2023-09-25-v0.31-keeping-dependencies-explicit.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,358 @@ | ||
--- | ||
author: Louis Pilfold | ||
title: Keeping dependencies explicit | ||
subtitle: Gleam v0.31 released | ||
tags: | ||
- Release | ||
--- | ||
|
||
Gleam is a type safe and scalable language for the Erlang virtual machine and | ||
JavaScript runtimes. Today Gleam [v0.31.0][release] has been released, let's | ||
take a look at what's new. | ||
|
||
[release]: https://github.com/gleam-lang/gleam/releases/tag/v0.31.0 | ||
|
||
## Requiring explicit dependencies | ||
|
||
A Gleam application's dependency graph contains no duplicate packages, each | ||
package has exactly one version. | ||
|
||
``` | ||
┌───────────────┐ | ||
│ │ | ||
│ Application │ | ||
│ │ | ||
└───────┬───────┘ | ||
│ | ||
│ | ||
┌──────▼──────┐ ┌─────────────┐ | ||
│ │ │ │ | ||
│ library_a ├───────► library_b │ | ||
│ │ │ │ | ||
└─────────────┘ └─────────────┘ | ||
``` | ||
|
||
Here the application has specified `library_a` as a dependency in its | ||
`gleam.toml`, and `library_a` has specified `library_b` as a dependency in its | ||
own `gleam.toml`. | ||
|
||
As there's no ambiguity as to what version to use Gleam has allowed importing | ||
modules from packages that you don't directly depend upon, the application | ||
could happily import modules from `library_b`. | ||
|
||
Over time it has become clear that this form of indirect dependency is unclear | ||
and is confusing to a lot of folks, so we're moving to making dependencies | ||
explicit and only permitting imports from direct dependencies. | ||
|
||
With this release Gleam will now emit a warning when importing modules from a | ||
package your application does not directly depend upon, and in future versions | ||
of Gleam this will become an error. | ||
|
||
```text | ||
warning: Transative dependency imported | ||
┌─ src/app.gleam:2:1 | ||
│ | ||
2 │ import mist | ||
│ ^^^^^^^^^^^ | ||
The module `mist` is being imported, but `mist`, the package it belongs to, | ||
is not a direct dependency of your package. | ||
In a future version of Gleam this may become a compile error. | ||
Run this command to add it to your dependencies: | ||
gleam add mist | ||
``` | ||
|
||
## Quality of life improvements | ||
|
||
As we're now ramping up to version 1.0 we're making lots of small improvements | ||
to the ergonomics of the language. | ||
|
||
The record access syntax (`person.name`) can now be used in case clause guard | ||
expressions. | ||
|
||
```gleam | ||
pub fn listed(names: List(String), person: Person) -> String { | ||
case names { | ||
[name, ..names] if name == person.name -> True | ||
[_, ..names] -> listed(names, person) | ||
[] -> False | ||
} | ||
} | ||
``` | ||
|
||
The `as` keyword can now be used to assign the prefix of a string to a variable when pattern matching. | ||
|
||
```gleam | ||
pub fn parse_tag(tag: String) -> Result(Tag, Nil) { | ||
case tag { | ||
"category " as key <> value | ||
| "region " as key <> value | ||
| "priority " as key <> value -> { | ||
let key = string.trim(key) | ||
Ok(Tag(key, value)) | ||
} | ||
_ -> Error(Nil) | ||
} | ||
} | ||
``` | ||
|
||
And the standard library `gleam/int` module now has a series of functions for | ||
performing bitwise operations. | ||
|
||
```gleam | ||
int.bitwise_and(9, 3) | ||
// -> 1 | ||
int.bitwise_or(9, 3) | ||
// -> 11 | ||
int.bitwise_exclusive_or(9, 3) | ||
// -> 10 | ||
int.bitwise_not(2) | ||
// -> -3 | ||
int.bitwise_shift_left(1, 2) | ||
// -> 4 | ||
int.bitwise_shift_right(1, 2) | ||
// -> 0 | ||
``` | ||
|
||
## Wisp | ||
|
||
Gleam has been used to make backend web applications for a good few years, but | ||
without a helpful web framework the programmer has to feel comfortable piecing | ||
together various packages to build their application. | ||
|
||
Most folks are not so interested in the nitty-gritty of how to put together a | ||
web application and want to focus on the business logic of their application, so | ||
the Wisp framework has been created to help folks get on with solving problems | ||
with Gleam. | ||
|
||
Wisp takes the lessons learnt from various existing Gleam web applications and | ||
web frameworks in other languages, and provides a practical, type safe, and | ||
magic-free experience for building web applications. A Wisp request handler | ||
looks a like this: | ||
|
||
```gleam | ||
import gleam/result.{try} | ||
import my_app/people | ||
import my_app/web.{Context} | ||
import wisp.{Request, Response} | ||
pub fn handle_request(req: Request, ctx: Context) -> Response { | ||
use json <- wisp.require_json(req) | ||
let result = { | ||
use params <- try(people.parse_params(json)) | ||
use person <- try(people.save(params, ctx.db)) | ||
Ok(people.to_json(person)) | ||
} | ||
case result { | ||
Ok(body) -> wisp.json_response(body, 201) | ||
Error(_) -> wisp.bad_request() | ||
} | ||
} | ||
``` | ||
|
||
Today Wisp has a small feature set similar to that of Ruby's Sinatra or Python's | ||
Flask, but it is expected to grow over time to include more features as the | ||
maintainers and community decides what is useful and how they should work. | ||
|
||
Wisp is not a Gleam-core project like the compiler or the standard library, but | ||
I (Louis Pifold, Gleam's creator) am the primary maintainer of Wisp, and the | ||
framework has been designed with the help of prominent members of the Gleam | ||
community. | ||
|
||
Check out [the website](https://lpil.github.io/wisp) and the | ||
[source code](https://github.com/lpil/wisp) if you'd like to learn more. 🧚 | ||
|
||
## Thanks | ||
|
||
Gleam is made possible by the support of all the kind people and companies who have | ||
very generously [**sponsored**](https://github.com/sponsors/lpil) or | ||
contributed to the project. Thank you all! | ||
|
||
If you like Gleam consider sponsoring or asking your employer to | ||
[sponsor Gleam development](https://github.com/sponsors/lpil). I work full time | ||
on Gleam and your kind sponsorship is how I pay my bills! | ||
|
||
<ul class="top-sponsors"> | ||
<li> | ||
<a href="https://fly.io" rel="noopener" target="_blank"> | ||
<img class="sponsor-fly no-shadow" src="/images/sponsors/fly.svg" alt="Fly"> | ||
</a> | ||
</li> | ||
</ul> | ||
|
||
- [Aaron Gunderson](https://github.com/agundy) | ||
- [Adam Brodzinski](https://github.com/AdamBrodzinski) | ||
- [Adam Mokan](https://github.com/amokan) | ||
- [Adi Iyengar](https://github.com/thebugcatcher) | ||
- [Alembic](https://alembic.com.au) | ||
- [Alex Manning](https://github.com/rawhat) | ||
- [Alexander Koutmos](https://github.com/akoutmos) | ||
- [Alexander Stensrud](https://github.com/spektroskop) | ||
- [Alexandre Del Vecchio](https://github.com/defgenx) | ||
- [Ali Farhadi](https://github.com/farhadi) | ||
- [Amaan Qureshi](https://github.com/amaanq) | ||
- [Andy Aylward](https://github.com/aaylward) | ||
- [Anthony Khong](https://github.com/anthony-khong) | ||
- [Anthony Scotti](https://github.com/amscotti) | ||
- [Arnar Gauti Ingason](https://github.com/arnarg) | ||
- [Arnaud Berthomier](https://github.com/oz) | ||
- [Ben Marx](https://github.com/bgmarx) | ||
- [Ben Myles](https://github.com/benmyles) | ||
- [Benjamin Peinhardt](https://github.com/bcpeinhardt) | ||
- [brettkolodny](https://github.com/brettkolodny) | ||
- [Brian Glusman](https://github.com/bglusman) | ||
- [Bruno Michel](https://github.com/nono) | ||
- [Bruno Parga](https://github.com/brunoparga) | ||
- [by34](https://github.com/macroby) | ||
- [Carlo Gilmar](https://github.com/carlogilmar) | ||
- [Carlos Saltos](https://github.com/csaltos) | ||
- [Chew Choon Keat](https://github.com/choonkeat) | ||
- [chiroptical](https://github.com/chiroptical) | ||
- [Chris Lloyd](https://github.com/chrislloyd) | ||
- [Chris Ohk](https://github.com/utilForever) | ||
- [Chris Rybicki](https://github.com/Chriscbr) | ||
- [Christopher Keele](https://github.com/christhekeele) | ||
- [cijiugechu](https://github.com/cijiugechu) | ||
- [clangley](https://github.com/clangley) | ||
- [Clay](https://github.com/connorlay) | ||
- [Coder](https://github.com/coder) | ||
- [Cole Lawrence](https://github.com/colelawrence) | ||
- [Colin](https://github.com/insanitybit) | ||
- [Cosmo Shin (신의하)](https://github.com/XiNiHa) | ||
- [Cristine Guadelupe](https://github.com/cristineguadelupe) | ||
- [Damir Vandic](https://github.com/dvic) | ||
- [Dan Dresselhaus](https://github.com/ddresselhaus) | ||
- [Danielle Maywood](https://github.com/DanielleMaywood) | ||
- [Danny Martini](https://github.com/despairblue) | ||
- [Dave Lucia](https://github.com/davydog187) | ||
- [David Bernheisel](https://github.com/dbernheisel) | ||
- [David Flanagan](https://github.com/rawkode) | ||
- [David Sancho](https://github.com/davesnx) | ||
- [dependabot[bot]](https://github.com/dependabot%5Bbot%5D) | ||
- [Dmitrii Maganov](https://github.com/vonagam) | ||
- [Dmitry Poroh](https://github.com/poroh) | ||
- [Edon Gashi](https://github.com/edongashi) | ||
- [Elliott Pogue](https://github.com/epogue) | ||
- [Erik Terpstra](https://github.com/eterps) | ||
- [Ernesto Malave](https://github.com/oberernst) | ||
- [Fernando Farias](https://github.com/nandofarias) | ||
- [Filip Figiel](https://github.com/megapctr) | ||
- [Florian Kraft](https://github.com/floriank) | ||
- [fly.io](https://github.com/superfly) | ||
- [Ganesh Gupta](https://github.com/extsalt) | ||
- [Giacomo Cavalieri](https://github.com/giacomocavalieri) | ||
- [Graeme Coupar](https://github.com/obmarg) | ||
- [Guilherme de Maio](https://github.com/nirev) | ||
- [Gustavo Villa](https://github.com/gfvcastro) | ||
- [Harry Bairstow](https://github.com/HarryET) | ||
- [Hayleigh Thompson](https://github.com/hayleigh-dot-dev) | ||
- [Hazel Bachrach](https://github.com/hibachrach) | ||
- [Henry Warren](https://github.com/henrysdev) | ||
- [Hex](https://github.com/hexpm) | ||
- [hms](https://github.com/polynomialherder) | ||
- [Ian González](https://github.com/Ian-GL) | ||
- [Ingmar Gagen](https://github.com/igagen) | ||
- [inoas](https://github.com/inoas) | ||
- [Ivar Vong](https://github.com/ivarvong) | ||
- [James MacAulay](https://github.com/jamesmacaulay) | ||
- [Jan Skriver Sørensen](https://github.com/monzool) | ||
- [Jechol Lee](https://github.com/jechol) | ||
- [Jen Stehlik](https://github.com/okkdev) | ||
- [jiangplus](https://github.com/jiangplus) | ||
- [John Björk](https://github.com/JohnBjrk) | ||
- [John Gallagher](https://github.com/johngallagher) | ||
- [John Palgut](https://github.com/Jwsonic) | ||
- [Jonas Hedman Engström](https://github.com/JonasHedEng) | ||
- [Jonathan Arnett](https://github.com/J3RN) | ||
- [Josef Richter](https://github.com/josefrichter) | ||
- [Kayla Washburn](https://github.com/aslilac) | ||
- [Kieran Gill](https://github.com/kierangilliam) | ||
- [Lars Wikman](https://github.com/lawik) | ||
- [Leon Qadirie](https://github.com/leonqadirie) | ||
- [lidashuang](https://github.com/defp) | ||
- [Manuel Rubio](https://github.com/manuel-rubio) | ||
- [Marcin Koziej](https://github.com/marcinkoziej) | ||
- [Marius Kalvø](https://github.com/mariuskalvo) | ||
- [Mark Holmes](https://github.com/markholmes) | ||
- [Mark Markaryan](https://github.com/markmark206) | ||
- [Mark Story](https://github.com/markstory) | ||
- [Markus](https://github.com/markusfeyh) | ||
- [Martin Janiczek](https://github.com/Janiczek) | ||
- [Matt Van Horn](https://github.com/mattvanhorn) | ||
- [matthew.cobbing](https://github.com/cobbinma) | ||
- [Matthias Benkort](https://github.com/KtorZ) | ||
- [max-tern](https://github.com/max-tern) | ||
- [Michael Chris Lopez](https://github.com/mcchrish) | ||
- [Michael Davis](https://github.com/the-mikedavis) | ||
- [Michael Duffy](https://github.com/stunthamster) | ||
- [Michael Jones](https://github.com/michaeljones) | ||
- [Mike Roach](https://github.com/mroach) | ||
- [Mikko Ahlroth](https://github.com/Nicd) | ||
- [Natanael Sirqueira](https://github.com/natanaelsirqueira) | ||
- [Nathaniel Knight](https://github.com/nathanielknight) | ||
- [NFIBrokerage](https://github.com/NFIBrokerage) | ||
- [Nick Reynolds](https://github.com/ndreynolds) | ||
- [Nicklas Sindlev Andersen](https://github.com/NicklasXYZ) | ||
- [NineFX](http://www.ninefx.com) | ||
- [Nino Annighoefer](https://github.com/nino) | ||
- [Noah Betzen](https://github.com/Nezteb) | ||
- [Ocean Armstrong Lewis](https://github.com/oceanlewis) | ||
- [OldhamMade](https://github.com/OldhamMade) | ||
- [Ole Michaelis](https://github.com/OleMchls) | ||
- [ontofractal](https://github.com/ontofractal) | ||
- [Parker Selbert](https://github.com/sorentwo) | ||
- [Paul Gideon Dann](https://github.com/giddie) | ||
- [Pete Jodo](https://github.com/petejodo) | ||
- [Peter](https://github.com/CrowdHailer) | ||
- [Prashant Singh Pawar](https://github.com/prashantpawar) | ||
- [Praveen Perera](https://github.com/praveenperera) | ||
- [qingliangcn](https://github.com/qingliangcn) | ||
- [Raúl Chouza ](https://github.com/chouzar) | ||
- [Redmar Kerkhoff](https://github.com/redmar) | ||
- [Rico Leuthold](https://github.com/rico) | ||
- [Robert Attard](https://github.com/TanklesXL) | ||
- [Robert Ellen](https://github.com/rellen) | ||
- [Rohit](https://github.com/Rohit-Sharmaa) | ||
- [Ryan Winchester](https://github.com/ryanwinchester) | ||
- [Sam Aaron](https://github.com/samaaron) | ||
- [Sammy Isseyegh](https://github.com/bkspace) | ||
- [Saša Jurić](https://github.com/sasa1977) | ||
- [Scott Wey](https://github.com/scottwey) | ||
- [Sean Jensen-Grey](https://github.com/seanjensengrey) | ||
- [Sebastian Porto](https://github.com/sporto) | ||
- [SEKUN](https://github.com/sekunho) | ||
- [Septem Li](https://github.com/septemhill) | ||
- [Seve Salazar](https://github.com/tehprofessor) | ||
- [shayan javani](https://github.com/massivefermion) | ||
- [Shuqian Hon](https://github.com/honsq90) | ||
- [Signal Insights](https://github.com/signalinsights) | ||
- [Simone Vittori](https://github.com/simonewebdesign) | ||
- [Stefan Luptak](https://github.com/stefanluptak) | ||
- [Strand Communications](https://github.com/strandcom) | ||
- [Szymon Wygnański](https://github.com/finalclass) | ||
- [Terje Bakken](https://github.com/terkiterje) | ||
- [Theo Harris](https://github.com/Theosaurus-Rex) | ||
- [Tomasz Kowal](https://github.com/tomekowal) | ||
- [Tristan Cacqueray](https://github.com/TristanCacqueray) | ||
- [Tristan Sloughter](https://github.com/tsloughter) | ||
- [Weizheng Liu](https://github.com/weizhliu) | ||
- [Willyboar](https://github.com/Willyboar) | ||
- [Wilson Silva](https://github.com/wilsonsilva) | ||
- [Wojtek Mach](https://github.com/wojtekmach) | ||
- [Wolf](https://github.com/sascha-wolf) | ||
- [Xetera](https://github.com/Xetera) | ||
- [Yasuo Higano](https://github.com/Yasuo-Higano) | ||
- [Yu Matsuzawa](https://github.com/ymtszw) | ||
- [Zsombor Gasparin](https://github.com/gasparinzsombor) | ||
- [Šárka Slavětínská](https://github.com/sarkasl) | ||
|
||
Thanks for reading! Happy hacking! 💜 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters