I think it all matters and should be applied only to public libraries and
only in order to let them keep the major version number stable as long as
possible. It's not always pragmatic to do and I would not bother applying
this in local libs/helpers of typical application.

On Sun, Mar 26, 2017 at 11:57 PM, Mark Hamburg <[email protected]>
wrote:

> I think I have some code that follows this pattern:
>
> module Mod exposing (Model, Msg, update)
>
> type Model = Model Imp
>
> type alias Imp = { ... private stuff goes here ... }
>
> update : Msg -> Model -> ( Model, Cmd Msg )
> update msg (Model imp) =
>     updateImp msg imp |> rewrap
>
> rewrap : (Imp, x) -> (Model, x)
> rewrap (imp, x) =
>      (Model imp, x)
>
>
> etc
>
> The chief barriers to this style have been:
>
>
>    - A bit of distaste for the name imp
>    - More boilerplate
>    - A concern that this inhibits potential efficiency around cases where
>    the update doesn't change the model but just results in additional commands
>    - Needing to train everyone working with the code to think in terms of
>    "now we're working at the imp" level. (Typical response: Why does Elm make
>    everything so hard? — clearly an over statement but I understand the sense
>    of pain.)
>
> This is one of those areas where it feels like the right way and the easy
> way are further apart than they should be and in my experience that tends
> to lead to trouble in codebases.
>
> Mark
>
>
> On Fri, Mar 24, 2017 at 3:43 PM, 'Rupert Smith' via Elm Discuss <
> [email protected]> wrote:
>
>> On Thursday, March 23, 2017 at 4:21:10 PM UTC, Mark Hamburg wrote:
>>>
>>> Should one wrap a model implemented as a record in a type to keep the
>>> details private?
>>
>>
>> If you wrap your Model to keep it private, you will only need to
>> wrap/unwrap the functions that the module exposes. Internal functions can
>> work with the model directly:
>>
>> module MyAwesomeModule exposes (update)
>>
>> type Model = M ModelRecord
>>
>> type alias ModelRecord = { ... }
>>
>> update : Msg -> Model -> Model
>>
>> someUpdateHelper : ModelRecord -> ModelRecord
>>
>> So perhaps wrapping might not be as great an inconvenience. Just don't
>> expose (..) always name the public functions being exposed.
>>
>> ====
>>
>> Also, I think if you wrap the model, you may end up with public functions
>> just to extract stuff from it:
>>
>> module MyAwesomeModule exposes (getUsername)
>>
>> type Model = M ModelRecord
>> type alias ModelRecord = { userName : String }
>>
>> getUsername : Model -> String
>>
>> Which is analogous to Java where, for reasons no-one is prepared to go
>> against, we do:
>>
>> public class Account {
>>   private String userName;
>>
>>   public String getUserName() { return userName; }
>>   public void setUserName(String userName) { this.userName = userName; }
>> }
>>
>> When really we could do:
>>
>> public class Account {
>>   public String userName;
>> }
>>
>> (Sometimes I do this, it really annoys some people :-P)
>>
>> In common with Java, Elm has a different syntax for extracting the
>> username with 'dot' notation and for writing a function/method to do it
>> (some languages have the same notation for both, which makes changing how
>> it is done transparent to the consumer of the interface).
>>
>> I think if you have fields that other modules need to read, perhaps don't
>> wrap them, just wrap stuff that is really private?
>>
>> type alias Model =
>>   { userName : String
>>   , private : Private
>>   }
>>
>> type Private = ...
>>
>> Nothing wrong with a public field, and I think it is better than forcing
>> yourself to write extract functions unnecessarily.
>>
>> --
>> 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.
>>
>
> --
> 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.
>

-- 
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