switch/case

Wow, what a crazy new syntax, switch. It seems like it is some kind of deeply embedded object in javascript itself – I have no analogues mentally for it. Before I try to explain myself into an incorrect hole (now there’s a strange metaphor..), I will just go ahead and junk out the syntax so I’ve got a record of it.

var varName = prompt("you have a choice of several things here.")

switch(varName) {
    case "first choice":
        // here is where stuff happens as a result of the first choice!
    case "second choice":
        // aaannnnd second choice
    default:
        // everything else goes here if the other cases do not happen

I will poke at this and try to see how to manipulate this in different-than-standard ways. Does it need to be a prompt? I bet it can take an element of a random array. Moving on!

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!

javascript and python’s range()

So in python, you can use a function called range() to (conventionally – I know there are other uses) easily iterate over, yknow, a range of numbers or through a list/array/yaddayadda. It works like this:

for i in range(13): # you can also limit it on the lower bound, a la range(7,13), 
    print i         # but be ye wary of yon fenceepostee

While going through some javascript tutorialling, I found a typical learner problem that I found later that I’d been approaching the wrong way, but if you’ll bear with me & restrain thyself from punching angrily through your computer/rotary telephone, COME WITH ME ON THIS JOURNEY:

For a Rock Paper Scissors game, lesson 11 or 12 of the Functions lesson of Codecademy‘s javascript class, it asks the student to use a randomize function (Math.random()) to call “rock” when the first third of the number, “paper” when the second, and “scissors” when the third. My FIRST thought was to use a range function, like if i in range(.33) and if i in range(.34,.66)! So I tried a couple of different syntactial approaches that seemed javascriptey, they didn’t work, so I went a-googlin’ (how you do) and found the following solution:

Array.apply(null, Array(5)).map(function (_, i) {return i;});
[0,1,2,3,4]

I know I’m new to javascript, but that is honestly barely parseable. I’m not here to wail about things that one language does that another doesn’t, but this was a difference that frustrated me – – until (and you patient few, I know you’ve been waiting for this) I realized that there’s another way to solve this problem! And that’s the beautiful thing about programming, particularly learning different languages. I remember using this syntax in other learning situations, back in the day when I first learned Python. The resolution is to use the (javascript) format of:

if (i < .33) {
    return "computer chose rock";
}
else if (i <= .66) {
    return "computer chose paper";
} else {
    return "computer chose scissors";
}

which looks (save the curly braces, ;, & s/else_if/elif) nearly the same as pythonic syntax.

MORAL OF THE STORY: there are many ways to do many different things! fabulous!

Forever Django

Yessss, I’ve found another giant tutorial that I am so excited about & have heard such good things about. How to Tango with Django! Hooray! Gonna go through it, lesson by lesson, just like LPTHW. I’ve already gone through the official Django Project tutorial a handful of times and have gotten a lot out of it, and I did another one that I’m not crazy about but that explained something that hadn’t been clear.

Oh, and the job? The job is great. I’m orchestrating a bunch of independent projects that all need to come together at the same time, and it’s pretty great to be the one pulling so many of the strings.

Aaahh aaaahhh aaaaaaahhhh I have to go, I will write my first entry on this soon!

EDIT: So I got to page 6! It’s awesome. But I’m going to move on anyway. More in the next post!

Edits to Beachmeals and more with Rinance

I am working on several projects right now, namely a new version of beachmeals as well as two new versions altogether of rinance, a personal finance program fitted to python (pynance already exists, and of course – what a cute name).

Beachmeals is probably where it’s going to stay until I talk some more with a mentor friend of mine, but Rinance is presenting a pretty good challenge to me. The first version, well, it just doesn’t work, ha ha! Looking back I’m not at all happy with what I was trying, there. So a weekish ago, I started over and it’s just top to bottom with a handful of conditionals, in the fixinto branch. Notice the to-do list at the top! The distribution of funds goes ok, but I still can’t quite figure out the importing of the file, turning them all into variables & manipulating them. No hints please! I know it is an easy answer & I’m still working on it 🙂

Because the to-do list in the fixinto branch is enormous, I started a whole new file – I wasn’t happy with the “functional” look of the fixinto branch, so, ha ha! I started over again! this objectish branch now contains a program map and the first piece of that is in there & complete. To get started, the program asks the user if the money'll be going in or out & then sends the user to the appropriate function based on their response. Easy-peasy, coming along!

Jobbed!

just to let y’all know, I have a job! wow! it can actually happen, to go from zero computer knowledge to some (what’s the axiom, “the more I know the more I know I don’t know,” right?) and then BE EMPLOYED is actually possible. seriously, I started with so little. and I have so much more to learn, good god. I want to explore the command line more, as well as security, web frameworks (hello django!), JSON, databases, vim, a different terminal, another linux install, a home server, learn about big people in tech & watch their tutorials & learn, AND maybe even do some tutorials! I don’t know what the tech community NEEDS, but I think it could be handy to find out what kinds of tools are out there to help “level up” from learning Python in whatever essential way most learn it.

Me, I learned Python in IDLE on Windows 7, a program that will get ANYONE up and running in 20 minutes, regardless of operating system. and now I operate nearly everything from the command line in a Linux Ubuntu 12.04 dual-install that I figured out & did myself. I use sublimetext to edit code (and a little bit of nano if it’s something small) and irc to troubleshoot with local coding buddies, and both virtualenv and miniconda to create environments on my machine to play around with. I plan on updating to ubuntu 14.04 in a few days, and the challenge that that will bring.

so! overall message! keep going!!