# Why underline on function parameter

**URL:** <https://forum.elixirforum.com/t/why-underline-on-function-parameter/904>\
**Category:** Questions\
**Tags:** phoenix\
**Created:** [June 21, 2016, 8:21pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904 "2016-06-21T20:21:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kostonstyle](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/5f9b8f/32.png) [@kostonstyle](https://forum.elixirforum.com/u/kostonstyle)\
**Post date:** [June 21, 2016, 8:21pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/1 "2016-06-21T20:21:13Z")

</div>

Hi all  
I am trying to learn phoenix and bought the book programming phoenix.  
I copied the code from book that looks as follow:

```
defmodule Rumbl.UserController do

  use Rumbl.Web, :controller

  def index(conn, _params) do
    users = Repo.all(Rumbl.User)
    render conn, "index.html", users: users
  end

end

```

Why the author give the parameter name **\_params** with underline? Any reason?  
Thanks

---

<div class="post-metadata">

**Author:** ![thinkpadder1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thinkpadder1/32/1618_2.png) [@thinkpadder1](https://forum.elixirforum.com/u/thinkpadder1)\
**Post date:** [June 21, 2016, 8:24pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/2 "2016-06-21T20:24:03Z")

</div>

[http://elixir-lang.org/docs/master/elixir/naming-conventions.html#underscore-\_foo-](http://elixir-lang.org/docs/master/elixir/naming-conventions.html#underscore-_foo-)

---

<div class="post-metadata">

**Author:** ![Calamitous](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/calamitous/32/541_2.png) [@Calamitous](https://forum.elixirforum.com/u/Calamitous)\
**Post date:** [June 21, 2016, 8:25pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/3 "2016-06-21T20:25:20Z")

</div>

That’s how you explicitly let Elixir know that you don’t care about the value in that variable. If you don’t prepend an underscore, the compiler will bark at you, since you have a parameter that you’re not using.

---

<div class="post-metadata">

**Author:** ![murphy](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/murphy/32/4530_2.png) [@murphy](https://forum.elixirforum.com/u/murphy)\
**Post date:** [June 21, 2016, 8:56pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/4 "2016-06-21T20:56:43Z")

</div>

Also the underscored variable will always match, using pattern matching.

So in this example the index function is called regardless what the second parameter acutally is.  
You will prob notice later, that an underscored variable or just an underscore can act as an default case using switch/case structures or as a “default” function if there are 2 or more functions with the same name.

Its not good practise but, you can technically use an underscored variable. If you want something that cannot be read from you could use only an underscore.

---

<div class="post-metadata">

**Author:** ![thinkpadder1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thinkpadder1/32/1618_2.png) [@thinkpadder1](https://forum.elixirforum.com/u/thinkpadder1)\
**Post date:** [June 22, 2016, 1:05am UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/5 "2016-06-22T01:05:20Z")

</div>

The guy who wrote _Programming Elixir 1.2_ said he uses underscored variables instead of underscores for documentation. It just makes it a bit more clear on what is being used and what is not.

---

<div class="post-metadata">

**Author:** ![kostonstyle](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/5f9b8f/32.png) [@kostonstyle](https://forum.elixirforum.com/u/kostonstyle)\
**Post date:** [June 22, 2016, 2:23pm UTC](https://forum.elixirforum.com/t/why-underline-on-function-parameter/904/6 "2016-06-22T14:23:17Z")

</div>

Thanks everyone.  
Phoenix is awesome ❤
