Of agile development's "loose programming" series: L-type code structure (one of programming)

Source: Internet
Author: User

This article is part 1 of the "loosely connected programming" series. (Loose Pair Programming topic directory)

As mentioned in the previous three articles on the L-type code structure, the micro-plan and estimation process of the L-type code structure will be different from the general programming method. Today, I want to write some new code, write and record the entire process. If the middle is stuck, I will try to record it as much as possible.

Business Requirements: This is a feature in Mars. In the past, user stories were presented using the story tree (that is, user stories with parent-child relationships). The story tree belongs to a product. However, when I want to release a version recently, I feel that a feature that I previously thought could not be used for the time being has become very urgent, that is, the current version (such as "online version ") in the next release of the current version (for example, "simplified trial version") of version (for example, "r20120331a"), what are the functions? If some features are released in this release, they will pass automated testing (some features now have automated test cases, but they may not pass if they are running because they are not released for the moment) and manual testing. It looks like this: 1. first, make a corresponding relationship with the user story on the version edition. 2. then, perform (subject to version constraints) on version 3. the general implementation on release (subject to version constraints) includes the following work: 1. three database tables are used as the corresponding link (if a table is used, there will be one more field, indicating whether it is a version, version, or release), estimated by 7 or 21 functional points, it takes 7 or 21 person-days (in OA project development, 1 function point requires about 7 ~ 9 hours, product R & D should be a little longer ). 2. (display the corresponding relationship, add a story, and create a story) × 3. Estimate based on 12 function points, it takes about 4 × 3 = 12 person-days. The person-days here include the total man-hours from Requirement Analysis to testing and release (including maintenance for a period of time to stability), and the actual development accounts for about 50%, that is, about 10 ~ About 15 person-days. Step 1 of L-type code structure: find similar businesses. This refers to business logic similarity, such as binary tree or query. We have previously done a "team-to-product ing" function, that is, to arrange which teams can access which products (and vice versa ). The interface is as follows (it's ugly. You will have the opportunity to change it later, and the style of the interface is being modified now ):
This kind of business is called item to item link at the bottom layer of the Martian. item is anything that exists in a parent-child relationship, and link is a link between any two things. The figure also shows the relationship between the department tree and the product tree. What is to be established soon is the relationship between the product tree (version, etc.) and the user story. Step 2: Find the Business Code team on the left and the product on the right (that is, "What products can the team access "):
Public actionresult linkteam2product (INT focused1_mentid = 0) {viewbag. itemtreeviewmodel = new itemtreeviewmodel ("team-product ing", productline. productrootid, systemitemwhat. product, whattypes: itemwhattype. productproductline + "_" + itemwhattype. productproduct + "_" + itemwhattype. productedition); focused1_mentid = focused1_mentid = 0? Department. departmentrootid: focused1_mentid; viewbag. linkitem2itemsviewmodel = new linkitem2itemsviewmodel (productline. productrootid, systemitemwhat. product, department. departmentrootid, systemitemwhat. deaprtment, focused1_mentid, whattypes: itemwhattype. productproductline + "_" + itemwhattype. productproduct + "_" + itemwhattype. productedition, leftpadwhattypes: itemwhattype. deprtmentprogram + "_" + itemwhattype. deprtmentteam); Return view (itemtree. viewpath );}
Itemtreeviewmodel is used to generate the tree on the right (note that the first-level directory is horizontally arranged to make good use of the wide screen space); linitem2itemsviewmodel is used to process links and display the tree on the left. This is another function, similar to the previous one, but the product is on the left, the team is on the right, and "which teams can access the product", the advantage is that you don't need to change it on the left:
Public actionresult linkproduct2team (INT focusedproductid = 0) {viewbag. itemtreeviewmodel = new itemtreeviewmodel ("product-team ing", department. departmentrootid, systemitemwhat. deaprtment, itemwhattype. deprtmentprogram + "_" + itemwhattype. deprtmentteam); focusedproductid = 0? Productline. productrootid: focusedproductid; viewbag. linkitem2itemsviewmodel = new linkitem2itemsviewmodel (department. departmentrootid, systemitemwhat. deaprtment, productline. productrootid, systemitemwhat. product, focusedproductid, whattypes: itemwhattype. deprtmentprogram + "_" + itemwhattype. deprtmentteam, leftpadwhattypes: itemwhattype. productproductline + "_" + itemwhattype. productproduct + "_" + itemwhattype. productedition); Return view (itemtree. viewpath );}

The two codes are similar, so it is more convenient to use the code later.
Step 3: Modify the New Business Code controller and modify the following parameters:

Public actionresult linkproduct2story (INT productid, Int? Focuseditemid) {viewbag. itemtreeviewmodel = new itemtreeviewmodel ("product-story ing", productid, systemitemwhat. story); viewbag. linkitem2itemsviewmodel = new linkitem2itemsviewmodel (productid, systemitemwhat. story, null, productline. productrootid, systemitemwhat. product, null, focuseditemid); Return view (itemtree. viewpath );}

Step 4: if necessary, modify the underlying code. There are two problems in the original New linkitem2itemsviewmodel: 1. the original programmer will not use Int ?, So the default variable = 0 is used in the action to use Int ?. 2. The code that processes = 0 (now = NULL) is

focusedProductID = focusedProductID == 0? ProductLine.ProductRootID : focusedProductID;

It is written in action, so it must be written once every time.
Instead, pass in the new viewmodel directly for internal processing. 3. There is a crossover of variable order, so we have to use: To identify the easy to see wrong places and re-adjust the order to become symmetric, so we don't need to write. So the newly written function has one row less than the original two (also changed) and two fewer: and its variable name.If you modify the code at this time, first test whether the original function is normal, and then debug the new function. Otherwise, it is difficult to locate the two errors.A major benefit of L-type code is that each improvement does not exist in addition form, but multiplication. As long as one person can change a place, many people can change a place.In this way, the highest collective ability can be taken as the overall ability of the team. In traditional teams, the minimum capability usually determines the final quality of the product.
Step 5: When debugging, there is actually nothing to debug. After copying and pasting the two partial views and renaming them twice, the result is displayed:

You can add "view all stories" to the "Lite version" release.

No view is written. How can this problem be solved? The following sentence:
return View(ItemTree.ViewPath);

To a reusable view, the structure of the view is a pad on the left, and a horizontal tree of the first-level directory on the right (or not ), it will find a name named "_ [action] leftpad in the current directory. cshtml "view to display pad and" _ [action] treenode on the left. cshtml file to display each node on the right. This is why you copied, pasted, and renamed the view. Similar to functions, the partial view can be regarded as the underlying layer. It can be reused if it can be reused. Summary: what is not mentioned? 1. Where are the database tables? Because the linkitem2items table already exists, you do not need to create a table. There are still some issues: 1. in business requirements, a user story cannot be added to the following release if it is not added to the version edition; or vice versa, if it is added to the release, it should be automatically added to the version. This requirement has not yet been met.
This is expected to require more than 10 lines of code. 2. I copied and pasted the renamed file and it worked without any changes. This sounds a good thing, but it also showsThere are two sections of code that are the same and need to be reused again. Otherwise, any changes in the future need to be modified in multiple places.. This is expected to require about 5 lines of code.
Benefits of L-type code

1. Reduced code

These functions are about 20 ~ 30 functional points (depending on the number of database tables created), according to the International Data on qtm, C # each functional point requires 59 rows, so 59 × (20 ~ 30) = 1200 ~ 1500 lines, but if there is an L-type code structure, more than 20 lines of code are required.

2. Reduced workload

The work just now started at and now at. It took less than one hour to deduct the time spent on blog writing. In addition, it took only one day to complete the remaining questions. So one day can work for 10 ~ 15 days.

This does not even require personal skills. Even new users are familiar with this architecture, and the speed is almost the same.

3. Quality Improvement

Each time the underlying layer is called multiple times, it will be discovered as long as one failure occurs. Each underlying change will help to optimize multiple functions, as will the bug modification.

4. New users are quick start

Generally, the "Code reduction" and "code optimization" often face the following problems: Can beginners understand and maintain them?

In fact, although this system seems quite complicated, the speed of the 20 lines of code is still 1200 ~ 1500 rows are much faster.

All the code in this example, except the new functions in step 3, other code, such as the linkitem2itemviewmodel and several actions that I reconstructed, and copy and paste the renamed leftpad/treenode code, actually, it was written by another person. He has only half a year of programming experience when writing this code (he has worked as a technical support for 4 years, has studied C ++ in college, and has never moved code since ), the number of lines of code actually written is estimated to be only 1000 (we only have 11000 lines of code ). Of course, when writing the code, he also referred to the design of another "Iteration plan" page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.