Skip to content

Remove unnecessary use of eval from install script #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Remove unnecessary use of eval from install script #226

merged 1 commit into from
Apr 21, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Apr 21, 2022

The "template" installation script hosted in this repository contains a checkLatestVersion() function which is used to determine the latest version of the project when the user does not specify a version to install.

The version number is required by the caller, but shell functions do not support returning such content.

As a workaround, the script author set up a system where the caller passed an arbitrary variable name to the function. The function then sets a global variable of that name with the release name. So it resembles a "pass by reference" approach, but isn't.

This was done using the eval builtin. This tool must be used with caution and best practices is to avoid it unless absolutely necessary. The system used by the script has some value for a reusable function. However, in this case the function is only intended for internal use by the script, and is called only once. So the unintuitive nature of this system and potential for bugs (e.g., arduino/arduino-cli#1714) don't bring any benefits when compared with the much more straightforward approach of simply using a fixed name for the global variable used to store the release name.


Related: #222

The "template" installation script hosted in this repository contains a `checkLatestVersion()` function which is used to
determine the latest version of the project when the user does not specify a version to install.

The version number is required by the caller, but shell functions do not support returning such content.

As a workaround, the script author set up a system where the caller passed an arbitrary variable name to the function.
The function then sets a global variable of that name with the release name. So it resembles a "pass by reference"
approach, but isn't.

This was done using the `eval` builtin. This tool must be used with caution and best practices is to avoid it unless
absolutely necessary. The system used by the script has some value for a reusable function. However, in this case the
function is only intended for internal use by the script, and is called only once. So the unintuitive nature of this
system and potential for bugs don't bring any benefits when compared with the much more straightforward approach of
simply using a fixed name for the global variable used to store the release name.
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Apr 21, 2022
@per1234 per1234 requested review from cmaglie and umbynos April 21, 2022 08:53
@per1234 per1234 self-assigned this Apr 21, 2022
@per1234 per1234 merged commit 16c002b into arduino:main Apr 21, 2022
@per1234 per1234 deleted the remove-eval branch April 21, 2022 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants