I strongly disagree with your colleague's claims:
* It is hard to test statically typed languages. (Although I don't think
Java is a good language for other reasons, it does have some excellent
testing frameworks.)
* You should use duck typing in your tests. (Duck-typing in tests is an
indication that your classes/types are too complicated and should be
refactored.)


If you have a function foo that only operates on Users

foo : User -> Int

then your test code should also be written in terms of Users. I would not
trust any set of tests that used partially-constructed objects like your
example does. I wouldn't trust them in Elm, and I *definitely* wouldn't
trust them in a weak/dynamically/duck typed language like JS or Ruby.

If User is a big record with lots of fields, you can easily encapsulate the
object construction into a function. So your tests stay short.


If you want your function foo to operate on any record with an "x" field,
then

foo : { a | x : Int } -> Int

is perfectly fine, and I don't think that there is anything wrong with that.


Lastly, Elm has a pretty awesome testing framework : elm-community/elm-test
<http://package.elm-lang.org/packages/elm-community/elm-test/latest>. You
should try it out! Then come back and tell us whether testing in a
statically typed language is hard :-)

On Mon, Sep 12, 2016 at 8:54 AM, Ashish Negi <[email protected]>
wrote:

> -- I was discussing with my colleague today about Elm and
> -- i asked him about his points about static typing..
> -- He said that it is difficult to write tests in static langs as
> -- duck typing is easier in dynamic languages.
>
> — I wrote some code to counter his point :
> type alias User =
>     { x : Int
>     , y : Int
>     }
>
> foo p = p.x
>
> — app code
> v = foo (User 1 2)
>
> — test code --
> z = foo { x = 3 }
>
> ```
> This code counters his point `BUT`
> one has to stop writing `type declarations` for functions altogether or
> just specify the used variables like
> `foo : { x : Int } -> Int`
> in above case..
>
> What does community think about this ?
>
> --
> 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