We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Three and a Half Ways

00:00

Formal Metadata

Title
Three and a Half Ways
Subtitle
Elixir Changed Me (and Other Hyperbole)
Title of Series
Number of Parts
133
Author
License
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Over the last six months I’ve been working with Elixir every day, non-stop. I’m lucky. I’m also semi-obsessed. Elixir has changed the way I think about programming and software in general. I’ve ditched side projects I’ve been working on for months so I can rebuild them in Elixir. I changed editors completely (Vim to Spacemacs) because of Elixir support with Alchemist. People keep asking me what’s so special about it and I keep saying “I wish I had an hour to just sit here and show you some beautiful Elixir”. And now I get my wish - I have that hour. In this talk I will show you some things that make me very, very happy about Elixir and the Erlang VM.
Software developerArtificial lifeCodeBitProcess (computing)Group actionInteractive televisionQuicksortMetropolitan area networkCalculationWebsiteSoftware developerJSONXMLUMLComputer animation
Software developerFormal languageWordExpert systemComputer programMultiplication signNeuroinformatikComputer animation
Software developerMereologyDrop (liquid)Functional programmingComputer programWechselseitiger AusschlussFunctional (mathematics)Computer animation
Software developerFormal languageSlide ruleErlang distributionMereologyDienstprogramm2 (number)Power (physics)HTTP cookieComputer animation
Software developerInstallation artCompilerScripting languageComputer fileMobile appSource codeElectric currentDefault (computer science)Task (computing)Electronic mailing listLocal ringKey (cryptography)Windows RegistryInformationLetterpress printingRevision controlConfiguration spaceUser profileStructural loadSoftware testingStatisticsSoftware testingBitProjective planeMixed realityDienstprogrammElectronic visual displayConfiguration spaceData structureCodePhysical systemOptical disc driveScripting languageElectronic mailing listComputer file1 (number)Computing platformGraphics softwareModule (mathematics)Right angleOnline helpAsynchronous Transfer ModeFormal languageDirectory serviceObservational studyWindowCartesian coordinate systemInheritance (object-oriented programming)Type theoryGoodness of fitLibrary (computing)Computer fontReading (process)Computer animationSource code
Software developerSoftware testingRouter (computing)BuildingWebsiteCodeFunction (mathematics)Software testing2 (number)Right angleInformationBitIdeal (ethics)Prisoner's dilemmaModule (mathematics)Computer fontMixed realityBoom (sailing)Lecture/ConferenceComputer animation
Software developerBitFormal languageTelecommunicationSoftware frameworkComputing platformCoordinate systemCodeProjective planeErlang distributionRight angleService (economics)WaveFunctional programmingHigh availabilityPower (physics)Water vaporControl flowCurveMetropolitan area networkDistanceOpen setTriangleSlide rulePerspective (visual)2 (number)Channel capacityHand fanComputer scienceFreezingComputer programObject (grammar)Physical lawGodNatural numberComputer animation
Software developerRule of inferenceRevision controlBefehlsprozessorFingerprintArchitectureFreewareHypercubeObject-oriented programmingBuildingSoftwareDemo (music)Software frameworkFunctional (mathematics)Erlang distributionMulti-core processorBounded variationRule of inferenceMaxima and minimaFormal language10 (number)Service (economics)Process (computing)Boolean algebraDemosceneCore dumpComputer animation
Software developerSoftware engineeringMusical ensembleSynchronizationErlang distributionVariable (mathematics)Interactive televisionDistribution (mathematics)InformationTable (information)Revision controlDemo (music)Electronic visual displayComputer fileService (economics)Link (knot theory)Process (computing)Right angleFrequencyMessage passingCommunications protocolServer (computing)Data structureSystem callBitFamilySynchronizationPattern matchingProgramming languageModule (mathematics)Parameter (computer programming)ExplosionPower (physics)RoutingComputer programmingNumberMultiplication signKey (cryptography)Musical ensembleTask (computing)CodeVariable (mathematics)Observational studyProgrammschleifeEnumerated typeInheritance (object-oriented programming)Attribute grammarLevel (video gaming)WordFunctional (mathematics)Semiconductor memorySequenceDifferent (Kate Ryan album)Scripting languageCode refactoring2 (number)MereologyPhysical systemRow (database)Graph coloringReal numberConcurrency (computer science)Range (statistics)QuicksortDisk read-and-write headOcean currentTelephone number mappingArithmetic meanCasting (performing arts)Parallel computingPrincipal ideal domainComputer animationLecture/Conference
Software developerTable (information)Musical ensembleSynchronizationProgrammable read-only memoryCodeHeegaard splittingIntegerComputer programmingRange (statistics)Right angleErlang distributionParameter (computer programming)String (computer science)Group actionMultiplication signDemo (music)Goodness of fitDisk read-and-write headResultantTelephone number mappingOperator (mathematics)Principal ideal domainService (economics)Musical ensembleInterpolationSystem callPositional notationElectronic mailing listFunctional (mathematics)Statement (computer science)QuicksortFerry CorstenLine (geometry)Function (mathematics)Data structurePoint (geometry)Pattern matchingBackupCASE <Informatik>ProgrammschleifeNatural numberMatching (graph theory)Series (mathematics)Interpreter (computing)Ultraviolet photoelectron spectroscopyExecution unitDemoscenePattern languageProcess (computing)Arithmetic meanSelf-organizationLecture/Conference
Software developerComputer programHecke operatorFigurate numberSpecial unitary groupRight angleErlang distributionMetropolitan area networkFormal languageArmstrong, JoeNeuroinformatikWave packetGoodness of fitString (computer science)Computer scientistRule of inferenceData miningPhysicistDifferent (Kate Ryan album)Line (geometry)Negative numberComputer animationLecture/Conference
EmailSoftware developerComputerErlang distributionEuler anglesIntegerWeb 2.0Server (computing)Software frameworkComputer programEmailRight angleCodeFormal languageGoodness of fitCodeComputer animation
EmailRevision controlSoftware developerCodeVirtual machineQuery languageCodeCode refactoringBuildingQuery languageServer (computing)Pattern languageBitConnected spacePositional notationProcess (computing)Functional (mathematics)Point (geometry)SequelComputer animation
Software developerDevice driverCodierung <Programmierung>FlagResultantRow (database)Dependent and independent variablesOrder (biology)2 (number)Position operatorFunctional programmingCASE <Informatik>Data structureStandard deviationField (computer science)Core dumpArithmetic meanSign (mathematics)State of matterBitRight angleErlang distributionNumberSource code
Singuläres IntegralSoftware developerTelephone number mappingScale (map)Pattern matchingResultantData structureRight anglePattern languageIntrusion detection systemMereologyTransformation (genetics)Electronic mailing listGroup actionFunctional (mathematics)Scaling (geometry)Position operatorTelephone number mappingIterationMathematicsRow (database)String (computer science)Parameter (computer programming)
Software developerTelephone number mappingScale (map)Equaliser (mathematics)Goodness of fitComputer scienceEquals signNichtlineares GleichungssystemArithmetic meanHash functionLevel (video gaming)Operator (mathematics)Pattern languageKey (cryptography)Transformation (genetics)Pattern matchingData structureElement (mathematics)Computer animationLecture/Conference
Scale (map)Software developerMenu (computing)DecimalBit rateHecke operatorSinguläres IntegralTelephone number mappingElectronic mailing listElement (mathematics)BitCodePosition operatorResultantMatching (graph theory)Right angleFunctional (mathematics)TupleMetropolitan area networkFunctional programmingCore dumpChainComputer animationLecture/Conference
Singuläres IntegralTelephone number mappingSoftware developerScale (map)Row (database)Electronic mailing listFunctional (mathematics)Functional programmingResultantPattern languageCode refactoringElectronic mailing listRow (database)TupleLink (knot theory)Pattern matchingElement (mathematics)Software developerPhysical lawComputer animationLecture/Conference
Software developerTelephone number mappingElectronic mailing listErlang distributionStandard deviationData structureKey (cryptography)Interior (topology)Functional (mathematics)Metropolitan area networkTelephone number mappingTupleRight angleCodeLecture/Conference
Software developerTelephone number mappingElectronic mailing listDifferent (Kate Ryan album)Level (video gaming)2 (number)Row (database)Power (physics)Electric generatorTelephone number mappingRight angleLine (geometry)BitArrow of timeComputer animationLecture/Conference
Software developerScale (map)String (computer science)Row (database)Electronic mailing listTelephone number mappingSquare numberPoisson-KlammerString (computer science)Key (cryptography)2 (number)Electronic mailing listPositional notationWebsiteRoutingComputer animation
Beer steinElectronic mailing listRow (database)Telephone number mappingSoftware developerTimestampScale (map)Key (cryptography)BitString (computer science)Element (mathematics)Inheritance (object-oriented programming)Position operatorSymbol tableLecture/ConferenceComputer animationSource code
String (computer science)Electronic mailing listTelephone number mappingSoftware developerCodeVirtual machineRow (database)Singuläres IntegralRight anglePoint (geometry)CodeVirtual machineCodeCASE <Informatik>Line (geometry)Functional (mathematics)Computer programRule of inferenceElectronic mailing listSingle-precision floating-point formatRow (database)Operator (mathematics)Error messageSoftware developerNumberLecture/ConferenceComputer animation
Software developerError messageFunction (mathematics)Computer fileRouter (computing)ParsingError messageFunctional (mathematics)InformationCodePosition operatorStatement (computer science)Message passingMereologyTransformation (genetics)Parameter (computer programming)Table (information)Pattern languageSource code
Software developerMessage passingFinitary relationComputer fileSinguläres IntegralError messageExecution unitString (computer science)Electronic mailing listTelephone number mappingPattern languageParameter (computer programming)Message passingData structureCode refactoringHand fanFunctional (mathematics)Online helpError messageCodeSoftware testingPoint (geometry)BitRight anglePresentation of a groupLecture/ConferenceComputer animation
Software developerEvent horizonState of matterStatement (computer science)Type theorySoftware bugLibrary (computing)Metropolitan area networkPattern languageComputer programCodeResultantOpen sourceEntire function
Software developerComputer programmingFunctional programmingWaveArmSound effectComputer programData structureObject-oriented programmingRule of inferenceMultiplication signEvent horizonDifferent (Kate Ryan album)Copyright infringementPerspective (visual)Computer programmingBuildingObject (grammar)Endliche ModelltheorieComputer animationLecture/Conference
Software developerDatabase transactionMultiplication signLimit (category theory)Condition numberBit ratePlastikkarteRule of inferencePoint (geometry)Functional programmingTransformation (genetics)Computer programMereologyPosition operatorState of matterPatch (Unix)Computer programmingMathematicsTerm (mathematics)Computer animationLecture/Conference
Software developerDifferent (Kate Ryan album)Perspective (visual)Different (Kate Ryan album)Service (economics)IP addressTerm (mathematics)QuicksortPerspective (visual)Computer programmingFormal languageFunctional (mathematics)Price indexProcess (computing)Forcing (mathematics)Point cloudLink (knot theory)Open setPrincipal ideal domainVirtual machineHypermediaAddress spaceComputer architectureComputer animation
Software developerComputer programOperator (mathematics)Device driverTelephone number mappingQuicksortDatabaseConnected spaceSystem callSemiconductor memoryElectronic mailing listDemo (music)Process (computing)Service (economics)Variable (mathematics)Modal logicPointer (computer programming)Disk read-and-write headCodeReading (process)Physical systemVirtual machineFunctional (mathematics)Data structureOpen setDiscrete element methodEqualiser (mathematics)Sound effectFunctional programmingCodeGroup actionRight angleTransformation (genetics)
Transcript: English(auto-generated)
Hello, everybody. How are you guys doing? Thanks for coming. I really appreciate it. It's kind of a small group. I like this. This is good. Because I want this to be a little bit more of an interactive kind of session, don't bother raising your hands.
Just yell stuff out. If you have questions, I'm going to be doing some live coding. If you have any questions, just yell it out and I'll do my best to try and code whatever you're thinking of asking me to do. Sort of. Okay. This talk today is about Elixir, obviously. And I'm going to show you what I've learned at my fictional company here,
Red4, where I work in the fictional science department. We do orbital calculations, sending manned vehicles up to Mars. Not really, but we're going to pretend that I do. And I've been working with Elixir, solving some really interesting scientific stuff. I highly suggest you go to Red4.0 and take a look if you want to see more. And I'm going
to be talking about what I learned with Elixir and how it's changed me as a developer. And it's been a very fun process. And that's what I want this talk to focus on is fun. Because I've had a ton of fun. And as geeks, that's what we do. We have fun coding. And I'm not here to actually tell you or sell you anything. I'm not here
to tell you that Elixir is the new way. I'm just simply going to tell you I have been having a blast the last six months learning this language. I am not an Elixir expert by any stretch. But if you're feeling that familiar tug of, well, my language can do that easily, that's cool. You know? Tell me. And it would be really cool. I have seen things with Elixir
that I haven't seen with other languages and I find it really, really interesting. I get asked by all my friends only one time, why do you like Elixir? And then I always say, I wish I could sit here and whip out my computer. We could sit and hack together and they'd say, well, okay, that's great. I got to go. This talk is that experience.
Everyone asks me, why do you like it so much? And that's what this talk is. I'm going to make you guys a deal. These are words you're not going to hear me say in this talk. Because I find it intensely boring when you talk to functional programmers
and they're like, oh, mutexes and immutable this and purity that and whatever. Didn't I say I was going to be nice except for this one little part. I got to be a little snarky. So I'm not going to say these things. I'm not going to go off with all the jargon drop that you normally hear from functional programming people, which I think is fine. But I'm just trying to get to the joy, which is underneath all the jargon. And that's what this talk is all about. Now that I've made you that deal, you have
to make me a deal. And that is, yes, I have tried F sharp. I swear to you, I've tried F sharp. I really like F sharp. But if you dig F sharp, that's cool. Talk to me afterwards and then we'll talk about F sharp. I'm not trying to dig on F sharp. I really like it. I do. I promise. Okay. So in this talk, I'm going to just cover
three areas. And if you're wondering why those slides look so kooky, my daughters made them for me. And I always promise them I'm going to put them in my talks. The experience that I've had with Elixir is kind of divided into three main parts. It is approachable. The utility of the languages and tools that come with it are really easy to use. And you're
going to see this in just a second. The second thing and probably the biggest thing maybe is it is incredibly powerful. Elixir runs on the Erlang VM. So you have all the facility of the Erlang VM with this very, very elegant language. And that's a third thing. I was told I have to do this since I'm in Europe. The third thing is it's so insanely
elegant that you can express these very powerful things in a really, really elegant way. And we're going to talk about that as well today. The first thing I actually want to go over is Mix. Mix is kind of the utility belt tool that comes with Elixir. So when you're working with it, you have to compile it, right?
You have tests you need to run. You have project coordination, packages you want to go install. That's what Mix does. So it's a little bit like NPM, a little bit not. And so let's take a look at that. And I need to switch my display here. There we go.
I'm going to do that. Okay. You can see that. Good. Let me bump that font just a little bit more. Okay. So once you install Elixir, and by the way, if you're sitting out there and want to play along, please do. If you have a Mac, it's just brew install
Elixir, and it drops on your system Erlang, it drops Mix, it drops a couple of other tools. And so right away, once you get it installed, if you're on Linux, you can do apt-get. If you're on Windows, there's an executable, you just download and run it. It's super simple to install. You can type in Mix and help. And what you get immediately is the
flavor of working with Elixir. It is one of the most helpful tools and languages and platforms I've really ever come across. I love this laid out list of all the commands that you can run with full sentences that describe what the commands do. I'm not going to go
over all of these things, but have a nice look if you like. Down below here are the ones I want to focus on, which is new. I'm going to use that right now. But there's also run. You can run an individual file or module. And then test. Mix tests your project for you. So right now I'm going to say Mix, new, NDC. And what has this done for me is it's created a project structure that I can now dive into. And going
through this, it even gave you a read me because it's assuming you're going to work with GitHub. Why not? Git ignore it. Prepared it for you so you don't have to think what do I need to ignore? It's done that for you. Mix.exes is your configuration for your
project. And then config.exes in the next directory. That is configuration for your application. And then in the lib directory, this is where we put our code, and then test directory is where we put our tests, right? There's one thing to note here if you see a .exes that is Elixir script that is different from .ex, which is the compiled
file. So you can run Elixir in script mode or just as a compiled app, which I think is really neat. All right. So let's take a look at this, and I'm going to open it up in Atom editor. And not that. Sorry. One second, please. Atom, do my bidding. Okay.
That's not doing my bidding. Oh, sorry. Now Atom will do my bidding. There we go. Sorry about that. All right. So here is our project, and I'm sorry that it's so small up there. I couldn't get the font to blow up. I don't know why I couldn't
do it. I'm a presenter. I think I'd be able to do this stuff. But I wanted to go through and show you what it looks like in here. I'm going to ramp this up in just a few minutes, but I just want to get your eyes familiar with Elixir if you haven't seen it. This is a module. It looks just like Ruby in many respects. This is a test. They've written and stubbed a test out for you so you can actually play with it and run a test
and see, like, oh, this is how I can write some code and test it as I go. And so to see this, let's actually bump this font up a little bit more. There we go. And to see this, I can run mix test. Boom. Test was run. You want to see something more? Mix test and then trace. And doing that, you can see just a little bit more
information here, if you like, a little bit more output. Really, that's it. It's a very simple tool to get into and get off the ground and start writing code, which we're going to do in one second. All right. So let's go back over here. I'm going to turn off my mirror. So now we're playing around with Elixir. Now we're off the
ground and running. And the very first day that I started playing with the language, I was actually kind of blown away at how fast I had code just structured and ready to go. And I just thought, wow, that's really neat. And that's your first introduction to playing with this language. Jose Valim, the project coordinator, a guy who made Elixir and so on, and the rest of his team have made a really compelling experience. Now let's get
into something a little bit more fun. The more you work with Elixir, the more you learn the language, the more you start playing with the underlying framework, which is OTP. It's the open telecom platform built for Erlang. Erlang is over 24, 25 years old. It has been around forever. It powers telecoms. If you guys were to make a phone call right now, chances are it
would go through an Erlang switch somewhere. This is a distributed functional language that was built to be high capacity and high availability. The Erlang VM is one of the most respected VMs in all of computer science. It's just unbelievable. And the more you get into it, the more you feel like this guy. This is Jeff Clark. That is Mavericks. If
any of you surfer fans out here know Mavericks, it is one of the best big waves in the entire world. They call it a hydraulic freak of nature, which is true. I'm using this slide for two reasons. The first is, that is the learning curve right there. You get dropped into playing with OTP because all of a sudden it blows your brain into thinking
differently because now you're working with little concurrent services that bounce off each other. It takes a while to get your brain into it. The second thing is, as you start getting into it and realizing the power at your fingertips, it's like Jeff's story. And I just have to take a small tangent and tell you his story. This is Half Moon Bay in California. And so Jeff grew up there. And he would sit with
his mates up there on a bluff at the naval facility and look out and see this wave a half mile off the beach, breaking. And you can't really tell how big it is given the distance. And it's kind of a weird perspective thing. And he said, let's go out there and try and ride that wave. And his friends are like, you're absolutely nuts because the water is close to freezing. The waves are generally
killer, literally. And it's full of sharks. It's in the great white triangle out there. And it's so funny. And so he said, I'll do it anyway. And he went out there and he rode this wave by himself, paddled a half mile out, shark infested waters and said, let's do it. For eight years, this man rode this
wave by himself. Can you believe that? He couldn't get anybody to go out with him. It's so crazy. And finally, he convinced his friends from Santa Cruz to go surfing with him. And they came back and reported back like, oh, my God, this thing is amazing. Surfer Magazine ran an article and now Mavericks is one of the big wave destinations of the world. This is how I
feel with OTP. Like, I love this quote. It's as if Jeff woke up one day and found Mount Everest in his backyard. And he did in the surfing world. I feel like this when I start programming this stuff, like, how did I not know this was here? And then you start talking to people who have been familiar with the Erlang landscape for a while, and they
come up with these great quotes, like Jessica Kerr or Jessitron. I love this. It's totally true. The more we have these object-oriented languages and frameworks and we try and do distributed stuff, we're reinventing Erlang. I love it. That was a variation of Greenspun's 10th rule. I found this online, and I can't remember who said it, but they kind of tweaked this. This was originally about Fortran
and Lisp, but I tweaked it to be, well, as you see. I don't want to be negative about it. It's pretty fun to dig into it. I want to touch on this before I get into the most ridiculous demo you've ever seen. Why do we care about distributed functional stuff, service-based, blah, blah, blah? The reason is simple. This is a quote from the
free lunches over, which basically means we are approaching the maximum clock speed you can get out of a processor. You can't squeeze any more speed out, yet the frameworks and software we're building are getting more and more intense, more and more demanding, so what's happening now is they're trying to take advantage of multi-core. They have to. To do that, well, how are you actually building
these things? Well, that's why a lot of the microservices and distributed things are coming around right now is people are trying to take advantage of more cores, not faster cores, so that's why you see languages like Elixir and Rust and everything else. Okay. Let's take a look at this. The most ridiculous demo ever. I really
am going to be honest with you. It is highly annoying, but that's why you're here to see me. Let's do it. Okay. So I'm going to mirror this display. There we go. And where is Adam? There it is. There we go. Okay. So to start off with, I am going to create a new file
here, and then I'm going to call it band.exs because this is going to be the little band that I'm going to pull together of singers, and they're going to sing to us, and so because I'm the world's worst typer, as you can tell right there, I have a little snippet in here and this is some Elixir code that I'll walk you through really quickly. The very top right here is what's called a module attribute. It looks just like Ruby to a lot of
eyes. Jose would jump up and down and say it's not like Ruby, but this is essentially you can think of it as a module-level variable. We'll just think of it for now. I have one public method right here that is running an enum.map. This is an enumerator module, and it's running map just like you'd see in JavaScript. Map just
basically takes a chunk of data and brings back select parts that you want. This is called a range, so if I do 1.20, that is a range of numbers from 1 to 20. I'm going to iterate 1 to 20. This is a callback. It's an anonymous function. You can think of it just like a callback. Fn instead of function. N is the argument, and this is basically saying here comes anonymous function.
I'm using enum.random to pick out a random voice, and then I'm piping this out to system.command. You get the idea. If I do this right, you'll hear NDC London 20 times in a row. So let's do this. So to run this, I'm going to use iex, interactive Elixir. This is another tool
that comes. It's just the Elixir REPL. I'm going to pass it the band.exs file. There we go. And here I'm going to say band, band.sing. It's not working, and it's scaring me. Okay, then. Would you believe? Because I
didn't save the file. I was going to say, Rob, your demo is just awesome. Okay. We know it works. We know it works. Okay. Thank you for that. We know it works. My challenge now is I want to start flexing some of the OTP
power that is built in, meaning I want the voices to sing all together at once, concurrently. So there's a number of ways I can do this. The first thing I can do is I can just create another method here, and I can call this sing together. See, I told you I'm a really
bad typer. And what I can do is I can use the spawn keyword, and this is kind of the gently opening door to the asynchronous world that's at your fingertips. Spawn just creates another process. You give it some code, and out it goes into its own little process that is a child of your running process. So whenever I run this file, I'm
running in a parent process, and then if I spawn another one, I have another process that runs in it. This is coding in Elixir. You code processes that talk to processes. That's how it's done. So I can do this, and I can say use the band module, this current module, use sing, and then that's it. No arguments in here. So
now that I have sing together, I can load this up again, and I can say band.sing together. So we have a problem. Can you guess what the problem is other than asynchronous programming? The problem is
that I'm spawning one process, and I'm giving it 20 things to do. So, of course, it's going to do what I tell it to do, but it's sitting in another process doing it. I wanted to point that out to you because that is something that stalls a lot of people that are unaware of these things when they first start using Elixir, like me. So what we want to do instead
of this is we want to actually work in a concurrent way, and if you start thinking about processes and coding one process, I know your head can kind of explode, like how can I actually put all this together? Well, the good news is OTP has done this for you. These guys have had 20-plus years to work this thing out. So what they have come up
with is the gen server. This is one of like a mountain of things that are available to you. There's agents, there's tasks, there's supervisors, there's all these things that allow you to code one process to talk to another. Gen server looks a little tricky. What it is is it's a protocol,
if you want to call it that, for services talking to another services. You have callbacks that you can override in there. There's a number of them, there's seven of them that you can actually override. The one that we care about is this one right here, handle cast. Its brother or sister is handle call. Handle call is synchronous. So if you want to talk
to a service and have it do some computation and wait for the answer to come back, you implement handle call. If you want, like we want right now, to do a synchronously use handle cast. So that is the internal workings of a gen server. You don't inflict that upon other people, however, you tend to wrap that kind of stuff in a public API.
So right here I'm saying, hey, start up a service for me, start up a process, and give me a link to you. That's what this is, and you'll see this in a second. The second one is the one public method I have, which is singit. And then we have to pass it the process ID. So there's a process running around in memory in the VM somewhere, and when we call in a singer, we're going to say use that process and send it this data.
And underneath the hood, we use gen server.cast. It basically means do the asynchronous call and I don't care what happens. Okay. So we have this, and now let's rewrite our code right here to actually use this. And I'll talk about what I'm doing here in just a second. And this is going to be singer, singer, and start link.
There we go. And singer.startlink, and then down here we are going to just say singer.singit. And we're going to pass in the PID and the voice. Okay. This right here is called pattern matching. If you have never seen this in Elixir
or other programming languages, I'm going to talk more about what this is, but basically what you're doing is you're matching the structure on the left to the structure on the right. This is how you do variable assignment in Elixir. I'm going to talk more about this in a bit. In fact, I'm going to go off on it. Then what I'm doing is now that I have this singer process kicked up in my little gen server, I'm just going to tell it to sing asynchronously.
Okay. So I should be able to come in here and reload this. And what do you guys think is going to happen? Anybody have a guess? You think so? Let's see.
Again, asynchronous programming. The difference we have back here, though, is it did indeed happen asynchronously. It did not happen concurrently. And this is the kind of mindset you start getting into, and this is one of the processes that literally broke my brain as I'm trying to figure out what's going on.
And I'm like, God, concurrent programming. The fun part is you actually get used to this. The sad part is getting used to it. What is happening back here is I have one process, again, doing 20 things. I want 20 processes to do one thing. Does anybody have a guess as how I can do that?
Just looking at this code. Shout it out. That's right. Move it inside the loop. All right. Anybody think this is going to work? All right. Let's see. If I say band.sing.
Sorry. Told you it was an annoying demo. All right. That worked, but that was a cacophony. That sounded horrible. Let's actually change this now to do cellos. So all one voice. The reason I want to do it this way is because I want to show you by listening by ear that it's happening at the same time.
So let's do band.sing. That's 20 voices at once, same time. We did it. That's very exciting. Sort of. Okay. I know you guys are mad at me. All right. So let's now move into doing something a little bit more complicated because you never actually do one or the other.
You don't actually do things serially and you don't do things all at once. Typically what you're going to do is you're going to have a bunch of workers that might then spawn more processes. So we can actually do this. And for this, I'm going to do my conductor. Yes. Yes.
I'll show you. The short answer is that because I am just looping over this all at once, it is essentially at the same time.
It's not literally you get down to some clock speed down there. But because I have created 20 services with no delay in there, no I O, no whatever, it'll just happen, if that makes sense. So that's how you know. But right now what I'm going to do is I'm actually going to go in there and start to tweak that. And that's a really good question. So right here I have a conductor and my conductor is going to be in charge of five voices,
five groups of five voices. I want to have three groups of five voices singing at the same time. So for that, let's see what kind of code it takes to do that. And here I'm just going to say groups. And then the first thing I'm going to do is I'm going to set voice equal to a case statement. And then let's see.
Let's do sorry. I'm totally missing something here. And then I'm going to do one to three. There we go. And then in. And then I'm going to set the voice equal to a case statement.
And then case n and one is going to be cellos. You didn't see that. That was horrible misspelling. And then good news.
OK. So basically all I'm doing right here is obviously a case statement deciding which voice, which group is going to sing. Now what I need to do is I need to have the three asynchronous groups sing things concurrently. Does anybody have a guess how I do that? With code you've already seen. Anyone guess? All right.
Spawn, band, conductor, conductor. And then this time I'm going to pass in the voice that I want it to sing. The conductor is going to spin up a single service for five individual song or singers, right?
And it's going to launch that. Now how do we actually know it's going to do it? Let's go down here and I'm going to put i o dot puts. And then we have one lovely little thing. String interpolation with elixir. I like it. So now let's make sure that this works.
And I am going to do band dot sing. Whoops. Did I blow it? Oh, I did band dot groups. I'm sorry. Band dot groups. I know. I know it's so bad. But the fun thing is you can see by the output here, cellos, cellos, cellos.
I have five cellos, I have five pipe organs, and I have five good news. So what I've just created here, and this is kind of the end of this silly demo. What I've just created here is a worker. That worker has spawned more processes. This is kind of the feeling that you get when working with OTP. A ridiculous example, but let your mind wander on the orchestration
that you can have now with concurrent programming at your fingertips in all of 46 lines of code, which I know is ridiculous, and I hate saying, oh, 46 lines of code. But it's true. I mean, it's true. And this is just the nature of programming. OK. I want to do one more, actually, because you asked about the timing on this. And I also want to show one other feature,
which is recursive programming. So I'm going to do the voices in a staggered way. And here I'm going to start out by saying enum to list. And this is going to take a range, and it's going to pipe that range. Actually, I need to do it this way. And it's going to pipe the range into itself.
That looks weird, doesn't it? So what's actually happening here is I'm using enum to list. All it's doing is it's taking that range right there, and it's turning it into an array of integers. I'm going to loop over that. Actually, I'm not going to loop over that. I'm going to pass it into another function. That next function here is this guy, staggered.
And then I'm just going to pass in the list. And then what it's going to do is it's going to iterate over everything, and I actually have to have what's called an exit function. And this is going to take in an empty list, and I am going to put io.puts all done. OK.
What we're using here is more pattern matching. When you call a function in Elixir, Elixir is going to try and match the argument to the function call. If it matches, it will get executed. So what I'm doing up here is I'm piping the result right here using the amazing pipe operator. The pipe operator just says take the result of the first function on the left,
pipe that result into what's coming on the right. If you use Linux, you know the pipe operator. And so that means that I'm going to call staggered with what's called an arity of one, one argument coming in. What can I do with this list? Well, I can loop over the list. I can do all kinds of things. But what you see Elixirists do is they match on a very particular structure for this list.
This is a broken-down list. This is actually splitting that list into a head and a tail. I put a list there. It should say tail. I'm sorry. So you can think of it like a centipede. We have a 20-piece centipede. We have a centipede with a head, and then we have two to 20 pieces left. Elixir will match on this, and it'll split that list for you
so you can have the first item and then the remaining items right here. So what I can do with this is I can now kick up my service, and I can say OK. PID equals singer start link. There we go. And now that I have this, I'm going to say singer.sing,
and then I'm going to pass in the PID, and then I'm just going to tell it to do the cello. Darn it. Why do I do that? Now that I've done that, I am going to use the timer again. Have I done this yet? I haven't done timer. No. Timer is an Erlang function. So you can dip into Erlang any time you want, because it's always there. You can just use the little colon notation right here,
or colon, as John Skeet says, and then I'm just going to tell the timer just to sleep. Just sit here. And that's, if Jose was here, yes. It is an atom. Sort of. Yes. Yes. If an atom matches an Erlang call, then you'll invoke the Erlang call.
Yes. Thank you. Thank you for that. OK. I'm going to set it to sleep, and then can you guess what the last line is going to be? Anyone? Yes. Staggered. And this time, however, I'm going to pass in the tail.
And so what this is going to do is it's going to pass the tail up, and then the tail is going to be separated in another head and tail, and so then I have two, and then I have three through 20, three, three through 20, blah, blah, blah, blah, blah. You get the point. All right. So what do you think this is going to sound like?
And then we're going to say band, bad, bad rob, band.staggered. Darn it. I almost had it. I almost had it. Singer.sing it. And then we say band.staggered.
You guys feeling the groove? This is the worst demo I've ever done. I'm sorry to inflict that on you. All right. Let's see what's our time. Good. We're good with time. Let's cut out of here. And head back over here. And let's kick this back up.
Okay. That's just musing around playing with OTP. All right. And it took me, I want to say, two nights sitting down, figuring this out.
I'm on Slack with my friends and trying to figure out what the heck is going on. And I literally was talking to myself for most of the night. Not kidding. And just trying to figure out, okay, I have a process. It does this task. I'm like, oh, this stuff. I'm like, whoa. And then once it clicked, all of a sudden, I just saw things totally differently. I swear to you. I just saw things totally differently.
I don't know why. I am not a very good programmer, and I swear to God, when I learn new things, it's like, oh, my God, I'm gonna do everything this way. Let's move on to the elegant side of Elixir, which I think is also insanely fun. This is Joe Armstrong right here, who is the creator of Erlang. And he did an interview with Johnny Nguyen, a good friend of mine,
who is doing the ElixirFountain podcast, if you're interested in Elixir at all, have a listen. It's great. He just interviewed Joe, and the guy is so funny. He's a very British bloke. Anyway, I'm saying this because Joe is a physicist, a very smart man. He's actually not a trained computer scientist, but he came up with this one stunning VM,
right? And so this is how Joe thinks of strings. And this isn't to say anything negative, but this is his approach to it. And that's kind of the feeling that people have with Erlang. It's like this neat language, but there's something they see in Elixir that isn't in Erlang. Dave Thomas, pragmatic programmer, the guy who wrote the Ruby pickaxe book, who made
Ruby famous, basically, wrote an Elixir book that is, to me, as good. He gushes in the first few chapters about how much this language has changed him. And this is a very established programmer. And for him to say what he said about Elixir is nuts. Well, Joe reads this and says, hey, you helped me write my Erlang book, and you
didn't get excited about it. And I don't know what it is about Elixir. Joe can't see it. He sees Elixir, and he sees Erlang. But there's other people that see the difference, and they go, whoa, the syntax really matters. This is Erlang. And you world programmers here, right?
We can look at this and reason our way through this. It's not that hard, but it sometimes feels a little crunchy. And looking at this, I see HTTP. I see headers. I see handlers. I see things. And I can reason that this is a web server or web framework. Whoopsie. Sorry. That was supposed to do that.
This is a web server, web framework. So, yeah. We can get into this, right? And I know friends that have worked in Erlang say, yeah, it takes a while to get used to, but it's really powerful. I see this thing, and I think it's going to explode. I would never make my way through it. I am not a good programmer. I'm one of those programmers that really appreciates the aesthetic, because I feel
like if you focus on the aesthetic, if you focus on communicating what your code's doing, you'll write better code, because people will see it and stop you from doing it if they understand what you're trying to do. And sometimes just the fact of communicating it through the code itself makes you think more. And I love this quote, and I can't remember who said it, but it's a really good one, because
Ruby is much more of an aesthetic language. Although, yes, you can write very aesthetic C sharp, but it doesn't look the same. It just doesn't. So let's see what I mean by this. Code is for people. Sheen doesn't care. And I said that, actually.
Let's go through refactoring. So this is from the fictional solar flare tracker that I'm building at my job, because we're sending astronauts to Mars, and if the solar flares kick up, it'll burn everybody to a crisp, so we have to track them. This is how you do a query. Again, we're using this notation down below in the connect function.
That's a private function. That's why it says def p. We're doing pattern matching, which I'm going to get into a little bit more in detail. We're pulling out the process ID, which you've already seen, so we know that's a gen server that's handling that connection. And then we're running some SQL above. When you run that query, this is what you get back, which is a bit of a mess, but it's very Erlang.
And what I mean by that is you get back a tuple, and it's very, very economical. You notice in there that the columns are not repeated. I'm going to get into this more in a second. But what you get at first position is this little flag that says OK. This is an atom descriptor of the data. So when you get the response back, it's a very standard Erlang-y kind of thing.
You get this tuple, right, and the first position it says what the data is or a response, some kind of response that you might have been expecting. And the second thing we get is this struct. And the struct in Erlang, or excuse me, in Elixir, has a little percent sign, and then in title case, it says postgrex.result.
This is the result from the driver. Then we have the fields on this struct called columns, decoders, command rows, num rows, and so on. They split it out because if they repeated all the columns everywhere, that would be inefficient, and we wouldn't want that, right? Here's the data that we're actually trying to get at. So we've got a lot of work to do, but this is functional programming at its core.
Transforming data from one state to another. And you do it all in a row, and I love that. So what we need to do right now is in our run command here, in order to refactor this, we need to pipe on a transform. You might not do it in one function called transform. You might do a multiple, but right now I'm just going to call it transform. And this is what this function looks like.
Down below here, we're doing some basic iteration. We're doing enum.map, which you saw me do before. We're accessing that struct, which is passed in right there as an argument. We're pattern matching against that struct, okay, and then result. Now we have access to that struct, result.rows. We're iterating over the row, and then the tricky part is this guy right here.
That is more pattern matching. If you remember what our columns look like in our result set, they were just a list of strings, like a string array, if you will. Because we know that the IDs in first position classification comes next in scale and date, we can prepare a matching structure on the left side
to match what's on the right, and that's how we pull the data out, and that is pattern matching in action. And a lot of people look at that and trip out, and I'd like to offer you this, that it is mathematics. It's only in computer science in the last few years that we have taken the equality sign and rethought of it as an assignment operator,
and that's not what equals means. Equals means one side is equal to the other. So if you look at this, you can solve X. Does anybody know what X is yet? Come on, there's some OCD people out here. Very good. X is three. That's kind of what Elixir is doing, right? So Elixir is saying, oh, you're trying to do this thing over here.
Okay, I can do that for you, and it will solve the equation. That's pattern matching. So then the next step that we have here is to return our data in what's called a map, and that's a map. A map is kind of like a map or a hash in Ruby. Key value in a structure that I can now access. So that's cool. That is our transform. Once we run it, it works.
This is what we want back. We want a list with each element being that map. Now we can work with the data just fine. Now we can get up and walk away. We could walk away. But hopefully you guys out there are looking at that going, really? Because that seemed a little bit hinky dink. And you'd be right. This is very loosey goosey right here.
This kind of code is fine. It's fine. It's working code. We like that. But what I can send in here at the result position can be anything. A tuple with an atom that says okay, and then the result can literally be goop, right? And you're matching against that, and then boom. So that's not very good. We can actually fix that to be better.
More than that, our function is doing way too much. This is not functional programming at its core. Generally, you want to have little functions that do a lot of things and you chain them together to transform the data. So here, we're parsing the results. We're turning it into a map. And not only that, things are hard-coded. So let's refactor this. The first thing I'm going to do is I'm going to flex pattern matching
to make sure that what I get in is a postgres result, which is that was the struct that was being handed back to us. And then I can assign a variable called rows. So I'm doing that there. That helps out. The next thing I can do here is I can actually remove the hard-coded stuff by passing in the columns
and accepting that in the pattern match as well. And then I can do enum.map rows, and then I'm looping over the rows, and then I've got this new thing called list.zip that I'm throwing at you. This is kind of like working with Elixir. You kind of have to understand the functions, but if you're Microsoft developers, it's sort of like working with Link. You get to know it.
And there's not a lot of them, but mainly what they do is they transform data. Zip is taking two lists and zipping the elements together. That's it, just like a zipper. And so it's taking our columns and the individual row and marrying them together. And what you get is you get a list of a list of tuples.
So it's kind of a mess, but this is actually a fairly standard structure in Elixir and Erlang. And if you take a look at each individual thing, you can see that the key is right next to the value. So what we want to do is we want to have something better than that. And what I can do is I can tack on another function, enum.into, and if you're thinking,
man, you're just moving code around, you're calling functions. Is this really doing anything better? I'm getting there. If we run this right now, what we're doing is we're actually zipping things together into that tuple structure, and then we're going to shove it into a map. enum.into will handle this, because it'll see the tuple and the value together and say, ah, I know what to do with that.
And then now we have our map back. We still have a problem with it, but we're going to fix that in just a second. Because right now what we have is something that's too mechanical. We haven't really done anything different than what we had in the very beginning. So let's fix this. And the first thing that I want to do is I want to fix enum.map. This is an abusive enum.map.
When you use it, what you're trying to do is say, I'm mapping some data here. And I'm expecting some different data back. And while that's true, we're doing a whole bunch of stuff inside that's not really good for a map. But what we should do is use what's called a comp-rehension. And this is one of the most powerful features of Elixir are these guys right here.
For row and rows, do something. This is called a generator, that row with an arrow and rows. It generates an iteration for you. You can chain in multiple generators. You can drop in a filter all in line. You can drop in a transform in there. Anyway, that reads a little bit better
and it's actually more appropriate right here. What we get back is the exact same thing, which is good. Okay, so we're getting a little tercer. Feel better about that. The next thing that we need to fix here is that we have a string key, which is a pain in the butt. We don't want string keys because to access the data, we have to access it using quotes and square brackets and square braces.
We don't like that. What we want to have is dot notation because we all like dot notation. So for this, I can solve this using atomized, or sorry, using another comprehension and I'm going to generate a string to atom list and hand it over to atomized and then I'm going to use atomized down below.
And if I do that, we're finally back to where we started, which I know is a long, circuitous route, but this is the kind of thinking that you go through and yet we can still do better and we should because when you look at this, that's still a mess to me, to my eyes, that's a mess.
Why do I say it's a mess? Because it would take me a while to actually figure out if I didn't know Elixir or if I was reading someone else's code. What are you doing? Is this not apparent to me? Atomized, the question is what is atomized? And when you add, you have a string key or an atom and the atom is the colon value.
Sorry, I didn't make that clear. What we want, I'll back it up a bit. At the first position there, as opposed to that, that first element is, the key is a string. We know that by the quotes. And so here, it's now an atom, which is a symbol.
Yes, yes, yes, exactly right. Very good, thank you. Okay, right. So the point that I'm trying to get across is that code is for people, again, machine doesn't really care how you write your code. When you write code, you're actually writing it for yourself in a year from now, two years from now, or your teammates who are gonna come in and pick up your code. And it's so easy just to say it works, I gotta go.
But you can do yourself a favor. One of the things that we can do is we can split out what we're doing with all those operations and wrap them in functions that have a good name. And you see this a lot with people that really care about how their Elixir code reads. This is explicit use of list.zip. I'm matching the columns to the rows.
I need to atomize the column names, so I'm gonna use that. Since each one of these is a single line operation, you can actually rewrite this to be single line. So it actually looks like you're aliasing one thing with the next thing. Now that I have done this, and by the way, I should explain that to do the one line operation,
you just have to put a comma and a colon after do. Silly syntax rules with Elixir, but that's what you have to do to make it single line. Now that I have this, I'm able to write a better comprehension that makes a little more sense. And if you didn't have, if you had a developer, somebody who's new to Elixir, is coming on your team, and you're using it,
and you're looking at it, you now have the ability to describe in great detail what you're doing, which when you think about that Erlang splash that we saw before, it's not quite the case. But if you really knew Erlang, you could dive yourself into it and feel good about it. Here, it's really brutally clear, at least to me. That's what I think. Now, if you're being good programmers out there, you're probably thinking,
what about errors? How is an error handled? And so let's do that. Let's bomb our code. I screwed up the SQL statement and renamed the table, and we get this weird error that says, no function clause matching, which is kind of a pain, and you see this a lot in Elixir, but the important parts are, no function clause is matching,
and then the atom right there at the first position that says, this is an error, and then you get a familiar thing. You get, now you get a struct back. Postgres.error. There's probably some information in there that I can grab, and indeed there is. That Postgres.error struct has the Postgres error on it, and then the message from Postgres itself,
which tends to be really, really helpful. So what I can do is I can match on that exactly by writing another transform method. That transform method is going to take in this exact argument structure. It'll be pattern matched, and so then I can now take that message and work with it directly. I can log it.
I can do what I want, but in here I'm just going to re-throw it. And so if I run that, now instead of getting no function clause matching, I actually get a very helpful error message. So if I take this all together, this is our final refactor, which I think is quite readable. I think, but maybe that's just me. I'm a big Elixir fan,
if you guys couldn't tell. And people can come in here and read this at some point and go, oh, okay, I know what's going on. Now if you look in here and you think about all the things that we're doing, there's one thing that is missing from all the code that you've seen me write for this entire presentation. Can anybody think of at least one bit of code that is missing?
No, aside from a test. Oh, there's no types. Well, there's types, but there's structure, the closest thing. I didn't write a single if statement, and this is one interesting thing about Elixir is there are Elixirists out there that think that an if statement is a code smell,
which means you haven't used pattern matching to the best of your ability, because you don't need to use if statement. Now, Elixir does have if statements. It has if and unless, and I've been lobbying Jose to actually get rid of them. I was about to put a bug in there, but I thought he'd get mad at me. Anyway, yeah, you can get through writing an entire program without a single if statement. Right now I have an open source
data access library. I have one if statement and I just logged an issue to get rid of it in an entire data access library, and I think that's really cool. I like that a lot. Did you have a question? I thought you were raising your hand. Sorry about that. Okay, so this is our final code, right here. Just look over that again, and I want to kind of end just by talking about functional programming in general,
and again, I'm not going to wave my arms and throw jargon at you, I promise, but I want to tell you what the effect of everything you've just seen has had on me as a programmer, and it's funny because I put this up here. This is actually a Lego set that my kids have and we've been building. It's really intense stuff. They like building these structures, but they really don't care
about the structures they care about the people, and so they have all of these really cool rules and kind of this reality they've put together, and all the, like you have the tyrannical queens, which are these elf queens, and they put them in the corner. They can only sleep in this one spot at this one time, and then they have the other elves at the top, and then lumberjacks, and the pirates, and whatever.
A lot of rules that go into this. Invariably, about every third time they do all this stuff, they start fighting because one of them violates a rule, and somebody has slept in the wrong person's bed, or something happens, and then stomp, stomp, stomp. Off one of them will go. This is how I feel about object-oriented programming.
I swear to you, we build these structures, these big models, these big things, and you say, if that happens there, and this tweaks, and this event goes off, then I'm going to do this over here, and you start to see this from a completely different perspective, and people have said, I don't know what you mean by that, and the only thing I can tell you is to imagine coming here to England,
or going to any foreign country, and you are going to go to the pub, and buy some food, and it comes time to pay, and you whip out your credit card, and you go pay. What happens at your bank? Does anybody have any idea? Foreign transaction fees? Maybe. You don't know the exchange rate, so you really just don't have any clue the amount of money
that's changed hands. Your limit could be exceeded. You could have gone over some daily thing. About a thousand conditions can go off, literally. What if you had all your money in your pocket, when you came here, and you took it from the bank as cash? Now, you might be thinking, that would be absolutely nuts. I'm not going to carry 500 pounds around with me,
but what if you had a really cool wallet, and you also had a part in your jacket, where you said, I'm going to stuck that in here, and so I'm only going to access at certain times, and you had rules around how you're actually going to do this. When it came time to pay for something, you would pay for it, and you would know exactly how much money you had always. That is why people freak out over,
God, I'm going to say it, and you guys are going to yell at me, about immutability, about you can't change the state of something in a functional program. You change data from one point to another. You actually transition states and move along. For me, I looked at this, and I was like, I think I get it. Now, is it the end-all be-all for programming?
No. I'm just saying, it's the first time I've really learned this, and now I can effectively apply it. Sometimes object oriented programs do work, but other times you come up against a functional thing, that should be, that's just pure data movement, dude, that should be like in some kind of transformation explicit and clear, as opposed to a construct where if I have a person over here
and money over here, and what happens when they come together, you know, you know, I said I was going to stay positive. So these are the three and a half things that have changed me as a programmer. I'm going to wind it up a little bit early, but I want to be able to take your guys' questions if you have any. I really do have a different perspective in terms of programming.
Languages like Elixir make me focus on clarity. Ruby sort of did as well, but I didn't need to, but with Elixir you absolutely have to. It forces you to do smaller functions. I think in terms of services that bounce around and do things together.
The question is, what's the deployment story for Elixir running in the cloud? That's a good question. How best to answer this? When you have an Elixir VM running on a machine, and deployment's not my strength, I'll just tell you, but when you deploy your beam file, that's your binary,
you get it up on a server, and that VM kicks up, that's called a node. If you need to distribute and have, let's say you have all your commerce stuff in one node, fulfillment stuff in another node, you just tell those nodes to link, and they do, and you tell them an IP address and give it a name ideally, and then they link together, and then,
yes, sort of. If you're gonna invoke a service, you just invoke it. So what you saw me do before is you saw me do a service invocation using the PID, but what you do instead of that PID, which is just something created internal to the VM,
you would give it a name, and that's when you start getting into bigger architectures, but you would say, fulfillment at this address, and then give it the explicit name of the service that you want. It'll find it.
I think they just talk. Does that make sense? I don't, I guess, they just do.
Yes. Thank you. Appreciate the answer. I bet you know Elixir way better than me.
So anyway, that's basically it, and I was going to tell you, if you're bored later today, head over to redfour.io. We have job openings, fictional job openings, and we have a manual that you can download and play around, and that's actually a coupon code for 25% off if you guys are interested at all. If you have any questions, please keep them coming. I'm not the world's best Elixir programmer.
Yes. Oh man. Yeah, the question is, is Elixir a pure functional language? I've read a lot of articles on this, and people say it is a almost pure,
because you can reuse the variables. So in one of the demos I had up there, you could have like v1 equals x, and then you could do v1 equals y, and that's allowed. It's not allowed in Erlang. And so when people look at that and say, you're doing reassignment, it's sort of true. I mean, it's rebinding is what they call it.
So they kind of look at that and say, well, it's not exactly a pure functional language, but it really is. I mean, it's just reusing that variable. We could argue about that. I don't, I'm out of my depth on that one, but that's the article I've read. Does that answer your question? Sort of? Sorry. Exactly right.
And you see this a lot with lists. So a lot of people say, well, when you're doing list transformations, like I was doing with list.zip, enum.map, you're moving list from list to list to list to list, and so a lot of people say,
well, let me back up. There's one operation that you can do where you can take a struct, and then you can append a value to it, or you can actually set a value on it by using a special pipe character. And people look at that and say, whoa, you're changing that. Well, no, you're not. You're actually getting a new struct back. And it's interesting because people say,
well, wait, there's like a memory issue here where if you keep looping over that, you're going to get a new struct, and then all of a sudden you're blowing up your machine. And it's funny because that's not what happens. It's actually a pointer, and it's a pointer to the previous one. And you can only have that happen because this is an immutable system. And so that's actually how you build out these lists
that depend on other lists, and you can change them apparently. And so again, that comes back to, is it really a pure functional language? It is, but it looks like it's not. Is that, would you agree with that? I didn't catch your name back there, the one who was helping me before. What's that? Yeah, Sunny?
I know, me neither. The database call that I did is,
the driver actually starts up, stop me if I'm not answering your question. The call right there started a connection service, an actual service in memory. And so that connected to the database and was live. Actually, I was gonna do a demo where I shut down Postgres, but I thought that was mean. When that happens, you still wanna stop the service
when you're done with it, because it'll keep the connection open. And so you do have to explicitly say stop. But if you're gonna be reusing that connection, you can leave it open and just have it sitting there and reuse the service later on. One thing I didn't show is a lot of people actually name their services so they avoid messes like that. So you might have connection one, connection two, all the way down to connection 50,
or whatever, 100. Yeah, they call it, yeah. It's the necessary side effect, that's what they call it, yeah.
Any other questions? I saw a few other hands. All right, I guess we're done. Thank you guys so much for coming.