
Integrating Elm and Phoenix Channels via Elm-Phoenix-socket - onlydole
https://www.dailydrip.com/topics/elm/drips/elm-phoenix-socket
======
ModernMech
How come no one (seemingly) uses Elm, despite all the love? I've noticed a lot
of quick, drive-by posts in Elm related threads about how great the language
is. This thread ("This is a great little webstack!") and today's other front-
page elm thread[1] both do this.

With such high praise, I would expect the language to be more popular. What's
with the disconnect? My hypotheses:

1) There are no unhappy users because unhappy users just don't use it. 2) HN
goes easy on technological curiosities, saving harsh criticism for large
projects that deserve it 3) While there may be a widespread lovefest for Elm,
there is too much momentum behind current technologies.

Any other thoughts as to what the disconnect is? Moreover, how do we get to a
world where the webstack we all use is "a great little webstack"?

[0]
[https://news.ycombinator.com/item?id=11846707](https://news.ycombinator.com/item?id=11846707)

edit: clarity

~~~
randomacct44
I'm looking at Elm for a product that I'm working on at the moment. The
language is great and I've wanted an excuse to do actual work in an ML-like
language for a long time.

The difficulty I'm having at the moment is just trying to find examples of
non-toy application architectures. An application with multiple top-level
screens, for example.

For a bit of context, the product I'm working on is a customer-facing kiosk.
It'll be driven by a C# ASP.NET back-end. We have several different products
using common back-end code but exposing different sets of features to the
customer. We're moving from an old architecture that was your standard
WinForms UI to something using HTML5 as the UI layer (definitely a big mindset
change!).

Right now I'm trying to figure out what the front-end Elm code structure would
look like. Is it going to be one huge monolithic Elm project that covers all
our cases? Can it be broken up? Does the front-end have to know in advance
what screens will be available? (the back-end uses the typical 'load features
as plugin DLLs') etc. These are all questions I'm facing right now.

This is especially exacerbated by the recent change from 0.16 to 0.17. The
changes themselves seem extremely positive (I jumped in at 0.17, so I'm only
going off an impression here) but much of the example material that I've found
which might be useful is still using stuff from 0.16 and I'm having trouble
wrapping my head around it right now.

So from a commercial dev perspective, Elm, like anything else so new, is
massively risky. I'm pushing on for the moment (would love any pointers if
anyone has them!). I'm aware of the huge element of "not knowing what I don't
know" that I've taken on right now. I'm hoping the payoff will be worth it :)

~~~
kawera
I'm also looking for more structured examples but so far haven't found much.
These are some apps that go a little beyond the "hello world" kind. Some of
them are being updated to elm 0.17.

[https://github.com/plentiful/shop](https://github.com/plentiful/shop)

[https://github.com/srid/chronicle](https://github.com/srid/chronicle)

[https://github.com/CultivateHQ/seat_saver](https://github.com/CultivateHQ/seat_saver)

[https://github.com/NoRedInk/elm-blogger](https://github.com/NoRedInk/elm-
blogger)

[https://github.com/massung/elm-hn](https://github.com/massung/elm-hn)

[https://github.com/sporto/elm-tutorial-app](https://github.com/sporto/elm-
tutorial-app)

------
knewter
Josh from DailyDrip here. My first realization that this was here was that we
started getting a ton of traffic. :) We just ran the first Remote Elm Meetup
today so my attention was elsewhere: [https://www.bigmarker.com/remote-
meetup/1-Elm-Remote-Meetup-...](https://www.bigmarker.com/remote-meetup/1-Elm-
Remote-Meetup-by-DailiDrip) (yes, I know our company name is misspelled in the
url :-\ )

I'd love to chat with anyone that wants to know what we're doing and why we do
it :)

~~~
brightball
I'd never heard of your site before but after looking at your video library
I'm about to be a customer. Great, great work.

~~~
knewter
Obviously thrilled, thanks. All we want to do is keep making awesome content,
and every customer helps us on that path. Let me know if you have any issues,
ok? Obviously I've tested the crap out of it, and we have a decent number of
customers, but this is our biggest traffic day by 4x already.

------
MrBlue
Elixir, Phoenix and Elm have absolutely rekindled my love of web application
development.

~~~
dmix
PureScript + learning Erlang/Hakskell rekindled mine :)

I ended up learning Erlang after hearing about Elixir and not being a fan of
the Rubyish syntax and immutability comporomise, which has been a very
rewarding experience. Haskell even more so. And Purescript has some nice Elm
inspired libraries [2].

[1] [https://purescript.org](https://purescript.org)

[2]
[https://github.com/search?utf8=%E2%9C%93&q=language%3Apuresc...](https://github.com/search?utf8=%E2%9C%93&q=language%3Apurescript+elm&type=Repositories&ref=searchresults)

~~~
knewter
pedant mode on...

there is no "immutability compromise" in Elixir. Static Single Assignment !=
Immutability. Elixir is entirely immutable - it has to be as it just runs on
the Erlang VM!

I think a _legitimate_ complaint along these lines would be "pinning is
confusing and error prone for beginners" and I think it's fair. Christopher
Meiklejohn mentioned this on Twitter yesterday, and it's a point that's caught
me plenty and I write more Elixir code than most people by far.

~~~
rdtsc
> Elixir is entirely immutable - it has to be as it just runs on the Erlang
> VM!

No, variables are mutable in Elixir.

    
    
       Interactive Elixir (1.1.0-dev)
       iex(1)> x=1
       1
       iex(2)> x=2
       2
    

Notice how x is 1 then x is 2. Variable x mutated.

In Erlang:

    
    
       1> X=1.
       1
       2> X=2.
       ** exception error: no match of right hand side value 2
    

Variables are immutable in Erlang.

I suspect you misunderstood gp's post and thought they were talking about
data, which is immutable in both languages in general.

~~~
geonnave
Actually, variables in Elixir can be _re-binded_ :

> x = [1, 2, 3]

> x = 2 # the structure [1, 2, 3] still exists in memory, but now the variable
> x is _bound_ to the value 2

All data is still immutable, the BEAM itself requires so. Dave Thomas explains
this in its "Programming Elixir" book.

~~~
rdtsc
> the structure [1, 2, 3] still exists in memory, but now the variable x is
> bound to the value 2

I wasn't talking about data, I was talking about variables. Yeah you just
called it "re-binded". I called it "changed" or "mutated".

You have a function, and you see x=1 first and print its value. You'd see "1".
Then you can have x=2 maybe a few lines or pages below, print it, you get "2".
Variable x has changed its value. I even illustrated with a short example.

> All data is still immutable, the BEAM itself requires so. All data is still
> immutable, the BEAM itself requires so

Agreed. I don't think I ever talked about data being mutable. Having used BEAM
VM for the last 5 years, yes, I noticed data is immutable ;-)

~~~
qaq
It's not mutated or changed it points to a totally different memory location.
It's called immutable data not immutable identifiers. Immutable data is what
eliminates a large number of potential bugs. Having a ton of intermediate
variable names could actually be a source of bugs plus you have to care if
someone reuses the name above the point in code you used it. By allowing
rebinding you only care about the code below the place your introduced a
variable.

~~~
rdtsc
> It's called immutable data not immutable identifiers.

immutable/mutable data and immutable/mutable identifiers are two different
things. One is not called the other, they are separate things really.

> It's not mutated or changed it points to a totally different memory location

So you said it yourself. It points to a different memory location. So how is x
not mutated then? "Mutated" is a synonym for "change", or so I thought
apparently.

I don't see how one can look at a variable being reassigned and say "nope,
variable didn't change", where it clearly has a new value in the line below.

> Immutable data is what eliminates a large number of potential bugs.

Agreed. Was using Erlang for many years and tried Haskell before. Immutable
data is pretty nice most of the time.

> care if someone reuses the name above the point in code you used it.

Wait, is it the opposite of what you were trying to say? Wouldn't you want to
care if you are now randomly re-using or changing variables someone else
assigned. I thought immutability was a good thing.

> By allowing rebinding you only care about the code below the place your
> introduced a variable.

Unfortunately in my code base, the code above the place where variables are
introduced is just as mission critical as the code after the place. Maybe I am
using a strange coding style or paradigm ;-)

~~~
qaq
I obviously phrased it poorly as not to copy too much text the post by Jose
Valim on the topic: [http://blog.plataformatec.com.br/2016/01/comparing-
elixir-an...](http://blog.plataformatec.com.br/2016/01/comparing-elixir-and-
erlang-variables/)

------
fbonetti
Author of elm-phoenix-socket[1] here. I'm happy to answer any questions about
the library, Elm, or whatever.

[1] [https://github.com/fbonetti/elm-phoenix-
socket](https://github.com/fbonetti/elm-phoenix-socket)

------
mgalka
I'm impressed by the Hacker News crowd. Pretty cool to see a topic as esoteric
(and awesome) as Phoenix / Elm hit the top spot. Very good post!

~~~
qaq
I does look like Elixir/Phoenix is growing fast enough that it will not be
considered esoteric in fairly near future.

------
perfq
We love this stack, and dailydrip and elixirsips have helped us get a lot of
the knowledge we have. Josh does an awesome job at explaining the technology
in a step by step fashion that is both concise and easy to understand.

------
brightball
Elm and Phoenix really seem like a perfect match for each other

~~~
kcorbitt
They're both very functional, but it's an interesting matchup given that Elm
is very strongly typed and (according to my understanding) Elixir is totally
dynamic. For those who are developing with both, I'd be interested in hearing
if there's a reason why types would be more useful on the client than the
server or whether there's another motivation for those particular choices.

~~~
im_down_w_otp
Look at Dialyzer and [http://elixir-lang.org/getting-started/typespecs-and-
behavio...](http://elixir-lang.org/getting-started/typespecs-and-
behaviours.html#types-and-specs)

Also, Elixir community... there seems to be a paucity of awareness of Dialyzer
and Typespecs. Perhaps they could be more prominent? They're included in the
reference docs, but not really so much in a way that indicates what they are
or how one would use them when writing their own software in Elixir.

There are many, many classes of problems that can be discovered before they're
discovered at runtime. It's made a little harder in Elixir-land due to limited
Map support in Dialyzer and Map usage being extremely common in Elixir code,
but still spec'ing your functions is a good practice and habit to get into
anyway.

~~~
knewter
The latest Erlang release fixed the Map problem with Dialyzer. It was entirely
the reason I was lax with specs. I'd love to get a workflow more like this
one: [https://medium.com/@barruumrex/seeking-simple-
satisfaction-2...](https://medium.com/@barruumrex/seeking-simple-
satisfaction-2a098902ddff)

~~~
im_down_w_otp
For the uninitiated...

Erlang 19's included Dialyzer improves the scenario of type-checking maps in
useful ways. Namely that now you can represent an empty map, an arbitrary map
of any type, and a partially arbitrary map which must include certain key type
and value type associations but is not limited to those. Which leaves out one
representation which is a map which includes _and only includes_ a specific
set of key type and value type associations.

Erlang 18's Dialyzer has basically just #{} =:= map() which is equivalent to
the union of #{none() => none()} and #{any() => any()}, so it was basically a
giant escape hatch in the type-checking system, and thus not particularly
valuable.

Looking forward to a pending change in laxness as a result of the coming
changes in 19. :-)

------
onlydole
I absolutely love dailydrip.com too on top of Elixir and Elm...those languages
paired with such a great learning source is simply phenomenal.

------
bfrog
This is a great little webstack!

------
jergason
What makes Elm + Phoenix so good together? I use Elm professionally and love
it, but a back end is a back end. Is the love just "I really like Phoenix?"
The way people talk about it makes it sound like it is uniquely suited to Elm,
which I don't understand.

~~~
griffinmichl
Out of curiosity, where do you work? And are you hiring? Haha. I only know if
~5 companies currently using Elm

