This week focuses on the Script that is Java. To tell you the truth, I wasn't a big JavaScript fan at first. It's grammer is more strict. You have to throw semi-colons around all over the end of lines like they're periods and your English teacher is watching. You ask Google questions, and those plentiful Stack Exchange articles that give you the answer to any Ruby question are sparser and farther between.
That being said, with restriction also comes creativity. Pretty much anything that can be built in Ruby can be built in JavaScript, it just has to be built differently. And there are also a few unique JavaScript methods that are pretty cool. For example, in Ruby to have a loop add 1 to an element or object you would do something like:
ruby_object += 1
With JavaScript, you can do:
javascript_object += 1
But you can also do
javascript_object++
Boom!
In general, though, JavaScript is the stricter language. To print something to the console, for example, in Ruby you can use
print
Or:
puts
Or my favourite,
p
In JavaScript you only have one option:
console.log()
Another Ruby benefit is called syntactic sugar. Syntactic sugar is basically a programming language giving you some leeway in the way you write the program to make it look "sweeter" or more easily interpretable (yes, that's a word, I just checked.) For example, you might want to make x equal to 1, so you could write:
x = 1
Ruby understands this as:
x=1
But lets you add spaces to make the code easier to read and better organized. With JavaScript there is a lot less sugar.
What it lacks in sweetness, though, it does make up for in versatility. It's kind of ironic that the language that affords less freedom is so versatile, certainly a black mark for capitalism, but it's true. You can implement JavaScript scripts into your HTML by simply opening a script tab. You cannot do the same for Ruby, although that would be awesome if you could.
My next goal is to try to publish a game that I wrote in JavaScript onto my website. I wasn't happy about writing this game in JavaScript instead of Ruby, but if I had written it in Ruby I wouldn't be able to share it online as easily. As the programming messiah said, give onto Ruby what is Ruby's, and give on to JavaScript what is JavaScript's. Amen.
That's it for this week, folks! Tune in next week - same Bat Time, same Bat URL.