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: CoffeeScriptWhich 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?
- 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.
- 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.
- 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.
- http://java.com/en/download/apple_manual.jsp?locale=en - Cool I don’t have to download anything on my Mac.
- http://java.com/en/java_in_action/ - Hmm.
- http://java.com/en/download/help/index.xml - A help, good!
- http://java.com/en/download/testjava.jsp - No hint yet.
- http://java.com/en/download/faq/develop.xml
- http://www.oracle.com/technetwork/topics/newtojava/overview/index.html - Finally a “New to Java” page.
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:
- http://download.oracle.com/javase/tutorial/getStarted/cupojava/win32.html#win32-2b - It’s a page for windows anyway and I’m annoyed enough to skip some instructions, so I:
- open vi
- copy&paste
- compile and run.
The output is OK (after 10 minutes)
But.... our exercise doesn't end here, how can we implement a timer?
- http://download.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html - So what? Search again: java timer example
- http://www.gammelsaeter.com/programming/simple-timer-example-in-java/ - Lots of comments here and there, let’s dig more and land here:
- http://www.java2s.com/Code/Java/Development-Class/UsejavautilTimertoscheduleatasktoexecuteonce5secondshavepassed.htm - It seems better
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!");
System.exit(0);
}
}
public static void main(String args[]) {
new ReminderBeep(3);
}
}
I go to:
- http://www.php.net/ then
- http://www.php.net/downloads.php - Good, I create a the php folder, untar the downloaded file, then
- http://it.php.net/manual/en/
- http://it.php.net/manual/en/tutorial.requirements.php - Hmm, should I install apache and mysql? I don’t need them, now, let’s move on
- http://it.php.net/manual/en/tutorial.firstpage.php - I don’t want to start a web server, is our favourite browser so smart to interpret php code?
- vi hello.php
- a bit of c&p
- open browser on file://......../hello.php it doesn’t work, of course.
- http://it.php.net/manual/en/install.php
- http://it.php.net/manual/en/install.macosx.php - “PHP is bundled with Mac”, wonderful!
- http://it.php.net/manual/en/install.macosx.bundled.php
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:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Now I make a search for a timer on Google: "php timer example"
- http://www.phpclasses.org/browse/file/1379.html - Hmm.
- http://php.net/manual/en/function.time.php (35 mins).
- http://www.daniweb.com/web-development/php/threads/256063 (38 minutes).
- http://www.hotscripts.com/forums/php/126-php-timer.html - Better.
Finally after 43 minutes that’s the simplified timer:
<?php
sleep(3);
echo "wake up<br />";
?>
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.
The usual breadcrumbs:
- http://jashkenas.github.com/coffee-script/
- http://jashkenas.github.com/coffee-script/#installation -The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (2.37 minutes)
- http://nodejs.org/
- http://nodejs.org/#download
- https://github.com/joyent/node/wiki/Installation - No, no, no Mac OSX users also have the option of installing a precompiled package from: https://sites.google.com/site/nodejsmacosx/ that includes npm. Cool!
- Download, install the pkg node.js. - Installed (7.42 minutes)
- 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.
- http://stackoverflow.com/questions/6536725/how-to-exit-coffeescript-repl - The answer is: ctr+d (after 14 mins)
- 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:
http://stackoverflow.com/questions/4917567/coffeescript-timer-and-this-pointer-on-callback - 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
Conclusion
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
Chicken timer by abbey*christine
Installation by zigazou76