KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Cleaning up a database's code
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: June 11, 2020

Converting a database from binary mode to project mode is a good idea for developers that want to be able to take advantage of a version control system. If so, a suggestion is to clean up the databases code to reduce the number of files and code to improve the efficiency of managing everything.

A quick way to do this is to use 4D's designer "Find Unused..." features located in the Edit menu:


Find Unused Methods and Global Variables will return a list of methods and global variables that have been created but not referenced anywhere within the scope of the database structure. This includes cases where the method is writted as a string such as when passed as the first parameter of the New process command, however methods listed in a comment will not affect this. After cleaning up the methods, the feature should be ran again as the feature is not as advanced to display methods that are only used within the scope of an unused method stack.

For example, if Method2 is only called by Method1, and Method1 is unused the feature will not list Method2 as an unused method until it is no longer called any where in the database.

This will also miss unused recursive methods that call itself.

Find Unused Local Variables will list the unused local variables that have been declared. This is only useful for those tht follow the suggerstion of using the "All variables are typed" Compilation path setting and declaring every variable. This feature will locate local variables in a method that have been declared but not used in any other form within the method.

For example, C_LONGINT($int) is in a method but $int is not used anywhere else in the method.
But on the other hand, if variables are not declared and the variable was instantiated by something like $myVar:="Hello World" and used no where else in the method then this would not show up in the list.

Unlike the search for methods, any variables only used in a string will still show up in the list. If the variable is declared and then only used in a string for something likst process 4D tags the variable and method will still get listed.
This is the same behavior for the Find Unused Methods and Global Variables results when parsing for the Global Variables.

While not as advanced, many databases can still take advantage of these features to trim down the contents of the structure, this can improve efficiency for managing a database. With project mode each method will be a separate file, removing unused methods will in turn reduce the number of files for the database. While removing unused variables can improve the efficieny of the code, and how the version control system parses the diffs.