delphi - Strings in a separate .pas file -



delphi - Strings in a separate .pas file -

this may not right place question, if not sense free move it. tagged delphi/pascal because it's working in atm, apply programming guess.

anyway doing code cleanup , thinking of moving strings in programme separate single .pas file. there pros , cons doing this? worth doing?

to clarify: mean creating separate file, strings.pas in create text string variables.

ex

current code

messages.add('the voucher not sent ' + sname+ ' because application in test mode.'); messages.add('voucher saved ' + sfullpath); messages.add('----------------------------------------------------------');

new code like:

messages.add(smsgtext1 + '' + sname + '' + smsgtext2 + '' + sfullpath)

the strings.pas file hold string data. hope makes improve sense

moving strings separate file idea! keeps them , allow alter them if required. question doesn't want able translate them, centralizing help to.

but, code like:

messages.add(smsgtext1 + '' + sname + '' + smsgtext2 + '' + sfullpath)

is not improve code like:

messages.add('the voucher not sent ' + sname+ ' because application in test mode.');

you've turned messy readable function phone call messy , un-readable function call. old code (the sec snippet above), can read code , see message going say, because lot of there in text. new code, can't.

second, reason moving strings to maintain related items , create easier alter them. if want alter above message instead of saying "the file 'foo' in path 'bar'..." phrased "the file bar\foo is..."? can't: way messages built still fixed , scattered throughout code. if want alter several messages formatted same way, need alter lots of individual places.

this more of problem if goal translate messages, since translation requires rephrasing message not translating components. (you need alter order of subitems included in messages, illustration - can't assume each language phrase-for-phrase in order substitution.)

refactor 1 step further

i'd suggest instead more aggressive refactoring of message code. you're on right track when suggest moving messages separate file. don't move strings: move functions well. instead of big number of messages.add('...') scattered through code, find mutual subset of messages create. many similar. create family of functions can call, similar messages implemented single function, , if need alter phrasing them, can in single spot.

for example, instead of:

messages.add('the file ' + sfile + ' in ' + spath + ' not found.'); ... , elsewhere: messages.add('the file ' + sfilename + ' in ' + surl + ' not found.');

have 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 function call, parameters) easier translate - provide alternate implementation of functions (don't forget translating substrings may not enough, need able alter phrasing substantially.) clear descriptions of message in function name, such itemnotfount(item, path), leads to clearer code when you're reading it

sounds me :)

delphi pascal

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -