dwyl / learn-elixir

:droplet: Learn the Elixir programming language to build functional, fast, scalable and maintainable web applications!
1.62k stars 109 forks source link

[Video] Content to include initially #68

Open ZooeyMiller opened 7 years ago

ZooeyMiller commented 7 years ago

For the sort of MVP of the videos I think we should make a small amount of content which covers some of the basics of Elixir to see how well the videos are received. Content I think would be good to cover:

I think these would be a good basis and be enough content that someone could go and play with Elixir. Some of this stuff (testing/doctesting and documentation) is not included in any of the free videos that I've seen on Elixir, and testing and documentation are both super important to us at dwyl so I think they are a must have.

Any suggestions of other content to include in the first series of the videos?

ZooeyMiller commented 7 years ago

(comments originally from @finnhodgkin )

Converting the dwyl Elixir dojo into an introductory video could work as a first basic introduction video.

It was my first experience of Elixir and I didn't freak out too much :upside_down_face: The only problem is that it's a little too similar to the Stephen Grider Elixir/Phoenix series on Udemy.

I'd also recommend adding some file system manipulation stuff.

Coding always seems more real to me once something outside of iex/the command line changes.

ZooeyMiller commented 7 years ago

@Cleop

I've made a first draft of the script for the first video. This is just based on introducing the user to the basic data types of elixir, and how to use iex. The info is very much taken from this repo, but converted to be a bit more in my own spoken language, and with directions as well. The directions are in code blocks.

Feedback would be very much appreciated!


me greenscreened onto dwyl teal

Hi, I'm Zooey, I'm a developer at dwyl

intro slide - dwyl heart with intro to elixir video 1 written. Heart could be animated?

today we're going to be looking at the basic data types in elixir, and the use of the command line tool ieX.

my face talking In this video I'm going to assume that you have already decided you want to learn elixir, if you need convincing check out these links show links to the intro to elixir videos from the learn-elixir readme on screen. I'm also going to assume you've already installed elixir, if not follow the link below (point downward) and then come back when you've got it installed.

a terminal window, maybe my face in the bottom right corner So we're going to start by loading up Elixir's Read/Eval/Print/Loop (or repl for short) in the command line, we do this by typing iex and pressing enter. We're now going to be given a prompt and we're going to be able to type in Elixir expressions, and see the result.

numbers

Elixir has two types of numbers, both Integers and Floating Point numbers, and the ability to do basic arithmetic in a similar way to other programming languages.

demonstrate addition, subtraction, multiplication and division

Doing division with the / will give us a floating point number, even if the result is round, in order to get an integer we can use the inbuilt div/2 function. You'll notice in Elixir I can either use brackets to call a function, or not, it's up to me.

demonstrate div 10, 5 is equivelant to div(10, 5)

Div will always round the result of the division down towards zero.

We also have the rem/2 function which will give the remainder in an integer division.

booleans

Elixir also supports the booleans true and false.

demonstrate true and false in iex

Elixir is a dynamically typed programming language and has a little type coercion, the only falsey values (values which are interpreted as false when coerced to a boolean) in Elixir are nil and false.

Strings

Strings in Elixir are declared with double quotes like so "hello world"

demonstrate hello world as a stirng in iex

String concatenation in Elixir is done with a less than sign followed by a greater than sign, like so

type "hello" <> " world" into iex

You can also do string interpolation in Elixir, this just means putting Elixir statements inside of a string, you do with by writing a hash symbol followed by a set of curl brackets, like so:

show "one plus two equals #{1 + 2}" in iex

Atoms

Atoms, at their core are constants where the value is the same as the name. In general, they are written with a colon at the start followed by the name/value, e.g. :hello.

They are very useful in data structures and pattern matching, both of which we will talk about in future videos.

Lists

Elxir uses lists, these are delcared using square brackets

show [1, 2, 3] in iex

These are enumberables (able to be looped over), and you can use the built in Elixir module Enum which is full of lots of really useful functions for working with lists.

you can concatenate lists using two plus symbols together

show [1, 2, 3] ++ [4, 5, 6] in iex

You can use two minus signs to remove elements from a list as well.

show [1, 2, 2, 4, "hello", "world"] -- [2, "hello"] in iex, should result in [1, 2, 4, "world"]

You'll notice it only removed one instance of 2 from the list, if I want to remove multiple instances of the same value in a list using the -- syntax then I have to put them into the right hand list X amount of times, where X is the amount I want to remove from the left hand side.

show [1, 2, 2, 4, "hello", "world"] -- [2, 2, "hello"] in iex, should result in [1, 4, "world"]

Tuples

There are also Tuples in Elixir. Tuples similar to lists, but they are not suited to being updated regularly. They are declared using curly brackets, like so:

show {"hello", :world, 1} as a tuple

They are not enumerable, and there are not so many functions in the Tuple module as there are in Enum.

You will see the use for Tuples more as you get more familiar with Elixir, they're very useful for when you want to return more than one value from a function and for pattern matching, again things we will talk about in a later video.

For now, Tuples are useful for data you only need to set, and read from, where lists are useful when you may want to update, add to, or remove some of the data in the list.

A bit about iex

Those are all of the basic data types in Elixir.

We've been playing with iex for this video, but I want to show you two really useful things which we haven't looked at so far

first is i. If you type i followed by a value into elixir then elixir will give you some information about it

show i 1 and i 1.0 in iex

So we get some useful information, and the same for any of the data types we've talked about.

shhow i "hello" in iex

This can be quite nice to look at information about data in your app, and you can use it for looking at variables as well.

The final thing is h. h is a way to see the documentation for any function directly in the terminal, it's really useful. We haven't looked at many functions today, but we have seen div so let's have a look at that in iex.

show h div in iex

We get examples of div, and a nice description. This is the first time you're seeing it, but documentation really is first class in Elixir, to the point where we see it baked into the REPL!

outro


finnhodgkin commented 7 years ago

Looks great so far :tada:

The only thing I can see that needs a bit of clarification is:

You can use two minus signs to remove elements from a list as well.
show [1, 2, 4, "hello", "world"] -- [2, "hello"] in iex

I'd clarify that it only removes the first instance of a variable: [1, 2, 3, 1, 2, 3] -- [1, 2] == [3, 1, 2, 3] //true

ZooeyMiller commented 7 years ago

@finnhodgkin if you only have an element in the right side of the -- it will only remove the first instance from the left side, but if you put it in the right side multiple times it will remove more. e.g.

[1, 2, 3, 1, 2, 3] -- [1, 2] == [3, 1, 2, 3] //true

[1, 2, 3, 1, 2, 3] -- [1, 2, 1, 2] == [3, 3] //true

I'll add an update to clarify this.

finnhodgkin commented 7 years ago

Makes sense :taco:

^^Ummm.. :tada:

ZooeyMiller commented 7 years ago

I just ran through this without filming and it's around 9 minutes. I think that's reasonable for this amount of content. I spoke quite slowly, with the idea that people who want it faster can always speed it up using youtube's speed control feature.

YvesMuyaBenda commented 7 years ago

Really useful for me here is the metalanguage for writing and transcribing programming videos. It was a puzzle in my mind how to go about doing it systematically, but it appears the solution has already been worked out!