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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The code is very similar to the one for the Word count exercise. The main difference is that here I used a set to validate that the given nucleotide is valid.
I eliminated the duplication between the set and the map contents in this second version:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
where I defined a set containing only DNA nucleotides, dna-nucleotides, that I used to define the nucletides set using conj. This dna-nucleotides set served to generate the counted-nucleotides map using the zipmap function.
Trying to avoid duplication I discovered several new things about Clojure.
You can nitpick my solution here or see all the exercises I've done so far in this repository.
--------------------------------
Update:
After learning some new stuff, I've been able to simplify the code a bit more:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It turned out that the frequencies function already did the counting out of the box,
I jut needed to merge it with the result for an empty strand to make frequencies output conform with what the tests were expecting.
I also made the dna-nucleotides and nucleotides sets private.
I wrote a first version using just regular functions:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This time I decided not to make the helpers local because they might be useful by themselves.
I also decided to separate in different functions the case-sensitive and case-insensitive versions of the anagram detection function.
You can nitpick my solution here or see all the exercises I've done so far in this repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I used a map to look-up the transcription of each nucleotide.
The AssertionError exception was necessary to pass the provided tests. I would have rather used a different exception.
You can nitpick my solution here or see all the exercises I've done so far in this repository.
--------------------------------
Update:
After learning some new stuff, I've been able to simplify the code a bit more:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I created some local helpers and played with partial and comp to make the code more readable.
I also reduced the number of parameters of some local helpers by using some free variables.
I really liked how the reduce function can be applied to a map data-structure in Clojure.
After learning some new stuff, I've been able to simplify the code a bit more:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is my solution to the Bob problem in Clojure:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This weekend I've started working through the Exercism exercises.
First of all, I'd like to thank Katrina Owen for starting this wonderful project.
Exercism is a great open source project that she started in order to "provide a space to think deeply about simple, expressive, and readable code, and experiment and discuss what good looks like".
There are exercises in many languages but I'm only working on the Clojure and Ruby ones.
Even though the exercises have been very simple so far, they've helped me to practise and learn more about Clojure's and Ruby's powerful collection and string functions.
I've also learned some tricks and functions I didn't know by looking at the solutions to the same exercises posted by other people. As soon as I gain enough confidence in Clojure and Ruby I will start giving them feedback.
I hope to start receiving some feedback about my solutions in order to improve them.
I've just watched this great talk by Mark Ethan Trostler in which he describes some great principles, techniques and patterns to make your JavaScript code more testable:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To document the process I commited the code after every passing test and every refactor.
I also commited the .lein-repl-history file so that you can see all the micro-tests I did on the REPL to create some of the features and learn about Clojure including many beginner mistakes :)
Today I needed to click on a select option that had a specific value using protractor.
After Googling for a while, I did it using the element selection by xpath.
This is the helper function I created:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Another problem we found last week using protractor was when we tried to click on a dropdown option.
This was the problematic code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
which caused the following error: ElementNotVisibleError: element not visible
This happened because the element we were trying to click on was hidden.
Googling a bit again, we found (here) that to avoid the error we had to click on the dropdown before clicking on the option to open it up, so that it wa visible to the user:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Again we extracted this bit of code into a helper method in out TestTools module:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
At work, we've recently started to use protractor to write end-to-end tests for a legacy AngularJs code base.
Last week we found a problem while trying to test that an element from a list was deleted:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The problem was that clicking on the delete icon was displaying an alert box, prompting the user to confirm whether they actually wanted to delete the element or not, that protractor didn't expect and was causing the following error: UnexpectedAlertOpenError: unexpected alert open
After searching in Google for a while, we found a solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
that fixed the problem by switching to the alert box and confirming that we wanted to delete the element.
Since it was a bit verbose and we'd probably have to use it again in some other tests, we extracted it to a helper function in our TestTools module:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Even though both solutions were very similar, doing the kata this time in Clojure was useful to practise with Midje.
To try to get to a different solution for the kata and use the Clojure sequence library, I set myself a constraint: Instead of mapping just a function on the sequence of numbers, I had to find several transformations that could be mapped one after another on sequences to get the same result.
Since I had to do a lot of trial and error, I prefered to use REPL Driven Development this time.
This was the REPL session to get to the first alternative version (eliminating a lot of errors..):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From this REPL session I got this alternative version for fizz-buzz:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's more complicated that the original version but it served me to practise some interesting Clojure features: recur, partial, map and let.
Then I tried a different approach: Reducing the sequence of transformation functions so that I can map the resulting transformation function on the sequence of numbers.
Again I worked in the REPL first:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From this second REPL session I got this other alternative version for fizz-buzz:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
which is again more complicated than the original version but served me to work with other intersting Clojure's features: reduce, comp and reverse.
After these two versions of FizzBuzz I did a web search to find nicer ways to use the Clojure's sequence library to implement FizzBuzz and I found these two in Rosseta Code that I specially like (I modified them a bit so they return the same that the precious versions):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These two last versions will serve me to learn about if-let and cycle.
Ok, that was all I got today.
Just to sum up, I think there is a lot you can get from even a simple kata like FizzBuzz if you set yourself some constraints and try different variations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
They are more or less the same (except that Clojure's version returns a string whereas Racket's one returns a list of strings).
On one hand, I prefer Clojure's cond which is more readable because it's more lenient with the parentheses.
On the other hand, I really like how Racket's local allows to define local functions inside another function in the same way they are defined in a module.
In Clojure I also defined a local function is-multiple-of? using let but the result is less readable than using Racket's local.
I've just watched this great talk in which Sandi Metz explains her approach to testing by commenting some of the code examples in the Defining Cost-Effective Tests chapter of her Practical Object-Oriented Design in Ruby book: