Intentions - split declaration and initialization

Granted, my Java knowledge is very rusty these and thank goodness for IDEA to help me get up to speed again rapidly before I start teaching a Data Structures course with it.

I've disable a few lightbulb suggestions in the past but I'm baffled by the suggestion that I should split a declaration and initialization into two parts.

In my experience, when possible, one should not only declare variables as close to where they will be used but also to make sure that if possible, they should never be uninitialized (even if Java's default is what one wants, which is mostly NOT the case).

So I don't understand why this particular suggestion is being made. It seems like very bad advice, particularly for new programmers.''

What's the thinking?

Thanks,
D



Attachment(s):
screenshot_273.png
4 comments
Comment actions Permalink

It's not something IDE suggests you to do, rather a quick access to the action that does it on your own intention.
https://www.jetbrains.com/idea/help/intention-actions.html .

So, it's just a quick access to a micro refactoring in this specific case.

0
Comment actions Permalink

I see what you're saying.

I have historically considered the lightbulb as a mechanism to tell me "there's a better way, dummy" rather than just another way. In this particular case, I'm not sure why one would ever be interested in that alternative.

Obviously the ability to turn it off is wonderful and I've been compiling a list of intentions that I want my students to turn off.

I am curious though as to why this particular intention exists. I'd rather see a "combine declaration and assignment into a single statement" intention (if that's not already there);)

Cheers,
D

0
Comment actions Permalink

See http://stackoverflow.com/questions/15953895/splitting-declaration-and-assignment-good-practice .

You may want to make assignment conditional, for instance.

> I'd rather see a "combine declaration and assignment into a single statement" intention (if that's not already there)

There is:

http://i.imgur.com/MoOaLtg.png

You can also use Inline refactotring.

0
Comment actions Permalink

Why am I not surprised :-)


Thanks again for fast responses!
D


-------------------
There is:

http://i.imgur.com/MoOaLtg.png

You can also use Inline refactotring.

0

Please sign in to leave a comment.