Everything you need to know about FFI in Gleam

  Рет қаралды 4,056

Isaac Harris-Holt

Isaac Harris-Holt

Күн бұрын

Gleam is a great language, but sometimes you just need to access the underlying platform, be it JavaScript, Erlang or Elixir. This video will teach you just how to do that using the power of foreign function interfaces, or FFIs!
Resources:
Externals in Gleam: tour.gleam.run/externals
gleam_javascript: hexdocs.pm/gleam_javascript/
gleam_erlang: hexdocs.pm/gleam_erlang/
__________________________________________
Check out my other socials!
🎮 Discord ▶ discordapp.com/invite/bWrctJ7
🐦 Twitter ▶ / isaacharrisholt
🖥️ Portfolio ▶ ihh.dev
📝 Blog ▶ isaacharrisholt.com
__________________________________________
Timestamps:
00:00 - Introduction and explanation
00:58 - Writing foreign functions
03:13 - Default implementations
04:17 - Erlang-specific FFI
05:59 - JavaScript-specific FFI
08:23 - When to use FFI
#gleam #softwareengineer #erlang #javascript #elixir

Пікірлер: 38
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
ERRATA: 6:45 - Gleam lists use a custom type for JS which can be switched to/from using custom `toList` and `fromList` functions NOTES: - You can FFI into Elixir, too! Just specify the `erlang` target and use the module name as you would in Erlang (thanks @JLarky!)
@zakariabenhadi4637
@zakariabenhadi4637 9 күн бұрын
Nice video again. Do you plan on doing one about hosting a gleam backend app? I struggle with finding info about that - I suppose a server running erlang vm is enough but a deep dive would be so nice
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Ooh good idea! Yeah any Erlang server would do, and I believe there are also some deployment guides on the Gleam website
@zakariabenhadi4637
@zakariabenhadi4637 9 күн бұрын
@@IsaacHarrisHolt Oh my god you're right, thanks !
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
No worries!
@JLarky
@JLarky 9 күн бұрын
Fun fact, you can also ffi into Elixir :)
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Yes! This is true, but I managed to miss it out of the video
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
I've added this to the pinned comment :)
@JLarky
@JLarky 8 күн бұрын
@@IsaacHarrisHolt yeah, the best part is that it allows you to install Elixir dependencies from hex, which makes it really easy to use
@IsaacHarrisHolt
@IsaacHarrisHolt 8 күн бұрын
Yes! Though I've been informed that you can just use the Elixir module name :)
@prethammuthappabs2241
@prethammuthappabs2241 9 күн бұрын
Thinking of getting into gleam , the syntax kinda looks look like rust and i kinda had a bit tough time with it , so is gleam easy? Or same as rust?
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Syntax and language difficulty are not correlated! Gleam is really easy to pick up, and I'd recommend giving it a go
@costinel57
@costinel57 8 күн бұрын
But how are js classes represented by gleam? 🤔
@IsaacHarrisHolt
@IsaacHarrisHolt 8 күн бұрын
They're generally not. You shouldn't be writing enough JS to the point where you need classes, honestly. However, if you NEED to return a class instance, you can, but you shouldn't try to introspect it on the Gleam side. In this case I would create a type with 0 constructors, like I did with the Date type.
@costinel57
@costinel57 8 күн бұрын
@@IsaacHarrisHolt I guess that makes sense, thanks!
@IsaacHarrisHolt
@IsaacHarrisHolt 8 күн бұрын
No worries!
@devyb-cc
@devyb-cc 7 күн бұрын
man, i wish python ffi is coming next...
@IsaacHarrisHolt
@IsaacHarrisHolt 6 күн бұрын
That's kinda unlikely. Gleam doesn't compile to Python, so it wouldn't make a lot of sense. You'd have to spin up a whole new Python process just to execute the code
@devyb-cc
@devyb-cc 6 күн бұрын
@@IsaacHarrisHolt fair enough hhh
@IsaacHarrisHolt
@IsaacHarrisHolt 6 күн бұрын
What's the reason for wanting a Python backend?
@devyb-cc
@devyb-cc 6 күн бұрын
@@IsaacHarrisHolt no particular reason, but i do some research on fastapi this week
@devyb-cc
@devyb-cc 6 күн бұрын
tbh it's still better to use a microservice approach if the project needs to be written in multi language
@lpil
@lpil 9 күн бұрын
First!
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Ffs Lewis 😂
@renefrusco2691
@renefrusco2691 9 күн бұрын
nth!
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
I wonder if people ever leave real comments these days...
@raccoonteachesyou
@raccoonteachesyou 9 күн бұрын
Fifth ?
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
I don't know how I feel anymore
@TheddunTOSS
@TheddunTOSS 9 күн бұрын
Third!
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Whyyy 😭😭
@xfldiazx
@xfldiazx 9 күн бұрын
Fourth!
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
I give up
@johtso1
@johtso1 9 күн бұрын
Second!
@IsaacHarrisHolt
@IsaacHarrisHolt 9 күн бұрын
Congrats!
The Ultimate Guide to Gleam Concurrency
13:36
Isaac Harris-Holt
Рет қаралды 13 М.
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 24 МЛН
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 102 МЛН
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 20 МЛН
The Dream Programming Language? Lobster
20:55
Code to the Moon
Рет қаралды 144 М.
Astro for Impatient Devs
10:35
Isaac Harris-Holt
Рет қаралды 6 М.
Let's end the FRAMEWORK war! Next js vs Laravel!?
2:02
PEXT
Рет қаралды 2,6 М.
Zig for Impatient Devs
9:48
Isaac Harris-Holt
Рет қаралды 72 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 371 М.
Create Robust Web Apps with Gleam and Lustre
12:32
Isaac Harris-Holt
Рет қаралды 27 М.
Functional Programming & Haskell - Computerphile
9:19
Computerphile
Рет қаралды 660 М.
Browser Tier List (For Software Developers)
0:59
Conner Ardman
Рет қаралды 2,3 МЛН
how websites learned to fit everywhere
6:15
Juxtopposed
Рет қаралды 83 М.
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 27 МЛН
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Кинг Комп Shorts
Рет қаралды 1,3 МЛН