Learn Elixir for JS Developers – Elixir vs JavaScript

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i thank you everyone for joining us today super excited to have you learn from uh our very own tim gremor at headway um so today we're going to talk about elixir for javascript developers um kind of how you can compare the concepts of elixir elixir and javascript and so you can kind of get a better grasp of how you can get started with elixir if you have experience with javascript um just before we get started today i just want to walk through a couple things this presentation will be recorded and available on our youtube channel afterwards um if you haven't subscribed be sure to do that and we appreciate any likes or comments and all that kind of stuff happy to help answer any questions along the way um and in the comments but also if you're on the live stream right now and you have a question be sure to submit it in the panel there and we'll do our best to answer it for you right here on the live stream and if you have any like personal questions about maybe an opportunity at headway we are hiring um or any questions about elixir and javascript um you can send us an email at ahoy headway.io and we'll do our best to get you the help you need to reach your goals so that's that's about it for um what to expect for today i'm just going to jump into one more thing before i hand it off to tim all right so this event is hosted by headway this is the headway youtube channel we launch and grow new digital products with less risk and we do that through business and product strategy design and software development and we like to work with startups or founders that are looking to launch a brand new product so we take their idea we help them validate it we help validate a possible software solution and we help them get it to market through design and development and strategy we also work with corporations that want to innovate and so maybe it's improving an internal process or creating a whole new product to create a whole new revenue stream for their business we help them figure that out as well and launch new products so that's it for me i think i can hand it over to tim and uh he can get started yeah welcome everybody thanks jacob uh so as jacob said i'm one of the developers at headway i've been with headway for what's going to be five years this fall i've been doing full stack development with headway first as a ruby on rails developer i've had a chance to work with some react native react for the web and an elixir and elixir is is my personal favorite as anybody at headway will tell you so this is exciting for me to be able to talk with you all about some of those some of those comparisons between javascript and elixir so we're going to stay fairly high level we're going to stay fairly basic as we work through a series of of foundational elements of each language compare and contrast those foundational elements we're going to talk about control flow we're going to talk about some various list operations and hopefully if you are a javascript developer who has been interested in elixir this will be a helpful primer to you as you uh try to transfer your knowledge into a new language so so yeah please post questions in the chat along the way um i will be more than happy to pause through the presentation and address those questions we'll also have a time for q a um after after we present so um any questions a good question anytime is a fine time and and we'll do our best i'll do my best to keep you informed what we're going to walk through today is in i'm going to be showing you something local on my machine but this is an application that has been deployed jacob will be sharing the address with you in chat this application walks it's going to walk you through again some of those foundational elements different control flows different list operations it's simply going to compare and contrast javascript and elixir and uh and you'll be able to reference that application you know long after our presentation wraps up today so um so without further ado let's take a look at elixir for a js dev uh let's see jacob do i need to there we go okay so as i mentioned uh there's sort of three categories that we're gonna look at three groupings there are plenty more but as i said we're gonna try to focus on foundational elements across these three categories and we're gonna start with what everybody wants to know and that's conventions how do people go about how does the community go about writing javascript that's consistent that's readable that's maintainable and if you're javascript developer you've seen this you use it you're familiar with it if you're not an elixir developer yet but again you're interested this is the compare and contrast between the two so javascript largely has adopted camel casing for how they how we name variables functions how we name things in a javascript application camel casing would be lowercase start and then word breaks start with a capital letter again followed by lowercase remaining characters of that word so welcome statement capital w or rather lowercase w capital s elixir the convention is to use snake casing so snake casing is all lower case word separated with an underscore and that applies both to a variable that you would declare an attribute or a function name so in this case we've got welcome statement as a variable and welcome statement as a function each being assigned the same same value now there are more conventions but again we just just want to stay stay at a a very basic level okay so you've seen assignment happening let's take a look and talk more specifically about how variables are declared in javascript you're likely familiar with what it is to declare a javascript variable you can use const let var some of these are have intention they don't necessarily have constraint in the language so a constant you're saying yeah constant you're saying foo is going to be one and it's always going to be one through the life of that variable within that scope let here we're saying bar can be is two initially but i might reassign bar to a different value further down in the scope of my application and var is really what what javascript um edits at his core is using so constantly is is helping us communicate meaning and intent and ultimately write better code but var is what we end up with additionally if you've got a constant so const not to be confused with what a constant would be in this use case foo is something that i want to be able to use across modules across pieces of my application so i might export const foo as a constant at least that's the intended that's the intention that's the convention and because it's a constant we communicate that intention through fully upper case variable name so in this case i'd export const foo from a module and then i'd be able to import and reference that constant in other pieces of application so let's compare variable declaration from javascript to what we get in elixir so we'll see foo equal to one notice that there's no there's no prefix to this declaration there's no type of variable declaration now there are there are type specs in elixir but in that's a little bit deeper than we want to go today so no just notice that there's no const let or var it's simply foo equals one additionally we've got there's different types and we're only calling out a couple in throughout this presentation one of the additional types that you won't find in javascript is something like an atom if you're familiar with ruby a symbol elixir has an atom and an atom is that the name of the atom the name of the variable in this case okay or error that's also its value and so it's a it's a very very descriptive way in an efficient way to to declare and uh and assign value within your application um okay so we've got um a variable named foo equal to one we've got an okay and an error atom this next piece here is showing us how we would declare module attribute so first we've got the declaration of a new module named my super special project and that module has a module attribute named foo with a value of one so if we went back up to javascript and we saw that we exported a constant named foo all uppercase foo with a value of one we can reuse that similar with a module attribute and elixir i can declare a module attribute named foo with a value of one there's an there's an additional um there's initial capability that elixir gives you because it's it's compiled so when your application is compiled the value that you would assign to a module attribute is there's a snapshot of that value in time so when it compiles you're going to get the value of the module attribute the value of your assignment at compile time so it's best illustrated by thinking about the clock if i declare a module attribute named foo and i want to assign now the current timestamp to that module attribute datetime.utc now that value is always going to be the moment it's processed during compilation it's not going to change at run time that would be different than if i assigned date dot now in javascript that value would would always be now not only when you've written and shipped built your product okay so just one one caveat there's there's uh it just introduces new possibilities when you have that layer of that compilation time concern um sometimes it can be a gotcha other times if you're aware of it it's actually a help because you're able to do some unique things with that um okay let's keep moving to comparison operators so so in javascript we can't write something like hi as a string assigned to hi as a string we're going to be throwing an exception in that high can't be reassigned to high okay now we can do we're talking about comparison so i illustrate this assignment attempt simply to contrast what we'll get to in the elixir equivalent of that now javascript does have double equals and triple equals so double equals is a little bit of a looser comparison as you're likely familiar with so high as a string equals equals high as a string that's true high as a string triple equals high as a string that is even more true because it's comparing the type not just the value and so we don't have a triple equals in elixir but we do have what's known as the match operator okay so this first the first uh example here of high equal to high that's acceptable in elixir because it's not assignment it's actually binding and there's there's a match the equal sign is called the match operator and uh and what happens is it won't you won't be able to bind the right hand side of a match operator to the left hand side if they're not equal if there's there's not um if they're not comparable so i this statement is true high equals high it is not you cannot do that in javascript it'll throw an error this statement is fine high equals high hello equals high is not that fails because the values don't match so the match operator gives us a much deeper much deeper let's see much deeper concern much deeper capability it empowers so much more throughout the elixir ecosystem than a simple assignment would do in as may be found in javascript and in other languages okay but there's so we are again we're talking about comparison so the match operator that's one thing um there's also just basic comparison so i can compare does the string high equal the string high yes it does does the string hello equal the string high it does not it's false so um so there's there's a fine distinction there just suffice to say that the match operator is not quite the same as assignment in javascript there's quite a bit more capability that comes with the match operator we do still have comparison as we as we would be familiar in javascript without a triple equals though simply a double equals will get you the same level of comparison okay let's keep keep moving we're going to look at importing so we've got resources in our javascript application that we want to reuse throughout we want to write a module or use an external library that provides us with functionality that we need currently in in our code that we're writing so we we're going to import there's different ways to export and import in this case these examples were saying import react which is a default export and also import use state which is a named export from the react library if i have a naming collision for example i want to import react again which is the default export from react but in the scope of my module i want it to be named my react again maybe you have an amy collision maybe there's some expressiveness that you want to add to your your code by giving it a custom name these are a couple very quick ways to just to illustrate that this is how we would import an external resource into a current module in elixir we've got a couple more options just a couple that we're going to highlight when i import something into a current module in elixir i'm actually importing the functions the definitions in that module and i'm mixing them into my current module so in in javascript i would use in import react i would use react dot react. my function name that i want to use in elixir i simply have those functions available to me without having to prefix the function name with the module it came from so if i import my super special project dot helper module any function on helper module is going to be available to me for use directly without having to prefix it with the fully qualified name now if i keep keep moving it down we can also see how there's the concept of an alias alias would be similar to the naming a custom name import in javascript as illustrated above where we import react as my react it's convenience if i want to alias something i can i can alias helper module giving me shorter hand reference throughout the scope of my module by aliasing my super special project.helper project.helpermodule so this would provide me with helper module dot instead of the fully qualified version and i can also customize the name of that alias which i haven't illustrated here but but that would be be available to me um and then finally if i want to import only certain only certain functions from helper module i can specify them i can whitelist them with only as a list of um that would only as a list of function names in purity okay so let's take a look at functions in javascript and how they compare to elixir so we've got just a couple basic examples here add two numbers and return the uh the sum of them um javascript likely familiar with with these two versions i can use add i can pass add around my application the reference to that is available for me to use in the scope of of where they're declared and then also outside the scope if i happen to export and import them similar can be said about elixir so we declare a function in elixir starting with def definition and then open up the body of that function with do and then we explicitly end with the word end comparating contrast with curlies as found in javascript um the name of that function add takes two parameters n one and two and you notice that there's no return statement there's not an explicit return in elixir so in this case n1 plus n2 is what gets returned um javascript you would call return explicitly unless you're using the the convenience of an arrow function a one-lined arrow function um okay so there's there's that's one way def add do and plus one and plus two there's also the ability to bind a function definition to to a variable named add and you can see here there's two examples fn is a stubby function different syntax but accomplishes the same thing where fn a and b as the arguments the function body is opened up with a stubby arrow a dash followed by greater than sign a plus b again it's returned there's no explicit return statement needed and then end to end of that function definition um the the all three of these def add function a b and then the ampersand which is called the capture operator all three of these are going to accomplish the the same thing um and then one additional piece worth calling out is that you do have private and public definitions in elixir which you don't have in javascript there's conventions for it but they're not strictly enforced like they would be in elixir and oh tim just wanted to we have a question that came in uh asking what did you mean by arity yep it looks like uh josh downs thanks for for responding and that's um that's right erity erdy is a general term you see it much more frequently elixir because it's built into function definitions it's used as part of the documentation really you're going to reference function including its arity instead of it's just different than javascript where javascript has aird2 you would declare a function that may have zero one two three parameters that it expects that's the arity the number of parameters that it expects elixir it's call out it's you would say mymodule.privated2 that's how you would describe a function name in elixir so that it's a little bit more descriptive it tells you exactly what what the function signature is awesome thanks josh thanks for and thanks tim too for wrapping it up as well yeah that's great yeah keep keep the questions coming that's a good question okay uh let's take a look at method chaining and in javascript we can see in this example we've got people which is an array of objects each object has name and age attribute on it and what we're going to do is we want to filter out from that array of objects that have an age greater than 21 and then we want to map over the result of that filtered array and only extract the name and so what we end up with after calling people.filter.map is an array of strings with a value bob because bob is the only one over 21. so that method chaining is you're not limited to that we could add on to map additional additional function calls that an array would provide us in elixir what that looks like is it's a little bit different we're not dealing with objects per se we're just dealing with functions so we're passing the return of one function into the start of another function and that's accomplished what with what is known as the pipe operator so um so we're going to start out with again a list in this case list instead of array list of maps again with name and age as the attributes and using the enum filter 2 function we're going to filter out those objects that have an age value which is greater than 21. and then we're going to pipe that into enum.map where we only want to get out the name the name value or the value of the name attribute leaving us with bob as one element in a list so so again we don't have dot syntax to trigger the next function in a chain of events that we want we have what's known as the pipe operator the pipe with greater than symbol and so that example is a common one where we have a a list or an array in javascript of objects and we want to want to transform that collection into some other value or we want to extract a specific element of that list and uh we can do that we can use the pipe operator for quite a bit more than just just a list though we can take something as simple as a a number in this case 45 and we can end up forming creating a function a mathematical equation using in this case the division function which comes from the kernel module we can use on math so this colon math is is calling an erlang function and um and then we also have kernel dot asterisk in order to multiply again the what the the result of that series of pipes is essentially this this algebraic equation at the bottom so okay let's see and yeah it looks like i see uh uh fran uh pronouncing that right thanks for calling that out um the the the fact that last line in the elixir function is is a return value it's good um okay let's keep rolling to destructuring so in javascript we're going to start with a const named o and it's going to be a nested object um nested would be the top level object at key name and then the value of that nested key is another object with prop as its key name and value of high if we want to in our code only get to prop of that nested object we can use destructuring like we have on the next line where nested open curly prop close curly along with a default assignment of an empty object gives us prop and then we can see in the comment hi is the is the output of console.log in elixir we have something similar something akin to destructuring but this actually has its roots in the match operator and in pattern matching which we won't get into too deeply but but you're gonna see it you really can't avoid it when studying elixir um you're gonna see it and it's akin to destructuring but again there's some very fundamental differences between the two in this case we have similar o is a nested a nested object in this case it would be a map an elixir percentage sign curly is is a map nested percentage sign curly prop with value of high if we want to again extract the value of prop we can do that with pattern matching and and the second line in this elixir section shows us how to do that we end up with prop as an attribute if we call io inspect which is akin to console.log in javascript i would add inspect of prop is going to give us the value of hi as a string and again pattern matching and match operator binding enables this syntax which is quite different than what we see in destructuring in javascript but but it is worth worth comparing and trusting the two okay let's keep going here so this is another example a little bit of a a more relatable example when talking about pattern matching where we have a function named list and that list is going to accept a user object and that user might be an admin or just a general user if it's an admin then show me all of the elements in my store if i'm not an admin then i then i should only get a subset of those which i have permission to see so that likely is familiar to you if if you spent time writing javascript in elixir you'll notice that we can accomplish that same goal without any conditional statements there's no if block there's there's no switch statement nothing like that in this case we have two functions each with the same name their private def p so their private functions each function is named list and each function accepts one argument so you would say whatever the module name would be my my helper module dot list arity one would refer to these two definitions the difference though this is this is what this is what's so powerful is the argument you passed in is user user is a map which which has an is admin attribute on it and the value that may be true or maybe false so when i call myhelpermodule.list with a user it's going to match and execute this first list function if the user is an admin has a value of true if not then it's going to use the second definition of list and simply give me a subset of all elements in my store so this is it's a it's more it's more declarative than having to use conditionals to work your way through certain business logic um this is a very common example um where you're looking for only things that a user has permission to see um it's a it's a bit more declarative where you can avoid those branching statements within a function and instead declare separate method definitions okay so let's take a look then at control flow i'm going to collapse the basic section and we've seen a couple examples of control flow example so far but let's take a closer look at some other examples and i've referenced switch case statements in javascript in this case we are making an http request most likely get a response that response object has a status attribute on it and it might be it might we want to address two specific statuses on that response object and then anything other than those two we're going to return and consider it an error so if response to status is 200 then it's successful if it's a 401 that means the user is not allowed if it's anything else we didn't expect it and there's an error okay so this is a nice concise way to write those different um those different branches within within your application and addressing different business concerns what that looks like in elixir you there's a couple of more options than what javascript provides an elixir we can use a case statement we can use a conditional block we can use with statement today we're going to look at case and conditional and the case statement is quite similar to switch i would say they're they're the most um they're the most similar in that you take an object um a variable in this case get a response well i suppose in this case it would actually be a function so get a response would execute a function and the return value of that function is going to be a tuple either okay as the first element of that tuple or error with a reason or error with something unexpected and so this case statement is very similar to switch in that you have one reference with multiple possible values and depending on that value you want to respond with success not allowed or an error statement the one additional one alternative way to to use and to address different branching aspects of your code of your business logic is to use a condition condition doesn't require you to give it a value up front so you could have what seem to be very disparate conditions in your flow and you can address each of those distinctly with the condition block so in this case i've got three different three different what very again very disparate comparisons to make but they all work together and i should only have one outcome based on the order of these conditions so if i have a variable named foo and that equals the string of foo i want to consider it a success if that's not the case then i want to look at the bar variable if bar is less than 1 i want to consider it not allowed and this little underscore down here is a catch-all so anything else i want to consider an error and so condition is you don't often end up with very disparate comparisons to make but it can be very helpful because it does occur where you have a system you're writing that has certain certain priorities step one if this is true then do that step two if this is true then do that everything else to do the other thing and and condition can be helpful to avoid writing multiple case statements and let's see we've also got an if else block that we've likely used in javascript where we can say if n is greater than 100 return 100 if any it's anything else if that's not true then simply return n and uh and there's also the ternary operator which says if n is greater than 100 question mark return 100 else colon return n um elixir also has conditional blocks where you've got an if else if n is greater than 100 do 100 else and end and so just a couple syntactic call outs to this there are parens required in javascript they're not required in elixir but but you could use them if you had to manage operator precedent you open up an if block with do and you end with end instead of the curlies that you are familiar with in javascript there's also an unless statement which reverses the business logic uh javascript doesn't have unless but it's uh it's convenient and ternary elixir doesn't technically have a ternary function but you can mimic it by doing a one-line if statement so if n is greater than 100 comma do colon 100 comma else colon n so it's very similar but it's not quite the same as the syntax you're accustomed to when writing a ternary in javascript and okay let's see control flow so there's an additional there's an additional control control structure an elixir name to the width block um it's very it's very useful uh there's not really anything in javascript that is comparable so we left that out of this example and it's a little bit more complex but i just want to put a plug for the width block because it is very very useful and as you get to know some of the more some of the more similar case and conditional if else you're likely going to want to dig into what the width block is all about okay uh last section we're going to look at list operations so um you've heard me say javascript array elixir list uh they're they're very similar they're they're the parallels to one another when we want to work with a list as we've seen already that often we want to map we want to filter we want to do some transformation or extract some value from a list and let's take a look at what it looks like in javascript when we want to map over a list in this case a very basic array of one two three we want to what we want to do is we want to add a multiplier to each of those elements in the array to give us a new array named b and in this case let's map over array a multiply each element by 2 in order to get a collection of elements with values two four and six named b in elixir similar we're gonna have two lines in order to accomplish that a is going to be bound to a list with values 1 2 and 3. using the enum.map function we can take in a as the first argument to map the second argument is an inline function a stubby arrow function that function takes one argument named n we multiply n times two in order to get back a list with values two four and six and then we bind that list to variable named b okay a couple more here when we want to filter an array there's very similar pattern through each of these list operations javascript here we've got again the same the same array where we've got array of objects with attributes name and age and we want to filter out people that are under the age of 22 and in this case we're going to call the filter array function on our array named people we are going to destructure our object it looks like we're actually missing some parens here around curly age closed curly we're going to destructure our object extract the value of age and then we're going to compare it to a value of 21 ending up with a single object in a list in an array excuse me with bob of age 30. an elixir similar enum.filter gives us the same capability we've got a list of maps name bob h30 we want to filter those out using an inline stubby arrow function comparing age to 21 giving us a new list with only bob of age 30 as the element within that list okay and let's see here we've got one more which is reduce so if you're new to reduce reduce is not distinct to javascript or elixir it's a as with any of these functions they're they're obviously there's equivalence across pretty much every language reduce is a concept but often the function is going to be named accordingly in each language in this case it's the same in javascript and elixir where you've got an array that you want to do some transformation on you might even end up with a completely different value and in this case we're not getting back uh an array in this case we're getting back a single value so what we want to do is take an array 1 2 and 3 and we want to reduce that down to the sum of its elements so if you if you're familiar with reduce um this likely will will come to you if you're new to the concept what happens with reduces you take an accumulator so you've got to start a starting place in this case our starting place is the number zero that becomes our accumulator and then the return function from each cycle through our list becomes the new accumulator value and in this case we're taking accumulator starting at zero and we're adding n to it so first cycle through we'll get one as a return value second cycle through we'll get three is a return value third cycle through we'll get six and you can see the comment below is saying sum is six after running that reduce function elixirs same same thing essentially and this is what the the syntax looks like where enum.reduce on a list of values one two and three starting with zero as our accumulator and then an inline function here with n and our accumulator as the parameters to that function giving us in the end sum is 6. and that is the end of our examples so what kind of questions do you all have after that after that walk through happy to to dig in and further explain any of this awesome this is great tim yeah if anyone has any questions feel free to throw it in the chat if you have like a deeper question it's hard to explain in in the chat there we actually can send you an invite uh to this call and you could ask in real time like on the phone basically um and we can walk through it together so if anyone needs that just let us know in the comments and we can send you a link and you can hop right in so but yeah this is great um while we're waiting for any questions tim what what kind of resources do you recommend to folks uh to kind of get started with elixir um and so you know it's something that's more digestible instead of just going through me i mean there is the documentation um but maybe if there's other resources out there yeah yeah good question jacob thanks um the well i don't i don't want to recommend it if you need a different type of presentation if your learning style is unique but if you're willing to read the written documentation in the elixir community is fabulous it's as good as i've seen in any language um you'll find examples you'll find clarity you'll find references to other elements within the language you'll see tips you know watch out for this or consider that and uh and so the the elixir language documentation is great um the language libraries within the elixir community uh you'll find in the documentation for those libraries i should say you'll find in hex docs and hex docs the again language the community takes a good amount of care in crafting documentation for their libraries so elixir the the entry for a lot of people into the elixir community is phoenix and the phoenix framework is is a very very capable framework for you to write web applications and the documentation for that is a great place to start so getting to know the foundations of a language which is what we tried to do today by comparing it to javascript is is excellent if you're more if your learning style is different where you'd rather start to build something and you want to learn it as you're building i would recommend starting with phoenix and getting creating an application locally and just working your way through the documentation on hex docs or with the phoenix framework website itself awesome yeah i dropped some links to the elixir lang documentation site and then the phoenix framework uh as well yeah and i'd say jacob one more that's worth mentioning elixir school there's plenty out there oh yeah elixir school is is excellent and uh one again you know again i can't speak highly enough of the documentation in the community um what what i found is there's not a lot of discrepancies when i go from resource to resource in javascript it can be difficult in javascript community it moves so fast and things change so quickly that it can be difficult to find a level of confidence in in the solution that you're reading about or the learning that you're gaining from another another presenter um i've seen much greater level of consistency across the elixir community when when trying to understand and learn so all right well awesome we have a question from josh since he helped us out before in the chat we'll we'll help him out so um he says i find myself wanting to write if uh condition statements more than i should coming from javascript can you give me an example of when it would be correct to use a conditional statement versus pattern matching that's a good question josh um let's see when would it be appropriate to do that um this might sound like a little bit of a cop-out but some of that would depend on your team some of that is just preference so as with any language there's a couple different ways to accomplish the same outcome and that's at the root of your question i would say it's it can be a team preference so you might take you know an if else if this thing is true do that else do the other thing you could write that as a multi-clause function which those multi-class functions are going to use pattern matching in order to accomplish their their their uh intention um what one of the so one of the distinctions leading to your you know well let's see one of the considerations leading to your decision would be team preference you might also look at it and say i can test these things separately so i can write a unit test if i write a multi-clause function in a way that's a little bit more direct the setup for that function might be a little bit easier to do than if you write a series of conditionals um you can also look at well if you're starting with if else but you're anticipating if else and then the other thing as your application grows you might also decide to do to leverage pattern meshing with a multi-clause function if you're sure it's going to be just either or i would i would recommend just stay with what you're comfortable with and write write your if statement and and and then you can always refactor right there's instead of um spending too much time trying to decide what's the best sometimes it's best to just get get what you know and what you're confident in and then come back and refactor as your application evolves awesome thanks tim can jump over to this next one fran asks uh could you talk a little bit of recursion uh yeah what let's see that's kind of a big that's a big question um frank could you maybe be a little more specific about recursion i don't know if we'd be willing to add in in what context um elixir has a functional language recursion's very important to it there's different there's what's known as the cons operator in order to take a list and recurse over that extracting head and tail if you're familiar with that head would be the first element in the list tail would be everything after it how do i use recursion in my projects okay so there's there's not often that i'm writing my own recursive functions in in the web applications that we've written usually what we find is we're way more often using various list operations to work our way through and transform or extract values but we're not often writing our own recursive functions what the enum module provides what the stream module provides which is lazy enumerable is it's a lot it's very powerful and so i don't often write a raw bit of recursive logic in my application i'm usually able to leverage something that's already been provided so yeah fran i don't i don't know that i have a good example because we just don't find ourselves having to do that very often um if if there's a different if you have a different example specifically if there's a use case that you're questioning how you might solve maybe i can help i'll provide some some suggestions as to how to solve it but i don't of myself have a a real solid example that i could provide all right thanks tim yeah no worries uh if a friend if you have a specific example uh beyond what you shared already with more context uh we'll do our best to answer it we can jump to this next one sparky shares you referenced uh tuplar before i read the docs before this and that was confusing to me can you explain how that plays in for elixir yeah that's a good question so tuple t-u-p-l-e i believe is what you're referring to and if you you could think about tuple as a fixed size list that can take various various types of elements within it and it's it's more restrictive than than a list or quite a bit more restrictive than what you're familiar with possibly in javascript as an array you can put any type of element any number of elements into a javascript array a tuple is fixed so when you create a tuple if it has 1 2 3 100 elements probably not going to do that but if you had whatever number of elements in a tuple it has to be that it has to remain that way you can't just continue to add to it or subtract from it now you can declare a different a different attribute which might represent a portion of your tuple but you can't take that existing tuple and mutate it into something else of a different length um it's it's very useful one probably the most common example of a use of a tuple would be an okay or an air tuple so as you think about making an http request for example one of these was actually in the elixir 4.js dev site that i've been sharing as you make an http request that either may have been successful or may have failed the function that you might call to execute that http request often is going to respond with an okay or an error tuple and it makes it very easy for you then on the receiving end of that function call to look and say it was okay this was successful and i want to look at the second element of my tuple to get the response from that http request or it was an error an error tuple i want to look at the second element of that tuple to get the error message or the error payload uh so it's it's very descriptive it's a it's the the object itself the death type itself is useful in many many ways that's probably the most common example of it of its use and uh yeah i find it very helpful instead of instead of maybe passing a string or or some other approach comparing numbers um as you may be familiar with in javascript when looking at http status so hopefully that helps sparky so this would not work for example like a list uh correct so you would if you have a list an unknown length of elements that you want to create an array of in javascript you wouldn't use a tuple for that in elixir you would use a list for that in elixir all right awesome we have this i think this will be our last question we'll wrap things up here just because we're running out of time so thanks everybody for your patience today and and and all your questions um alice asks is there a framework like express in js or flask in python yeah so uh the phoenix framework is is the one i mean it's the most popular one it's what has brought probably the most attention to elixir community um there's others as well i haven't played with the others so i can't really speak to them um but i suspect they're i suspect they're worth looking at i just i know that if you use phoenix you'll be very very pleased it's fantastic especially if you're familiar with express or flask or rails a lot of the a lot of inspiration that you'll see in phoenix and even some of the conventions in elixir you'll you'll find had some origination in the rails community so uh yeah so hopefully that helps if you want to check out phoenix phoenixframework.org that would be my best advice awesome thanks tim i'm going to actually we'll wrap things up i'm going to share my screen uh let's see here get my sharing things going there we go i just wanted to let everyone know we have some more events coming up on our youtube channel here you can also subscribe or register should say and get reminders on your calendar all that kind of stuff um on our website so if you go to headway dot io slash events you'll be able to see these so we had our event today tomorrow we'll be talking with chris ewell the the co-founder and ceo kinetic about how he kind of validated his idea and solution of building a new professional networking platform um which is pretty cool uh we'll be talking about guiding design with product strategy next week uh with katie from our design team uh kelsey will be talking about advanced typescript and some of the things you can explore to to level up your typescript skills so that'll be cool um and then next month we're also talking with teresa torres about continuous discovery habits within product strategy and then billy will be wrapping up june about creating user flow diagrams from customer journey maps uh from a designs perspective so lots of stuff coming up and then we're also hiring so if you're if you're a designer developer and you're looking to for a change in your career or you're looking for a new opportunity we're hiring product strategists designers different different types of developers so be sure to check those out and we hope that you find something that you're looking for and to please please apply so that's it for today thank you everyone again as a reminder this will be available on the youtube channel after this so if you want to re-watch it and be sure to check out the link at the top of the chat i pinned it as the resource for uh what tim was sharing today um and yeah we appreciate everyone taking the time to to to be with us today so tim do you have anything else you want to share before we wrap things up and uh say goodbye um no just thanks everybody again appreciate your time and your questions um if you do visit elixir4js.dev uh there's a link at the bottom feel free to click submit issues through through the github repo and we'd be happy to add more more information more detail to that site so you can all continue to learn and benefit from it awesome cool yeah i got it set up right here so be sure to check it out and uh everyone take care and have a great day
Info
Channel: Headway
Views: 1,678
Rating: undefined out of 5
Keywords: elixir programming, elixir language, elixir language 2021, why use elixir programming language, learn elixir programming, elixir programming for beginners, phoenix framework, elixir lang, elixir phoenix, functional programming, elixir language tutorial, elixir language basics, elixir language programming, elixir programming language tutorial, elixir vs javascript, elixir javascript, headway, learn elixir, js developer, elixir javascript framework
Id: fMY9-iGZYIA
Channel Id: undefined
Length: 58min 8sec (3488 seconds)
Published: Wed May 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.