RSS
 

Archive for the ‘Programming’ Category

Most Hated Programming Languages on Hacker News

11 Oct

From the recent poll on Hacker News “Poll: What are your liked and disliked programming languages?” I compiled a list of all the programming languages ordered by the percentage of their dislike votes. Cobol & Coldfusion are the two most hated languages with 94% dislikes. C & Python still gets a lot of love as the two most liked languages. I find it strange that my favorite language Ruby is not even in the top 15 most liked. Most Rubyists believe Ruby is the best scripting language to ever run on a computer, but 38% of these votes don’t agree, Ruby and Javascript are tied at 38% dislikes.

Complete list (Ordered by Percentage of Dislike votes:
Cobol – 94%
Coldfusion – 94%
Visual Basic – 88%
actionscript – 82%
PHP – 76%
Rexx – 72%
Groovy – 69%
Fortran – 67%
Java – 67%
Tcl – 64%
Perl – 61%
Delphi – 60%
C++ – 58%
Objective-C – 58%
CoffeeScript – 55%
Pascal – 48%
ada – 47%
R – 45%
Shell – 44%
D – 39%
Other – 39%
JavaScript – 38%
Ruby – 38%
Scala – 38%
Forth – 31%
Smalltalk – 30%
Assembly – 29%
C# – 29%
SQL – 28%
Ocaml – 27%
F# – 27%
Go – 24%
Erlang – 23%
Clojure – 21%
Rust – 21%
Haskell – 20%
Lisp – 18%
Lua – 16%
Scheme – 15%
Python – 13%
C – 12%

 
 

Ruby Class Variables in the main context

05 Sep

Since ruby class variables belong to the class hierarchy, all objects in that class hierarchy all the way up to ruby’s main object, share the same class variable. This could lead to unexpected behavior, especially since the class variable can be modified in the main context. See below modifying @@name in the main context changes its value on all objects.

class Cat
end
 
class Tiger < Cat
  def me
    @@name = 'tiger'
  end
 
  def show
    @@name
  end
end
 
tiger = Tiger.new
 
tiger.me
#=> "tiger"
 
tiger.show
#=> "tiger" 
 
class Cat
  def me
    @@name = 'cat'
  end
 
  def show
    @@name
  end 
end
 
cat = Cat.new
 
cat.me
#=> "cat" 
 
cat.show
#=> "cat"
 
tiger.show
#=> "cat"
 
@@name = 'animal'
#=> "animal" 
 
cat.show
#=> "animal"
 
tiger.show
#=> "animal"
 
 

Coffeescript Cheatsheet for JQuery

02 Sep


Corrections and suggestions are welcome.

 
 

More readable Javascript code

30 Aug
// BAD
$( document ).ready(function() {
 
    $( "#magic" ).click(function( event ) {
        $( "#yayeffects" ).slideUp(function() {
            // ...
        });
    });
 
    $( "#happiness" ).load( url + " #unicorns", function() {
        // ...
    });
 
});
 
// BETTER
var PI = {
 
    onReady: function() {
        $( "#magic" ).click( PI.candyMtn );
        $( "#happiness" ).load( PI.url + " #unicorns", PI.unicornCb );
    },
 
    candyMtn: function( event ) {
        $( "#yayeffects" ).slideUp( PI.slideCb );
    },
 
    slideCb: function() { ... },
 
    unicornCb: function() { ... }
 
};
 
$( document ).ready( PI.onReady );

Source:http://learn.jquery.com/code-organization/beware-anonymous-functions/

 
 

gem install worldpeace

06 Aug

What’s the one gem you wish existed but doesn’t?

https://rubygems.org/search?utf8=%E2%9C%93&query=worldpeace

 
 

Could Dancing Have an Algorithm

13 Jun

This Choreography qualifies as a technical post. I really want to tag it as programming.

Source: https://www.youtube.com/watch?v=HHwVfO1hvs0

 

Tear-able cloth in Javascript

23 Apr

Awesome effect with no proprietary plugin, no flash, java applet, or silverlight, just HTML,CSS & javascript.

Check out this Pen!


Source: http://codepen.io/stuffit/pen/KrAwx
And HN thread here: https://news.ycombinator.com/item?id=5592679

 
 

Invalid JSON in CouchDB

03 Dec

I recently upgraded from Ubuntu 12.04 to 12.10 and Ubuntu automatically upgraded my CouchDB installation from 1.0.1 to 1.2.0. After the upgrade I started getting the error message “Bad request… Invalid JSON” anytime I try to add or query an existing design document.

A lot my code depends on CouchDB so this was a big deal, after hours of googling, still no solution until I found the JSONlint test. I realized that the old JSON parser in CouchDB 1.0.1 would parse invalid JSON with no problems but the parser in CouchDB 1.2.0 would throw an error.

This code below is invalid JSON but works fine on CouchDB 1.0.1. It will throw the ‘Invalid JSON’ error on CouchDB 1.2.0

{
 "language" : "javascript",
 "views" :{
   "age" : {
     "map" : "function(doc){
        if(doc.age)
          emit(doc.age,doc);
       }"
    }
 }
}

To work on CouchDB 1.2.0 it has to be valid JSON like the code below

{
    "language": "javascript",
    "views": {
        "age": {
            "map": "function(doc){ if(doc.age) emit(doc.age,doc); }"
        }
    }
}

This small change fixes the problem. You can always test your JSON for validity here: jsonlint.com.

 
 

JavaScript: 2011 Technology of the Year

01 Feb

JavaScript had a great year in 2011. Here are some of the best moments for JavaScript last year, in no particular order:

-Adobe killed Flash on mobile devices and will start the transition of their web technologies to HTML5/CSS/JavaScript here.

-Microsoft killed Silverlight as their cross platform runtime environment to focus on HTML5/CSS/JavaScript here.

-Microsoft announced that “metro style” apps for Windows 8 will be built in JavaScript/CSS/HTML. More about it here.

-Adobe acquired Nitobi (Creator of PhoneGap), and donated PhoneGap to Apache Foundation. This move could make  PhoneGap a standard for mobile development here.

-Rails 3.1 adopted CoffeeScript causing great controversy and the most colorful Github page ever here.

-There was always a cool new JavaScript project on the first page of Hacker News. Here’s some of the best I remember:

J-OS – JavaScript operating system

JS Linux – Boot a Linux kernel right in the browser.

Broadway.js – H264 decoder in JavaScript.

pdf.js – PDF reader in JavaScript.

JavaScript IDE- Create web apps in JavaScript right from your browser.

There you have it and jQuery was everywhere. I write this as a Ruby/Unix guy, who thinks JavaScript had an extra-ordinarily great year. I may have missed other important moments. Feel free to add more in the comments.

It’s equally important to give credit to the players that helped make JavaScript the Technology of the Year. I will list them below:

  •  The Open Source community:  For all the awesome  wizardry.
  • Google: For moving the open web forward, supporting the FOSS community and releasing great open source technologies like Google Chrome and V8.
  • The Webkit Open Source project and Apple.
  •  Steve Jobs for excluding Flash on iDevices and selling HTML5 as the future of the open web.


Let’s have a toast for JavaScript.
 

Hey programmer, what is it that you do?

01 Dec

Sometimes, I simply can’t put a price on what I do.

Two years ago, I was kidnapped by monkeys, who appeared to be in a trance. They took me to the top of the Swayambhunath Buddhist complex, in Kathmandu. I was told that this was the Monkey Temple. As a monk translated the wishes of the holy monkeys, I discovered that I was required to rewrite the OS of their ancient computer, which had failed to reboot, back in 1839. Since then, they had searched the world for a programmer competent to handle the situation. They were about to give up, as they stumbled onto me, and realized that I was the reincarnation of ChiChu Gomptar, the lead programmer for the CS monkey gang, which had served their monkey king, the creator of this computer. I was flummoxed by its design, as it was made of smooth stones, uniform beads, colored sand, and wooden levers inlaid with gold. I told them that I couldn’t remember anything from my past life. They gave me something to smoke, saying that it would connect me, through the eternal ether, to my previous memories.

It did, and after 25 days of extreme programming, of which I recall no details, I had completed the monumental task. I stood up, and ceremoniously dropped the special IPL bead onto the machine, which then awoke from its 170-year slumber with a mighty roar. The holy monkeys were pleased. They handed over a small golden box, with mysterious carvings. It seemed empty, and I was told not to open it unless my circumstances had become truly dire. I thanked them, both for the box, and for the tremendous experience. Unfortunately, I was not able to sell them continued maintenance for their new OS, but that was mostly due to their language not having the word “maintenance”. Anyway, I have those memories, and this box to use when things go really bad, plus the always-present hope of future adventure.

This was a comment on hacker news. Original source: http://news.ycombinator.com/item?id=3146786

 
 
Premium Wordpress Plugin