Re: Variable Namespace Best Practice Question

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

When it comes to standard Euphoria programming practice, which is preferred?

I'm concerned mainly with the declaration of the line variable.

Well, since you asked, I'd say the preferred method would be this:

sequences lines = read_file(myfile) 
for line in lines do 
... 

But that'll have to wait. So I would prefer this:

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.

-Greg

P.S. read_lines() returns separate lines. read_file() returns the whole file as one big string. blink

P.P.S. I think you meant "scope" instead of "namespace"

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

Search



Quick Links

User menu

Not signed in.

Misc Menu