# Love I Julia : the need for a direct object notation

**URL:** <https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [January 13, 2017, 8:35pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472 "2017-01-13T20:35:58Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 18, 2017, 8:40am UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/21 "2017-01-18T08:40:20Z")

</div>

If we are to compare Julia with natural languages, [Latin](https://en.wikipedia.org/wiki/Latin) is an interesting example. While word ordering was mostly [subject-object-verb](https://en.wikipedia.org/wiki/Subject%E2%80%93object%E2%80%93verb) in spoken language, the order doesn’t really matter, what’s most important is the [case](https://en.wikipedia.org/wiki/Grammatical_case) of nouns (thus effectively making Latin a [free word order](https://en.wikipedia.org/wiki/Free_word_order) language). In this regard, Julia is similar to Latin: what is important is the type of the arguments, with the caveat that in Julia the order does matter, so the correspondence isn’t complete.

Some modern languages, like German, have cases, so speakers of these languages may find it familiar to pay attention to this feature.

In addition, there do be a few languages with [verb-subject-object ordering](https://en.wikipedia.org/wiki/Verb%E2%80%93subject%E2%80%93object), like in Julia (and many other imperative languages, actually).

In the end, claiming that the subject-verb-object is the “natural” one is somewhat narrow-minded, since, as this isn’t even the most common ordering, according to [this table](https://en.wikipedia.org/wiki/Template:Language_word_order_frequency) (see also [Introducing English Linguistics International Student Edition - Charles F. Meyer - Google Books](https://books.google.co.uk/books?id=MWbrvUiYzSkC&pg=PA36&hl=en#v=onepage&q&f=false)).

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 18, 2017, 10:39am UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/22 "2017-01-18T10:39:09Z")

</div>

> [@cce](#):
>
> I use _direct object_ in the English sense – “`I love Julia`” where “`I`” is the _direct object_, “`love`” is the function, and “`Julia`” is an indirect object.

By the way, isn’t “Julia” the [direct object](http://dictionary.cambridge.org/grammar/british-grammar/about-words-clauses-and-sentences/objects) here? “I” is the [subject](http://dictionary.cambridge.org/grammar/british-grammar/about-words-clauses-and-sentences/subjects).

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 18, 2017, 12:42pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/23 "2017-01-18T12:42:53Z")

</div>

I don’t really buy the “subject comes first” claim, not even in English.

If I look at the sort of code I write, and what I am actually telling the computer to do, it is more along the lines of “sum the columns of this matrix”, “plot this function” or “print this statement”. Verb coming first is certainly _not_ unnatural when you are speaking in the imperative. “I love Julia” is the most natural in English, but that’s not the kind of thing you say to a computer, except perhaps in the source code comments…

---

<div class="post-metadata">

**Author:** ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)\
**Post date:** [January 18, 2017, 12:49pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/24 "2017-01-18T12:49:04Z")

</div>

> [@andyferris](#):
>
> That is to say, our brains aren’t wired to think is “I love Julia” is the correct order

Just as an extra data point, it has been statistically shown that starting with the verb is the least common order across natural languages (which doesn’t mean PLs should necessarily follow suit). From an [analysis](http://wayback.archive.org/web/20160529215449/http://idibon.com/the-weirdest-languages/) using [WALS](http://wals.info/) data (emphasis mine):

> There are 1,377 languages that are coded for word order in WALS and 35.5% of them have SVO word order. Meanwhile **only 8.7% of languages start with a verb** —like Welsh, Hawaiian and Majang—so cross-linguistically, starting with a verb is unusual. For what it’s worth, 41.0% of the world’s languages are actually SOV order.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 18, 2017, 1:57pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/25 "2017-01-18T13:57:10Z")

</div>

> [@waldyrious](#):
>
> Just as an extra data point, it has been statistically shown that starting with the verb is the least common order across natural languages

But do those numbers apply when considering only sentences that are instructions, or which are otherwise imperative in nature? I would think that verb-first should be much more common in cases like that.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 18, 2017, 6:02pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/26 "2017-01-18T18:02:01Z")

</div>

Actually, Julia doesn’t disallow that notation at all (it may be looked down upon though!)  
You can accomplish that by making a type that has fields of type `Function`, creating an instance of that type called `I`,  
and then call the function in field `love`.

```julia
julia> immutable MyObject ; love::Function ; end

julia> I = MyObject((x)->string("I ❤ " , x))
MyObject(#1)

julia> I.love("Julia")
"I ❤ Julia"

```

Isn’t Julia grand? 😉

---

<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:** [January 18, 2017, 6:09pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/27 "2017-01-18T18:09:35Z")

</div>

You can just go all the way:

> <https://stackoverflow.com/questions/39133424/how-to-create-a-single-dispatch-object-oriented-class-in-julia-that-behaves-l>

---

<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:** [January 18, 2017, 6:28pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/28 "2017-01-18T18:28:47Z")

</div>

> [@YongHee-Kim](#):
>
> I think question is not about what is “natural” but about how many users would feel uncomfortable because Julia don’t allow I.love(“Julia”) notation, and how much is it going to hamper their decision to choose Julia over Python.

If this is a major factor for someone, I am not sure that they need to pick Julia. The language has so many great features, which combine to an extremely powerful toolkit. Surface syntax is not where the interesting things happen.

For someone coming from another language, trying to recreate familiar features is all too natural. Surface syntax is what our eyes and fingers are used to, so that’s the first thing on the list for many people. IMO it is more productive to accept the this part of the language and start using it as it is, and focus on features that really distinguish it from other ones.

---

<div class="post-metadata">

**Author:** ![musm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/musm/32/3675_2.png) [@musm](https://discourse.julialang.org/u/musm)\
**Post date:** [January 18, 2017, 6:30pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/29 "2017-01-18T18:30:37Z")

</div>

Building up on @ScottPJones’s suggestion

Hacky, but that syntax can be made to work I believe

```julia
julia> type Object
           name::String
           # methods
           loves::Function
       end

julia> function Object(x::AbstractString)
           self = Object(x, x -> string(self.name, " loves ", x))
       end
Object

julia> person = Object("Steve")
Object("Steve",#1)

julia> person.name
"Steve"

julia> person.loves("pizza")
"Steve loves pizza"

```

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 18, 2017, 6:45pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/30 "2017-01-18T18:45:26Z")

</div>

Oh, I hadn’t seen that, I particularly love @jeff.bezanson’s response.  
However, truth be told, using what the rest of the world considers “Object Oriented” (classes with single dispatch) anymore, feels like programming with one hand tied behind my back, compared to using Julia “as intended”.

---

<div class="post-metadata">

**Author:** ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)\
**Post date:** [January 19, 2017, 12:49am UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/31 "2017-01-19T00:49:41Z")

</div>

See also issue about function chaining…  
[https://github.com/JuliaLang/julia/issues/5571#issuecomment-266245510](https://github.com/JuliaLang/julia/issues/5571#issuecomment-266245510)

---

<div class="post-metadata">

**Author:** ![jballanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jballanc/32/328_2.png) [@jballanc](https://discourse.julialang.org/u/jballanc)\
**Post date:** [January 19, 2017, 1:40am UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/32 "2017-01-19T01:40:36Z")

</div>

> [@Tamas\_Papp](#):
>
> For someone coming from another language, trying to recreate familiar features is all too natural. Surface syntax is what our eyes and fingers are used to, so that’s the first thing on the list for many people. IMO it is more productive to accept the this part of the language and start using it as it is, and focus on features that really distinguish it from other ones.

I agree heartily! In fact, I think Julia being a bit “weird” or “different” for programmers coming from Python should be seen as a Good Thing™. All too often I’ve seen converts from one language to another write the first in the second. That is, for example, I’ve seen C coders move to Ruby and _never_ use classes except as glorified `struct`s. Their code ends up being an imperative “bag of functions”, and as a consequence they end up missing out on Ruby’s best features.

There’s the same risk in migrating from ~~Julia to Python~~ Python to Julia. Yes, the transition is a bit uncomfortable, but instead of seeing each hurdle to overcome as an annoyance, I think programmers would be better served seeing these hurdles as opportunities to re-evaluate their assumptions about how code should be structured.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 19, 2017, 1:24pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/33 "2017-01-19T13:24:44Z")

</div>

On the other hand, when moving from one language to another, if there are features lacking in the new language that you had in the old language(s), that can be a spur to try to recreate them in the new language, and that _can_ be very positive (like Julia not supporting anything but 1-based arrays originally, but now with Tim Holy’s OffsetArray type, you have the same capability that Fortran 90 has [which is much more flexible than just having either 1-based or 0-based])

(I had to do similar things when I moved from Scheme & CLU to having to write in (pre-ANSI) C for a living, I ended up making a way of having the equivalent of try/catch/finally, which then helped me make the core of the database code a lot more reliable).

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 19, 2017, 1:32pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/34 "2017-01-19T13:32:33Z")

</div>

> [@jballanc](#):
>
> There’s the same risk in migrating from Julia to Python.

I wonder how common this is.

---

<div class="post-metadata">

**Author:** ![jballanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jballanc/32/328_2.png) [@jballanc](https://discourse.julialang.org/u/jballanc)\
**Post date:** [January 19, 2017, 2:10pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/35 "2017-01-19T14:10:16Z")

</div>

Heh…whoops, small transposition there 😉

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 19, 2017, 2:11pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/36 "2017-01-19T14:11:45Z")

</div>

Yes, that surprised me as well. Just my opinion, but I’d think anybody migrating _from_ Julia _to_ Python would need their head examined! 😉

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 19, 2017, 2:18pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/37 "2017-01-19T14:18:23Z")

</div>

I actually learnt Julia, and then had to pick up Python for a project at work. Needed some couch time after that… (oh, actually it went more-or-less ok.)

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 19, 2017, 2:23pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/38 "2017-01-19T14:23:32Z")

</div>

Yep, after I wrote that, I realized that many people might get forced into it (just like I had to start programming in C instead of Scheme & CLU) 😉 I should have said, people who _voluntarily_ migrate need their head examined (although people who are forced to may need a shrink afterwards, for PTSD! 😜)

---

<div class="post-metadata">

**Author:** ![catawbasam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/catawbasam/32/2936_2.png) [@catawbasam](https://discourse.julialang.org/u/catawbasam)\
**Post date:** [January 19, 2017, 3:30pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/39 "2017-01-19T15:30:52Z")

</div>

Guess somebody should call my shrink. I find both Julia and Python to be very nice languages, and that the richness of Python’s ecosystem often makes it a good option.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 19, 2017, 3:50pm UTC](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472/40 "2017-01-19T15:50:27Z")

</div>

You don’t find the access that Julia provides to that ecosystem via `PyCall` sufficient?  
But, that isn’t really the case I was talking about, which was _migrating_ from Julia to Python, whether voluntarily or forced, which is a quite different kettle of fish from picking and choosing which tool is best for whatever task is at hand (which I believe to be a mark of a good programmer)

[Previous page](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472.md?page=1)

[Next page](https://discourse.julialang.org/t/love-i-julia-the-need-for-a-direct-object-notation/1472.md?page=3)
