This is another implementation of the Game 2048 in Reason React. It was my first Reason React project, and is basically a fork of LIU9293's implementation.
Key Observations
- Reason React is really easy to pickup. I am not much more than a javascript tinkerer, yet I was able to develop this, starting from Reason Scripts within 5-6 hours. The syntax proves very familiar for someone who knows javascript. It's readable and straightforward.
- It was jawdroppingly powerful
- Pattern Matching is amazing! I was hooked from the first one I wrote. It allows the programmer to focus on the logic, as the implementation becomes very easy.
- Encouraged by the toolset, I found myself quickly migrating to more functional-style programming. I avoided loops, and found myself writing recursive code!
- Tuples are great too. I loved wrapping-together a few variables and treating them as a unit. Although I found the parentheses syntax kinda confusing. There were times when I had 3-4 open or closed parentheses side-by-side for a simple callback function.
- I loved the typechecking. I haven't programmed with types since the Java era. I can't believe that there was a bullet-proof typesystem that didn't require annotating everything. It just worked. I was floored when the typechecking found errors within my JSX. Wowzers.
- I did have a number of challenges that took a little while to work-through
I found the module system a bit confusing. I couldn't figure-out how to create private helper-functions without putting them within the definition of the public function. That ended-up working for this project, however it makes it impossible to share these helper functions within the module, and it made unit testing harder.Module Signatures solve this ompletely- Jest doesn't fully support Bucklescript, yet. I worked mostly with linked-lists, but those aren't well supported by Jest. I usually had to convert an list to an array for testing purposes.
- Given its newness, ReasonML there aren't a ton of Reason example code and Stack Overflow ansers out there. But there's a ton for OCAML, which maps 1:1 to reason. The playground proved invaluable, as I would paste-in OCAML and instantly get out Reason.
- Reason / Bucklescript / React is HEAVY. This very light applicaiton is 58kb gzipped.... My code is a few hundred lines... THat's a lot of library code. I was somewhat surprised to see how much of it was Bucklescript code to handle language features like Linked Lists and Currying.
All-in-all, it's been a very fun experience. And I'm amazed with the power. I'm going to look for opportunities to use Reason, instead of javascript, going forward.
Todos
- Fix keyboard bindings.... Right now the user has to click first. A bit stuck. Could use help here from any react experts
- Detect game-over
- Gestures
- Delay adding new cells after transform for a fraction of a second
- Retitle the page