const, final, scope function parameters

Derek Parnell derek at psych.ward
Mon May 28 04:31:38 PDT 2007


On Mon, 28 May 2007 13:05:47 +0200, Myron Alexander wrote:

 
> Once again, please post an example. I am curious to see your code style, 
> maybe I can learn from it.

I have a style which has the program gathers a lot of it's "literals" from
optional data supplied to it at run time. In other words, I prefer to write
highly user-customisable applications. This has the effect that a lot of
variables are set to default values then overridden as nominated by the
user running the program. This makes using 'final' and 'invariant'
problematic, I think.

I might have to change my style to something like ...

  string[string] UserOptions;
  UserOptions = CollectUserOptions();

  // Move them to final vars for performance reasons.
  final string OptionOne = UserOption["One"].dup;
  final string OptionTwo = UserOption["Two"].dup;

  UserOptions = null; // get rid of mutable stuff.
   . . .
   // From here on the options can't be changed.


  string[string] CollectUserOptions()
  {
    string[string] temp;

    // Set default values.
    temp["One"] = "aaaa";  
    temp["Two"] = "bbbb";

    // Who knows where these are collected from
    // as it doesn't matter for this example
    if (<option one supplied>)
       temp["One"] = <suppliedvalue>;

    if (<option two supplied>)
       temp["Two"] = <suppliedvalue>;
  
    return temp;
  }

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list