Sunday, May 25, 2014

Interesting Talk: "The Curious Clojurist"

I've just watched this talk by Neal Ford introducing Clojure: It's a really great introduction to Clojure.

Saturday, May 24, 2014

Bizarre factorial in Clojure

I'm reading Brian Marick's Functional Programming for the Object-Oriented Programmer book.

This is my solution for an exercise from the first chapter, Just Enough Clojure in which I had to write a "bizarre version of factorial that uses neither iteration nor recursion":
Tested at the REPL it seems to work fine:
However, there are problems for big enough results because they don't fit into integers:
This can be easily solved using arbitrary precision integers.
You just need to append an N after any number in the calculation, since it's "contagious" to the rest of the calculation:
Now it works:

That's ok but how does bizarre-factorial works?

Let's first examine range function:
So, for example, to get the first 10 positive arbitrary precision integers we'd write:
We might refactor bizarre-factorial using let to create a helper function, positive-ints-until, to make this more explicit:
Let's see now how apply works:
So in the case of bizarre-factorial the apply function is applying the * function to a list of numbers returned by the positive-ints-until helper function.

That's how bizarre-factorial works.

Finally we can use partial to give a better name to the partial application of apply and *:
This version of bizarre-factorial is much more readable.

Wednesday, May 21, 2014

Interesting Debate: "Kickstart Academy Podcast - with Sandi Metz "

Last night I watched this great conversation with Sandi Metz about object oriented design, writing maintainable software and more: I really recommend it.

Interesting Talk: "Rules of Simple Design"

I've just watched this interesting talk by Corey Haines in which he comments some ideas from his last book:

Sunday, May 11, 2014

Saturday, May 10, 2014

Interesting Talk: "Decoupling from Rails"

Great talk by Jim Weirich where he refactors a Rails application code to decouple it from the framework so that it follow the clean architecture: There's a lot of wisdom in this talk.

Values without practices

"All of this high-minded talk is well and good, but if there isn't some way to reduce it to practice, to reinforce it, to make the values a natural habit, then all we will have is yet another brave leap into the swamp of methodological good intentions."
Kent Beck, Extreme Programming Explained

Tuesday, May 6, 2014

Interesting Talk: "The Architecture of Uncertainty"

I've just watched this great talk by Kevlin Henney: This talk gives great insights in the relationships among uncertainty, design, learning and change.

Lately I've been reading and thinking a lot about this after reading Sandi Metz great book on OO design and several interesting discussions with @remosu.

Some intuitions are growing in my head but they are still quite fuzzy.

Kata: Revisiting Gilded Rose in Java

Yesterday Jaume Jornet and I were practicing together doing the Gilded Rose kata in C#.

At the end of the session, we left the code in a point where it was ready to substitute several conditionals with polymorphism. Then we discussed how we would do it without modifying the Item class (to avoid the goblin's rage).

We talked about wrapping Item in another object DegradableItem and then create several subtypes for it. Once having this design in place the Conjured items might be implemented using a decorator over DegradableItem.

When I got home I did the whole kata again in Java and coded these ideas we had talked about with some slight variations:



You can compare it with another version I did nearly a year ago.

Our lifes would be much easier without the goblins :)