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 884081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:41:56+00:00 2026-05-15T12:41:56+00:00

An Example Suppose we have a text to write and could be converted to

  • 0

An Example

Suppose we have a text to write and could be converted to “uppercase or lowercase”, and can be printed “at left, center or right”.

Specific case implementation (too many functions)

writeInUpperCaseAndCentered(char *str){//..}
writeInLowerCaseAndCentered(char *str){//..}
writeInUpperCaseAndLeft(char *str){//..}
and so on...

vs

Many Argument function (bad readability and even hard to code without a nice autocompletion IDE)

write( char *str , int toUpper, int centered ){//..}

vs

Context dependent (hard to reuse, hard to code, use of ugly globals, and sometimes even impossible to “detect” a context)

writeComplex (char *str)
{    
    // analize str and perhaps some global variables and 
    // (under who knows what rules) put it center/left/right and upper/lowercase
}

And perhaps there are others options..(and are welcome)

The question is:

Is there is any good practice or experience/academic advice for this (recurrent) trilemma ?

EDIT:

What I usually do is to combine “specific case” implementation, with an internal (I mean not in header) general common many-argument function, implementing only used cases, and hiding the ugly code, but I don’t know if there is a better way that I don’t know. This kind of things make me realize of why OOP was invented.

  • 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-15T12:41:57+00:00Added an answer on May 15, 2026 at 12:41 pm

    I’d avoid your first option because as you say the number of function you end up having to implement (though possibly only as macros) can grow out of control. The count doubles when you decide to add italic support, and doubles again for underline.

    I’d probably avoid the second option as well. Againg consider what happens when you find it necessary to add support for italics or underlines. Now you need to add another parameter to the function, find all of the cases where you called the function and updated those calls. In short, anoying, though once again you could probably simplify the process with appropriate use of macros.

    That leaves the third option. You can actually get some of the benefits of the other alternatives with this using bitflags. For example

    #define WRITE_FORMAT_LEFT   1
    #define WRITE_FORMAT_RIGHT  2
    #define WRITE_FORMAT_CENTER 4
    #define WRITE_FORMAT_BOLD   8
    #define WRITE_FORMAT_ITALIC 16
    ....
    write(char *string, unsigned int format)
    {
      if (format & WRITE_FORMAT_LEFT)
      {
         // write left
      }
    
      ...
    }
    

    EDIT: To answer Greg S.

    I think that the biggest improvement is that it means that if I decide, at this point, to add support for underlined text I it takes two steps

    1. Add #define WRITE_FORMAT_UNDERLINE 32 to the header
    2. Add the support for underlines in write().

    At this point it can call write(…, … | WRITE_FORMAT_UNLDERINE) where ever I like. More to the point I don’t need to modify pre-existing calls to write, which I would have to do if I added a parameter to its signature.

    Another potential benefit is that it allows you do something like the following:

    #define WRITE_ALERT_FORMAT  (WRITE_FORMAT_CENTER | \
                                 WRITE_FORMAT_BOLD |   \
                                 WRITE_FORMAT_ITALIC)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several delimiters. For example {del1, del2, del3 }. Suppose I have text
For example suppose I have the following two functions function a(param1) { console.log(param1); }
For example suppose I have the following app.get('/', function(req, res) { var ip; if(req.headers['x-forwarded-for']){
How to create jinternalframes who's action depends on each other? example suppose i have
For example suppose client side I have a JavaScript function function getLocation() { var
Suppose I have a example.php file like that: <p> <?php echo _('Hello world') ?>
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
Suppose I have a page located at www.example.com/foo , and it contains an <iframe>
Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')

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.