Generalise variable usage inside code
- by Shirish11
I would like to know if it is a good practice to generalize variables (use single variable to store all the values).
Consider simple example
Strings querycre,queryins,queryup,querydel;
querycre = 'Create table XYZ ...';
execute querycre ;
queryins = 'Insert into XYZ ...';
execute queryins ;
queryup = 'Update XYZ set ...';
execute queryup;
querydel = 'Delete from XYZ ...';
execute querydel ;
and
Strings query;
query= 'Create table XYZ ... ';
execute query ;
query= 'Insert into XYZ ...';
execute query ;
query= 'Update XYZ set ...';
execute query ;
query= 'Delete from XYZ ...';
execute query ;
In first case I use 4 strings each storing data to perform the actions mentioned in their suffixes.
In second case just 1 variable to store all kinds the data.
Having different variables makes it easier for someone else to read and understand it better. But having too many of them makes it difficult to manage.
Also does having too many variables hamper my performance?