Julia: OOP or not

后端 未结 6 1137
难免孤独
难免孤独 2021-02-01 00:46

I\'m working on Juno with Julia.

I don\'t know if Julia supports OOP or not.

For example, is there something like class or struct of c+

6条回答
  •  野性不改
    2021-02-01 01:34

    I'm no expert on the language but my understanding is: Yes..and no.

    It has the equivalent of classes and structs, however there are no methods on those objects other than a single constructor.

    In mainstream object oriented languages, such as C++, Java, Python and Ruby, composite types also have named functions associated with them, and the combination is called an “object”. In purer object-oriented languages, such as Python and Ruby, all values are objects whether they are composites or not. In less pure object oriented languages, including C++ and Java, some values, such as integers and floating-point values, are not objects, while instances of user-defined composite types are true objects with associated methods. In Julia, all values are objects, but functions are not bundled with the objects they operate on. This is necessary since Julia chooses which method of a function to use by multiple dispatch, meaning that the types of all of a function’s arguments are considered when selecting a method, rather than just the first one (see Methods for more information on methods and dispatch). Thus, it would be inappropriate for functions to “belong” to only their first argument. Organizing methods into function objects rather than having named bags of methods “inside” each object ends up being a highly beneficial aspect of the language design.

提交回复
热议问题