Topic: Proposal: new keywords: freeze | unfreeze | hide | unhide | forget
Author: andre@ba-z.co.jp (Andre Caldas)
Date: Fri, 8 Apr 2005 02:06:08 GMT Raw View
> It would be useful if the language had the following additions:
>
> 1) "freeze" (and "unfreeze") varname, ...
> to freeze a variable's current content, that is to make it
> constant for the rest of the function (or upto an "unfreeze"
> within the same function).
> (volatile variables shall still be changable from other locations).
>
> 2) "hide" (and "unhide") varname, ...
*snip*
> 3) "forget" varname, ...
*snip*
> This would help making programs more robust.
Write smaller functions and your program will be more robust.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Alberto Barbati <AlbertoBarbati@libero.it>
Date: Sat, 9 Apr 2005 15:29:18 CST Raw View
Uenal Mutlu wrote:
> It would be useful if the language had the following additions:
>
> 1) "freeze" (and "unfreeze") varname, ...
> to freeze a variable's current content, that is to make it
> constant for the rest of the function (or upto an "unfreeze"
> within the same function).
> (volatile variables shall still be changable from other locations).
Considering that you may have references or pointers to a variable's
contents, making one variable "frozen" may not be enough to make it
immutable:
void foo()
{
int a = 0;
int& b = a;
freeze a;
// a is now frozen
b = 1; // OOPS! changed the value of a
}
It is *very* unreasonable to require the compiler to track the
frozen-ness of variables in order to make this example ill-formed. So
instead of making life simple, this keyword is going to introduce an
unnecessary complication without a real usefulness, IMHO. If you want a
variable to be immutable, you should consider making it const in the
first place.
>
> 2) "hide" (and "unhide") varname, ...
> to make a variable hidden, ie. not accessible for the rest
> of the current function (or upto an "unhide" within the same
> function).
Just if name lookup rules weren't already complex enough... ;-)
>
> 3) "forget" varname, ...
> to forget a variable, ie. to remove it from the list.
What would happen to the variable contents? Will the destructor be
called? If no, then "forget" is the same as "hide", so I don't see why
you're proposing two different keywords. If yes, I see tons of problems
with exception handling. Please remember that you can obtain similar
results in a well-defined manner within current C++ in at least three
different ways:
1) using braces {}
2) using tr1::scoped_ptr (aka boost::scoped_ptr)
3) using boost::optional
>
> This would help making programs more robust.
>
I fail to see how. Could you please provide use-cases supported by code
samples?
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]