Coder Social home page Coder Social logo

wintermeyer / elixir-phoenix-ash Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 4.0 9.14 MB

An Elixir, Phoenix and Ash Beginner's Guide

Home Page: https://elixir-phoenix-ash.com

License: Other

CSS 16.16% Handlebars 82.63% Elixir 1.21%
ash-framework ecto elixir phoenix-framework

elixir-phoenix-ash's People

Contributors

hellosmithy avatar hyperoceanic avatar j0urneyk avatar nizarmah avatar riverrun avatar siaw23-retired avatar wintermeyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

elixir-phoenix-ash's Issues

Ideas for formatting code examples

This issue is intended to help us decide on which format we should use for the code examples.

Currently, we use the following format:

iex(1)> defmodule Area do
...(1)>   def circle(radius) do
...(1)>     pi() * radius * radius
...(1)>   end
...(1)>
...(1)>   defp pi do
...(1)>     3.14
...(1)>   end
...(1)> end
{:module, Area, ...
iex(2)> Area.circle(10)
314.0
iex(3)> Area.pi <3>
** (UndefinedFunctionError) function Area.pi/0 is undefined or private
    Area.pi()

Other formats

The Elixir getting-started guide (example taken from the Modules and Functions page:

iex> defmodule Math do
...>   def sum(a, b) do
...>     a + b
...>   end
...> end

iex> Math.sum(1, 2)
3

Compared with our current format, the getting-started guide does not include the command numbers, and it does not show the module return value (it displays a blank line instead).

If we find any examples of other formats, we can add them in the comments below.

The result of running the string interpolation in the elixir guide is different from the example.

Hello. Thank you for writing such a great guide.

I am currently working my way through the Elixir guide and I am not getting the same results when I run the example in String Interpolation locally.

In the first cell in the following image, I expected to get something like "The list is [72, 101, 108, 108, 111].", but I am getting something like "The list is Hello".

The second Cell expects to get a result like "The tuple is {72, 101, 108, 108, 108, 111}." when executed, but gets a Protocol.UndefinedError error.

livebook-result

I suspected it was an issue with the Livebook environment, so I tried running it through iex, but I'm getting the same results as when I ran it in Livebook.

iex-result

Move modules / functions section in elixir-introduction to before anonymous functions section

I think we can move the Modules and Functions section to an earlier and more prominent position (before the Anonymous Functions section) in the elixir-introduction. This is because most of the functions that developers will read and write are regular functions (within modules) and it makes it easier to look at anonymous functions (and the capture operator) in the way they are most often used (as arguments in higher-order functions) if we look at them after covering regular functions.

My proposal is to move the Modules and Functions section to after the Strings section and to move the Anonymous Functions and Capture Operator sections to subsections before the Hierarchical Modules section. Also, I want to add more examples using higher-order functions to the Anonymous Functions and Capture Operator sections.

The example code in `Type Conversions in Elixir` in the Elixir guide is not running correctly.

Hello.

While looking at Type Conversions in Elixir in the Elixir guide, I ran the following example code locally and did not get the same result as the example.

Example Code

iex> to_string([1, 2, 3])
"[1, 2, 3]"

iex> to_string({:ok, "Hello"})
"{:ok, \"Hello\"}"

My Local Result

result

In addition to this problem, Now, how can i string interpolate variables of types like List and Tuple?

The example code in `Pattern Matching With Various Data Structures` in Elixir in the Elixir guide is not running correctly.

Hello.

While looking at Pattern Matching With Various Data Structures in Elixir in the Elixir guide, I ran the following example code locally and did not get the same result as the example.

Example Code

defmodule User do
  def greet(name, opts \\ []) do
    greet(name, opts)
  end

  defp greet(name, [role: "admin"]) do
    "Welcome, #{name}. You have admin privileges."
  end

  defp greet(name, [role: "moderator"]) do
    "Welcome, #{name}. You can moderate content."
  end

  defp greet(name, _) do
    "Welcome, #{name}."
  end
end

IO.puts User.greet("Alice") # Outputs: "Welcome, Alice."

IO.puts User.greet("Bob", role: "admin") # Outputs: "Welcome, Bob. You have admin privileges."

IO.puts User.greet("Carol", role: "moderator") # Outputs: "Welcome, Carol. You can moderate content."

My Local Result

screenshot

If the content of the example code is not available in the latest version of Elixir, what is the latest alternative approach?

Possibly incorrect code example in phoenix-basics

In the 'link class' subsection in the phoenix-basics file, there is the following example:

<%= link "Ping!", to: Routes.page_path(@conn, :ping, class: "btn") %>

Has this been tested? I think class: "btn" should be added to the link function, not to the Routes.page_path function, so I think it should be:

<%= link "Ping!", to: Routes.page_path(@conn, :ping), class: "btn" %>

Add information about keyword lists to the elixir introduction

We will need to include some information about keyword lists. They are often used to set options in a function, and anyone creating a Phoenix app will see them very soon because the render function uses keyword lists to populate the assigns values.

We could add a short Keyword Lists section just before, or just after, the Maps section.

Briefly introduce the concept of context modules in ecto-basics

In the ecto-basics file, there is the following line:

Note:  One can argue that get_author!(id) is not easier/better than Repo.get!(Author, id). 

This touches upon one of the reasons for organizing code into context modules - that is, to provide an interface between the controller and the data layer. The trend now, since Phoenix 1.3, is to query / manipulate data in the context modules, rather than doing so directly in the controller code.

I propose that we edit this line to point out that, although there does not seem to be much point in creating the get_author/1 function (as we could just call Repo.get/2 from the controller), there is a clear design rationale for creating this new function and not calling any of the Repo functions directly in the controllers.

It is important that we keep this mention of context modules brief and try not to overwhelm the reader.

Useful links:

Remove / simplify parts of the elixir introduction

Parts that I think we can remove:

  • the {:module ...} return value when defining a module
    • this takes up space and does not give any useful information to the user
    • maybe we can keep it for the first example and then add a comment saying that it will not be shown in the next examples (similar to the comment about the BREAK menu)
  • variable scope
    • this is something that the user can learn about later
  • example of writing a mix task
    • this is something that the user can learn about later
  • mix format section
    • instead, add a list of useful mix tasks to the mix section and add mix format to that list

Parts that we can simplify:

  • dates and times
    • introduce the subject by looking at DateTime, and then add links to the docs for the other date / time types
    • this will use less space and will focus on the most important points - at the same time, the user will easily be able to find any further information that they need by following the links
  • sigils
    • let the reader see that the ~ introduces a sigil and then provide brief examples of using the regex and string sigils
    • again, this is a matter of reducing the space used and focusing on the key points

Elixir Introduction: Explain "use ..."

Neben der der Erklärung von "import" und "alias", solltest du auch "use" erklären. Die Unterschiede sind auf den ersten Blick nicht klar, wenn man von anderen Sprachen kommt. Aber sie sind durchaus relevant zu wissen.

In my computer and phone, website's `\00a7` becomes `\<?>a7`.

Hello, thank you for providing the learning content. Currently in my computer and phone, \00a7 becomes \<?>a7. My computer is a Window 11 Laptop and my phone is an Android phone.

image

image

Then I use this e0d0ca42a72a7698beb7e71b867a0369a9ab56fb commit and npx antora antora-playbook.yml and VS Code's Five Server(Live Server) extension, \00a7 can display normally.

image

Section on match operator seems to be incorrect

I do not get the match error described. Perhaps the behavior has changed? I have started with elixir recently so I'm not familiar with much history, but I was very surprised to see the example of the match error in this section and was not able to reproduce it.

Interactive Elixir (1.15.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> x = 5
5
iex(2)> x = 7
7

Add brief introduction to functional programming in the elixir-introduction

This proposal is to add a brief outline of certain principles / benefits of function programming near the beginning of the elixir-introduction file.

This might provide users with pointers to keep in mind while they read the rest of the book - especially if they are used to languages that belong to other paradigms.

Further details

We should mention the following:

  • functions as first-class citizens and higher-order functions
  • immutability
  • disciplined state
    • easier to run code in parallel

The already existing sections on functions as first-class citizens and immutability could be simplified and moved to this introduction.

Add String and List Functions sections with links to the docs - elixir-introduction

I propose that we remove the Maps Functions and Tuples Functions sections in the elixir-introduction and add links to the documentation for these functions in the Maps / Tuples sections. This is so that we save space and help the reader focus on the key points.

We will also need to add links to documentation for:

  • the Enum and List modules to the Lists section
  • the String module to the Strings section

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.