Hi Matthieu, Welcome to elm! I too have a background in Python and here are some things I've learned as I've written projects in elm.
You're right it is more verbose in a lot of cases. What you get in a lot of cases is that it's very clear what's going on while in python there can be a decent amount of 'hiding the magic'. As for Dicts, I would say double check to make sure you don't actually want a record. Basically if you know all the fields at compile time...you probably want a record, not a dict. (as previous people have noted) a few of your issues are definitely on the community radar. There's a recent post about proposed string interpolation, stuff like that. So, there's actually a good amount of work going on to cover the cases you mention. It's a young language. The list comprehension thing is interesting. In elm the focus is on the List module as opposed to a specific syntax for list comprehensions. I've found it to be very expressive. So for something like `[i +5 for i in range(20)]` in python, you could do something like `List.map ((+) 5) [0..20]` Cheers and again, welcome to elm. -Matt On Thursday, June 23, 2016 at 1:06:28 PM UTC-4, Matthieu Amiguet wrote: > > Thanks Ian for your suggestions! > > As for pulling the common code into another function, my threshold is > probably still the python one ;-) > > But I finally adopted your solution with the helper function defined in a > let expression. That's already much better than my initial code! > > let > formatTime time = > String.pad 2 '0' <| toString time > in > String.join ":" [formatTime (hour date), formatTime (minute date)] > > Thanks, > > Matthieu > > > 1. You could try > http://package.elm-lang.org/packages/mgold/elm-date-format/1.1.4/ if > you're not opposed to using a third party package. > > 2. Or pull the duplicate code out into a function: > > | > > formatTime :Int->String > > formatTime time = > > String.pad 2'0'<|toString time > > > > anddo > > String.join ":"[formatTime (hour date),formatTime (minute date)] > > | > > > > That's still not quite as tidy as string interpolation but I've found > it's a good habit to get into to pull anything you do more than once out > into its own function, especially in Elm; in Python my threshold tends to > be three uses :) > > > -- 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.
