Create code templates in NetBeans

You self-respecting programmer certainly uses some IDE to develop your applications and projects. And don’t give me DreamWeaver, because this tool is far from what we call organization, efficiency and quality when programming.

For those who prefer IDEs to simpler publishers, today’s tip is to speed up your development process. We will be focused on NetBeans , but I believe that other tools also provide this facility.

Well, it’s about creating code templates. This technique boils down to creating a common block of code once and then calling that block in your source code just using a ” shortcut “. For example: we can create all the syntax of a connection to a mysql database and then expand a small combination of characters to the ready structure of the connection.

How to make?

  • Go to the Tools -> Options menu .
  • Select the Editor icon
  • Go to the Code Templates tab
  • Select Language: PHP

Note that there are already a series of templates ready for php (See if the template you are going to make doesn’t already exist).

To create a new model, click New . A “ window ” will appear asking you to enter the abbreviation (this abbreviation is what we should type in the future to call the code block). We will put the name of our abbreviation as: mycon

In your expanded text , we will put:

mysql_connect ($host, $user, $password) or die ("Error connecting to the server");

Then we define the option “Define model for:” . Tab; will expand when the TAB key is pressed;  SHIFT + SPACE : when the combination of these two keys is activated and so on. Choose the one that is most convenient for you.

Now go to any document in PHP or create a new one. In the source, type mycon and then press the key combination you chose and you will see that it will generate a syntax for connecting to mysql instantly.

Very simple example, but you can apply this technique to some more refined block.

Hope this helps.

Hugs!

Holds a university degree in Information Systems, a postgraduate degree in Database Systems and a master's degree in Education with a focus on Sociocommunity Technologies. He works as a professor of technical and technological education at the Federal Institute of Education, Science and Technology of São Paulo, teaching subjects in the areas of programming, database, project development and software engineering.

Posts relacionados

Leave a Reply

Your email address will not be published. Required fields are marked *