# Best way to separate method to multiple lines

**URL:** <https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765>\
**Category:** General Usage\
**Created:** [March 20, 2017, 12:13am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765 "2017-03-20T00:13:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 20, 2017, 12:13am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765/1 "2017-03-20T00:13:07Z")

</div>

How do you keep method lines from going over 80 characters?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 20, 2017, 12:46am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765/2 "2017-03-20T00:46:50Z")

</div>

Note that you can define methods as `f(x) = ...` for short one-liners (although even that can be broken over multiple lines via `begin/end` blocks, parentheses, etcetera), but for complicated methods that take multiple lines, you would normally use the more verbose syntax:

```julia
function f(x)
   ...
end

```

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 20, 2017, 2:08am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765/3 "2017-03-20T02:08:32Z")

</div>

Thank you!

This is going to sound dumb, but from a cursory reading of the docs, it sounds like methods and functions are distinct.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 20, 2017, 2:10am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765/4 "2017-03-20T02:10:48Z")

</div>

They are distinct. But you define multiple methods for the same function just by defining different dispatches.

```julia
function f(x)
  ...
end 

function f(x,y)
  ...
end

```

those are different methods for the same function.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [March 20, 2017, 8:03am UTC](https://discourse.julialang.org/t/best-way-to-separate-method-to-multiple-lines/2765/5 "2017-03-20T08:03:32Z")

</div>

Also note that if you define a callable with the same name in 2 different modules, e.g.:

```julia
module A
    f(x) = ...
end

module B
    f(x,y) = ...
end

```

then `A.f()` and `B.f()` not only define different methods, but also _different functions_. There’s a long discussion about it somewhere on the old forum, but in short it’s done to avoid mixing totally different concepts like e.g. `Database.connect(host, port)` and `Facebook.connect(person1, person2)`. If you want, for example, `B.f()` to extend `A.f()`, you should do:

```julia
module A
    f(x) = ...
end

module B
    import A: f
    f(x,y) = ...
end

```

This way `B` will know that `f` comes from `A` and thus it should extend existing function instead of creating a new one.
