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

  • SEARCH
  • Home
  • 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 6139275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:58:11+00:00 2026-05-23T17:58:11+00:00

This may not be the correct place for this question, if not feel free

  • 0

This may not be the correct place for this question, if not feel free to move it. I tagged as Delphi/Pascal because it’s what I am working in atm, but this could apply to all programming I guess.

Anyway I am doing some code cleanup and thinking of moving all the strings in my program to a separate single .pas file. Are there any pros and cons to doing this? Is it even worth doing?

To clarify: I mean that I will be creating a separate file, Strings.pas in it I will make all my text string variables.

Ex

Current Code

 Messages.Add('The voucher was NOT sent to ' + sName+
                          ' because the application is in TEST MODE.');
 Messages.Add('Voucher Saved to ' + sFullPath);
 Messages.Add('----------------------------------------------------------');

New Code would be something like:

Messages.Add(sMsgText1 + '' + sName + '' + sMsgText2 + '' + sFullPath)

The Strings.pas file would hold all the string data. Hope that makes better sense

  • 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-23T17:58:12+00:00Added an answer on May 23, 2026 at 5:58 pm

    Moving your strings to a separate file is a good idea! It keeps them together and will let you easily change them if required. Your question doesn’t say you want to be able to translate them, but centralizing will help that to.

    But, code like:

    Messages.Add(sMsgText1 + '' + sName + '' + sMsgText2 + '' + sFullPath)
    

    is not better than code like:

    Messages.Add('The voucher was NOT sent to ' + sName+
                          ' because the application is in TEST MODE.');
    

    You’ve turned a messy but readable function call into a messy and un-readable function call. With the old code (the second snippet just above), you can read the code and see roughly what the message is going to say, because a lot of it is there in text. With the new code, you can’t.

    Second, the reason for moving the strings to to keep related items together and make it easier to change them. What if you want to change the above message so that instead of saying “The file ‘foo’ in path ‘bar’…” it is phrased “The file bar\foo is…”? You can’t: the way the messages are built is still fixed and scattered throughout your code. If you want to change several messages to be formatted the same way, you will need to change lots of individual places.

    This will be even more of a problem if your goal is to translate your messages, since often translation requires rephrasing a message not just translating the components. (You need to change the order of subitems included in your messages, for example – you can’t just assume each language is a phrase-for-phrase in order substitution.)

    Refactor one step further

    I’d suggest instead a more aggressive refactoring of your message code. You’re definitely on the right track when you suggest moving your messages to a separate file. But don’t just move the strings: move the functions as well. Instead of a large number of Messages.Add('...') scattered through your code, find the common subset of messages you create. Many will be very similar. Create a family of functions you can call, so that all similar messages are implemented with a single function, and if you need to change the phrasing for them, you can do it in a single spot.

    For example, instead of:

    Messages.Add('The file ' + sFile + ' in ' + sPath + ' was not found.');
    ... and elsewhere:
    Messages.Add('The file ' + sFileName + ' in ' + sURL + ' was not found.');
    

    have a single function:

    Messages.ItemNotFound(sFile, sPath);
    ...
    Messages.ItemNotFound(sFileName, sURL);
    

    You get:

    • Centralized message strings
    • Centralized message functions
    • Less code duplication
    • Cleaner code (no assembling of strings in a function call, just parameters)
    • Easier to translate – provide an alternate implementation of the functions (don’t forget that just translating the substrings may not be enough, you often need to be able to alter the phrasing substantially.)
    • Clear descriptions of what the message is in the function name, such as ItemNotFount(item, path), which leads to
    • Clearer code when you’re reading it

    Sounds good to me 🙂

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

Sidebar

Related Questions

I may not be asking this in the correct place, but is there somewhere
This may not be the correct way to use controllers, but I did notice
This may not be a programming question, but I don't know where to ask
This may not be the kind of question one should ask on StackOverflow, but
Sorry, this may or may not be a programming question directly, but I am
This question may not directly relate to programming. I have noticed that the technology
This may be a silly question to a graphics guru (which I am not),
This may sound like a stupid question but I'm a beginner not just to
This may seem an easy question, but not to me, also a search has
If this is not posted in correct place, please migrate it I kept a

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.