Monday, August 13, 2012

Comparing Syntax

At this time, I see some similarities between coffeescript syntax and ruby syntax. Here's an example...

I created a script,
name = "jim"
greet = "Hello #{name}"

console.log greet

Running this on my terminal...
$ coffee

Hello jim

To see how the file comes out into javascript, I do...
$coffee -p
...and I get...

(function() {
  var greet, name;
  name = "jim";
  greet = "Hello " + name;

If I were to write into ruby, the script will come out like...
def greet
  name = "jim"
  greet = puts "Hello #{name}"


See what I'm doing here?

I am teaching myself web development using ruby. At this time, I am learning Sinatra and now have a simple blog up running in heroku. So that I can spiffy up that blog, I am learning html5, css (SASS, or LESS), and javascript via coffeescript.

I am intimidated to learn javascript as is. I got spoiled with ruby syntax. I don't want to bore myself having to learn js with all those curly braces and semi-colons. As a workaround, I am teaching myself javascript by way of coffeescript, which, I think, is similar to ruby.

No comments:

Post a Comment