9

I am using eclipse for android programming, and every here and there i see the statement, "TODO Auto-generated method stub."

I understand that these methods were generated automatically by eclipse upon creation of classes and other trigger activities but I do not understand the need to have it mentioned everywhere.

What's the need to have it mentioned everywhere repeatedly?

  • 1
    you can change the template in Eclipse if you don't like it – DPM Jul 15 '13 at 14:07
  • 3
    This question appears to be off-topic because it does not demonstrate a minimal understanding of the IDE being used. – Jim G. Jul 15 '13 at 14:53

4 Answers4

16

Eclipse creates just empty methods that return null (hence "stub"). The comments are inserted to remind the developer that he'll probably want to do something in those methods, otherwise why should they exist? You're supposed to delete the comments when you've done that.

If you see those comments all over the place, then either (if the actually contain implementations) the developers are lazy or believe the comments have some other purpose and therefore don't delete them, or it's an indication of weak design, usually interfaces that are too big and have implementations (and users) that don't actually use all the methods in the interface.

Michael Borgwardt
  • 51,037
  • 13
  • 124
  • 176
8

TODO is one of several default keywords which indicate tasks to perform in Eclipse. Under windows->Preferences->Java->Compiler->Task Tags, you should see these keywords. It is thought to add a comment with this keyword to automatically indicate the things that are still to complete, which is convenient if you make use of these task tags.

However, if you don't use them, you should modify the code templates (Preferences->Java->Code Style->Code Templates) to eliminate these comments.

In particular:

  • Code->Method body
  • Code->Constructor body
  • Code->Catch block body
Neil
  • 22,670
  • 45
  • 76
  • 5
    It's more than just Eclipse that supports TODO comments - NetBeans, Visual Studio, JetBrains, and more also provide task list functionality that extracts from TODO-style comments. In addition, this doesn't answer the question asked - what the TODO style comment means and how it is of value. – Thomas Owens Jul 15 '13 at 13:59
  • 2
    I prefer Visual Studio's (ReSharpers?) behavior of generating stubs that `throw new NotImplementedException();` since they're much harder for an obliviot to ignore than a silently failing empty method. – Dan Is Fiddling By Firelight Jul 15 '13 at 15:34
  • 1
    @ThomasOwens He named eclipse, not NetBeans, Visual Studio, JetBrains, and others. In addition, this is precisely what TODO means and how it is used. – Neil Jul 15 '13 at 16:13
  • 1
    @DanNeely I like this too, that's why my auto-generated code templates in Eclipse look like this: `throw new UnsupportedOperationException("Auto-generated method stub"); // TODO Auto-generated method stub` – Simon Lehmann Jul 15 '13 at 17:06
7

Many IDEs, including Eclipse, use "TODO" in a comment to generate task lists. These task lists include the text of the comment and the file and method that the comment is in. This lets everyone using a tool with this functionality generate lists of things that are still open. There are also some other common identifiers, like FIXME or XXX that have similar functionality in some IDEs. This question on Stack Overflow asks about the comment keywords in Eclipse, and provide some additional information.

When you autogenerate some functions, it's expected that you'll be inserting your own implementation. It adds the appropriate stub so that your code will compile, but adds the comments so that you can quickly find methods that need to be implemented. Note that some autogenerated functions, like autogenerated toString and hashcode functions do not contain these comments because it's not expected that you'll modify them.

There are ways to disable the insertion of these by editing the templates used to create autogenerated code, if it bothers you that much. However, they are useful. Simply searching your codebase for things like TODO and FIXME can be the basis of a task list if they are coupled with a decent comment about what needs to be done, especially on smaller projects.

Thomas Owens
  • 79,623
  • 18
  • 192
  • 283
4

TODO simply mean "TO DO", stub is generated but developer or programmer need to add code as required.

user42588
  • 41
  • 1