Saturday, May 24, 2014

Interesting Interview: "Stuart Halloway on Clojure and Functional Programming"

Today I watched this great interview with Stuart Halloway: It's a great way to get an overview of where Clojure can be helpful for you.

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

Saturday, May 17, 2014

Interesting Talk: "Clojure for Java Programmers"

I've just watched these interesting talks by Rich Hickey:

Interesting Talk: "Dealing with Dynamically-Typed Legacy Code"

I've just watched this interesting talk by Michael Feathers:

Interesting Talk: "Making Little Classes out of Big Ones"

I've just watched this interesting talk by Avdi Grimm:

Interesting Talk: "Build a Bigger Brain: How Healthy Living Makes You Smarter"

I've just watched this interesting talk by Joe Kutner:

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:

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.

Saturday, May 3, 2014

Interesting Talk: "Less - The Path to Better Design"

I've just watched this great talk by Sandi Metz:

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 :)