Replies: 7 comments 17 replies
-
I like this Turtle Graphics example in Julia: https://github.com/JuliaGraphics/Luxor.jl/blob/master/src/Turtle.jl. Here you see it using multiple constructors. It doesn't look like they're chaining constructors (they all call the 'true' constructor directly) so this is something that would work in all of our current targets except Python. Turtle(x::Float64, y::Float64) = Turtle(x, y, true, 0, (0, 0, 0))
Turtle(pos::Point=O) = Turtle(pos.x, pos.y, true, 0, (0, 0, 0))
Turtle(pos::Point, pendown::Bool) = Turtle(pos.x, pos.y, pendown, 0, (0, 0, 0))
Turtle(pos::Point, pendown::Bool, orientation::Real) = Turtle(pos.x, pos.y, pendown, orientation, (0, 0, 0))
Turtle(pos::Point, pendown::Bool, orientation::Real, col::NTuple{3, Number}) = Turtle(pos.x, pos.y, pendown, orientation, col)
Turtle(pos::Point, pendown::Bool, orientation::Real, r, g, b) = Turtle(pos.x, pos.y, pendown, orientation, (r, g, b)) Here you can see the type signature for one of its functions. All the other functions are very similar as well. function Forward(t::Turtle, d=1) I like how straightforward this library is compared to some others. It's very easy to read, and the API is simple and consistent. It also demonstrates that a traditional library structure can be used in Julia. |
Beta Was this translation helpful? Give feedback.
-
By the way, I started a wiki page about the design decisions related to converting GOOL classes into struct libraries. Here is the link. It's currently quite basic and somewhat out-of-date, but I'll do my best to update it. |
Beta Was this translation helpful? Give feedback.
-
Another place that I should have thought to mention earlier is the Julia standard library!
|
Beta Was this translation helpful? Give feedback.
-
First: I don't think we should be trying to 'translate' OO idioms to non-OO languages. It's not that it won't work -- it will work well enough for a while, and then get increasingly hacky, until it feels like it's not working anymore. What we should be doing is figuring out how to "bundle functionality" together. This belongs in The question then becomes: where do the OO assumptions come in (in the current code base)? Then we can figure out what to do about it. |
Beta Was this translation helpful? Give feedback.
-
I spent some time today tracing out the typeclasses in ClassInterface.hs, trying to get a grasp on how we can start splitting it up into OO-only, OO and Procedural, and Procedural-only typeclasses. I created a draw.io diagram mapping them out, viewable here. I have two things that immediately arise from this:
|
Beta Was this translation helpful? Give feedback.
-
I was looking at From experimenting, it looks like the use of
Based on this, I believe my initial assessment was incorrect, and |
Beta Was this translation helpful? Give feedback.
-
It seems like the main focus(es) of this discussion are finished. We chose a focus on how to deal with the differences between OO and procedural languages, and were able to make the necessary changes. There's still a few loose ends, but #3871 and #3904 take care of them for the most part. |
Beta Was this translation helpful? Give feedback.
-
This discussion started in #3789. The summary is, I was bringing up an issue I was having with translating GOOL classes into Julia libraries, and @smiths brought up the question of whether this is the right way to go. The danger of translating OO patterns into a non-OO language is that we might end up with code that is trying to emulate the OO patterns rather than achieving the functionality in a way that is idiomatic in that language.
As I mentioned in the issue, I don't think this is necessarily the case, at the very least not for C code. The examples I have seen of libraries in procedural languages usually end up looking quite similar to classes anyway, so I don't think this is a bad way to go.
With that said, I might need to do a bit more research on Julia (and potentially Matlab as well) to see if there different patterns that it considers idiomatic, in particular with respect to its more unique features. The documentation certainly hints at possible patterns, though as of yet I am unsure of whether these patterns are used in production code. I will do some digging, and I might also write an example 'by hand' if I think that will be helpful.
An example I remembered of a procedural library deviating from the OO way of doing things is GameMaker's particle system. In GameMaker to create particles you need a particle system, a particle type, and a particle emitter. These are separate constructs in GameMaker, so functions often take an instance of each (e.g. part_emitter_burst needs one of each, as well as the number of particles to generate). In OO this would likely be done differently, for example with has-a relationships. Using structs we can still express has-a relationships in procedural languages, but this might serve as evidence that that isn't always the most idiomatic way of doing it.
I guess that my question is, how fragmented do we want to allow GOOL to become? Currently we have a nice system where we generate one GOOL program, and it cleanly translates to all of the targets (with a few minor exceptions). Do we really want to push the differences between languages above GOOL and into
drasil-code
? It seems to me that GOOL would be neither Generic nor OO at that point 😄. Depending on what I find about Julia and Matlab it might not come to that, but I think it's an important question that we should have an answer ready for.Some of this is just my thoughts, so what are your thoughts @smiths @JacquesCarette @balacij? Do you agree that it's still worthwhile to translate GOOL classes into Julia libraries? Do you think we should investigate generating GOOL code designed specifically for some targets, even at the risk of losing reusability?
Beta Was this translation helpful? Give feedback.
All reactions