Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Feb 2005 12:30:37 -0800
From:      Marcel Moolenaar <marcel@xcllnt.net>
To:        Paul Richards <paul@originative.co.uk>
Cc:        arch@freebsd.org
Subject:   Re: c99/c++ localised variable definition
Message-ID:  <fa820cbe585add3bebb31954175460f3@xcllnt.net>
In-Reply-To: <20050201190416.GG61409@myrddin.originative.co.uk>
References:  <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Feb 1, 2005, at 11:04 AM, Paul Richards wrote:

>> And wonder why i gets such a strange value...  It appears that unless
>> you have WARNS=4 set, warnings about:
>> t.c:10: warning: declaration of 'i' shadows a previous local
>>
>> don't show up.  So, I would say we HAVE to get the tree building with
>> WARNS=4 and -Werror before we let this into style(9)...
>
> The issue with shadowing outer scope variables is only an issue if
> you need to access them. If your only using the syntax for loop
> variables to do the looping then there's no issue.

Never forget that you want to be able to debug you application.
While technically you're right, it's bad practice to do so.

In general, localized variable definitions increases the chance that
a bug is being made, because it increases the complexity of the
language -- there are more things/cases to be aware off and that need
checking before you can be sure the code is correct. Hence, there's
more you can forget about when you code. Therefore, it's not a feature
you want to promote.

Put differently: it doesn't fundamentally change the expression power
of the language, but rather introduce new ways of doing things that
can already be done. It doesn't buy you anything. It's just window-
dressing. It would have been very adequate if it were kept as a C++
(or more correctly object oriented) feature only...

-- 
  Marcel Moolenaar         USPA: A-39004          marcel@xcllnt.net



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fa820cbe585add3bebb31954175460f3>