1. #1
    Ext User papasi's Avatar
    Join Date
    Mar 2007
    Posts
    129
    Vote Rating
    0
    papasi is on a distinguished road

      0  

    Default Closure coding convention suggestion

    Closure coding convention suggestion


    Hi Jack,

    I'm certainly not as productive / good as you are (that's an overstatement, I'm way way less productive than you are) but while reading your code there are certain things I wish you'd have done that will make life much easier for the reader.

    In many occassion you'd use a closure to protect the local variables when you define a top level objects

    For instance while I was reading EventManager.js

    at the beginning I see

    Code:
    Ext.EventManager = function(){
     .............
     600 lines below
    }
    At first glance I was thinking that this

    Code:
    function(){...}
    is the constructor of Ext.EventManager.

    Not until I see something like
    Code:
    var pub = {.........}
    I start to feel strange and then at at line 321 I see

    Code:
    return pub;
    Of course at line 322 we can cleanly see that it is a closure.

    Code:
    }();

    So my humble opinion is that if we wrap the function{} literal in parenthesis then it would be very clear from the start that it is not a constructor but a closure.

    So instead of

    Code:
    function() {
    ......
    600 lines
    ......
    }();
    this would be much easier to read.

    Code:
    (function() {
    ......
    600 lines
    ......
    })();
    I hope this makes sense. Maybe 10 years later this will help you pickup ext1.0 again faster :-)

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Considering how I am constantly trying to trim bytes, adding extra ones that serve no purpose doesn't look too appealing. At the top of the file and in the docs it is defined with @singleton (right before the closure starts) which should signal for you that it is a closure (since it can't be a constructor).

Similar Threads

  1. new namespace convention
    By sjivan in forum Community Discussion
    Replies: 8
    Last Post: 29 Jan 2007, 6:44 PM
  2. This is horrible coding I am sure
    By JohnT in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 22 Jan 2007, 1:03 PM
  3. Fighting Convention
    By hunkybill in forum Sencha Cmd
    Replies: 1
    Last Post: 6 Dec 2006, 8:36 AM
  4. Coding for YUI/YUI-EXT in PHP
    By sycophant in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 26 Nov 2006, 5:12 AM
  5. HTML coding
    By Compugasm in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 7 Nov 2006, 3:50 PM

Thread Participants: 1