I’m teaching Elm to a computer science tutee of mine (He’s learning a lot of CS outside academics, especially in the summer.) And I’m actually pretty new to Elm myself.
I wanted to teach him a number guessing game. You know, you try to guess the computer’s number and it tells you “high” or “low”. I started writing this myself and quickly realized it’s pretty complicated.
I then Googled it and found this: https://github.com/kittykatattack/randomNumberGame
Compared to a Python version of this game, this is rather complicated. (Like 10 times more code.) Is this complexity something we need to accept about Elm, or is there a better way?
Hi Mike! I can see how this kind of example feels complex compared to Python but I wonder if you’d agree that perhaps it’s just more verbose? With strong types and managed side-effects such as randomness trivial examples tend to be a little more verbose while large applications tend to be simpler at scale.
Here is a guessing game I put together quick but if you want a slightly more beginner friendly starting point here is the same example without randomness (the answer is hard coded).
Something like the latter example might be a better entry point as it’ll allow anyone to get to know the language better prior to the introduction of the concept of a
Cmd which is something that randomness requires.
I hope that helps!
Thanks for putting that example together.
One thought about the complexity of Elm vs. Python. Maybe it’s GUI vs. command line.
In Python, the state of the game is implied by the current execution point and current variable values, so it doesn’t have to be explicitly modeled. In any GUI, including JS you have to define “widgets”, respond to their events and model the state more explicitly.
On the other hand, it might be slightly more difficult with Python and a CLI to get a “real-time” evaluation like in this even more basic example: https://ellie-app.com/5WWbZfXbB7da1
So this might be showcased to illustrate the strengths of Elm.
Thanks for the examples. Can I download or save things from Ellie? I tried “share” and “download zip” but it was non-responsive (no download initiated).
Hm, “Download Zip” works for me. Do you see any errors in your browser console?
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.