Will we only create and use dynamic languages in the future?

January 7, 2012

Since I’ve playing with some dynamic languages (Ruby and Clojure), I have been thinking about why would anybody create a new static typed language?! And I didn’t get the answer.

I started programming in Visual Basic and I taste its roots, which are almost all full of procedure commands (bunch of do, goto and end), then I moved to C#, sharper it changes the end’s for }’s and give us a little more power based on some premises: we can treat two different things in the same way, polymorphism. The last static language, but not the least, I used (and I use it) Java, abusing of his new way of treating a set of things equality, the interfaces and using its “powers” on reflections.

Although when I started to use Ruby I saw that I could treat a group of things equality without doing any extra work. I still need to code models and composed types, even though we can create or change them dynamically using “real power” of metaprogramming.

When I start to study and apply the Clojure and its principles, my first reaction was the rejection, how can I go on without my formal objects, how can I design software without a model in the head and so on. I wasn’t thinking about how actually I do software, currently I use TDD to design software and I don’t think what models I need to have, I do think in terms of “what I want”. At minimum, Clojure make me think about, do we really need object to design software?! .  A three days ago I saw an amazing video about similar thoughts: Some thoughts on Ruby after 18 months of Clojure.

Summarising: With my limited knowledge of theses languages, let’s suppose we use a function (which we don’t have source code) and we want to do something before that function is executed (intercept) using: VB I’ll need to check every single piece of code which we call this function and call another one, in Java we can use a AOP framework, in Ruby we can use the spells of metaprogramming. It seems that some frameworks, patterns and extra work aren’t needed more because of this dynamic language evolution.

My conclusions using dynamic languages (Clojure/Ruby) for now it’s: I write less code and reuse them more easy, so I don’t see any reason to create/use a new static typed language, would you see any motivation to do that?

PS: When I use C# (.Net Framework 1.3 – 2.0) it was not so super cool as today.


Clojure resources

November 29, 2011

Always that I start to learn a new language, I promise to keep the best resources links I found, but it never works. This post suppose to be updated often. Any broken link or suggestion, just comment and I’ll try to fix, add or remove it.

Links, tutorials, guides, documentations, screencasts and etc.

  1. Clojure official site
  2. Installing Clojure, clojure-contrib and setup EMACS.
  3. VIM for Clojure
  4. Quick-start with examples
  5. VIDEO – Great short introduction videos for Clojure!
  6. VIDEO – Introduction to logic programming with Clojure
  7. VIDEO – Clojure for Java Programmers 1 of 2
  8. VIDEO – Functional programming by UCBerkeley 
  9. VIDEO – Great tutorial for Clojure focused on concurrency
  10. Try code clojure online
  11. Leiningen tutorial for beginners
  12. Midje – A test framework for Clojure
  13. Clojars – Community repository for open source clojure libraries

Books


Functional programming with Clojure

November 27, 2011

Clojure

I’ve been studying the new language called Clojure (all the cool kids are talking about Clojure). It is a functional language created by Rich Hickey around 2007. This is a(nother) dialect of Lisp. It is a dynamic language as Ruby, JavaScript and others. As said before Clojure (pronounced as closure) it’s a impure functional language in contrast with Haskell, a pure functional language. It runs over the JVM, so it’s fast, interoperable with Java among a lots of good stuffs that JVM give us. To put hands-on and try code something you can use the try Clojure online or you can download the clojure.jar file and run it. Surprisingly Clojure it’s easy to learn.


java -jar clojure-x.x.x.jar

What it a functional language? (concepts)

first-order functions -> functions are treated as values. You can store a function on a variable, you can pass one function to another or you can return a function from another function.

var sum = function(a,b){
  return a + b;
};

var obj = function(sum){
  return {
    hello: "hello",
    sum: sum
  };
}();

obj.sum(3,5);

functions constructs -> the language constructs are function instead of keyword. Constructions for conditions (if), for iterations (for, while), catch exceptions (try, catch) and others.


(if condition do-it else-do-it)

stateless -> it’s functional in the sense of math, you have functions which defines values input and output and doesn’t rely on outside global state. In such pure function you won’t produce any side-effect (read, write outside resource). Obviously we will produce programs which causes side-effects, clojure helps you build “mutable” data . On other pure languages like Haskell side-effects are treated as expections so you have concepts like actors and monad.

immutable data -> collections and local variable, in clojure, are immutable. The immutability, helps us in parallelism, since the “values” are immutable you can shared then without worry about locks.

currying -> is the technique of transforming a function that takes multiple arguments (or an n-tuple of arguments) in such a way that it can be called as a chain of functions each with a single argument (partial application).

memoization -> is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously processed inputs.

Resources


Put the bricks together on gnu linux

November 8, 2011

Why Linux?

It is easy, flexible, very secure, updated, “free”, open source… and the list goes on however what makes me more happy on this little world *unix it is its flexibility.

The power

Let start with a simple command, like ps, which can show you a list of current process and its details.

ps -aux

Now, I would like to just shows the output lines which has usr on it. To do that I will use the output of ps -aux command as input to grep filter the data. On linux you can pass the output of a command to another by using a pipe. So we can redirect the last output as input to another one.

ps -aux | grep usr

Now we have the output from ps filtered by only lines which contains ‘usr’. But what if want only the process id’s. There is a program for that too, the cut.

ps -aux | grep usr | cut -d " " -f 8

This program cut is simple creating fields (-f) delimited (-d) by a space (” “) and I ask the program to pick the field 8, which is the process ids. But if you notice there is some lines without number. The next step is remove this lines without values. We can do it by using sed program.

ps -aux | grep usr | cut -d " " -f 8 | sed '/^$/d'

Now our output has only lines with numbers, sed program receives a simple regex and says delete this pattern. Nice but I just need those numbers ending with 2. We can grep again.

ps -aux | grep usr | cut -d " " -f 8 | sed '/^$/d' | grep $2

I also want to sum all this numbers and show on the screen the result. To achieve that we are gonna use awk program.

ps -aux | grep usr | cut -d " " -f 8 | sed '/^$/d' | grep $2 | awk '{ sum += $1; print "+" $1} END {print "_____" ; print sum}'

The first code (surrounded by brackets) will create a variable called sum and it also prints plus and each first argument passed to it. This first block will be called for every line we pass (processed by all the programs we did it) and it follows by END that will print a line and finally prints the sum of all this stuffs.

+1692
+1712
+1732
+1752
+1762
+1962
+2062
_____
12674

You can use programs connect them produce output that only one program can not do. PS: I know I could too all this with less programs/commands but the intend here was not teach linux/GNU programs it was show you how powerful can be linux.

Bonus round

You can put this output to a file just using the redirect to a file. ( > or >> to append)

ps -aux | grep usr | cut -d " " -f 8 | sed '/^$/d' | grep $2 | awk '{ sum += $1; print "+" $1} END {print "_____" ; print sum}' > file.txt


UX – Teach your users how to use properly your webthing

November 5, 2011

Very inspired by Modelo mental and this amazing video here.

How Google taught me use it properly!

I always use Google.com as a tool for an uncountable things! And I always use the advanced search, mainly for search only over the last week. This feature (I mean Advanced Search) used to be at the home page.

However right now, there is no such link on google home page. (or at least in my browser for the last weeks). But the google guys also used to put this feature link on the top’s search page, as the bellow image.

And now there is no this link there too, this feature link was moved to the lower part of result list page. That’s okay, at the first sigh I thought they could facing performance issues with more and more users using this kind of search. But man they are the Google.com they face and win perforamance challenges.

What was really interesting about this place changing feature links, was I “discovery” that google already provide a side bar links to search only on last X age. I learn that looking for the advanced search. This is what I call the masterpiece of UX, I learn a new feature just by using it naturally.


Follow

Get every new post delivered to your Inbox.