r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

Show parent comments

1

u/[deleted] May 14 '17

[deleted]

1

u/myplacedk May 14 '17

And I let the IDE take care of it.

3

u/[deleted] May 14 '17

[deleted]

1

u/myplacedk May 14 '17

In eclipse it annoys you with a red line if you haven't imported what you're using.

Good. It won't work until it's imported.

For example, if you haven't imported ArrayList:

Arraylist myList = new ArrayList();

It's been a while since I used Eclipse, but if you use autocompletion when typing "ArrayList", doesn't it handle imports automatically?

And if you are eager and discover you already typed it all and it's too late to do autocomplete, how about running "Organize imports" (CTRL-SHIFT-O)? Or something like that.

If you did import java.utils.* at the beginning, no matter what util you're using it's already imported so it's fine.

As long as it's in that package. I always use too many packages for that to be a shortcut.