Programmers face many challenges when developing code for programs, applications, and other software solutions. Programmers will typically deal with changing business and design guidelines throughout a project's development cycle. Communication among a myriad of stakeholders including project managers, developers, testers, and other team members must also be effectively managed. In addition, programmers need to achieve design, performance, user experience, and quality goals for their code while meeting expectations for cost and schedule.
As well as the challenges noted above, programmers are increasingly having to write code that meets with various regulatory and compliance guidelines. Such guidelines are typically not dictated by traditional technical considerations for the code per se, but are driven instead by legal, business, and/or policy considerations. Dealing with the various guidelines can often be inconvenient for programmers, and it is possible for even careful programmers to accidently write code that violates a guideline or other type of requirement. Guidelines may also change over time which can cause programmers to have to retroactively modify legacy code to conform to the changes. This can increase development costs as well as present an opportunity for bugs to be introduced into the code.
This Background is provided to introduce a brief context for the Summary and Detailed Description that follow. This Background is not intended to be an aid in determining the scope of the claimed subject matter nor be viewed as limiting the claimed subject matter to implementations that solve any or all of the disadvantages or problems presented above.
A compiler deployed as a component of an integrated development environment (“IDE”) is adapted to transform source, code into target code that is correct by construction by complying with approved patterns described by an external configuration file which is utilized to parameterize the generation of the target code by a code generator. The approved patterns can express various design requirements, guidelines, policies, and the like that are acceptable for the target code to include as well as those which are unacceptable. A rules generator that applies regular tree grammar is configured to encapsulate the approved patterns in the external configuration file using a formal description that is machine-readable by the code generator. A source code translator is alternatively utilized to transform non-compliant source code into compliant source code that adheres to the approved patterns.
In various illustrative examples, a rules generator may be utilized to transform informal descriptions of correct software behavior into rules that formalize acceptable patterns that are desirable for the target code to include (for example, to improve performance of code by speeding up execution and avoiding unbounded memory growth) and unacceptable patterns which the target code is expected to avoid (for example, to ensure compliance with legal guidelines such as license restrictions). During compilation of the source code, the code generator applies the rules from the external configuration file to generate compliant target code in view of the acceptable and unacceptable patterns. However, if the target code is constrained, and is not able to be generated in a manner that is compliant with one or more of the patterns (for example, because there is no defined workaround to avoid an unacceptable pattern), then the IDE can return an error or other warning back to the programmer to indicate that the source code cannot be reduced to compliant target code.
Advantageously, by moving the compliance mechanism down to a lower level in the IDE at the compiler, programmers are freed from having to take the approved patterns into consideration. They can write source code without taking any special actions but still know that the generated target code will be correct by construction. This freedom can be expected to improve productivity and reduce coding errors, particularly since programmers may often view compliancy issues as being difficult and constraining.
The rules in the external configuration file can be tailored to avoid generating code that exposes known bugs. In addition, the parameterization of the code generation from utilization of the external configuration file provides significant flexibility so that the generated target code may be readily tailored to suit different runtime environments and application configurations. Parameterization also accommodates changing policies without the compiler needing to be rewritten with each change.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
Like reference numerals indicate like elements in the drawings.
Processor 160 may include at least one conventional processor or microprocessor that interprets and executes instructions. Memory 130 may be a random access memory (“RAM”) or another type of dynamic storage device that stores information and instructions for execution by processor 160. Memory 130 may also store temporary variables or other intermediate information used during execution of instructions by processor 160. ROM 140 may include a conventional ROM device or another type of static storage device that stores static information and instructions for processor 160. Storage device 170 may include compact disc (“CD”), digital versatile disc (“DVD”), a magnetic medium, or other type of storage device for storing data and/or instructions for processor 160.
Input device 120 may include a keyboard, a pointing device, or other input device. Output device 150 may include one or more conventional mechanisms that output information, including one or more display monitors, or other output devices. Communication interface 180 may include a transceiver for communicating via one or more networks via a wired, wireless, fiber optic, or other connection.
The computing platform 100 may perform various functions in response to processor 160 executing sequences of instructions contained in a tangible machine-readable medium, such as, for example, memory 130, ROM 140, storage device 170, or other medium. Such instructions may be read into memory 130 from another machine-readable medium or from a separate device via communication interface 180.
IDE 200 in this example includes a user interface 206 (which is typically implemented as a graphical user interface or “GUI”) that exposes development tools to a programmer, including a code editor 211, automation system 220, and project system 228. These tools are typically utilized to enable the programmer to readily generate source code 231 in some human-readable computer programming language (e.g. C#, Visual Basic, .NET programming language, etc.). Source code 231 is compiled by the compiler 238 into target code 241. As shown, the compiler 238 is coupled to the user interface 206 to expose errors to the programmer that may occur during compilation of the source code 231.
The code editor 211 is arranged to enable source code to be written and edited and will often include features to speed up input of source code such as syntax highlighting, automated completion, and bracket matching functionality. The code editor 211 may also check syntax of the code on-the-fly as it is typed in some implementations. The automation system 220 is configured to automate some of the tasks encountered when developing software. The automation system 220 may include scripting or other automation tools to automate linking and compiling processes, for example, by performing scripted calls to the compiler 238.
The IDE 200 also supports a debugger 246 that typically enables the programmer to observe run-time behavior of a program and locate logical and/or semantic errors in the code. For example, the debugger 246 allows the programmer to break, or suspend, execution of the program to examine the code, evaluate and edit variables in the program, view registers and instructions created from the source code 231, and view the memory space used by the program. Although debuggers can be implemented as standalone functionality, in this example the debugger 246 is accessed via the commonly-utilized user interface 206 in the IDE 200. Some debuggers are configured to work with code at various stages in development, for example as source code (as indicated by arrow 250) and/or as target code (as indicated by arrow 252).
As shown in
The components in the front end (indicated by reference numeral 450) are configured to perform conventional functionalities. Here, the lexical analyzer 406 converts a stream of characters into a sequence of tokens which are defined, for example, by regular expressions. The parser 410 then parses the token sequence to identify the syntactic structure of the program. A parse tree can be constructed to replace the linear structure of the token sequence by application of some formal grammar. In some implementations, additional semantic analysis may be performed on the parse tree by performing type checking (in the type checker 416) or other processes to add semantic meaning to the parse tree. It is noted that the particular components utilized in the front end 450 of the compiler 238 and the functionality embodied therein can vary from that shown in
As shown in
The approved patterns are used in this example to express various types of guidelines (and/or requirements) to which the target code is desired to adhere and can comprise either acceptable patterns that the target code can include or unacceptable patterns that the target code needs to avoid, or both. As shown in
It is emphasized that the list above is not intended to be exhaustive and that other types of guidelines may be utilized as may be needed to meet the requirements of a particular implementation. For example, law, regulations, rulings, edicts, or other type of imperatives to which strict adherence is needed can also be incorporated into the approved patterns. Typically, the approved patterns will be expressed informally, as indicated by reference numeral 612, for example by being written in a memorandum, e-mail, or other conventional form.
A programmer may utilize a rules application 625 that exposes a rule editor 632 to enable the informal expression 612 to be formally expressed as the machine-readable representation that is encapsulated in the external configuration file 505 as one or more rules. The rules application 625 may be implemented as a standalone application, or alternatively be deployed as part of the IDE 200 (
A rule generator 640 will apply regular tree grammar to generate rules that are added to an assembly as the embedded resource 525 (
Illustrative examples of code generation with approved patterns are now presented. In a first example, the legal guidelines 6055 may be applicable to a given programming scenario because of license or other legal restrictions on the use of particular programming techniques, user experiences, and the like. Here, it is assumed that strict guidelines for the activation of ActiveX controls in webpages are applicable to the generated target code. It is emphasized, however, that the activation restrictions could be in place for other reasons.
ActiveX controls are typically downloaded and executed by a web browser running on a client computer to establish rules for how applications share information.
1. A call to an external script function that outputs the APPLET, EMBED, or OBJECT element cannot be parameterized.
2. A reference to an external script file must be located in a separate part of the HTML document than the call to the external script function.
3. A reference to an external script file cannot have parameters passed using a URL (Uniform Resource Locator) or HTTP (Hypertext Transport Protocol) POST method data. Exception: A GUID (globally unique identifier) can be included in the URL if it is not the same GUID as the classid attribute of the <object> tag.
With regard to pattern 1,
With regard to pattern 2,
With regard to pattern 3,
Several code generation techniques, or workarounds, can be utilized so that the compiler 238 (
The resulting code will satisfy the acceptable pattern shown in
In the second illustrative example of code generation, certain unacceptable patterns are avoided where the target code is constrained and cannot be implemented properly or efficiently. For example, in some versions of the Microsoft Internet Explorer® brand web browser, the implementation of JavaScript does relatively little caching of member lookup (i.e., a process in which the meaning of a member name in the context of a type is determined). In the code sample 1800 shown in
Similar optimizations for JavaScript running on Internet Explorer can be embodied in other patterns, for example, by caching local variables and function pointers whenever possible, avoiding the use of expensive functions such as eval, optimizing string manipulations by avoiding intermediate results, avoiding use of closures and property accessor functions, and a variety of other known techniques as described, for example, at http://blogs.msdn.com/ie. These and similar techniques may be encapsulated as acceptable and unacceptable patterns in the external configuration file 505 described above in the text accompanying
In some cases, multiple passes may need to be made to achieve compliance with the patterns, as shown by path 2025 from the decision block 2031.
That is, the target code is utilized in a feedback loop back to the compiler to ensure that the output of the code generator is correct by construction and complies with the desired patterns. If, after some predetermined number of passes (which may include just a single pass), the source code cannot be reduced to compliant target code, then an error message is output (2036) which can be displayed to the programmer via the user interface 206 in the IDE 200 (
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.