views:

210

answers:

5

Hello

I have recently tried code templates after reading http://www.symfony-framework.com/2008/06/03/speed-symfony-developing-with-eclipse-snippets-templates/ in my Eclipse IDE for PHP development.

I have an idea, when such tools can benefit for developer. Developers are constantly learning new tools, programming languages, frameworks etc. When you work with something new to you, your productivity is usually not very high, because you don't know(or don't remember the syntax).

I think that code templates can become very useful at this point.

Just to give you an idea, I will make an example:

Here is an code snippet of PHP Doctrine ORM finder method usage.

$table = Doctrine::getTable('User');
// find by primary key
$user = $table->find(2);

If I remember this snippet, just like Dfind(ctrl+space to run intellisense and code template replace later). Dfind (D - first letter in Doctrine word).

So, I don't need to remember all this API syntax, and just use Dfind to run Doctrine's finder method.

This is very trivial example, and maybe it is too hard to see the benefits of this approach, but you can use this feature for replacing bigger constructs(which are harder to remember).

I googled on that topic before, but didn't find any information on that unusual using of this IDE feature.

So, please, let me know what do you think about it?

+2  A: 

I'm using devexpress coderush and refactor in Visual Studio. I do use code templates often and I found they boost my productivity a lot. But for some it's more, for others less. It's a personal thing and depends on how you work.

Sascha
+1  A: 

I see it as a benefit. Some people are vehemently opposed to using templates and code completion for reasons that range from 'its annoying' to 'it makes programmers lazy'. I don't personally use templates, but that's just personal preference.

I do agree, when working with a library that has some 200+ exposed functions, its more productive to get hints until you use it enough to just remember.

Tim Post
A: 

IMO it's definitely a very useful feature, especially for all of the common language features - e.g. a for loop.

You save a lot of keypresses with snippets - e.g. auto-completing the snippet and allowing you to move rapidly over the changeable parts.

for ( variable = value ; variable < value2 ; variable++ )
{

}

So when you change variable, all three occurrences change.

Andy
A: 

Auto-completion is definitely useful, especially when working with big libraries. But code templates sounds like something that encourages violating DRY principles.

Imran
+1  A: 

Not in the long run. It is better to improve your typing skills. Anything beyond automatically closing braces and quotes for you is treacherous. It adds stuff to your code and may lure you into using a long-winded solution to a problem that can be solved with less code and more thought.

TomA