
Code faster with Intellij IDEA live templates - javinpaul
http://maciejwalkowiak.pl/blog/2014/01/14/code-faster-with-intellij-idea-live-templates/
======
Cieplak
I use Intellij to write python and love live templates. For instance, I've set
ipdb<tab> to expand to import ipdb; ipdb.set_trace(), which seems small but
has probably saved me so much time. It's really a win for programming in Java,
because it automates the boilerplate. There's similar functionality in other
editors too, such as YASnippet
[https://github.com/capitaomorte/yasnippet](https://github.com/capitaomorte/yasnippet)

~~~
akx
Similarly, I have `ni` (yes, blatant Monty Python reference) in PyCharm expand
to `raise NotImplementedError("%file% %line%")`, for an ad-hoc web app
breakpoint.

------
Cthulhu_
Could also be a subtle hint that the language in question (Java, Maven/XML)
are too verbose. I mean, for dependencies and the like there's alternatives
(for Java & co) in Gradle and SBT, or the very simple NPM and Bower formats;
for build tools, see the same (and Grunt). There's no real benefit (anymore)
to use XML for that kind of configuration.

Same with Java. Functional programming makes for much more expressive
iteration than the iterator / for-loop pattern does, and it's much less
verbose (think list.map(doSomething)).

~~~
pron
Yes, but so what? Sometimes a little IDE love is a lot easier and more
productive than changing your entire stack to use a different language/tool.
Verbosity is a downside which might be more than offset by other upsides. It
might certainly be beneficial to change your stack, but that's usually a very
big decision that might have some serious and unforeseen consequences.
Verbosity alone is rarely reason enough to make a switch.

~~~
jbrechtel
Why the "Yeah, but so what?" rhetoric?

This is an important point, regardless. Sometimes new projects are started and
it's not a matter of switching. Sometimes verbosity, and the things it
negatively impacts, are worth switching. That's what.

------
Roboprog
I still don't know what a monad is, but I agree with the "pure" functional
programming crowd that this kind of boiler plate generation is _expletive_
retarded.

If your language isn't Lisp and cannot make macros to sub in the variable bits
in an otherwise redundant template pattern, you might have some other options,
though.

For those of us condemned to industrial, "enterprise" languages, you might try
using a DSL or (build-time!) code generator, rather than cluttering up your
source code with editor generated crap.

------
blameless
I've been using these for years in Visual Studio.

My most commonly used one is "prop" which generates an automatic property in
C#: "public string Name { get; set; }". I type "prop", then hit tab, string is
selected and I can change it to any type I want, hit tab again, I can now
change the name of the property, hit enter and I'm done Takes 1.5 seconds.

~~~
afsina
Idea had this back in 2001.

------
ChronosKey
For vim users: [https://github.com/garbas/vim-
snipmate](https://github.com/garbas/vim-snipmate)

------
noir_lord
This works really well for php on phpstorm as well (when working with
bootstrap and knockout.js it's _very_ handy).

What I would love (and if it can do it I've not found it) is to be able to do
something like

koo(fooBar)<TAB> and get something like

    
    
        self.fooBar == ko.observable("");
    

would be amazing!.

~~~
makepanic
You can create live templates yourself in intellij:

Settings -> Editor -> Live Templates -> JavaScript

And add the live template for abbreviation 'koo' and template text like:

self.$VAR$ == ko.observable("")

See [http://www.jetbrains.com/idea/webhelp/live-
templates.html](http://www.jetbrains.com/idea/webhelp/live-templates.html) for
more information.

~~~
noir_lord
I already do that.

That though inserts the template and lets you tab through it.

What I'm suggesting is to pass fooBar _before_ you expand the template so that
you don't need to tab through it (similar to how zen-coding does id's and
classes on html)

i.e.

func(returnFoo,$foo,$bar,$fizz,$buzz)<TAB>

becomes _without having to tab through_.

    
    
        public function returnFoo($foo, $bar, $fizz, $buzz)
        {
        
        
        
        }

~~~
IanCal
If you use vim you can use
[https://github.com/SirVer/ultisnips](https://github.com/SirVer/ultisnips) and
write python code to generate the output.

~~~
noir_lord
That looks awesome.

Embarrassingly for someone who has been a Linux user for more than 15 years
I'm terrible with Vim (I can just about use it systems administration (though
I often just use nano)) and use IDE's for most things.

------
nusbit
Does anybody know another resources about live-templates ( some advanced ) ?

~~~
sghill
I found the IntelliJ docs[1] handy for discovering predetermined variables
like $END$ and $SELECTION$.

[1]: [http://www.jetbrains.com/idea/webhelp/live-
templates.html](http://www.jetbrains.com/idea/webhelp/live-templates.html)

~~~
kremlin
Yes, setting up variables in the live templates is just...so BEAUTIFUL! You
can create default values and tab through them, changing them as needed.

Don't know what I'd do without PyCharm.

