Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Warnings, exceptions, and constant modifications, redux.

Thread Tools

Warnings, exceptions, and constant modifications, redux.

Posts: n/a
Hello, all. With your permission I'd like to resurrect a topic that
seems to have died in 2002. At least, this is the most info I've
found. The question was, Why does modification of a constant produce
a warning and not an exception? Matz's answer, ruby-talk 48168, was
as follows (angle brackets added):

> Hi,
> In message "warning modifying constant & 'global constant'"
> on 02/08/26, David Garamond <davegaramond /> writes:
> |1. if someone attempts to modify a constant, why does ruby choose to
> |emit a warning instead of a fatal error?
> If it is a fatal error, something like Ruby embedded editor will meet
> serious problems, e.g.
> M-x eval-ruby-expression
> Eval: Foo = 42<ret>
> bang!
> |2. is there a beast called a 'global constant'? i tried defining $Foo
> |and ruby allows me to rebind $Foo later.
> No. $Foo is a plain global variable.
> matz.

Unfortunately, I'm not familiar with 'eval-ruby-expression', which
looks like some sort of Emacs command. So I still consider it a
fairly serious problem that modification of a constant produces
nothing more serious than a warning, which is useless without human
supervision. Especially because, even if an exception were raised
instead, a bypass system is still so easy to arrange:

class Module
def const_set!( name, val )
remove_const(name) if const_defined?(name)
const_set( name, val )

Is this 'embedded editor' problem the same as it was five years ago?
Could somebody who *does* know about embedded editors explain what it
is about them that makes constants so hard to deal with? Ruby-talk
48271, from the same thread:

> Hi,
> In message "Re: warning modifying constant & 'global constant'"
> on 02/08/27, Paul Brannan <pbrannan /> writes:
> |> M-x eval-ruby-expression
> |> Eval: Foo = 42<ret>
> |> bang!
> |
> |What problems would there be with making it an exception?
> for example, eval-current-buffer may cause trouble if it redefines
> contants.
> matz.

How do embedded editors normally handle exceptions?
Thanks to David Garamond for creating the prior thread.

- Jonathan
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"error C2057: expected constant expression", "error C2466: cannot allocate an array of constant size 0". Why doesn't my simple program work??? C++ 13 01-22-2007 02:03 PM
pointers to constant characters and constant pointers to characters C Programming 4 12-14-2006 11:10 PM
len(var) is [CONSTANT] equal to len(var) == [CONSTANT]? Tor Erik Soenvisen Python 14 11-23-2006 09:57 PM
"Non-constant" constant can't be used as template argument Martin Magnusson C++ 2 10-08-2004 08:41 AM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM