# Argument ordering: subject first or last? Just pick one and stick with it!

**URL:** <https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655>\
**Category:** Internals & Design\
**Created:** [August 31, 2017, 9:10am UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655 "2017-08-31T09:10:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ford](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ford/32/1741_2.png) [@Ford](https://discourse.julialang.org/u/Ford)\
**Post date:** [August 31, 2017, 9:10am UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655/1 "2017-08-31T09:10:53Z")

</div>

I have decided to use julia for a small script, that changes string ip4 address to integer ip4 address in a `.csv` with ~20e+6 rows. I have to say **the syntax for function chaining is pretty bad**. You can’t even put `|>` at the beginning of line!

```julia
function ip4ToNumber(string)
    hexa = split(string, ".") |>
         x -> parse.(x) |>
         x -> hex.(x, 2) |>
         x -> join(x, "")
    parse(Int, hexa, 16) 
end

```

It seems like julia tries to take little bit **subject last** approach (e.g. `map` takes _verb_ (function) as first argument and _subject_ (data) as last argument) but falls back to **subject first** most of the time (see `join`, `hex`).

Now - `parse` really creeps me out, since it puts subject at the end, but because it has optional argument, the subject ends up in the middle!

It would be so much better, if julia just picked one approach and followed it:

- subject last & currying - functional languages primarily use it

```haskell
ip4ToNumber string = 
    hexa = split "." string
        |> map parse
        |> map (hex 2)
        |> join ""
    parse Int 16 hexa

```

- subject first & dot notation - OOP languages primarily use it

```java
ip4ToNumber(string) {
    hexa = string
         .split(".")
         .parse.()
         .hex.(2)
         .join("")
    hexa.parse(Int, 16)
}

```

Not following convention is one thing, but complete lack of it is whole new level.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 31, 2017, 9:28am UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655/2 "2017-08-31T09:28:03Z")

</div>

Try  
[https://github.com/MikeInnes/Lazy.jl#macros](https://github.com/MikeInnes/Lazy.jl#macros)

If you want the chain macros on the next line, you need to delimit the whole expression so that the parser does not stop too early. AFAIK there is no other way around this.

---

<div class="post-metadata">

**Author:** ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)\
**Post date:** [August 31, 2017, 11:18am UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655/3 "2017-08-31T11:18:36Z")

</div>

[https://github.com/JuliaLang/julia/issues/5571](https://github.com/JuliaLang/julia/issues/5571)

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [August 31, 2017, 2:38pm UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655/4 "2017-08-31T14:38:23Z")

</div>

This doesn’t address your larger concern, but converting string IPv4 addresses to ints is relatively straightforward:

```julia
julia> a = "1.2.3.4"
"1.2.3.4"

julia> Int(IPv4(a))
16909060

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 31, 2017, 3:28pm UTC](https://discourse.julialang.org/t/argument-ordering-subject-first-or-last-just-pick-one-and-stick-with-it/5655/5 "2017-08-31T15:28:04Z")

</div>

Related: [https://github.com/JuliaLang/julia/issues/19150](https://github.com/JuliaLang/julia/issues/19150).
