Sunday, 17 November 2013

Functional programming and Assignment 2

I've solved the assignment 2 in Scala, now I would like to prepare the same in Clojure but I'm a little disappoined. Reading inside the assignment 2 classes I can't find any without a mutable state.... where is the functional programming? I'll write the assignment 2 in a functional style way. But it will took me some time. Meanwhile I'm disappointed, the first Scala course was all based on functional programming and now after only one week it is disappeared. Can we use functional programming style, or on the first simple project we do we will use only imperative style and forgot about the functional part?

Tuesday, 12 November 2013

Week 2: Circuit Simulation, Functional Wires

Mmm actually I think that write Protocol and Record is not so so "Clojure's Style".
What do you think about this implementation?
I'm learning Clojure.. I'm not a Guru so I'm trying to always improve my "Clojure Functional Style".
I'll really appreciate any opinion you have on this!! :D

Monday, 11 November 2013

Week2: Circuit Simulation, Wires

This week's first 3 videos are a introduction to state management inside a functional language, actually I can't read slides from video one, so I'll give you a Bank Account conversion in Clojure as soon as the slide will be out. In the second and the third video there isn't any code that can be usefull written in clojure (actually I can't understand what I had to learn from the third video... ). In the other videos video Martin start the implementation of a domain specifil language to simulate circuits.
This are the Wires, rewritten in Clojure:
Actually I'm thinking a lot on differences beetween this two languages.
I think that to create DSL Scala has the huge advantage of type system, but I think that if we can build these kind of DSL we will be in jail...
One great programmer in each society that will build the DSL, and all low-profile programmer that will use it without knowing anything of real Scala.
Another little consideration. What the heck is this O_o:
Ok the Scala's match is AWESOME, I said it in another post. But this is quite confusing, I had to watch the video 3 times to understand what was appening, in Clojure that are a lot of parenthesis, and someone can be frustrated from it, but here we need some parenthesis. The part with <= => it's very horrible in my opinion.
For now It's all :D, I'll come soon with the rest of Circuit implementation.

PS: The assignment will be quite a challenge .. there is also a Display for the Epidemic Simulation... I need days of 30 hours ....

Week 2 is OUT

O_o week 2 is out and the Assignment seems AWESOME :D
Clojure code will be on the blog as soon as possible... I think I can't sleep anymore....

Sunday, 10 November 2013

Assignment 1 done in Clojure and Scala

I have solved the Assignment in this 2 languages...
My opinion....
Clojure: I know more this languages, I had fun solve the assignment with clojure check, but actually I can say it's a good start but it has to be improved.
The problem was OO designed, so the solution and the assignment design it's not as great as I would like.
If I'll have time I'll come back to this assignment to re-design it to be more "clojure-friendly"
Scala: I did it in Scala, it was quite a shock to write because it was really easy to solve writing generators and properties. I think ScalaCheck is a great library, and the syntax of the solution is more clear than Clojure's one. The match of Scala is absolutely AWESOME.
I'll post my solution after the hard deadline :)

Saturday, 9 November 2013

Assignment 1

And the assignment 1 in clojure is here finally :), it has been quite hard to convert it.
I have rewritten the heap without doing any change in the design to make the same questions that are in the scala's assigment.
Actually the properties have to be done as functions. 
The properties function are in the file quick_check_properties.clj

As said the assignment instructions you have to write a good number of properties check to make all test pass.
If you launch "lein test" in the directory of git you will see there are 5 test that fail.
They will pass when you will write the properties that check the fault in the 5 bogus implementation.
I'll post the solution after the hard date, in this way I'll not not give any hint.
The Heap implementations are made with protocols, actually I think it his quite a bad implementation, probably made for educational purpouse, if I have time I'll make a better implementation with multi methods.
Let me know what do you think, I'm new also to clojure, so I'll appreciate any tip/hint you can gave me :)
For any question feel free to comment I'll reply as soon as possible.
Again, the repository is here, you will find the quick_check_properties.clj where you have to write the functions to solve the assignment.

NB: I'm working on it, there are some problems but I'll fix it soon!! :)....
02:33--> Assignment is ready, you can solve it :), have fun

Friday, 8 November 2013

GitHub repository

Like i wrote in About this Blog, there is a repository (that I'll update while the course go on) with the code:

Stay in touch :)

Thursday, 7 November 2013

Week1 Videos

In the first week Martine spoke about the importance of Reactive Programming, I suggest you to watch the videos of the course (Principles of Reactive Programming).

Code for video: Recap: Functions and Pattern Matching

In this video there is an implementation of a Json parser with case classes, and a show methods, one possible implementation in clojure is:

Here I used a simple Map with Json inside, the show method is pretty_json, instead of match I used multi function.

Code for video: Functional Random Generators

In this video Martin introduce the idea of functional generators to use for tests made with ScalaCheck, we will use clojurecheck that is a property base testing framework like ScalaCheck.
The code of generators is:
I jumped the two recap video on language because I think that who came on this blog is a clojure developer, but if you want I can make a little tutorial on clojure.


This blog will be used to make lessons on Reactive Programming using clojure.
It will follow the Principles of Reactive Programming by Erik Meijer, Martin Odersky and Roland Kuhn but it will use Clojure to make the same things.