About `programWithFlags` naming

124 views
Skip to first unread message

Bobby Priambodo

unread,
Sep 28, 2016, 2:58:50 PM9/28/16
to Elm Discuss
Hi! I'm building my first Elm app using the embed-to-HTML approach. I'm already using a backend (Node.js with Hapi), and since I think server-side-rendering is not supported anytime soon, I'm just passing the data from the server to Elm through JS interop.

I've initially used subscription ports to do it, but several days ago Evan updated the interop part in guide.elm-lang.org/interop/javascript.html to show how to do it with `programWithFlags`. I remember skimming through the docs and saw that function, but I didn't even think that it will achieve what it does. It's kind of unintuitive that `programWithFlags` means "an app which allows initializing model through JS", since in many programming stuff "flags" just mean boolean values or switches.

Was there any reason why it's named that way?

Nick H

unread,
Sep 28, 2016, 4:22:18 PM9/28/16
to elm-d...@googlegroups.com
I think it's pretty common to use "flag" to refer to any option passed to a program when it starts. For instance, in

elm-make src/Main.elm --output=main.js

the "--output=main" is often referred to as a flag, even though it is not a boolean value.

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

Duane Johnson

unread,
Sep 28, 2016, 8:41:42 PM9/28/16
to elm-d...@googlegroups.com
FWIW, my initial interpretation of programWithFlags was in the sense of "red flags" as in, "don't use this function". Before reading the documentation of course.

Bobby Priambodo

unread,
Sep 29, 2016, 12:28:12 AM9/29/16
to Elm Discuss

Yeah, that’s also the conclusion I came to after some reasoning. But I still think that it’s kind of confusing for first-timers in Elm; it might make sense if the context was a CLI program, but I don’t think I've heard it used in, say, web applications (other than feature flags). It’s great that now it’s in the guide, but it was not on my first pass and left me effectively confused.


If we want to be explicit, why not something along the lines of `programWithInitialValues`?

To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.

OvermindDL1

unread,
Sep 29, 2016, 10:15:29 AM9/29/16
to Elm Discuss
I'd personally use `programWithArgs`, or just `program` and bake flags in, defaulting to an empty tuple or some other nil type or so that comes from javascript's `undefined`.  Like define init via `init () = { blah model }` for the 'no argument' case, that way it accepts 'undefined' from javascript, such as when there is no argument passed in from javascript.

Bobby Priambodo

unread,
Sep 29, 2016, 10:31:57 AM9/29/16
to elm-d...@googlegroups.com
`programWithArgs` could also work, but I agree that your second option can make it more consistent throughout Elm apps (we will then just have `beginnerProgram` and `program`). I don't know if the use case (giving data to Elm app on init) is common enough to justify doing that, though.

To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

OvermindDL1

unread,
Sep 29, 2016, 10:37:47 AM9/29/16
to Elm Discuss
On Thursday, September 29, 2016 at 8:31:57 AM UTC-6, Bobby Priambodo wrote:
I don't know if the use case (giving data to Elm app on init) is common enough to justify doing that, though.

It has been so far for me, but still that is why I suggest having it default to some nil value like `()` or equivalent.  :-) 
Reply all
Reply to author
Forward
0 new messages