Archiv

Archiv für Oktober, 2009

Naming of Classes, Methods and Member Variables

18. Oktober 2009 Keine Kommentare

This article is not about syntax style. It’s only about right naming of classes, their methods and their member variables. Because there’s nothing better for other programmer (ie. like me) to see a constant name schema.

General Provisions

  • leave out articles like ‘a’ and ‘the’ – these are totally unnecessary (TheCar)
  • don’t use ‘my’ in the name – it’s not yours (myVar, MyClass)

Classes

  • try to use a noun or a short phrase with a noun (Tree, SubTree)
  • always use singular instead of plural
  • avoid imperatively ‘object’ in class names – classes are not a objects. You can find bad examples everywhere: stdObject, ArryObject, Zend_Date_DateObject

Methods

  • the name should simply describe what does the method do
  • try to use a verb or verb with a noun, like save(), build(), getTitle()

Member Variables

  • if type of boolean, then prepend ‘is’
  • avoid variables like ‘x’, ‘i’ – use for example ‘index’

jCharacterfall

15. Oktober 2009 Keine Kommentare

This is the first article of my new section “javascript/hacking”.

Firefox and and the Firebug add-on are required for the most scripts, I will post from time to time.

First go to this site http://demo.marcofolio.net/jcharacterfall/, put the code at the bottom in the console and run it. Then start the game.

Have much fun!

$(function () {
    var still = [];
    var $document = $(document);

    window.setInterval(function () {
        var $drop = $('#waterfall .fallingchar:last-child');
        var id = $drop.attr('id');

        if ($drop.length !== 1 || $.inArray(id, still) !== -1) {
            return true;
        }

        var letter = $.trim($('p', $drop).text());

        $document.trigger({
            type: 'keydown',
            keyCode: String.charCodeAt(letter)
        });

        still.push(id);
    }, 1);
});
Kategorienhacking