我有一些让我感到骄傲的东西,其中一些是几年前由我自己写的。它不必一定是错误的,只是错误的代码。
我有一些让我感到骄傲的东西,其中一些是几年前由我自己写的。它不必一定是错误的,只是错误的代码。
Answers:
我不为修复感到骄傲,因为它是如此明显,但是我记得修复的最恐怖的代码就是这个。
if (userName=="John O'Reily") { userName= "John O''Reily";}
if (userName=="Stacy O'Neil") { userName= "Stacy O''Neil";}
if (userName=="Finnegan O'Connor") { userName= "Finnegan O''Connor";}
...
someSQL = "SELECT * from Users where UserName='" + userName + "'";
显然,每当新用户(通常是爱尔兰人)开始在应用程序中出现错误时,以前的开发人员就一直在添加新行。
我将其保留为全班的练习,以解决其固定方式。
UserName='John O''Reily'
会成为UserName='John OReily'
(就像C如何将相邻的字符串文字连接起来),但是没有想到丢失的内容'
:(
我不应该为此感到自豪,但是出于某种原因,它令人满足。
除了在学校里使用COBOL之外,我没有任何经验,但是我在图腾柱上是个卑鄙的人,我们需要向外包商提供编译源代码以进行Y2K检查。我们有一个带有多个例程的COBOL文件,该例程在文件中相互调用,类似意大利面条,而且太大了,无法加载到当前的IDE中进行编译。需要将其拆分成至少两个物理文件,并且这些文件当然需要在自己的文件中包含它们所需的所有内容。(或者也许有一种将它们链接在一起的方法,但是我并不真正了解COBOL。)
无论如何,我拿走了大约100,000行的文件,然后轻轻地将数十个例程分开,以找到两组彼此独立的例程,因此可以存在于两个单独的文件中,每行大约50,000行左右。(我认为编译器可以处理的最大行数约为80,000,因此确实需要相当平均地匹配。)
我正在读一本我不知道的古老语言,并且在这项任务上仍然很成功。
我将光标移出触发器,将插入40,000条新记录的时间从一个小时减少到不到一分钟。最终,这使我能够在不到冰河时间的情况下插入2100万条记录,但是修复之后我们从未尝试导入2000万条记录,直到现在,所以我没有关于节省了多少时间的统计信息。
我见过最糟糕的是一些Java代码从文本语料库中提取关键句子。
公平地说,与我们那里的一些东西相比,这算不了什么,但是前后的质量仍然存在巨大差异。考虑以下一个函数的实际前后代码:
之前(尝试查看之后,先弄清楚它的作用!):
public static void getCluster() {
count = new Vector();
for (int i = 0; i < begin.size(); i ++)
count.add("1");
if (begin.size() > 1) {
for (int i = 0; i < begin.size() - 1; i ++) {
for (int j = i + 1; j < begin.size(); j ++) {
int b1 = Integer.parseInt(begin.get(i).toString());
int e1 = Integer.parseInt(end.get(i).toString());
double w1 = Double.parseDouble(wght.get(i).toString());
int c1 = Integer.parseInt(count.get(i).toString());
int b2 = Integer.parseInt(begin.get(j).toString());
int e2 = Integer.parseInt(end.get(j).toString());
double w2 = Double.parseDouble(wght.get(j).toString());
int c2 = Integer.parseInt(count.get(j).toString());
int max = Math.max(e1, e2);
boolean toRemove = true;
if (b1 == b2) end.set(i, Integer.toString(max));
if (b1 < b2) {
if (b2 < e1) end.set(i, Integer.toString(max));
else {
if ((b2 - e1) <= 3) end.set(i, Integer.toString(e2));
else toRemove = false;
}
}
if (b1 > b2) {
if (e2 >= b1) {
begin.set(i, Integer.toString(b2));
end.set(i, Integer.toString(max));
} else {
if ((b1 - e2) <= 3) {
begin.set(i, Integer.toString(b2));
end.set(i, Integer.toString(e1));
} else toRemove = false;
}
}
//System.out.println(b1 + ", " + e1 + ", " + b2 + ", " + e2 + " ---> " + begin.get(i).toString() + ", " + end.get(i).toString());
if (toRemove) {
wght.set(i, Double.toString(w1 + w2));
count.set(i, Integer.toString(c1 + c2));
begin.removeElementAt(j);
end.removeElementAt(j);
wght.removeElementAt(j);
count.removeElementAt(j);
j --;
} //end of if
} //end of for j
} //end of for i
} //end of if
//System.out.println(begin);
//System.out.println(end);
//System.out.println(wght);
//System.out.println(count);
}
后:
/** Returns the result of merging all overlapping-with-leeway clusters into single combined clusters.
* @param leeway The minimum number of word-spaces which must separate two clusters in order for them to not be overlapping.
* @requires clusters != null
* @requires leeway >= 0
* @ensures result != null */
private static List<TermCluster> combineOverlappingClusters(Iterable<TermCluster> clusters, int leeway) {
if (clusters == null) throw new NullPointerException("clusters");
if (leeway < 0) throw new IllegalArgumentException("leeway < 0");
//Sort to allow linear folding
List<TermCluster> sortedClusters = Iter.sort(clusters, new Comparator<TermCluster>() {
@Override public int compare(TermCluster o1, TermCluster o2) {
return new Integer(o1.begin).compareTo(o2.begin);
}
});
if (sortedClusters.size() == 0)
return sortedClusters;
//Combine left-to-right
List<TermCluster> result = new ArrayList<TermCluster>();
TermCluster acc = sortedClusters.get(0);
for (TermCluster cluster : sortedClusters.subList(1, sortedClusters.size())) {
if (acc.isOverlappingWithLeeway(cluster, leeway)) {
//combine
acc = acc.combineWith(cluster);
} else {
//next
result.add(acc);
acc = cluster;
}
}
result.add(acc); //leftovers
return result;
}
我认为没有什么比这更接近了:
function pmn_Sort(strBy)
local tblA = {};
local tblB = {};
local tblC = {};
local tblD = {};
local tblE = {};
local tblF = {};
local tblG = {};
local tblH = {};
local tblI = {};
local tblJ = {};
local tblK = {};
local tblL = {};
local tblM = {};
local tblN = {};
local tblO = {};
local tblP = {};
local tblQ = {};
local tblR = {};
local tblS = {};
local tblT = {};
local tblU = {};
local tblV = {};
local tblW = {};
local tblX = {};
local tblY = {};
local tblZ = {};
local tblOT = {};
local iA = 0;
local iB = 0;
local iC = 0;
local iD = 0;
local iE = 0;
local iF = 0;
local iG = 0;
local iH = 0;
local iI = 0;
local iJ = 0;
local iK = 0;
local iL = 0;
local iM = 0;
local iN = 0;
local iO = 0;
local iP = 0;
local iQ = 0;
local iR = 0;
local iS = 0;
local iT = 0;
local iU = 0;
local iV = 0;
local iW = 0;
local iX = 0;
local iY = 0;
local iZ = 0;
local iOT = 0;
if strBy == "Name" then
strSort = "Name";
numPlcount = ListBox.GetCount("Playlist");
numPLitem = 1;
numPLadd = 0;
while numPLitem <= numPlcount do
strPLtxt = ListBox.GetItemText("Playlist", numPLitem);
strPLdata = ListBox.GetItemData("Playlist", numPLitem);
strPLleft = String.Left(strPLtxt, 1);
if strPLleft == "a" or strPLleft == "A" then
iA = iA + 1;
tblA[iA] = strPLdata;
elseif strPLleft == "b" or strPLleft == "B" then
iB = iB + 1;
tblB[iB] = strPLdata;
elseif strPLleft == "c" or strPLleft == "C" then
iC = iC + 1;
tblC[iC] = strPLdata;
elseif strPLleft == "d" or strPLleft == "D" then
iD = iD + 1;
tblD[iD] = strPLdata;
elseif strPLleft == "e" or strPLleft == "E" then
iE = iE + 1;
tblE[iE] = strPLdata;
elseif strPLleft == "f" or strPLleft == "F" then
iF = iF + 1;
tblF[iF] = strPLdata;
elseif strPLleft == "g" or strPLleft == "G" then
iG = iG + 1;
tblG[iG] = strPLdata;
elseif strPLleft == "h" or strPLleft == "H" then
iH = iH + 1;
tblH[iH] = strPLdata;
elseif strPLleft == "i" or strPLleft == "I" then
iI = iI + 1;
tblI[iI] = strPLdata;
elseif strPLleft == "j" or strPLleft == "J" then
iJ = iJ + 1;
tblJ[iJ] = strPLdata;
elseif strPLleft == "k" or strPLleft == "K" then
iK = iK + 1;
tblK[iK] = strPLdata;
elseif strPLleft == "l" or strPLleft == "L" then
iL = iL + 1;
tblL[iL] = strPLdata;
elseif strPLleft == "m" or strPLleft == "M" then
iM = iM + 1;
tblM[iM] = strPLdata;
elseif strPLleft == "n" or strPLleft == "N" then
iN = iN + 1;
tblN[iN] = strPLdata;
elseif strPLleft == "o" or strPLleft == "O" then
iO = iO + 1;
tblO[iO] = strPLdata;
elseif strPLleft == "p" or strPLleft == "P" then
iP = iP + 1;
tblP[iP] = strPLdata;
elseif strPLleft == "q" or strPLleft == "Q" then
iQ = iQ + 1;
tblQ[iQ] = strPLdata;
elseif strPLleft == "r" or strPLleft == "R" then
iR = iR + 1;
tblR[iR] = strPLdata;
elseif strPLleft == "s" or strPLleft == "S" then
iS = iS + 1;
tblS[iS] = strPLdata;
elseif strPLleft == "t" or strPLleft == "T" then
iT = iT + 1;
tblT[iT] = strPLdata;
elseif strPLleft == "u" or strPLleft == "U" then
iU = iU + 1;
tblU[iU] = strPLdata;
elseif strPLleft == "v" or strPLleft == "V" then
iV = iV + 1;
tblV[iV] = strPLdata;
elseif strPLleft == "w" or strPLleft == "W" then
iW = iW + 1;
tblW[iW] = strPLdata;
elseif strPLleft == "x" or strPLleft == "X" then
iX = iX + 1;
tblX[iX] = strPLdata;
elseif strPLleft == "y" or strPLleft == "Y" then
iY = iY + 1;
tblY[iY] = strPLdata;
elseif strPLleft == "z" or strPLleft == "Z" then
iZ = iZ + 1;
tblZ[iZ] = strPLdata;
else
iOT = iOT + 1;
tblOT[iOT] = strPLdata;
end
numPLitem = numPLitem + 1;
end
ListBox.DeleteItem("Playlist", LB_ALLITEMS);
for ii, id in tblA do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblB do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblC do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblD do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblE do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblF do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblG do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblH do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblI do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblJ do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblK do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblL do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblM do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblN do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblO do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblP do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblQ do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblR do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblS do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblT do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblU do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblV do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblW do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblX do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblY do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblZ do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
for ii, id in tblOT do
if id ~= "" then
numPLadd = numPLadd + 1;
strPLtxt = String.SplitPath(id).Filename..String.SplitPath(id).Extension
ListBox.AddItem("Playlist", strPLtxt, id);
end
end
elseif strBy == "Type" then
strSort = "Type";
if File.DoesExist(_ProgramFilesFolder.."\\MediaX\\playlist.mx") == true then
play_file2 = TextFile.ReadToTable(_ProgramFilesFolder.."\\MediaX\\playlist.mx");
if play_file2 then
ListBox.DeleteItem("Playlist", -1);
for rl,rPath in play_file2 do
r2Path = String.TrimLeft(rPath, nil);
ListBox.AddItem("Playlist", String.SplitPath(r2Path).Filename..String.SplitPath(r2Path).Extension, r2Path);
end
end
end
end
end
解决办法?嗯,这不需要太多解释。