Fight Repetition

?

Fight Repetition

Niclas Nilsson

ARE youR dEvElopERS performing recurring tasks that need little think- ing? Can you find recurring patterns in the code? Can you spot code that’s been written copy-paste-modify style? If that’s the case, your team is moving slower than it should and, oddly enough, you may be the cause.

Before explaining why, let’s agree on a couple of truths about software development:

? Duplication is evil.

? Repetitive work slows down development.

As an architect, you set the tone. You’ve got the best overall grasp of the system and you probably wrote a trend-setting, end-to-end, vertical slice of the sys- tem that serves as an example for the team—an example that has been copied many times by now. Whenever a developer copies anything—be it a few lines of code, an XML file, or a class—that’s a clear indication that something could be made simpler or even completely abstracted away. Most often, it’s not the domain logic that is copied; it’s the infrastructure code that just has to be there to make it work. For that reason, it’s crucial that you can envision the effects your examples have. Any code and configuration in your examples will be the base for tens, hundreds, or maybe thousands of other slices of the system, which means you have to make sure that your code is clean, intention reveal- ing, and containing nothing except what can’t be abstracted away: the domain problem itself. As an architect, you need to be highly sensitive to any kind of repetitive patterns, since anything you write will (ironically) be repeated.

?

??But that doesn’t happen in your system, right? Take a look at that configura- tion file. What needs to be different if applied on another slice of the system, and what will stay the same? Look at a typical business layer method. Is there a pattern that shows up in other methods as well, containing things like transac- tion handling, logging, authentication, or auditing? How about the data access layer? Any code in there that will be the same except for names of entities and fields? Look broader. Can you find two or three lines of code that frequently seem to go together, and even though they operate on different objects, feel like the same thing? These are all examples of repetition. Repetition in code is something that developers eventually learn to filter out and ignore when read- ing the code, once they figure out where the interesting variabilities are found, but even if the developers get used to it, it slows them down. Code like that is clearly written for computers to execute, not for developers to read.

Your responsibility is to remove it. To do that, you may need to harvest frame- works, create better abstractions, perhaps ask the toolsmith to set up an aspect framework or write a few small code generators, but the repetition won’t go away unless someone does something about it.

That someone is you.

时间: 2024-10-25 05:59:14

Fight Repetition的相关文章

poj 3693 Maximum repetition substring(后缀数组)

题目链接:poj 3693 Maximum repetition substring 题目大意:求一个字符串中循环子串次数最多的子串. 解题思路:对字符串构建后缀数组,然后枚举循环长度,分区间确定.对于一个长度l,每次求出i和i+l的LCP,那么以i为起点,循环子串长度为l的子串的循环次数为LCP/l+1,然后再考虑一下从i-l+1~i之间有没有存在增长的可能性. #include <cstdio> #include <cstring> #include <vector>

黑书例题 Fight Club 区间DP

题目可以在bnuoj.soj等OJ上找到. 题意: 不超过40个人站成一圈,只能和两边的人对战.给出任意两人对战的输赢,对于每一个人,输出是否可能是最后的胜者. 分析: 首先序列扩展成2倍,破环成链. dp[i][j]表示i和j能够相遇对打,那么dp[i][i+n]为真代表可以成为最后胜者. 枚举中间的k,若i和j都能和k相遇,且i和j至少一人能打赢k,那么i和j可以相遇. 复杂度o(n^3) 1 #include<cstdio> 2 #include<cstring> 3 usi

(状压dp)HDU 4778 Gems Fight!

Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 2395    Accepted Submission(s): 1087 Problem Description Alice and Bob are playing "Gems Fight!": There are Gems of G differe

POJ 3693 Maximum repetition substring (后缀数组)

题目大意: 求出字典序最小,重复次数最多,的子串. 思路分析: RMQ + height 数组可以求出任意两个后缀的lcp 我们枚举答案字符串的重复的长度. 如果这个字符串的长度为 l ,而且这个字符串出现过两次或两次以上 那么你会发现在原串中  str[0] str[l] str[2*l] ....肯定有相邻的两个被包含在重复的串中. 我们求出这两个相邻的后缀的lcp 我们上面仅仅说的是被包含在重复的串中,但并不一定就是以 str[0], str[l],str[2*l]....为起点的. 那我

POJ3693:Maximum repetition substring(后缀数组+RMQ)

Description The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings. For example, the repetition number of "ababab" is 3 and "ababa" is 1. Given a

Maximum repetition substring 后缀数组

Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7578   Accepted: 2281 Description The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same conse

HLJU 1042 Fight (种类并查集)

1042: Fight Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 26  Solved: 8 [Submit][Status][Web Board] Description 虽然格斗是非常需要技术的一项运动,但是打群架却不需要什么技术,而且场面一般比较混乱,分不清谁和谁是一伙的,只能看出谁和谁不是一伙的,而且打群架经常会出现猪一样的队友,误伤自己人.现在给你一些信息,请你依据这些信息判断是否一定存在猪一样的队友. Input 包含多组测试样例

增量队列Delta Queue(RSA7)中的增量更新区Delta Update、增量重复区Delta Repetition

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4296586.html "增量更新Delta Update"区:存储的是至上次提取之后到时目前所有增量的数据:每次抽取之后(不管是从"增量更新Delta Update"区还是从"增量重复Delta Re

poj3693 Maximum repetition substring 后缀数组

http://poj.org/problem?id=3693 Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7241   Accepted: 2162 Description The repetition number of a string is defined as the maximum number R such that the string can b