2 added 790 characters in body
source | link

One possible approach is to reduce the code by using constants.

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ sucessful')
   else
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ Failed');

would become:

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive)
   else
   Log(2, SqlInstal, Action, CopyMapFailure, sOSdrive)

which has a better log code/other code ratio when counting the number of characters on the screen.

This is close to what you suggested in the point 2 of your question, except that I wouldn't go so far: Log(9257) is obviously shorter than Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive), but also quite difficult to read. What is 9257? Is it a success? An action? Is it related to SQL? If you work on this codebase for the past ten years, you'll learn those numbers by heart (if there is a logic, i.e. 9xxx are success codes, x2xx are related to SQL, etc.), but for a fresh developer who discovers the codebase, short codes will be a nightmare.

You can go further by mixing the two approaches: use a single constant. Personally, I wouldn't do that. Either your constants will grow in size:

Log(Type2SuccessSqlInstallCopyMapSuccess, sOSdrive) // Can you read this? Really?

or the constants will remain short, but not very explicit:

Log(T2SSQ_CopyMapSuccess, sOSdrive) // What's T2? What's SSQ? Or is it S, followed by SQ?
// or
Log(CopyMapSuccess, sOSdrive) // Is it an action? Is it related to SQL?

This also has two drawbacks. You'll have to:

  • Keep a separate list associating log info to their respective constants. With a single constant, it will grow fast.

  • Find a way to enforce a single format in your team. For example, what if instead of T2SSQ, someone will decide to write ST2SQL?

One possible approach is to reduce the code by using constants.

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ sucessful')
   else
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ Failed');

would become:

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive)
   else
   Log(2, SqlInstal, Action, CopyMapFailure, sOSdrive)

which has a better log code/other code ratio when counting the number of characters on the screen.

This is close to what you suggested in the point 2 of your question, except that I wouldn't go so far: Log(9257) is obviously shorter than Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive), but also quite difficult to read. What is 9257? Is it a success? An action? Is it related to SQL? If you work on this codebase for the past ten years, you'll learn those numbers by heart (if there is a logic, i.e. 9xxx are success codes, x2xx are related to SQL, etc.), but for a fresh developer who discovers the codebase, short codes will be a nightmare.

One possible approach is to reduce the code by using constants.

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ sucessful')
   else
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ Failed');

would become:

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive)
   else
   Log(2, SqlInstal, Action, CopyMapFailure, sOSdrive)

which has a better log code/other code ratio when counting the number of characters on the screen.

This is close to what you suggested in the point 2 of your question, except that I wouldn't go so far: Log(9257) is obviously shorter than Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive), but also quite difficult to read. What is 9257? Is it a success? An action? Is it related to SQL? If you work on this codebase for the past ten years, you'll learn those numbers by heart (if there is a logic, i.e. 9xxx are success codes, x2xx are related to SQL, etc.), but for a fresh developer who discovers the codebase, short codes will be a nightmare.

You can go further by mixing the two approaches: use a single constant. Personally, I wouldn't do that. Either your constants will grow in size:

Log(Type2SuccessSqlInstallCopyMapSuccess, sOSdrive) // Can you read this? Really?

or the constants will remain short, but not very explicit:

Log(T2SSQ_CopyMapSuccess, sOSdrive) // What's T2? What's SSQ? Or is it S, followed by SQ?
// or
Log(CopyMapSuccess, sOSdrive) // Is it an action? Is it related to SQL?

This also has two drawbacks. You'll have to:

  • Keep a separate list associating log info to their respective constants. With a single constant, it will grow fast.

  • Find a way to enforce a single format in your team. For example, what if instead of T2SSQ, someone will decide to write ST2SQL?

1
source | link

One possible approach is to reduce the code by using constants.

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ sucessful')
   else
   LogBook.Log(2,'[POSTGRESQL INSTALLATION] :  [ACTION]:copying Mapannotation.txt to '+sOSdrive+'\ Failed');

would become:

if CopyFile(PChar(sTxtpath+'Mapannotation.txt'), PChar(sOSdrive+'\Mapannotation.txt'), False) then
   Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive)
   else
   Log(2, SqlInstal, Action, CopyMapFailure, sOSdrive)

which has a better log code/other code ratio when counting the number of characters on the screen.

This is close to what you suggested in the point 2 of your question, except that I wouldn't go so far: Log(9257) is obviously shorter than Log(2, SqlInstal, Action, CopyMapSuccess, sOSdrive), but also quite difficult to read. What is 9257? Is it a success? An action? Is it related to SQL? If you work on this codebase for the past ten years, you'll learn those numbers by heart (if there is a logic, i.e. 9xxx are success codes, x2xx are related to SQL, etc.), but for a fresh developer who discovers the codebase, short codes will be a nightmare.