Skip to content
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

Use local variables to improve maintainability/documentation #9

Open
dehesselle opened this issue Nov 10, 2019 · 1 comment
Open

Use local variables to improve maintainability/documentation #9

dehesselle opened this issue Nov 10, 2019 · 1 comment

Comments

@dehesselle
Copy link
Collaborator

Although it is perfectly fine to use parameters as $1and $2 in the code like here...

notification()
{
# $1: system (myname)
# $2: message
if [ "x$IFTTT_KEY" != "x" ]; then
if [ "x$IFTTT_EVENT" != "x" ]; then
if [ "x$1" != "x" ]; then
MY_NAME=$1
MY_STATUS=$2
writelog "D" "$MY_NAME"
writelog "D" "$MY_STATUS"

... I suggest to always assign those to local variables as first thing in every function. This is a measure to make the code speak more for itself (instead having comments do that - have comments explain the non-trivial stuff).

Example

 notification() 
 { 
 	local system=$1    # myname
        local message=$2
 
 	if [ "x$IFTTT_KEY" != "x" ]; then 
 		if [ "x$IFTTT_EVENT" != "x" ]; then 
 			if [ "x$system" != "x" ]; then 
 				MY_NAME=$system 
 				MY_STATUS=$message
 				writelog "D" "$MY_NAME" 
 				writelog "D" "$MY_STATUS" 
@rfuehrer
Copy link
Owner

I have already corrected this in prominent places and it has to be tested. At this point we should also consider how local/global/... variables should be written at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants