Wednesday, October 19, 2011

Which Programming Language? CoffeeScript, Java, PHP

Today we are going deeper on the importance of feedback when choosing a programming language.

Did you try to spike a little with a new programming language? A very useful way to do it is through the measure of feedback you have from the language and its environment or ecosystem.
So if you tried to download, install, compile... (stopwatch at hand) good! If you didn’t, I’m going to free you from the effort through this and other next posts, so keep in touch.

Which Language?

Let’s consider two “old” languages: Java and PHP and a new one: CoffeeScript

Which Platform?

I’m working on a Mac, and so let’s suppose we want to deploy on it.
It’s important to define your platform because you can try something on a platform and deploy on another one, but of course if you change it on the way, you have an unknown.

Which Context?

I’m writing during the weekend and, unlike other working days, I usually take a nap after lunch, it’s something I’ve been carrying since I was young, it’s a break in the daytime and it lasts about 30 minutes or so, a sort of reversed pomodoro or, better, a pomodoro focused on sleeping ;-)
After that, I’m "energized" and ready for the afternoon. So what?
  1. Let’s consider a preliminary of N languages (only three today) some mainstream, some cutting edge. The goal is to hack a timer that wakes me up from my nap after 30 minutes.
  2. Note: some languages implement sound generation more smoothly; other are not really sound-friendly, so for this first attempt, a timer that prints “wake up” is enough.
  3. Finally for this specific experiment I’d add another requirement: let’s jump to light speed and go somewhere in the universe where 30 minutes are equal to 3 seconds (my nap is incredibly reduced ;-)
psst: If you are lazy like me, you can go directly to the Conclusion, otherwise continue to read.

First I create a directory named contest in which we save all our spikes.

The first language to consider is Java

I create a subdirectory for Java and look for Java on Google like any newbie.

Following my breadcrumbs with some comments:
Actually we have spent 6 minutes, but no info worth on. 

So I search for something like “first java program” on the favorite search engine and..... at 8.36 minutes I land here:
The output is OK (after 10 minutes

But.... our exercise doesn't end here, how can we implement a timer?

I search again: “java timer”
I do a bit of c&p, remove all comments, compile and run. It works (17.20).
Now I reduce frills, and change time to 3 seconds

After 18.05 minutes we have our timer:

import java.util.Timer;
import java.util.TimerTask;

public class ReminderBeep {
  Timer timer;

  public ReminderBeep(int seconds) {
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds * 1000);

  class RemindTask extends TimerTask {
    public void run() {
      System.out.println("Time's up!");

  public static void main(String args[]) {
    new ReminderBeep(3);

Anyway the Java syntax is not concise nor essential, but 18 minutes is a pretty fast time even if I was almost confident to read the example for windows.

Now let’s pick PHP

I go to:
I try to write the hello.php file and then I point the browser directly on it.
  • vi hello.php 
  • a bit of c&p 
  • open browser on file://......../hello.php it doesn’t work, of course. 
I surf the web again:
I locate and open the Apache configuration file, it should be here: /private/etc/apache2/httpd.conf and I change it accordingly.
Than I go to: /Library/WebServer/Documents and I write a simple phpinfo

<?php phpinfo(); ?> 

Now I restart apache with: sudo apachectl graceful and then I point the browser here: http://localhost/info.php, it works.
Now I move hello.php here: /Library/WebServer/Documents , it works

After 27.00 minutes we have:

  <title>PHP Test</title>
 <?php echo '<p>Hello World</p>'; ?> 

Now I make a search for a timer on Google: "php timer example"

Finally after 43 minutes that’s the simplified timer: 

echo "wake up<br />";

As you have seen, php drives you to use a web server and to execute the code inside it, even if we have not a real need to build up such infrastructure.
I’d like to underline this concept: of course php scripts run in a web server.... at the end. But now, our focus is to learn the language, all other “mandatory” steps distract us from our goal and put it away. I don’t think about it as a" una tantum" stuff, I think as a clue you have to evaluate the language ecosystem and the intentions of the creator of the language.
Anyway the php example is really minimal compared with java.

And finally CoffeeScript

The usual breadcrumbs:

Now I create the directory coffeescript under contest then
  • sudo npm install -g coffee-script 
  • I test the installation, type: coffee - Cool it runs.
  • I type: number = 42 - OK, it returns 42 it seems working,
  • And I exit the REPL, how? It could be: exit, no, quit, no, bye, no, open sesame no way.
I'm defeated. I google: "exit coffeescript repl"
I exited, but it’s not yet clear to me how to print something, let’s look deeper at the overview and try:
  • alert “hello” - ReferenceError: alert is not defined 
  • coffee -e "console.log num for num in [10..1]" - Gotcha! 
  • console.log "hello" - That's fine.  
 After 29 minutes

Finally let's look for a timer: - found it.

Now I rearrange the script in the coffee repl to have something like:

setTimeout((-> console.log "wake up"), 3000) - It works!

After 38 minutes

Actually CoffeeScript is really playable and it has a minimal syntax, but I expected a more clear documentation: the repl delayed me a bit


Let's sum up some results:

The chart shows the time spent doing installation plus some initial check and the time spent hacking a timer.

PHP and CoffeeScript result in the same amount of time for the installation, but hacking a simple timer in CoffeeScript is quicker and it's comparable with Java, but I can't tell you more, the trial is not ending here and I still need a couple of posts to show other insights.

Next week time we'll analyze three other languages, keep in touch and... mind the feedback!

Chicken timer by abbey*christine
Installation by zigazou76

Tuesday, September 27, 2011

Two Reasons Your Favorite Programming Language Becomes Cumbersome

Regarding "Is Your Programming Language A Burden?", a couple of days ago, a reader asked me:
“How can I find a language more cumbersome the more I use it?”

Nice question and the answer is quite simple:

  • The first reason can be that the language was born cumbersome, but we didn’t have the fine taste to recognize its useless complexity. 
Let’s take an example: think about String class in Java or C# you know it’s final/sealed, you cannot extend it to open its behavior. Moreover you cannot modify it because it’s integrated with the language (grrrrr). I can bet when programmers realize those obstacles they become aware that language holds their creativity.

  • The second reason is about a language born simple, but release after release, version after version new constructs are stuffed in and finally it becomes bloated.
Look at  Java history and pick your top worst updates.

In conclusion, the more you play with a language the more you discover if it solves your programming needs or if it’s only a parking brake.

There is a third reason of course: a language starts cumbersome and in the meantime grows with useless syntax additions, that's the worst case dear readers ;-)

photo by

Friday, September 23, 2011

Is Your Programming Language A Burden?

Hi folks,
 How are you? I'm fine, coaching a bit, programming a bit, observing, planning.

As you are reading this blog, I guess your workdays look like mine: wondering who was able to write that messy code (it's you, last month, you know) but you are not an ordinary developer you study, you delve... and day after day, while you are improving, you have a feeling your programming language is slowing you down.

It's something I often see: at some point you feel the language doesn't follow your thoughts, suddenly the syntax becomes cumbersome, types are a cage, primitives reduce your ability to create concepts.

In "How To Choose A Programming Language" I talked about feedback and level of magic and I'd like to hear your voice: did you measure the feedback of your favorite programming languages? You can do it now ;-)
Tell me about it on Twitter @Varvello or Facebook or Google+ or wherever

Thursday, September 15, 2011

How To Choose A Programming Language

Welcome back. It has been a long time since my last post, but I was on vacation than my fish was sick and I needed to take it to the vet and my neighbor's daughter got a round hair brush stuck in her hair and I needed to help her get it out and in addition I fell off a ladder fixing the roof on my house and I landed on my elbow and etc. etc.

Anyway, in the last post, Wordpress vs. Blogger II, I stressed the importance of feedback and how it’s valuable for a programmer to gather feedback from her daily tools. More the feedback is fast, more we learn and more we can tune our product. If we have a result back in a month we learn after a month, if we have it in a week after a week in a second after a second.

I also give you this tidbit: our brain is very fast, it reacts in a jiffy: some days ago I was looking at my wife struggling with a web page where there was a button that said: “to reload press here” so I told her: “look at the button, don’t press it”. I didn’t end the phrase yet and my wife started moving her mouse over the button, she began reacting immediately.
Brain’s feedback is really fast, to be more effective I should have said something like: “don’t press the button now it's useless".

But I’m digressing.

As a programmer needing to be productive, which kind of language should I use? Which criteria are valuable? Where should I start?

Let’s suppose on the web there is some hype about a new programming language and you are almost interested in it, so you bring a reference book, after which you should focus on three things:

  • Feedback: how long it takes from the first time you see a line of code on the reference to the time you have that line running on your pc. That includes: downloading, installing, configuring, compiling… (stopwatch at hand).
  • Feedback: how it’s easy to play with the language. Close the reference and spike a bit. Can you immediately have some results? Are error messages communicative?
  • And of course, Feedback: look for something more complex e.g. saving data of a web page on db. Does the language solve it in a couple of lines of code? It means it’s very powerful, but be careful, that’s what I call: Level of Magic. It’s not really a drawback per se but you should be aware that the language does a lot of stuff in a very few lines of code, if you have to change something, you’ll have to understand its behavior and actually that behavior is hidden -> high level of magic.

Now, I give you an example of the second kind of feedback. The example is not new, but it’s something that has been fascinating me for a long time.

Comments in Smalltalk are enclosed in double quotes:
“this is a comment”

Of course a comment can be like this one:
“example {}as:Set”

I can select  {}as:Set  and evaluate it, I can execute a comment and see the result. That comment is living, I can play with it... I can learn: fascinating.

Monday, July 25, 2011 vs. Blogger II

Here we are at the second episode of vs. Blogger.
As you know my first motivation is simplicity. The second one is... look at the following videos:

Did you see? Blogger performs some actions faster than

The creation of a new post is slower on (~6 secs) than Blogger (~3 secs) .
Blogger's autosave is within one minute, autosave is within two minutes and moreover, if you want to manually save your draft, look at the video! The action is not really immediate.
Finally also on preview Blogger is faster than

Conclusion: you can easily imagine, when you write a post, you start dropping a few lines, than see how they look like, than rewrite and see again and so on. That's why feedback while editing a text is important.

Now I've a question for you, when you write a program are you editing a text? Indeed, it is something more than editing a text, we need feedback and more. So next post we'll see how a few languages, like Smalltalk, can provide you a fast feedback.

See you.

Monday, July 4, 2011 vs. Blogger

If you are reading this post, probably you are aware last week I changed blogging platform: from to blogger.
I specified because there is also a but that's the carry-over-your-shoulders  platform.

The very first days I set up my blog, I found on the net a lot of useful plugins for wordpress, wonderful - I said - I tried to install some plugins or to search for the right option in .com, but unfortunately they was for the .org version (side note: dear reader, you have to know I'm a simple mind, I get lost immediately when I find something it's not crystal clear).
Finally I discovered the difference: .com is all-inclusive but restricted, .org is free as a bird but you've also to mount an ikea wardrobe.
I discarded the .org solution sure the .com version was downhill all the way.

Now, let see the "easy" way: Dashboard

In your personal dashboard there are: five items in the top bar and fourteen items in the admin bar on the left, i.e. nineteen first level items, but  if you expand every item there are many others links or buttons eager to be clicked.   G o s h.

Now let's go to the blogger dashboard

Blogger Dashboard

Six first level (tabbed) items, plus a "view blog" link

Why do you want to start a blog? Probably because you want to write something worth of and I say writing, not configuring or searching for the right option or whatever else. All other activities are needed but should be done with less hassle. Writing should be immediate!
I've to admit the settings tab in blogger is quite crowded and can be simplified, but almost all the default options are ok.

Good, that's enough but I'll tell you more in the next post.
See you.

Update: The second part of this post is here: vs. Blogger II

Thursday, June 23, 2011

...Change No.1

Ah-ha, here we are! Welcome again.
As you can see, you can find all my "old" posts here. I hope you like this new home.
 Stay tuned.