YOU NEED TO KNOW About Code Generators for Quick Web Development

      Comments Off on YOU NEED TO KNOW About Code Generators for Quick Web Development

As a web developer, one thing that helps me to swiftly develop web applications is to use a common application framework that is flexible and robust. Additionally, I love to use code generators to create code for custom applications I build for my consumer. My most effective code generators, create code for interacting with the local database dedicated to my website.

Normally, it really is bad practice to repeat code when doing development. However, there are specific instances when this can be beneficial and assist in creating dynamic web applications. Right here, we will discuss a few of the many applications that I have found useful and ways to apply them to your own business.

Object-Oriented Classes

A proven way I enforce code reuse is by using object-oriented design. For my data access layer I create an abstract category which contains the common features. Next, I create derived classes which implement the precise methods which are essential for the entity style (usually a database table).

These derived classes have several fields which represent the fields defined for the table. They also contain mappings for the principal keys, any related fields that are retrieved from related tables, and custom methods for querying the database. The theory is that all the database telephone calls are encapsulated in the data access layer classes.

These derived classes have sufficient similarities between one another that it made sense for all of us to create a code generator to create these files from the data source schema.

How to Generate Code in Your Intranet

On our intranet, we have the code generated connected right to our database operations scripts. When an administrator is definitely viewing a table schema, they have a button on the bottom of the screen to create the code for the data access layer. When the user presses this option, the code is quickly generated and an individual can click anyplace on the code to select the code block and backup it to the clipboard.

The procedure of generating code is surprisingly simple. We just retrieve the schema from the data source and from that we define all the macros that are needed to substitute into a program code template. These macros include points such as the script name, database table name, primary key fields, public fields, private areas, and a generated class name.

The code is end result to the monitor as pre-formatted text. Below that is a web form where in fact the user may tweak any of the macro values which were generated. After making changes to these values, they are able to click a submit key which regenerates the code utilizing the custom macro values. Needless to say this step is optional. The user may simply choose to copy all the program program code and paste it in their program code editor and continue making adjustments that way.

Table Administration

In my own website administration panel, I have a lot of pages that are built for managing database tables. I have an extremely capable library which handles all the heavy lifting for paging through a table of records, developing a new document, editing and deleting an archive. That is an object-oriented class that requires a variable number of parameters.

To create a new administration area, I just need to instantiate this class, define all of the required properties, and call a method called “Process”. The resulting document is usually no longer than 25 lines of code. Creating these files doesn’t take lengthy when done by hand. However, I knew that creating a program code generator for these server-part scripts would save us considerable time.

Again, the key to accomplishing this goal was to first read the database schema for a desk to get all of the field definitions. From these definitions, it would be a simple matter to generate the code from an existing script template. I simply define macros for several of the properties I have to substitute in the template. As the table schema is read, I develop these components which are later substituted into the template.

Special Considerations

When generating code, it is very important keep in mind the way the script will likely be used. In my data access layer scripts, I know they are usually two directories beneath the website root. For this reason, I know that any relative links have to go up two levels to get to the site root.

Another important area to consider is form validation. There are certain constraints you can place on a web web form to limit the quantity of characters a user enters into a text field. You can even make Boolean areas display as radio buttons labeled “Yes” and “No”. Date fields can display utilizing a specialized date picker.

Other special data fields can be displayed using the field name. For instance, fields containing the word “Password” could be displayed as password fields. I take advantage of fields with the name “created” and “modified” to monitor when a record has been changed. Fields that have the text “email” could possibly be validated to make sure they contain a valid email address. Also, fields that have the text “postalcode” could possibly be tested for legitimate postal codes.

I try to build my code generator so it is as smart as can be. The thinking behind this is that the developer can easily remove extra code that was added if they find too much validation is being done or the incorrect type is performed. The more work it is possible to save for the developer, the higher off you will be in the long run.