Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Less typing in java print statements - Epic Win !

 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Bliss !!!

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modern day IDEs already have a feature where a particular key combination gets you that, without you having to type all of it.
 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:Modern day IDEs already have a feature where a particular key combination gets you that, without you having to type all of it.


Ok, how do i enable that on my eclipse ? I don't see anything when i type Sys...It starts appearing only when i type System.
After that, there is more selection and pressing keys.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jack wrote:
Jaikiran Pai wrote:Modern day IDEs already have a feature where a particular key combination gets you that, without you having to type all of it.


Ok, how do i enable that on my eclipse ? I don't see anything when i type Sys...It starts appearing only when i type System.


I'm on IntelliJ these days, but from what I remember, you have to just type sop and then Ctrl+Space (or whatever the auto completion key combination is).
 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:
I'm on IntelliJ these days, but from what I remember, you have to just type sop and then Ctrl+Space (or whatever the auto completion key combination is).


Why do you use intellij ? Is eclipse and netbeans not good enough for you ?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jack wrote:
Jaikiran Pai wrote:
I'm on IntelliJ these days, but from what I remember, you have to just type sop and then Ctrl+Space (or whatever the auto completion key combination is).


Why do you use intellij ? Is eclipse and netbeans not good enough for you ?

Personal preference.

Jaikiran Pai wrote:
I'm on IntelliJ these days, but from what I remember, you have to just type sop and then Ctrl+Space (or whatever the auto completion key combination is).

Actually, turns out it is sysout and not sop (see here http://www.makeuseof.com/tag/8-keyboard-shortcuts-beginner-eclipse-ide-users/)

 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jack wrote:
Jaikiran Pai wrote:Modern day IDEs already have a feature where a particular key combination gets you that, without you having to type all of it.


Ok, how do i enable that on my eclipse ? I don't see anything when i type Sys...It starts appearing only when i type System.
After that, there is more selection and pressing keys.


Hit Ctrl+space at anytime and eclipse will popup auto suggest for you. If there is only one option it will fill it for you. You can even setup macros (forgot what it is called exactly) so if you type sop Ctrl space, it will convert it into code for you
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option is



which lets you type all sorts of things:



This has the (arguable) advantage that the actual source code is less wordy. Sometimes this could make your code clearer, although other times it might be considered confusing.


 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:Another option is



which lets you type all sorts of things:



This has the (arguable) advantage that the actual source code is less wordy. Sometimes this could make your code clearer, although other times it might be considered confusing.


Thanks. But thats still long - sopln(arg) < out.println(arg). Actually, I use sopln for debugging and i have many debug statements that i keep on removing and adding.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, of course, use a debugger for debugging!
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:You can, of course, use a debugger for debugging!

Or set up a logging system that you can configure without a need for recompiling (such as log4j). I'd say this is a handy tool, since the logging statements remain in the program and can be turned on or off as needed, even in production.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other posts you have seemed concerned with how things would reflect on an employer, so I'll let you know that if you were on my team, this would be an epic fail!

Adding superfluous wrapper methods around existing methods -- especially those that are widely used and understood -- just to "save typing" would not fly on my watch. Extra cruft is bad. It's a bug waiting to happen, and it's confusing to everyone else.

As has already been pointed out, it's an IDE's job to make writing code easier, not adding extra goop to the actual code.
 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:In other posts you have seemed concerned with how things would reflect on an employer, so I'll let you know that if you were on my team, this would be an epic fail!

Adding superfluous wrapper methods around existing methods -- especially those that are widely used and understood -- just to "save typing" would not fly on my watch. Extra cruft is bad. It's a bug waiting to happen, and it's confusing to everyone else.

As has already been pointed out, it's an IDE's job to make writing code easier, not adding extra goop to the actual code.


Ok, i get the point. It makes the code confusing and bloated (wrapping). Thanks for letting me know.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:[I]f you were on my team, this would be an epic fail!

Couldn't agree more.

Consider that you spend more time debugging code than writing it in the first place, I would think any time saved with this 'trick' would be lost by others trying to figure out what "sopln" does.

Also, I have types System.out.println() so many times, it's like typing hello or rosenberger - I don't think about the individual keys...my fingers just know what to do.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to pile on, but I agree, this "shortcut" is a really bad idea.

A major part of writing code is to communicate to the human who reads it six months after you wrote it. Your local/custom stylings obscure what is an instantly recognizable idiom: System.out.printXX causes printing on the console. No one knows what your idiom does, until they slog through your code to find the method.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just type "syso" and hit Ctrl+Space it will write the complete System.out.println();
It works for me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is specific to your IDE; it will not work for everyone. Most IDEs will allow such shortcuts to be defined.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have just been born too late Andy. I remember grizzled old programers showing me how to alias ls to l and cp to c in order to save keystrokes. Java tends to discourage abbreviations though, which I like because it means I don't have to remember how someone chose to abbreviate something. Was that variable called mgr, mngr, or man? With IDEs to take up the tedium of having to type things out, there's really no need to abbreviate anyway. As long as I'm on a soapbox, let me say this. You'll never regret time put in to learning how to use your tools well. The templates (like sysout) in Eclipse can save you a lot of typing, and you can even define your own. Learning how to use a debugger well is much more effective than using printlns everywhere, and real logging is better than printlns as well. These things take a certain investment to learn, but they pay great dividends.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:You may have just been born too late Andy. I remember grizzled old programers showing me how to alias ls to l and cp to c in order to save keystrokes.


I remember using C macros for printing logging statements *shudder*
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember well the chaos resulting from everyone defining their own macros.

At one company, we instituted a group-wide C macro "library" that only the senior developers could add to. No one was allowed to define their own, so everyone used the same macro set.

Earlier, when I was working for DEC, we used a language called BLISS, which had a very powerful macro capability that put the macro facility in any other language to shame. The downside was that everyone used it to basically set up their own DSL. So code written by any developer looked like a completely different language than anyone else's. This was decidedly not A Good Thing™.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote: DEC, we used a language called BLISS, which had a very powerful macro capability that put the macro facility in any other language to shame.

Almost true. Its macro facility was based on the macro facility in the PDP-10/PDP-20 assembly language that was named, Macro-10. It had an amazing macro facility that was used everywhere by systems programmers. When the "use Bliss or die" directive came down, they had to provide similar in Bliss to bring the systems programmers along.

Bliss' was good, but not quite as powerful as Macro-10.

It took very strong technical management to control the wild home-grown-DSL in both Macro-10 and Bliss.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic