count it off!

Things that don’t change

Deadlines and Deliverables, in or out of college, that shit always means crunch time. I think I’ve worked 40 hrs in the last 3 days easily.

So much coding…

Leveraging Higher Order Functions in Javascript

I swear I’ll try to make this as clear and straight forward to understand.
So let’s say you have a list of objects that you want to traverse

list = ["John", "Mary", "Joe", "Jenny", "Jack", "Manny", "Jose"];

And maybe you want to do something neat with each element, something that’s similar but different in once place and now you’re like “hmm…do I copy paste or, idk there should be a way to make this better…”

    $.each(list, function(index, value) {
       console.log(value+" sucks");
    //Hmmm, now I wanna say they rock..., or other various things
    //Do I really have to write my function over again?
    $.each(list, function(index, value) {
       console.log(value+" rocks");
    //This is getting repetitive, and my code is getting long, sad times

Well there is another way, you could use a higher order function. Wouldn’t it be nice if you could say something like this

    var do_this = function (opinion, index, value) {
       console.log(value+" "+opinion);
    $.each(list, do_this("sucks"));
    //AwesomeTimes...if it worked...sad times

And you know, just have jQuery know that you’re trying to fill in only the first argument. Well you’re most of the way there, some languages will know wtf you’re trying to do and be like AwesomeSauce, and work, Javascript needs a bit of a hint, so this is the “work-around” to trigger something like this.

The reason this fails is because it will try to use do_this(“sucks”) return value’s call method, and what does it return? Nothing. So lets give it something, we’re almost all the way there, what if that function is super fucking long? it’s worth the extra effort. So lets revise our code

    var do_this = function(opinion) {
          return function (index, value) {
             console.log("object at index "+index+" "+value+" "+opinion);
    $.each(list.slice(0,2), do_this("sucks"));
    $.each(list.slice(2,5), do_this("rocks"));
    $.each(list.slice(5,list.length), do_this("I dont know"));

and there we go! So if ever someone’s being an esoteric dick to you about how awesome languages that treat functions as first class citizens are and how Haskell is the most awesome language ever — this is the kinda shit they’re talking about, and function currying, and other sexy awesome stuff that Haskell does.

BUT since we have to live in the real world, and work on real systems, this will save you some REAL headaches. Hope this was helpful.

No, Comrade. Java is the opiate of the corporate bourgeoisie. In the glorious developer paradise, there will be no Java. Only efficient Ruby code.

So I’m a peculiar developer in that most people that deal with software development are good at using new tech — I’m not if I didn’t build the software. As such I’m now making an effort to use new features in new tech.

Anyway here’s a vid made using the 5s.

The future is now

So I’ve gone into this habit of using Fringe technology as if it had been established, like a full and a wholehearted embracement of the technology, in order to sort of be able to gain an understanding of where things are going and something I’ve tried recently and actually works surprisingly well is dictated posts that I then sign with dictated but not read—Siri