Re: Deck of Cards Question...
- Posted by Derek Parnell <derekp at solace.com.au> Nov 21, 2000
- 421 views
>-----Original Message----- >From: George Henry [mailto:ghenryca at hotmail.com] >How does Euphoria encourage global variables? I don't feel >encouraged to use >them, except as simple control flags where "ctrl_flag=1" is equivalent to, >but more straightforward than, "set_ctrl_flag()" (and similarly for >"ctrl_flag=0" vs. "clear_ctrl_flag()"). I must admit that I said this just to see if somebody would bite. Euphoria is not much different than most other languages in its encouragement of global-scoped variables. The one situation where I'm forced to make the scope of a variable larger than required, is when a routine needs to use the value of variable that is only used by the routine, and was set by an earlier invocation of the routine. For example... integer CurVal CurVal = 0 function xyz(atom cmd) integer temp if cmd = 0 then CurVal = rand(100) else temp = rand(cmd) if temp > CurVal then CurVal = temp end if end if return CurVal end function If this function is inside a file with lots of others, then "CurVal" is exposed. If I put this function in its own include file and make xyz() a global function, I then have to be aware of potential name clashes with other (future) include files. >Euphoria itself encourages me to use the function method. Euphoria doesn't >let one pass a reference or pointer, so "append(seq1, seq2)" >wouldn't do the >job as a statement, it has to be a function, and following that >model makes >sense and is good practice. True it does. And won't it be nice when Robert allows pseudo pass-by-reference so that we can reduce typing such that append(&seq1, seq2) is syntactically identical to seq1 = append(seq1, seq2) Hey!, I can dream can't I ----- cheers, Derek Parnell