[elm-discuss] main : Program Never Model Msg -- What does it mean?

2017-07-20 Thread Eeek
I am beginner in Elm, and going through elm-tutorial.org. I have problem in 
understanding the declaration of main function in 
https://www.elm-tutorial.org/en/02-elm-arch/02-structure.html. It says 

main : Program Never Model Msg

 What does it represent? I read under functions tutorial that, arguments 
are separated with ->. If there are no arguments then I would expect only 
one return. This don't belong to any of it. What is this way of declaring 
the function types?

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Systemic problem in Object Oriented languages

2017-07-20 Thread Alex Barry
Here's my take.

In C++ (Or Java, what-have-you), you could have something like this:

class Square {
  private float size;

  Square(float size) {
this.size = size;
  }

  void size(float size) {
this.size = size;
  }

  float size(void) {
return this.size;
  }

  float perimeter(void) {
return this.size * 4;
  }

  float area(void) {
return this.size * this.size;
  }
}


In Elm, you end up with a much different looking structure and code:

module Square exposing (Square, perimeter, area)


type alias Square = { size : Float } 


perimeter : Square -> Float
perimeter square = square.size * 4

area : Square -> Float
area square = square.size * square.size 

 



It forces immutability. In an object oriented language, what would the 
point be of having immutable data?  Why would `Square(oldSquare, newSize)` 
ever be better than `oldSquare.size(newSize)`?  You end up working against 
the language. It's not that OOP is bad, but it encourages mutation, a thing 
that Elm is strictly against.

Mutation can be a problem because it means there is more to debug. In C++, 
if I had something like:

foo.bar = "baz";
foo.someSpecialFunction();
std::cout << foo.bar << std::endl;


What is the expected value of foo.bar? When we initially evaluate the code, 
we make an educated assumption that foo.bar is probably going to be "baz", 
but is that actually the case? We need knowledge about what 
someSpecialFunction does, because we know it could, in a non obvious way, 
change the value of bar.

In Elm:

type alias Thing = { bar : String }

someSpecialFunction : Thing -> a

foo = Thing "baz"
_ = someSpecialFunction foo
valueOfFooBar = Debug.log "value of foo.bar" foo.bar


This example is intentionally leaving out some parts, but we will always 
know that foo.bar  results in "baz". If someSpecialFunction where to return 
a Thing, we could assume it is a copy of the original with some changes. In 
this case, it's obvious that something about that result will be different 
from foo, and we can deal with it appropriately.

Testing probably ends up being harder in C++ since you aren't just testing 
results, you need to test mutations, so `this` may cause misdirection. It 
tethers operations on your class to that instance. It means things can 
change without you necessarily knowing they have changed.

In Elm, it is hard to do this. Not impossible, but hard. The idea is that 
the less work a developer has to do to understand a piece of code, the more 
productive (s)he can be.

I think the statement does boil down to a point about immutability and 
guarantees provided by all constant variables. I'm not convinced that it is 
a systemic problem, but it is just another layer of knowledge that a 
developer must have every time (s)he runs an instance method on a variable. 
There are always a set of rules that a developer can follow to minimize the 
impact `this` and mutations has on his/her code, like a function can only 
perform one thing, having well defined names for functions, following a 
code guide for a project, etc..

In a broad and maybe stretched sense, perhaps the author is suggesting that 
rather than developers having to opt into rules to keep good and tidy code, 
perhaps it is better that those rules are strictly enforced outside of the 
developers control, under the assumption that the forced rules will always 
result in better code.

- Alex


On Thursday, 20 July 2017 03:55:54 UTC-4, Dave Ford wrote:
>
> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Christophe de Vienne


Le 20/07/2017 à 12:15, Peter Damoc a écrit :
> 
> 
> On Thu, Jul 20, 2017 at 12:49 PM, Christophe de Vienne
> > wrote:
> 
> 
> Well, it is more an intuition after more than 20 years of coding that an
> elaborated opinion.
> 
> But the first thing that comes to my mind is the resulting complexity,
> and often confusion. I find that having a clean separation between data
> & logic makes things a lot cleaner, easier to understand and maintain.
> 
> I do realize I would need to elaborate a little more to be convincing on
> this, but so far it is all I got :-)
> 
> 
> Out of curiosity, are you keeping your Model, update and view in
> separate modules?  

At first no, then depending on how much of the module I want to reuse, I
separate them.

In the end, I have reusable models as submodules of a "Data" module, a
few model+update modules (mainly for the session data, which has no
global view), and the rest are single modules with model+update+view
(for pages mainly, and a few subcomponents).

It is in great part inspired by the SPA example from Richard Feldman:
https://github.com/rtfeldman/elm-spa-example

-- 
Christophe de Vienne

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Peter Damoc
On Thu, Jul 20, 2017 at 12:49 PM, Christophe de Vienne <
christo...@cdevienne.info> wrote:

>
> Well, it is more an intuition after more than 20 years of coding that an
> elaborated opinion.
>
> But the first thing that comes to my mind is the resulting complexity,
> and often confusion. I find that having a clean separation between data
> & logic makes things a lot cleaner, easier to understand and maintain.
>
> I do realize I would need to elaborate a little more to be convincing on
> this, but so far it is all I got :-)
>
>
Out of curiosity, are you keeping your Model, update and view in separate
modules?


-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Christophe de Vienne


Le 20/07/2017 à 11:12, Dave Ford a écrit :
> Now, is it actually a systemic problem ? My intuition is that it is the
> root of many difficulties OO languages can have, even though it does not
> seem like a problem at first.
> 
> 
> Can you give an example? Specifically, without confusing the unrelated
> issue of immutability?
> 

Well, it is more an intuition after more than 20 years of coding that an
elaborated opinion.

But the first thing that comes to my mind is the resulting complexity,
and often confusion. I find that having a clean separation between data
& logic makes things a lot cleaner, easier to understand and maintain.

I do realize I would need to elaborate a little more to be convincing on
this, but so far it is all I got :-)

-- 
Christophe de Vienne

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Dave Ford
>
> Now, is it actually a systemic problem ? My intuition is that it is the
> root of many difficulties OO languages can have, even though it does not
> seem like a problem at first.


Can you give an example? Specifically, without confusing the unrelated
issue of immutability?

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Peter Damoc
On Thu, Jul 20, 2017 at 11:52 AM, Dave Ford  wrote:

> On Thu, Jul 20, 2017 at 4:14 AM, Peter Damoc  wrote:
>
>> "this" is associated with mutation. Elm is an immutable language.
>>
>
> I don't think that's true. I might be wrong, but I'm pretty sure that
> "this" has nothing specifically to do with mutation. I write immutable
> objects all day long in java and kotlin making use of "this" and mixing
> data and logic.
>

I'm not saying that "this" implies mutation only that it is associated with
mutating the current object.

Of course one can write immutable objects using "this" but in OO languages
you can also use it to mutate the state of the object.

-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Christophe de Vienne
Regardless of immutability, saying "this" imply a bound between the data
and the function, which is the very thing Elm wants to avoid.

So I think the systemic problem referred to here is "separation of data
and logic", and its incarnation (sort of) is the ability to say "this".

Now, is it actually a systemic problem ? My intuition is that it is the
root of many difficulties OO languages can have, even though it does not
seem like a problem at first.

Le 20/07/2017 à 09:55, Dave Ford a écrit :
> 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 elm-discuss+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
Christophe de Vienne

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread John Orford
I have minimised (almost 0% now) my use of this in JS, by using arrow
functions. Perhaps 'this' is a bad example, they're an arcane artifact...

Basically you're right, the guide isn't clear at best, wrong at worst : )

On Thu, 20 Jul 2017 at 10:52 Dave Ford  wrote:

> On Thu, Jul 20, 2017 at 4:14 AM, Peter Damoc  wrote:
>
>> "this" is associated with mutation. Elm is an immutable language.
>>
>
> I don't think that's true. I might be wrong, but I'm pretty sure that
> "this" has nothing specifically to do with mutation. I write immutable
> objects all day long in java and kotlin making use of "this" and mixing
> data and logic.
>
> --
> 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 elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Dave Ford
On Thu, Jul 20, 2017 at 4:24 AM, John Orford  wrote:

> It's ambiguous
>
It's not. In Java it's very clearly and deterministically defined.

this.x = 123
>
Immutability is a different issue.  "this" has nothing specifically to do
with mutability. The use of "this" is orthogonal to mutability.

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Dave Ford
On Thu, Jul 20, 2017 at 4:14 AM, Peter Damoc  wrote:

> "this" is associated with mutation. Elm is an immutable language.
>

I don't think that's true. I might be wrong, but I'm pretty sure that
"this" has nothing specifically to do with mutation. I write immutable
objects all day long in java and kotlin making use of "this" and mixing
data and logic.

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread John Orford
It's ambiguous, I also imagine it means avoiding:

this.x = 123

But then again, why do you need 'this' in the first place? In Elm you can
access anything in scope in the module.

I suppose this is useful for accessing class stuff which isn't in your
immediate method scope... which again leads you down something like ideas
around local (object) mutable state...

Good question!

On Thu, 20 Jul 2017 at 10:15 Peter Damoc  wrote:

> "this" is associated with mutation. Elm is an immutable language.
>
> In theory, one could have immutable objects where data and logic are
> grouped together.
> The best expression I've seen so far is the FauxO system in Gary
> Bernhardt's Boundaries talk.
>
> Something like this would constitute a non-trivial expansion of the
> language and, as far as I can understand it, there are other priorities.
>
>
> On Thu, Jul 20, 2017 at 10:55 AM, Dave Ford  wrote:
>
>> 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 elm-discuss+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>
> --
> 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 elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Peter Damoc
"this" is associated with mutation. Elm is an immutable language.

In theory, one could have immutable objects where data and logic are
grouped together.
The best expression I've seen so far is the FauxO system in Gary
Bernhardt's Boundaries talk.

Something like this would constitute a non-trivial expansion of the
language and, as far as I can understand it, there are other priorities.


On Thu, Jul 20, 2017 at 10:55 AM, Dave Ford  wrote:

> 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 elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Systemic problem in Object Oriented languages

2017-07-20 Thread Dave Ford
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.