While I while away the javascrours

This post is mostly reference, with some thoughts on structure at the end!

Pythonic

while i < 3:
    print "still less than three!"
    i = i + 1                       # i += 1

Javascripture

var i = 0;

var whileloopfunction = function (counter) {
    while (i < counter) {
        console.log("a way more complicated way to do this, it seems!");
        i++;
    }
}

whileloopfunction(3)

Not sure exactly how to simplify this. The reason that I’ve made the parameter counter is because it seems that I must create a function with a parameter so that it can be called.

Ah – I just tried it taking the counter param out altogether and made the while loop’s condition (i < 3), calling whileloopfunction() with no argument and it works just fine. Experimentation! Sliiiightly simpler than previously, though it was a good lesson all the same.

This is looking so much to me like a simplified object, at least, simplified from the perspective of Python. This statement may confuse people – after all, Python is a more human-readable language, right? Well, its objects are a mess if you ask me, though the rest of it is lovely. I was once told that you start to really understand OOP when you learn a second OOP language. I think that is becoming true. What a relief – it's been frustrating not knowing.

Ah, one last thing – I'm pleased to present these posts to you, now written in Markdown instead of the hammer-where-you-need-a-toothpick html formatting! Thanks, WordPress!

Advertisements

2 thoughts on “While I while away the javascrours

  1. As far as I am aware, you don’t need the wrapping function in JS either. You can just write the while loop bare and it will work fine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s