Browse DevX
Sign up for e-mail newsletters from DevX


Put Modern Code Generation to Work : Page 4

The notion of software that writes software has been around for decades, but it is only recently that developers are taking this notion of code generation seriously. What changed? Code generation changed—and much for the better.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Minimum Requirements
In the end, regardless of which type of application generator you choose, you want the generated code to be something you can get your arms around. A modern application generator should:
  • Start from scratch with an application-specific data model.
  • Create everything needed for a functional three-tier application, link everything together, and deliver a bug-free, functional prototype of the desired application.
  • Automatically generate all of the source code for the application, native to the target platform and optimized for the production environment.
  • Provide complete and well organized source code that's easy to modify and extend.
  • Automatically preserve and reintegrate customizations or extensions during subsequent application regenerations.
Extending the Code Generator Itself
Let's consider this last point in a bit more detail.
Automatically preserve and reintegrate customizations or extensions during subsequent application regenerations.
Most good declarative code generators are themselves extensible. A major drawback of past efforts at code generation is that the tools were one-way streets: Once you push the generate button you own the code. That just doesn't work for today's iterative style of development.

Ideally, the code generator should allow you to put your extended or modified custom code back in, and allow that custom code to become part of what the code generator tool can generate for future applications. Rather than just spit back out what is put in, the code generator adds value by creating a repository of code assets, making the customized code written for one application more flexible and multi-purpose. You (and developers anywhere in your organization) should be able to leverage these code assets over and over again.

In essence, the code generator does what no developer has time or incentive to do: It manages selected application code and creates a knowledge base of re-usable code that meets the specific standards and practices of that unique organization. Now, code written specifically for one application can be regenerated for future application development. All without any additional work or drag on the initial application's project schedule.

Specifically, you might leverage custom code in the following areas:

Presentation Layer: Because many large enterprises require that locally constructed applications conform to a distinct set of functionality as well as look-and-feel, the custom HTML page layouts used in one application can be re-used in future applications.

Application Layer: Any aspect of the application logic should be able to be extended and then re-generated for future applications. A simple example is generating different order validation logic for orders coming from outside your system (i.e.: from partners) than for those originating inside the company network (i.e.: from the inside sales team).

In the data validation example shown below, I added additional logic to the "safe class" in order to override the validateData function. A "safe class" is generated once and never overwritten. Thus, it does not have to be rewritten for future applications if your code generator can adopt it and make it available for future development efforts.

'This Handler implements server side validation logic_
for the V_CityFieldCustomValidator control Private Sub V_CityFieldCustomValidator_ServerValidate_
(ByVal source As Object, ByVAl args As_
System.Web.UI.WebControls.ServerValidateEventArgs) _ Handles V_CityFieldCustomValidator.ServerValidate 'get the value to validate Dim value As String = Me.V_CityFieldCustomValidator.GetValueToValidate() If (value <> "Mountain View")) Then Me.V_CityFieldCustomValidator.ErrorMessage_
= "Please move to Mountain View." args.IsValid = False End If End Sub

After acquiring the City field, we compare it to "Mountain View." If the City is not Mountain View, then we return "False," generating an error message, and keeping the user on the page. If the validator returns "True" the user proceeds to the next page.

What's the Bottom Line on Code Generators?
In the end, you need your development tool to generate a lot of code very quickly for those aspects of the application that you really don't want to build. Of course, code generation is not a magic bullet. It may generate a majority of the application, say 80 percent, but it will never be able to do the entire application for you. For now at least, George Jetson is still just a cartoon.

Alan Fisher is co-founder and chairman of Iron Speed, Inc., maker of Iron Speed Designer, the popular application generation software for rapidly building Microsoft .NET Web applications. You can reach him .
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date