Java return intellityping?

B

bob smith

You know how there are all kinds of typing shortcuts nowadays?

Let's say there's code like this:

m_socket.getOutputStream();

Is there some general way to get your editor (i.e. Eclipse) to create a variable of the correct type and assign it like so:

OutputStream outputStream = m_socket.getOutputStream();

I feel like this could save a lot of work.
 
L

Lew

bob said:
You know how there are all kinds of typing shortcuts nowadays?

Let's say there's code like this:

m_socket.getOutputStream();

You should not violate the Java Coding Conventions like this.
Is there some general way to get your editor (i.e. Eclipse) to create a variable of the correct type and

"General" and "i.e." are not consistent.

It looks like Eclipse Preferences / Java / Editor / Templates is the way to go.
Check your Eclipse documentation.
assign it like so:
OutputStream outputStream = m_socket.getOutputStream();

I feel like this could save a lot of work.

http://www.oracle.com/technetwork/java/codeconv-138413.html
 
A

Andreas Leitgeb

bob smith said:
You know how there are all kinds of typing shortcuts nowadays?
Let's say there's code like this:
m_socket.getOutputStream();
Is there some general way to get your editor (i.e. Eclipse) to create a variable of the correct type and assign it like so:
OutputStream outputStream = m_socket.getOutputStream();
I feel like this could save a lot of work.

When I need this, I type some bogus type and the intended varname like this:
Foo outputStream = m_socket.getOutputStream();

Then, eclipse marks it as an error, and among the "Quick-fixes" there's one that
changes my bogus Foo to the actual return-type of the expression.

hth.
 
R

Robert Klemme

You know how there are all kinds of typing shortcuts nowadays?

Let's say there's code like this:

m_socket.getOutputStream();

Is there some general way to get your editor (i.e. Eclipse) to create
a variable of the correct type and assign it like so:

Yes. Mark the code. Then Refactor -> Extract local variable (Alt-Shift-L).

Cheers

robert
 
J

Jim Janney

bob smith said:
You know how there are all kinds of typing shortcuts nowadays?

Let's say there's code like this:

m_socket.getOutputStream();

Is there some general way to get your editor (i.e. Eclipse) to create a variable of the correct type and assign it like so:

OutputStream outputStream = m_socket.getOutputStream();

I feel like this could save a lot of work.

In Eclipse, use Quick Assist - Assign to local variable

Usually bound to Ctrl+2, L
 
D

Daniel Pitts

You know how there are all kinds of typing shortcuts nowadays?

Let's say there's code like this:

m_socket.getOutputStream();

Is there some general way to get your editor (i.e. Eclipse) to create a variable of the correct type and assign it like so:

OutputStream outputStream = m_socket.getOutputStream();

I feel like this could save a lot of work.
In IntelliJ IDEA, you use "introduce variable" (command-ctrl-v), and it
will do exactly that.

I wouldn't be surprised if Eclipse had an equivalent hot-key.
 
D

Daniele Futtorovic

....

You'd think with all that typing time saved, it would translate into
more thinking time.

In my depressing experience, it doesn't. Rather, below a certain
threshold, they appear to be congruent.

_Note_: this is not an argument, it's a </rant>
 
L

Lew

Daniele said:
...
You'd think with all that typing time saved, it would translate into
more thinking time.

In my depressing experience, it doesn't. Rather, below a certain
threshold, they appear to be congruent.

_Note_: this is not an argument, it's a </rant>

Typing team is not exclusive of thinking time.
 
D

Daniel Pitts

That's probably the gist of the matter... :)
Often, most of my thinking is done before I start typing, whether it be
to use a shortcut or not. I find that although my available "thinking"
time may not be increased, the time-to-delivery is improved (decreased)
because of shortcuts. I can also use my knowledge that there *are*
short-cuts to allow my to defer thinking and decisions until a later
time. For example, I may be writing a class which might be better as two
classes, but it might not be. I know that I have refactoring tools, so
I'll start with the easiest to implement, and then consider refactoring
when it becomes relevant.
 
R

Robert Klemme

Often, most of my thinking is done before I start typing, whether it be
to use a shortcut or not. I find that although my available "thinking"
time may not be increased, the time-to-delivery is improved (decreased)
because of shortcuts. I can also use my knowledge that there *are*
short-cuts to allow my to defer thinking and decisions until a later
time. For example, I may be writing a class which might be better as two
classes, but it might not be. I know that I have refactoring tools, so
I'll start with the easiest to implement, and then consider refactoring
when it becomes relevant.

.... which also can lead to the opposite effect: you end up changing the
same logic so often that time actually increases vs. the variant where
the absence of refactoring tools led you to do more thinking upfront and
start coding later.

Kind regards

robert
 
D

Daniele Futtorovic

Often, most of my thinking is done before I start typing, whether it be
to use a shortcut or not.

Then you are my superior and I bow to you. As for me, I often find bugs
in the code that were clearly and solely due to my not thinking (enough)
while writing it, and at other times I my find myself in an impasse
because I didn't think ahead enough while coding.

At the same time, it may be due to my approach to designing -- I tend to
do about half of a design deductively (top-down) and the other half
inductively, bottom-up, by coding the thing and seeing whether it feels
natural and just falls into place. If it does, it means the design as a
whole is usually sound.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top