Sonntag, 3. Juli 2011

Simple Problem, Simple Solution(s)

Borrowed from :
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
Which right triangle that has integers for all sides and all sides equal to or smaller than 10 has a perimeter of 24? 


Haskell
[ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]


Scala

for {c <- 1 to 10; b <- 1 to c; a <- 1 to b; if(a+b+c == 24 && (a*a) +(b*b) ==(c*c))} yield (a,b,c)



C#

var result= from c in Enumerable.Range(1, 10)
from b in Enumerable.Range(1, c)
from a in Enumerable.Range(1, b)
where a+b+c == 24 && (a*a) + (b*b) == (c*c)
select a+" "+b+" "+c;


More on comprehensions:
http://patternsinfp.wordpress.com/2012/01/19/comprehensions/
Haskell
[2 * a + b | a <-[1,2,3], b <- [4,5,6],  b `mod` a == 0]


Scala
for{a <- 1 to 3; b <- 4 to 6; if (b % a == 0)} yield(2 * a + b)

Radical Simplicity by Stuart Halloway

Yet another talk by Stuart Halloway, his presentation style and pronunciation are really good. And personally I find it comforting and pleasant to listen to his voice which makes it for me really easy to follow. Putting not too much emphasis on the technical aspects, this talk raises a number of important questions, in my opinion. I want to name two aspects here in a bit more detail:
1. Simplicity
Around 00:53 reflection API Example is given to demonstrate what simplicity means. I think it is important to define, even simple (hu?, ha!) terms like simple because again, it becomes apparent that different people have different meanings and perceptions for terms. Maybe its obvious to some maybe not but simple does not easy or beauty. Now how can we grasp simple in terms of programming or rather API's? The reflection example demonstrates this quite nicely. The API should consist of small reusable parts which can be used to build higher level functionality or abstraction.

In the following he asks: Why we don't have radical simplicity?
And to observe the answer or even pursuing the question is a very worth goal for every programmer.
Stuart names Pressure (about 1:09) and the lack of trust. Could you justify to build 4 Prototypes in your curent/next project (Even if the first worked)? How do we, that is the programmer side and the stakeholder side define and agree on 'good enough'?


2.  (simple) Foundations of programming
On 1:03 these four foundations are listed:

  • functions
  • logic
  • relational model
  • associative model

and it is concluded that all these have a mathematical foundation.  But actually OOP has none. It is pointed out that OO is inherently complex and there could be a potential danger by having features that could do harm if abused. Specifically applied to Java he claims Java is: compound, complex and complicated.

Eventually this talk has inspired me to sharpen my point of view on API's and to question for simplicity in my programming job, consciously.

http://skillsmatter.com/podcast/java-jee/radical-simplicity/js-2051