First of all, let's agree that both Java and Javascript are successful 
languages in that you can solve most, if not any, given software problems 
in those languages. Does that mean the languages themselves are 
unproblematic? What does it mean to have a problem? Does it mean you cannot 
get anything done? Or could you still write a very successful program 
despite those problems. Cold you, in fact, have a problem without 
considering it one?

What constitutes a problem is highly subjective. It's good to keep in mind 
in this discussion.

So, the line in the docs is not wrong. "this" effectively combines logic 
and data, and Elm does maintain a separation there. The systemic problem 
being referenced, is the comingling of data and logic, not that you can 
write "this".

So why is this is a problem?

We've already defined that it is not a problem which prevents you from 
solving problems, in fact, very few thing in Javascript or Java or any 
other functional language pose such a problem. But there are some downsides 
that is worth considering:

1. What is "this"?
In a single class, "this" is a very easy thing. It refers to this instance 
of a class. But what does "this" mean in a context where the class is a 
child? Does "this" refer to this instance, or a parent instance, or a 
parent parent instance? This might not be conceived as a problem, since we 
got fancy IDE's helping us keep track of things, but I would argue that 
having "this" in any non-trivial piece of code makes it difficult to 
understand such code if you're reading it for the first time. Avoiding 
"this" makes code, IMHO, easier to read.

2. What's the downside of coupling data and logic?
Let's say we have the two following classes:

    class Person { public int age; }
    class Animal { public int age; }

Why can't we store both of these in an array? They look the same, the carry 
the same information, but they are different. If I write a function which 
operates on the age field, why do I need to write this twice for both 
classes? I can of course write a `Ageable` interface which declares a 
`getAge` function, but why is that necessary? What benefit do we get here 
by combining logic with data?

In Elm, you would define these as type aliases, meaning every function 
would work on one or the other, and you could store them in Lists or what 
not. You can also easily create extendable types if you only care about one 
or more fields.

Another downside: I need a function that works on all integers. Why do I 
have a create a static class for this? Why can't I just have a free 
function for this? What is the benefit of having it this way?

These aren't big things. But for me, combining logic and data makes it 
harder to understand code and to re-use it. There also doesn't seem to be 
any benefit in that combination.

Note: Javascript can avoid all these functions quite easily, but that's 
because javascript really is just as functional as it is object-oriented.

I'd also like to leave this link here, great talk on the 
subject: https://www.youtube.com/watch?v=-6BsiVyC1kM

torsdag 20. juli 2017 09.55.54 UTC+2 skrev Dave Ford følgende:
>
> There is a line from the docs that I am trying to understand: "Elm 
> encourages a strict separation of data and logic, and the ability to say 
> this is primarily used to break this separation. This is a systemic 
> problem in Object Oriented languages that Elm is purposely avoiding."
>
> What is the systemic problem being reference? Is it the [lack of] "separation 
> of data and logic" or "the ability to say this"?
>
> I have been programming in Java (an OO language) for a long time. I can 
> name dozens of systemic problems in the language. But the ability to say 
> "this" is not one of them. Nor is it the commingling of data and logic. 
>
> Please help me to understand what the author is talking about.
>
> Thanks.
>
> Side note: "this" *is* a problem in JavaScript. But not in OO generally.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to