Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
If you hardcode user names, you might be a crappy coder
Message
From
04/06/2021 17:26:21
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
If you hardcode user names, you might be a crappy coder
Miscellaneous
Thread ID:
01680936
Message ID:
01680936
Views:
83
The application I inherited from a crappy coder - such coders are far too common, hard coded user names through out the application. To find the correct place to give another user access is very difficult. MaxFrame, a tool for developer teams - which I helped build, had a data driven facility to create groups of users and associate those groups with menu options, controls etc. etc.

The application is stuck in vfp6 - because the previous developer kept making bad choices. So I could not simply include MaxFrame features when they would be better. A compromise was to create a function called user_access. In it we created a means of creating groups that we could associate with features, etc. Then we would hard code the names in a single place. This takes very little time to alter. It is just as long a process to create a group and relocate the hard-coded names, as it is to add a person to the list of hard-coded names. The compiled version of this was excluded from the exe, so we could change permissions at any time, without deploying a new exe.

Recently I had to try to find out why one user had different access than another user. The problem with hard-coding is not knowing where the one user had the permission. The solution that occurred to me was to use the coverage profiler. The profiler is mostly for timing how slow a section of code is, if you're a bad enough coder that you don't know how to keep slow code from being added in the first place.

By SET COVERAGE TO firstuser.cvr, I can run the application to the point where a particular button is active, exit the app and SET COVERAGE TO to close the file. Then repeat the exercise to seconduser.cvr. Then open the two files side by side and scroll down in both until the executed lines diverge.

That is the IF or DO CASE where there is a difference in behavior between the two users. You then go to that place, and in my case, find a list of user names that does not include the second user. Relocate this code, add a new group and the new user, recompile both the exe and the user_access.fxp and deploy. Overtime many things were moved so a simple search and replace in a single program worked to remove employees that left, etc.

It is not a great stretch to realize not to hard-code names into an app, but when people think programming is art instead of engineering, they will not engineer a simple thing like this instead of a primitive hard-coding of names.

All I need now is a small piece of code to wade through 2 files or 40,000 lines to find where they differ. Woe is our society from such lame duck programmers.
Next
Reply
Map
View

Click here to load this message in the networking platform