Java return intellityping?

Discussion in 'Java' started by bob smith, Nov 1, 2012.

  1. bob smith

    bob smith Guest

    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.
     
    bob smith, Nov 1, 2012
    #1
    1. Advertising

  2. bob smith

    Lew Guest

    bob smith wrote:
    > 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

    --
    Lew
     
    Lew, Nov 1, 2012
    #2
    1. Advertising

  3. bob smith <> wrote:
    > 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.
     
    Andreas Leitgeb, Nov 1, 2012
    #3
  4. On 01.11.2012 18:39, bob smith wrote:
    > 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


    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
     
    Robert Klemme, Nov 1, 2012
    #4
  5. bob smith

    Jim Janney Guest

    bob smith <> writes:

    > 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

    --
    Jim Janney
     
    Jim Janney, Nov 2, 2012
    #5
  6. bob smith

    Daniel Pitts Guest

    On 11/1/12 10:39 AM, bob smith wrote:
    > 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.
     
    Daniel Pitts, Nov 2, 2012
    #6
  7. ....

    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>

    --
    DF.
     
    Daniele Futtorovic, Nov 2, 2012
    #7
  8. bob smith

    Lew Guest

    Daniele Futtorovic wrote:
    > ...
    > 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.

    --
    Lew
     
    Lew, Nov 3, 2012
    #8
  9. On 03/11/2012 19:58, Lew allegedly wrote:
    > Daniele Futtorovic wrote:
    >> ...
    >> 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 time is not exclusive of thinking time.
    >


    That's probably the gist of the matter... :)

    --
    DF.
     
    Daniele Futtorovic, Nov 4, 2012
    #9
  10. bob smith

    Daniel Pitts Guest

    On 11/4/12 8:39 AM, Daniele Futtorovic wrote:
    > On 03/11/2012 19:58, Lew allegedly wrote:
    >> Daniele Futtorovic wrote:
    >>> ...
    >>> 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 time is not exclusive of thinking time.
    >>

    >
    > 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.
     
    Daniel Pitts, Nov 4, 2012
    #10
  11. On 04.11.2012 18:47, Daniel Pitts wrote:

    > 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

    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
     
    Robert Klemme, Nov 5, 2012
    #11
  12. On 04/11/2012 18:47, Daniel Pitts allegedly wrote:
    > 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.

    --
    DF.
     
    Daniele Futtorovic, Nov 5, 2012
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    3,002
  2. wl
    Replies:
    2
    Views:
    606
    Dimitri Maziuk
    Mar 5, 2004
  3. Ganesh Gella
    Replies:
    4
    Views:
    371
    Stuart Gerchick
    Nov 12, 2004
  4. Seong-Kook Shin
    Replies:
    1
    Views:
    521
    Richard Bos
    Jun 18, 2004
  5. Greenhorn
    Replies:
    15
    Views:
    884
    Keith Thompson
    Mar 6, 2005
Loading...

Share This Page