Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:44+00:00 2026-05-28T00:11:44+00:00

This is a common occurence when I code…I see some code that looks kind

  • 0

This is a common occurence when I code…I see some code that looks kind of alike..and I know that it is obviously not good to have redundant functionality in my code.

However , is this absolute? 0 Redundancy? I have two functions below, which look kind of alike. ViewH.bookmark and ViewH.tweet.

I’m trying to decide if I should pull out the common functionality into a function called ViewH.mark().

EDIT

var ViewH = {
    MARK: 
    {
        FIELD:      '|',
        ROW:        '||',
        PASS:       '<xx_p>',
        FAIL:       '<xx_f>'
    },
    return_string:  '',
    mark: function(passed_function, embeddedAml)
    {
        var return_string,
            first_split, 
            element_count, 
            second_split;

        return_string = '';
        first_split = embeddedAml.split( ViewH.MARK.ROW );
        for( element_count=0; element_count < first_split.length; element_count++)
        {
            second_split = first_split[element_count].split( ViewH.MARK.FIELD );
            passed_function(second_split);
        }
        return ViewH.return_string;
    },
    bookmark: function ( embeddedAml ) 
    {
        ViewH.return_string='';
        return ViewH.mark(ViewH.bookmark_inner, embeddedAml);
    },
    tweet: function ( embeddedAml ) 
    {
        ViewH.return_string='';
        return ViewH.mark(ViewH.tweet_inner, embeddedAml);
    },
    portfolio: function ( embeddedAml ) 
    {
        ViewH.return_string='';
        return ViewH.mark(ViewH.portfolio_inner, embeddedAml);
    },
    bookmark_inner: function ( second_split )
    {
        ViewH.return_string = ViewH.return_string 
        + '<img name="bo_im" class="c" src="'
        + 'http://www.google.com/s2/favicons?domain=' 
        + second_split[0] 
        + '" onerror="Arc.BookmarkError(this)"><a target="_blank" name="bookmark_link" class="b" href = "' 
        + second_split[1] 
        + '">' 
        + second_split[2] 
        + '</a>';
    },
    tweet_inner: function ( second_split )
    {
        ViewH.return_string = ViewH.return_string 
        + '<div class="Bb2b"><img class="a" src="' 
        + Constant.PICTURES + second_split[ 0 ] 
        + '.jpg" alt=""/><a class="a" href="javascript:void(0)\">' 
        + second_split[ 1 ]  
        + ' posted ' 
        + ViewH.pretty( second_split[ 2 ],second_split[ 3 ] ) 
        + '</a><br/><p class="c">' 
        + second_split[ 4 ] 
        + '</p></div>';
    },
    portfolio_inner: function ( second_split )
    {
        if( ( second_split[ 1 ] === 'docx' ) || ( second_split[ 1 ] === 'xlsx' ) )
        {   
            ViewH.return_string = ViewH.return_string 
            + '<img name="bo_im" class="c" src="' 
            + Constant.IMAGES + second_split[1] 
            + '.ico"><a target="_blank" name="bookmark_link" class="b" href = "/' 
            + Constant.ROOT 
            + second_split[1] 
            + '/' 
            + second_split[0] 
            + '.' 
            + second_split[1] 
            + '">' 
            + second_split[0] 
            + '.' 
            + second_split[1] 
            + '</a>';
        }
        else
        {
            ViewH.return_string=ViewH.return_string 
            + '<simg name="bo_im" class="c" src="' 
            + Constant.IMAGES 
            + 'generic' 
            + '.ico"><a target="_blank" name="bookmark_link" class="b" href = "' 
            + Constant.TEXT 
            + second_split[0] 
            + '.txt">' 
            + second_split[0] 
            + '.' 
            + second_split[1] 
            + '</a>';
        }
    },
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:11:44+00:00Added an answer on May 28, 2026 at 12:11 am

    This is a great question, but there is no answer that will apply to all cases. It really is going to depend on what your code looks like. Redundancy is generally to be avoided but it is sometimes worse to over-engineer your code and try to make it fit into a box that it does not really fit into.

    In your case you could definitely benefit from taking common code and pulling it into a common method. It looks like the only difference between your methods is the rendering part and it would be simple to pass a rendering function into your “mark” method.

    Your “mark” method would look a bit like this:

    mark: function(embeddedAml, renderer) {
        var return_string,
            first_split, 
            element_count, 
            second_split;
    
        return_string = '';
        first_split = embeddedAml.split( ViewH.MARK.ROW );
    
        for( element_count=0; element_count < first_split.length; element_count++)
        {
            second_split = first_split[element_count].split( ViewH.MARK.FIELD );
            return_string = return_string + renderer(second_split);
        }
    
        return return_string;
    }
    

    You would keep your bookmark and tweet methods but they would change as well:

    bookmark: function (embeddedAml) {
        return this.mark(embeddedAml, function(data) {
            return '<img name="bo_im" class="c" src="' + 
            'http://www.google.com/s2/favicons?domain=' +
            data[0] + 
            '" onerror="Arc.BookmarkError(this)"><a target="_blank" name="bookmark_link" class="b" href = "' +
            data[1] + '">' + 
            data[2] + '</a>'
        });
    }
    

    Now your rendering code (the only code that was different) is controlled independently, but the code that overlapped is in a common place and if it changes you only have to update it in one place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have this common scenario where we have a method that performs some action
I know this is a common convention, but what does the k in variable
I know this is a common error, but bear with me. I've pursued the
Perhaps I'm missing something simple, as I believe that this is a common scenario...
I would love some help on a particular design. This is the code I
Ok, consider this common idiom that most of us have used many times (I
I am aware that questions about recurring events are common but I have not
I was wondering if this common IDE feature is available. Suppose I open many
In Bash I can create a map (hashtable) with this common construction hput() {
I'm taking over a project and wanted to understand if this is common practice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.