Is it wrong to use a function from another function and pass the same parameter twice? - Swift3

I am new to iOS development and would just like to know if there is bad practice to do something in accordance with:

func bigFunc(){
    var parameter: String = "foo"
    firstFunc(parameter: parameter){

}

func firstFunc(parameter: String){
    let word: String = secondFunc(parameter: parameter)
    //do stuff with word
}

func secondFunc(parameter: String) -> String{
    return "bar"
}

Instead of just making a global variable parameter and calling both functions in the bigFunc () file?

Thank!

+4
source share
1 answer

Where possible, global variables should be avoided. The best practice is to limit the visibility of variables in the area where they are needed, and if you make a global variable there, it will be visible in the whole file, which jeopardizes the names of variables, etc.

, , "" .

+4

Source: https://habr.com/ru/post/1675869/


All Articles