Code consolidation vs complexity
<p>I have certain modules which handle user actions - they are Control Modules.  There were 6, Now there are 5 as I consolidated 2 which were very similar into a Module called Control</p>

<p>What I noticed is that as I consolidate similar code....it becomes a tad bit less efficient.  For example in Control I now have an extra logical statement to determine program flow.</p>

<pre><code>if( this.type === 'signup' &amp;&amp; !this.text_object.checkPattern( 'name' ) )
</code></pre>

<p>This simple line allowed me to combine ControlSignIn and ControlSignUp as the only difference was checking the name in Sign Up which Sign In did not have.</p>

<p>I can continue in this manner and I get more complex code but my code footprint is smaller.  </p>

<p>There is a trade-off between ( complexity and run time ) vs ( code foot print ).</p>

<p>I'm guessing it does not matter but I just wanted to make sure.</p>

<p>As an example I put in <code>ControlTweet</code> which I could also fit to <code>Control.</code></p>

<p>Question?</p>

<p>Should I consolidate ControlTweet with Control?</p>

<p>In general, where do you draw the line or is it a matter of preference?</p>

<p><strong>Control</strong></p>

<pre><code>/**
 *Control - receives incoming requests for client use
 */

var Control = ( function () 
{
    var Control = function ( type )
    {
        this.TIME = 4000;
        this.type = type;
        this.form_element = document.getElementById( type ), 
        this.response_element = document.getElementById( type + '_response' );

        this.text_object = new TextValidator( this.form_element ),
        this.message_object = new Message( this.response_element ),
        this.effects_object= new Effects( this.response_element );
    };
    Control.prototype.invoke = function( ) 
    {
        if( Global.validate_input_on === 1 )
        {
            if( !this.text_object.checkEmpty() ) 
            {
                this.message_object.display( 'empty' );
                this.effects_object.fade( 'down', this.TIME );
                return false;
            }
            if( this.type === 'signup' &amp;&amp; !this.text_object.checkPattern( 'name' ) ) 
            {
                this.message_object.display( 'name' );
                this.effects_object.fade( 'down', this.TIME );
                return false;
            }
            if( !this.text_object.checkPattern( 'email' ) ) 
            {
                this.message_object.display( 'email' );
                this.effects_object.fade( 'down', this.TIME );
                return false;
            }
            if( !this.text_object.checkPattern( 'pass' ) ) 
            {
                this.message_object.display( 'pass' );
                this.effects_object.fade( 'down', this.TIME );
                return false;
           }
        }
        var response_element = this.response_element;
        new Ajax().invoke( serializeArray( this.form_element ) + '&amp;ajax_type=' + this.type + '_control', function( server_response_text ) { ajaxType( server_response_text, response_element, 'respond' ); } );
    };
    Control.in = function()
    {
        new Control( 'signin' ).invoke();
    };
    Control.up = function()
    {
        new Control( 'signup' ).invoke();
    };
    Control.out = function()
    {
        new Ajax().invoke( '&amp;ajax_type=ControlSignOut', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
    };
    Control.try = function()
    {
        new Ajax().invoke( '&amp;ajax_type=ControlTryIt', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
    };
    return Control;
} () );
</code></pre>

<p><strong>ControlTweet</strong></p>

<pre><code>/**
 *    ControlTweet
 */

function interfaceTweet()
{
    var fill_element = document.getElementById( 'tweet_fill' ),
        form_element = document.getElementById( 'tweet' ),
        response_element = document.getElementById( 'tweet_response' );

    var text_object = new TextValidator( form_element ),
        message_object = new Message( response_element ),
        effects_object = new Effects( response_element );

    if( Global.validate_input_on === 1 )
    {
        if( !text_object.checkEmpty() ) 
        {
            message_object.display( 'empty' );
            effects_object.fade( 'down', 4000 );
            return;
        }

        if( !text_object.checkPattern( 'tweet' ) ) 
        {
            message_object.display( 'tweet' );
            effects_object.fade( 'down', 4000 );
            return;
        }
    }
    new Ajax().invoke( serializeArray( form_element ) + '&amp;ajax_type=ControlTweet_add', function( server_response_text ) { ajaxType( server_response_text, response_element, 'tweet', fill_element ); } );
}
</code></pre>

<p><strong>What I ended up using:</strong></p>

<pre><code>/**
 *Control - receives incoming requests for client use
 */

var Control = ( function () 
{
    var Control = function ( type )
    {
        this.TIME = 4000;
        this.type = type;

        this.form_element = document.getElementById( type ), 
        this.response_element = document.getElementById( type + '_response' );
        if( type === 'tweet' ) { this.fill_element = document.getElementById( type + '_fill' ); }

        this.text_object = new TextValidator( this.form_element ),
        this.message_object = new Message( this.response_element ),
        this.effects_object= new Effects( this.response_element );
    };
    Control.prototype.invoke = function( ) 
    {
        if( Global.validate_input_on === 1 )
        {
            if( !this.text_object.checkEmpty() ) 
            {
                this.message_object.display( 'empty' );
                this.effects_object.fade( 'down', this.TIME );
                return false;
            }
            switch( this.type )
            {
                case 'signin':
                    if( !this.text_object.checkPattern( 'email' ) ) 
                    {
                        this.message_object.display( 'email' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    if( !this.text_object.checkPattern( 'pass' ) ) 
                    {
                        this.message_object.display( 'pass' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    break;
                case 'signup':
                    if( !this.text_object.checkPattern( 'email' ) ) 
                    {
                        this.message_object.display( 'email' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    if( !this.text_object.checkPattern( 'name' ) ) 
                    {
                        this.message_object.display( 'name' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    if( !this.text_object.checkPattern( 'pass' ) ) 
                    {
                        this.message_object.display( 'pass' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    break;
                case 'tweet':
                    if( !this.text_object.checkPattern( 'tweet' ) ) 
                    {
                        this.message_object.display( 'tweet' );
                        this.effects_object.fade( 'down', this.TIME );
                        return false;
                    }
                    break;
                default:
            }
        }
        var response_element = this.response_element;
        if( this.type === 'tweet' ) { var fill_element = this.fill_element; }
        new Ajax().invoke( serializeArray( this.form_element ) + '&amp;ajax_type=' + this.type + '_control', function( server_response_text ) { ajaxType( server_response_text, response_element, 'respond', fill_element ); } );
    };
    Control.tweet = function()
    {
        new Control( 'tweet' ).invoke();
    }
    Control.in = function()
    {
        new Control( 'signin' ).invoke();
    };
    Control.up = function()
    {
        new Control( 'signup' ).invoke();
    };
    Control.out = function()
    {
        new Ajax().invoke( '&amp;ajax_type=ControlSignOut', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
    };
    Control.try = function()
    {
        new Ajax().invoke( '&amp;ajax_type=ControlTryIt', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
    };
    Control.bookmarkDelete = function( event_pull )
    {
        event_pull.preventDefault();
        domBookmarkDelete( this );
        new Ajax().invoke( encodeURIComponent( this.name ) + "=" + encodeURIComponent( this.innerHTML ) + '&amp;ajax_type=ControlBookmark_delete', function( ) { } );
    }
    return Control;
} () );
</code></pre>
