You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucy.apache.org by "Logan Bell (Assigned) (JIRA)" <ji...@apache.org> on 2011/12/16 22:40:32 UTC

[lucy-issues] [jira] [Assigned] (LUCY-146) Reduce iterator variable scopes

     [ https://issues.apache.org/jira/browse/LUCY-146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Logan Bell reassigned LUCY-146:
-------------------------------

    Assignee: Logan Bell
    
> Reduce iterator variable scopes
> -------------------------------
>
>                 Key: LUCY-146
>                 URL: https://issues.apache.org/jira/browse/LUCY-146
>             Project: Lucy
>          Issue Type: Sub-task
>            Reporter: Marvin Humphrey
>            Assignee: Logan Bell
>            Priority: Minor
>
> C99 allows you to declare iterator variables within "for" loops, but C89 does
> not:
> {noformat}
>     // C99
>     for (int i = 0, max = 10; i < max; i++) {
>         // ...
>     }
>     /* C89 */
>     int i, max;
>     for (i = 0, max = 10; i < max; i++) {
>         /* ... */
>     }
> {noformat}
> The C99 idiom is superior because it limits the scope of the iterator
> variable.  
> We have a number of C89-style iterator variables which should be switched
> over.  In some cases, the iterator variable is declared at the top of a scope
> and then reused within several loops.  That's the sort of pattern we'd like to
> avoid.
> The following crude grep command detects some candidates which ought to be
> reviewed:
> {noformat}
> grep -r "for ([a-z] =" lucyalt | grep -v -e "svn\|charmonizer\|modules\|\.pm"
> {noformat}
> Care must be taken when performing this refactoring, because some code may
> in fact be *relying* on iterator variables holding values across multiple
> loops -- such as in PriorityQueue.c.  It will be good when this refactoring
> pass is finished because such code will stand out more.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira