[vtk-developers] vtkNew<>

Brad King brad.king at kitware.com
Fri Jan 29 12:16:33 EST 2010


Will Schroeder wrote:
> Well I have to say the vtkSmartPointer macro discussion was one of the
> most entertaining threads I've had the pleasure of participating in.
> It's good to know that after 17 years we finally know how to instantiate
> objects in VTK and that we are making progress :-)

March of progress:

1980: C
    printf("%10.2f", x);
1988: C++
    cout << setw(10) << setprecision(2) << showpoint << x;
1996: Java
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);
2004: Java
    System.out.printf("%10.2f", x);

-----------------------------------

1994:
    vtkPolyData* pd = vtkPolyData::New();
    ...
    if(some_error)
      {
      pd->Delete(); // Hopefully we remember this one.
      return;
      }
    ...
    pd->Delete();
2004:
    vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New()
2010:
    vtkNew<vtkPolyData> pd;

I guess we did better than formatted printing.

> Has anyone thought about how we are going to roll this out?
[snip]
> I assume Bill and others are going to continue with experiments

That is my understanding.

> and if we still like it what then? We've got examples,
> tests, code base, tutorials, books, etc. to contend with.

When the vtkSmartPointer<>::New() approach was added, it just slowly
moved into tests and examples.  It probably hasn't finished yet either.
Unlike vtkSmartPointer<>, vtkNew<> is useable only for local variables.
Perhaps its brevity and clear purpose will lead to quicker adoption.

> My current favorite solution is to ask Brad to fix everything

Hey, I voted for (1)!

-Brad



More information about the vtk-developers mailing list