Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What's wrong with the code, then, is that it was written under a little too much pressure for the developer to think clearly.

    for ( int i=0 ; i < this.MyControl.TabPages.Count ; )
    {
       this.MyControl.TabPages.Remove ( this.MyControl.TabPages[i] );
    }


Why not just:

  while (this.MyControl.TabPages.Count > 0)
  {
    this.MyControl.TabPages.Remove ( 0 );
  }


Indeed. But the point I was making was that this hypothetical coder introduced more complexity by adding "i--;" whereas the code could equally well be fixed, in the same number of keystrokes, while reducing complexity, by removing "i++;".


Very inefficient on most array lists (but a very good idea on linked lists)


How many tabs do you use?

Less than 50?

Then don't worry about the optimization until you have to port it to a PDP10.


> Less than 50?

No, over nine thousands.


> Less than 50?

No, way more than that.


  while (this.MyControl.TabPages.Count > 0)
  {
    this.MyControl.TabPages.Remove ( this.MyControl.TabPages.Count-1 );
  }


Or Even this.MyControl.TabPages.Clear();




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: