Lately, in Clojure Developers Barcelona's events, we've been practicing by doing several variations on the Lights Out Kata.
First, we did the kata in ClojureScript using Reagent and Figwheel (described in this previous post).
In the last two meetups (this one and this other one), we redid the kata.
This time instead of doing everything on the client,
we used the Compojure library to develop a back end service that reset and flipped the lights,
and a simple client that talked to it using cljs-http and core.async libraries.
As we've been doing lately, we did mob programming and REPL-driven development.
First, let's see the code we did for the server:
These are the tests:
and this is the definition of the routes and their handlers using Compojure:
We had some problems with the Same-origin policy until we discovered and learned how to use the Ring middleware for Cross-Origin Resource Sharing.
Finally, this is the code that flips and resets the lights (it's more or less the same code we wrote for the client-only version of the kata we did previously):
Now, let's see the code we wrote for the client:
First, the core namespace where everything is initialized (notice the channel creation on line 12):
Then the lights-view namespace which contains the code to render all the components:
The lights-view's code is also very similar to the one we did for the client-only version of the kata.
And finally the lights namespace which is in charge of talking to the back end and updating the lights atom:
Notice how we used the pipe function to take the values that were coming from the channel returned by the call to cljs-httphttps://github.com/r0man/cljs-http's post function and pass them to the channel from which the code that updates the lights state is taking values.
You can find the code we produced in these two GitHub repositories: the server and the client (see the flip-lights-in-backend branch).
As usual it was a great pleasure to do mob programming and learn with the members of Clojure Developers Barcelona.
Record of experiments, readings, links, videos and other things that I find on the long road.
Registro de experimentos, lecturas, links, vídeos y otras cosas que voy encontrando en el largo camino.
Wednesday, August 24, 2016
MOOCs: Networking for Web Developers on Udacity
I recently finished this Udacity course:
I found it very interesting. I did it, mainly, because I'd like to start filling some gaps in my knowledge about the stack of networking protocols under the hood of HTTP.
After the course, I've started to read Ilya Grigorik's High Performance Browser Networking book bit by bit.
Thanks a million Udacity!
After the course, I've started to read Ilya Grigorik's High Performance Browser Networking book bit by bit.
Thanks a million Udacity!
Monday, August 22, 2016
Interesting Talk: "Taming Asynchronous Workflows with Functional Reactive Programming"
I've just watched this great talk by Leonardo Borges
You can find the slides here.
Tuesday, August 16, 2016
Kata: Lights Out in ClojureScript using Reagent and Figwheel
In a recent Clojure Developers Barcelona event we did the Lights Out Kata in ClojureScript using Reagent (a minimalistic ClojureScript interface to React.js) and Figwheel (which builds your ClojureScript code and hot loads it into the browser as you are coding).
We did mob programming and REPL-driven development.
Once at home I went on working on the kata.
This is the resulting code:
First, the core namespace where everything is initialized:
The lights-view namespace which contains the code to render all the components:
Finally, the lights namespace which contains all the business logic:
You can check all the code in the everything-in-client branch of this GitHub repository.
As usual it was a great pleasure to do mob programming with the members of Clojure Developers Barcelona.
Thanks!
We did mob programming and REPL-driven development.
Once at home I went on working on the kata.
This is the resulting code:
First, the core namespace where everything is initialized:
The lights-view namespace which contains the code to render all the components:
Finally, the lights namespace which contains all the business logic:
You can check all the code in the everything-in-client branch of this GitHub repository.
As usual it was a great pleasure to do mob programming with the members of Clojure Developers Barcelona.
Thanks!
Monday, August 15, 2016
Kata: Bank Account in Clojure using outside-in TDD with Component and Midje
I did the Printing Account Statement subset of the Bank Account kata in Clojure using Component and Midje.
I started the kata in a Barcelona Clojure Developers event.
The truth is that, since I was learning how to use the Component library, I didn't use TDD.
Instead I worked on the REPL to get everything in place and make it work.
Then I wrote the tests I would have liked to write if I had used outside-in TDD with Midje.
I find that, when I'm learning something new, it works better for me what Brian Marick describes in these tweets:
This is the acceptance test I would have started with:
Then I would have written this unit test for Account:
And these are the ones for InMemoryTransactions, ConsoleStatementPrinter and NiceReverseStatementFormat:
You can check the rest of the tests and code in this GitHub repository.
Doing this kata I learned and practiced how to use Component.
I also learned how to use Midje's defrecord-openly and provided macros to mock protocols which helped me correct something I did wrong in another kata.
I started the kata in a Barcelona Clojure Developers event.
The truth is that, since I was learning how to use the Component library, I didn't use TDD.
Instead I worked on the REPL to get everything in place and make it work.
Then I wrote the tests I would have liked to write if I had used outside-in TDD with Midje.
I find that, when I'm learning something new, it works better for me what Brian Marick describes in these tweets:
Now I'll show you the tests I actually wrote afterwards, in the order I would have written them doing outside-in TDD.(6) the immediately-following writing of tests to capture what I've learned counts as Schön-style reflection on just-prior practice.
— Brian Marick (@marick) July 26, 2016
This is the acceptance test I would have started with:
Then I would have written this unit test for Account:
And these are the ones for InMemoryTransactions, ConsoleStatementPrinter and NiceReverseStatementFormat:
You can check the rest of the tests and code in this GitHub repository.
Doing this kata I learned and practiced how to use Component.
I also learned how to use Midje's defrecord-openly and provided macros to mock protocols which helped me correct something I did wrong in another kata.
Subscribe to:
Posts (Atom)