Re: Variable Namespace Best Practice Question

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu