Code That Made Me Cry, #CTMMC™

95% of all code makes me cry. The other 5% are white space.

Compressed Code (JavaScript, #41 / 43)

for (var i=0; i<6; i++) {
    var row = document.querySelector("table").insertRow(-1);
    for (var j=0; j<6; j++) {
        var letter = String.fromCharCode("A".charCodeAt(0)+j-1);
        row.insertCell(-1).innerHTML = i&&j 
            ? "<input id='"+ letter+i +"'/>" 
            : i||letter;
    }
}

var DATA={}, INPUTS=[].slice.call(document.querySelectorAll("input"));
INPUTS.forEach(function(elm) {
    elm.onfocus = function(e) {
        e.target.value = localStorage[e.target.id] || "";
    };
    elm.onblur = function(e) {
        localStorage[e.target.id] = e.target.value;
        computeAll();
    };
    var getter = function() {
        var value = localStorage[elm.id] || "";
        if (value.charAt(0) == "=") {
            with (DATA) return eval(value.substring(1));
        } else { 
            return isNaN(parseFloat(value)) ? value : parseFloat(value); 
        }
    };
    Object.defineProperty(DATA, elm.id, {get:getter});
    Object.defineProperty(DATA, elm.id.toLowerCase(), {get:getter});
});
(window.computeAll = function() {
    INPUTS.forEach(function(elm) { 
        try { elm.value = DATA[elm.id]; } 
        catch(e) {} 
    });
})();        

You wouldn't believe that the above piece of JavaScript code is actually a simple implementation of a Spreadsheet where you can use Excel-style formulas. I'm not sure whether this code makes me cry with joy or pain. Don't believe it? Read the full article by Martín Proenza, explaining the code:

Source: http://css.dzone.com/articles/how-read-code-mars-story

comments powered by Disqus

Submit your own Code That Made You Cry

Send us your own example of code that made you cry! Please include:

Send the above to ctmmc@datageekery.com. All accepted submissions will be licensed as CC BY-SA 3.0. Submit only code of a compatible license.

Note that we may choose not to publish some submissions if we feel they're not appropriate. We hope you understand.

Don't let your SQL code make you cry!

Use jOOQ, instead of JDBC.

jOOQ generates Java code from your database and lets you build typesafe SQL queries through its fluent API.

Don't let your SQL code make you cry! Get back in control of your SQL with jOOQ.