Bug 429804 - Remove " // TODO Auto-generated method stub" from default method generation template
Summary: Remove " // TODO Auto-generated method stub" from default method generation t...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2014-03-06 12:37 EST by Lars Vogel CLA
Modified: 2017-04-25 05:12 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2014-03-06 12:37:59 EST
If I create a new method via content assists I always delete the generated TODOs. I talked to several other developers about it and they see don't see this as an added value. 

I think we should generate code as efficient for the developer as possible.

As the additional deletion step creates additional work, I suggest to remove that from the default templates. Someone who really like that can still add this.

Here is an example a generated inner class:

	button.addControlListener(new ControlListener() {
		
		@Override
		public void controlResized(ControlEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void controlMoved(ControlEvent e) {
			// TODO Auto-generated method stub
			
		}
	});
Comment 1 Martin Mathew CLA 2014-03-13 01:37:41 EDT
As a Java developer i find this functionality very useful especially while working on huge files. 'TODO' is a task tag which gives a blue marker on the gutter and so it is easier to find where this new method was added.
Lars, i agree with you that for small files it might not add much value, but when we look at the bigger picture i would like to keep it the way it is now.
Comment 2 Timo Kinnunen CLA 2014-03-13 10:56:38 EDT
How about, instead of a method with TODO like this:
		public static void controlMoved() {
			// TODO Auto-generated method stub
		}
produce 
		public static void controlMoved() {
			;
		}

Now instead of a TODO that could easily be forgotten this version gives something better: a compiler warning and the beginnings of the implementation, all-in-one!
Comment 3 Lars Vogel CLA 2014-03-13 11:04:35 EDT
(In reply to Timo Kinnunen from comment #2)
> How about, instead of a method with TODO like this:
> 		public static void controlMoved() {
> 			// TODO Auto-generated method stub
> 		}
> produce 
> 		public static void controlMoved() {
> 			;
> 		}
> 
> Now instead of a TODO that could easily be forgotten this version gives
> something better: a compiler warning and the beginnings of the
> implementation, all-in-one!

-1 for additional compiler warnings. If he have to choose between TODO or compiler warning I go for a TODO.
Comment 4 Timo Kinnunen CLA 2014-03-13 14:13:21 EDT
(In reply to comment #3)

> -1 for additional compiler warnings. If he have to choose between TODO or
> compiler warning I go for a TODO.

Hahaha, but this is exactly why you should pick the compiler warning out of the two, because it feels more uncomfortable :) A method stub which hasn't been implemented yet and a method whose implementation consists of one lone semicolon like above are the same thing in the end, after all. 

And if I may muse a bit, having any of 
	// FIXME can throw NPEs sometimes
	// TODO optimize this feature
	// XXX is this correct?

implies defects, deficiencies and uncertainties about the code, so I'd say a warning can and should be issued here as well.
Comment 5 Dani Megert CLA 2014-04-02 10:18:21 EDT
(In reply to Timo Kinnunen from comment #4)
> (In reply to comment #3)
> 
> > -1 for additional compiler warnings. If he have to choose between TODO or
> > compiler warning I go for a TODO.
> 
> Hahaha, but this is exactly why you should pick the compiler warning out of
> the two, because it feels more uncomfortable :) A method stub which hasn't
> been implemented yet and a method whose implementation consists of one lone
> semicolon like above are the same thing in the end, after all. 
> 
> And if I may muse a bit, having any of 
> 	// FIXME can throw NPEs sometimes
> 	// TODO optimize this feature
> 	// XXX is this correct?
> 
> implies defects, deficiencies and uncertainties about the code, so I'd say a
> warning can and should be issued here as well.

Note that those who actually prefer the warning or error over the task can easily achieve that by changing the template to be empty or contain the ';' plus setting the corresponding compiler options.

I agree with Manju that we'll leave this as is.
Comment 6 Lars Vogel CLA 2017-03-27 07:35:24 EDT
I discussed this issue with Noopur on Devoxx. IMHO especially the //TODO for anonymous inner classes forces developers to use code completion and afterwards delete the generated TODO line.

Please also note that IntelliJ does not generate such statements.

I had the impression that Noopor agreed that this is not a good pattern for simple cases like anonymous inner classes and that she was open for a new discussion. 

Reopening so Noopur can have the discussion with her team.
Comment 7 Noopur Gupta CLA 2017-04-06 06:41:39 EDT
We had a discussion on this in the team.

Lars, could you please list down the cases where you feel that the generated TODO comment can be omitted by default?

We can consider those cases to see if it would be fine to omit the default TODO comment there.
Comment 8 Lars Vogel CLA 2017-04-06 07:26:21 EDT
(In reply to Noopur Gupta from comment #7)

> We can consider those cases to see if it would be fine to omit the default
> TODO comment there.

Great news. I'm currently at a customer side, hence my first short answer would be:

1.) Anonymous inner classes

I update the bug once I have time to test the standard code templates from Eclipse again (for myself I remove the //TODO's from the templates whenever I see them)
Comment 9 Lars Vogel CLA 2017-04-07 02:59:23 EDT
I suggest to remove the //TODO code templates from the following entries in the preferences:

- Method body
- Constructor body

For catch blocks I think it is OK to leave the //TODO

Also for Comments I suggest to replace the 

/* (non-Javadoc)
 * ${see_to_overridden}
 */

with 

/**
 * 
 */
Comment 10 Dani Megert CLA 2017-04-07 10:40:34 EDT
(In reply to Lars Vogel from comment #8)
> 1.) Anonymous inner classes

Where do you find this?


(In reply to Lars Vogel from comment #9)
> I suggest to remove the //TODO code templates from the following entries in
> the preferences:
> 
> - Method body
> - Constructor body
> 
> For catch blocks I think it is OK to leave the //TODO

Fine with me.
Comment 11 Lars Vogel CLA 2017-04-07 10:45:58 EDT
(In reply to Dani Megert from comment #10)
> Where do you find this?

Ignore, this was from memory.
 
> (In reply to Lars Vogel from comment #9)
> > I suggest to remove the //TODO code templates from the following entries in
> > the preferences:
> > 
> > - Method body
> > - Constructor body
> > 
> > For catch blocks I think it is OK to leave the //TODO
> 
> Fine with me.

Great news!
Comment 12 Dani Megert CLA 2017-04-10 05:44:09 EDT
Currently we generate an empty line in the body, e.g.

	private void foo() {
		// TODO Auto-generated method stub

	}

I suggest to keep that empty line:

	private void foo() {

	}
Comment 13 Dani Megert CLA 2017-04-10 05:51:40 EDT
(In reply to Dani Megert from comment #12)
> Currently we generate an empty line in the body, e.g.
> 
> 	private void foo() {
> 		// TODO Auto-generated method stub
> 
> 	}
> 
> I suggest to keep that empty line:
> 
> 	private void foo() {
> 
> 	}

This won't work without code changes. Currently, if a code template only contains whitespace it will be trimmed and we get

	private void foo() {
	}
Comment 14 Noopur Gupta CLA 2017-04-10 06:30:20 EDT
Removing TODO comments in Code Templates preferences for method body and constructor body will remove these comments in all the cases where method and constructor stubs are generated based on these templates. 

This is fine for simple cases like content assist and quick fix/assist where the stubs are created in front of the user. 

But it also affects refactorings where the stubs could be created in multiple files. In these cases, TODO comments act as an indicator of the changed code in all the files, which is useful in my opinion. Though we have previews for these refactorings, the user will still have to remember all the locations where the method stubs are created.
Comment 15 Dani Megert CLA 2017-04-10 07:27:42 EDT
(In reply to Noopur Gupta from comment #14)
> Removing TODO comments in Code Templates preferences for method body and
> constructor body will remove these comments in all the cases where method
> and constructor stubs are generated based on these templates. 
> 
> This is fine for simple cases like content assist and quick fix/assist where
> the stubs are created in front of the user. 
> 
> But it also affects refactorings where the stubs could be created in
> multiple files. In these cases, TODO comments act as an indicator of the
> changed code in all the files, which is useful in my opinion. Though we have
> previews for these refactorings, the user will still have to remember all
> the locations where the method stubs are created.

Good point. One solution would be to add new code templates, so that we and the user can choose different templates for the different cases.
Comment 16 Lars Vogel CLA 2017-04-25 05:03:45 EDT
(In reply to Noopur Gupta from comment #14)

> But it also affects refactorings where the stubs could be created in
> multiple files. 

Which refactorings result in method stubs which have TODO included? I'm only aware of the (non-Javadoc) one for extracting interfaces. If that is the only one, we could skip it for the first step.
Comment 17 Noopur Gupta CLA 2017-04-25 05:12:27 EDT
(In reply to Lars Vogel from comment #16)
> (In reply to Noopur Gupta from comment #14)
> 
> > But it also affects refactorings where the stubs could be created in
> > multiple files. 
> 
> Which refactorings result in method stubs which have TODO included? I'm only
> aware of the (non-Javadoc) one for extracting interfaces. If that is the
> only one, we could skip it for the first step.

You can remove the TODO from default-codetemplates.xml and run the JDT UI tests to see some examples like org.eclipse.jdt.ui.tests.refactoring.PullUpTests.test52().