RFE: Falling back to method based resolution on missing field

132 views
Skip to first unread message

Adam Strzelecki

unread,
Aug 20, 2014, 8:32:11 AM8/20/14
to juli...@googlegroups.com
Hi,

I know Julia isn't OO by design, but is there any reason it couldn't be? Consider following code:

str = "some test"
beginswith
(str, "some")

I know that with defining extra methods for colon we can get:
str:beginswith:"some"

But wouldn't it be nicer if Julia actually tried to resolve this as well:
str.beginswith("some") # === beginswith(str, "some")

In theory this would let us have some dynamic properties (accessors) on objects, i.e:
str.length # === length(str)

Or even setters:
str.length = 3 # === setlength(str, 3)

Of course only if referenced field does NOT exists, so if does not charm existing codebase.

Finally a "dream come true would" to be able to define type specific methods using following notation:

function String.mysanitize
 
this.lowercase
end
# equvalent
function mysanitize(s::String)
  lowercase
(s)
end

This would make Julia friendly for OO programmers, and IMHO making programs more readable.

John Myles White

unread,
Aug 20, 2014, 10:00:45 AM8/20/14
to juli...@googlegroups.com

gael....@gmail.com

unread,
Aug 20, 2014, 9:47:37 PM8/20/14
to juli...@googlegroups.com
Speaking about which (I think I misunderstood), would that mean that ANY method acting on type T would be dot-callable from any instance of that type T? Without opting-in or -out?

Jameson Nash

unread,
Aug 20, 2014, 10:34:57 PM8/20/14
to juli...@googlegroups.com
It should be noted that dot-oriented programming and object-oriented programming are not synonyms. Julia is or is not OO based on features of the language, not the surface syntax. Personally, I would say that Julia is an OO language, by design, due to having multiple dispatch and a type hierarchy.

ele...@gmail.com

unread,
Aug 20, 2014, 11:47:05 PM8/20/14
to juli...@googlegroups.com


On Thursday, August 21, 2014 12:34:57 PM UTC+10, Jameson wrote:
It should be noted that dot-oriented programming and object-oriented programming are not synonyms. Julia is or is not OO based on features of the language, not the surface syntax. Personally, I would say that Julia is an OO language, by design, due to having multiple dispatch and a type hierarchy.

Agree.

Note http://en.wikipedia.org/wiki/Object-oriented_programming doesn't even mention the dot syntax, it just happens to be the syntax chosen by *single* dispatch languages for their limited take on object orientation.
 


On Wed, Aug 20, 2014 at 9:47 PM, <gael....@gmail.com> wrote:
Speaking about which (I think I misunderstood), would that mean that ANY method acting on type T would be dot-callable from any instance of that type T? Without opting-in or -out?
 
https://github.com/JuliaLang/julia/issues/1974 is about field access, and field like setters/getters, not method calling.

Adam Strzelecki

unread,
Aug 22, 2014, 3:22:54 PM8/22/14
to juli...@googlegroups.com
> Check out https://github.com/JuliaLang/julia/issues/1974

Thanks, I'll continue there.

--Adam
Reply all
Reply to author
Forward
0 new messages