Re: Variable Namespace Best Practice Question
- Posted by euphoric (admin) Jul 26, 2019
- 1077 views
My initial reply was deleted! Or vanished somehow!
Anyway...
ghaberek said...
I'd say the preferred method would be this:
sequences lines = read_file(myfile) for line in lines do ...
Agreed! Let's get it!
ghaberek said...
sequence lines = read_file(myfile) for i = 1 to length( lines ) do sequence line = lines[i] ...
Performance-wise, there really won't be a difference, because the backend is going to reserve memory and reuse for each assignment.
So you don't incur the penalty of repeated malloc/free calls. And there's an advantage to keeping the variable private to the scope of the for loop.
Thank you! That's what I was wanting to know.
ghaberek said...
P.P.S. I think you meant "scope" instead of "namespace"
Indeed.