|
Yes! I'm sorry I could only give you one five. When the problem domain calls for decimal calculations rather than floating point, casting from a floating point type would be a greater horror. Please do not read this signature.
|
|
|
|
|
Gets the offset of the last backslash of a path. Enjoy!!
int PathLen( LPCWSTR sWholePath)
{
CString sTmp(sWholePath),sTmp2;
int iPos=sTmp.Find('\\'),iStart=iPos+1;
while(1)
{
sTmp2=sTmp.Mid(iStart);
iPos=sTmp2.Find('\\');
if(iPos >= 0)
iStart+=(iPos+1);
else
break;
};
return iStart;
};
|
|
|
|
|
Bah! Go recursive!
|
|
|
|
|
I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking.
“I go through the string from the first char through all the backslashes until there aren’t any”
instead of
“I go through the string from the last char until there is a backslash”
Or maybe he was just trying to make things harder for anyone else that would look at the code... I have no smart signature yet...
|
|
|
|
|
or he hasn't heard of the LastIndex string method O_o
|
|
|
|
|
LastIndex is only more efficient if you already know how long the string string is.
In C, that would have to scan the entire string and then back up, which is less efficient.
|
|
|
|
|
Ohhhh, I've known many developers that write code harder because they think it looks cool.
Unfortunately I've known WAY too many especially this fat pig that preached about how website development is very difficult; he then went on to develop a very difficult website.
Mike's code was soooooooo bad that they have to run to instances of the website on the same machine to properly test it....according to him. He was also complaining about how hard it was to test his code after his iterative code went more than 30 levels deep.
|
|
|
|
|
I was asked to check why they're query wasn't working, so I was going to add a column to their table. I started to copy/paste a line... and the parens are just one of the million issues with this "classic" asp code... lovely
Response.Write "<table width=1000 cellspacing=0 cellpadding=0 class=style1><tr>" _
& "<td width=40>" & (rsSearch("WKCTR") & "</td>" _
& "<td width=65>" & (rsSearch("START") & "</td>" _
& "<td width=65>" & (rsSearch("FINISH") & "</td>" _
& "<td width=60>" & (rsSearch("JOBNO") & "</td>" _
& "<td width=55>" & (rsSearch("ORDNO") & "</td>" _
& "<td width=35>" & (rsSearch("OPSEQ") & "</td>" _
& "<td width=55>" & (rsSearch("FITEM") & "</td>" _
& "<td width=215>" & (rsSearch("FDESC") & "</td>" _
& "<td width=45 class=style4>" & (rsSearch("REMAINING") & "</td>" _
& "<td width=45 class=style3>" & (rsSearch("TQCTD") & "</td>" _
& "<td width=45 class=style3>" & (rsSearch("SCRAP") & "</td>" _
& "<td width=45 class=style3>" & (rsSearch("ORTTL") & "</td>" _
& "<td width=45 class=style3>" & (Round(rsSearch("LABTIME")) & "</td>" _
& "<td width=45 class=style3>" & (Round(rsSearch("MACHTIME")) & "</td>" _
& "<td width=15 class=style3>" & (rsSearch("CONDS") & "</td>" _
& "<td width=45 class=style3>" & (rsSearch("CONQT") & "</td>" _
& "<td width=80>" & (rsSearch("OSTAT") & "</td>" _
& "</tr><br></table>")))))))))))))))))
|
|
|
|
|
I should note that it's printing each data-row in it's own table.
|
|
|
|
|
ColinBashBash wrote: I should note that it's printing each data-row in it's own table.
Not always a bad thing. If some items are overly long, they'll cause some rows of the table not to match others, but the entire table won't get pushed out by an overly-long item. Further, depending upon how many items there are, some browsers may display a number of short tables better than one really long one. I wouldn't consider the HTML table split horrible, even though the formatting of the source code is nasty.
|
|
|
|
|
Guys,
If you look careful, you will discover that the problem is not actually the HTML table, but the wrong usage of parenteses which make the code very dificult to understand.
In each line, the guy put a open parenteses to separate the function call, and not close it in time. So, at the end of code block, you have a lot of parenteses.
In time, the parenteses aren't need it this case and don't change the return of expression.
|
|
|
|
|
Personally I'm glad the parentheses are there because now I can clearly see the precedence of the & operators. Without the parentheses I would be totally lost and wouldn't be able to follow the code. I think this is an excellent example of self-documenting code.
|
|
|
|
|
The other users got this right of course...bad and incorrect use of parens but jeez dont you just hate this style of ASP coding! I havent done ASP is years now but isnt this so much easier to look at that than trash:
<table width="1000" cellspacing="0" cellpadding="0" class="style1">
<tr>
<td width="40"><% = rsSearch("WKCTR") %></td>
<td width="40"><% = rsSearch("START") %></td>
<td width="40"><% = rsSearch("FINISH") %></td>
<td width="40"><% = rsSearch("JOBNO") %></td>
</tr>
</table>
|
|
|
|
|
if (DeleteSomething1(peopleToKeep))
{
Assert.IsTrue(true, "DeleteSomething1");
if (DeleteSomething2(peopleToKeep))
{
Assert.IsTrue(true, "DeleteSomething2");
if (DeleteSomething3(peopleToKeep))
{
Assert.IsTrue(true, "DeleteSomething3");
if (DeleteProfile(peopleToKeep))
{
Assert.IsTrue(true, "DeleteProfile");
if (DeleteCompany(peopleToKeep))
{
Assert.IsTrue(true, "DeleteCompany");
if (DeletePerson(peopleToKeep))
{
Assert.IsTrue(true, "DeletePerson");
}
}
}
}
}
}
|
|
|
|
|
Person is afraid, that someone will steal the "truth" of his true values. He is just watching his TRUE values and virtues, what's wrong with that?
|
|
|
|
|
I think he was actually trying to monitor progress via the VS Unit test UI...
|
|
|
|
|
|
In all of computer programdom, I've never encounterd this arrangement of i & iCount in a for loop:
i = getcountofsomething()
For iCount = 0 To i
If something(iCount)) Then
bOk = True
Exit For
End If
Next iCount
modified on Thursday, February 11, 2010 6:33 PM
|
|
|
|
|
It's not that bad - I assume getcountofsomething() takes a while, so the coder has just manually optimised it out of the loop. If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
nah, it's bad. who names their variables like this in a for loop? were it written "for i = 0 to iCount", I'd be giving this guy a high 5 already.
|
|
|
|
|
A high 5 around the earhole? cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|
|
|
It's straight from the guide on How To Write Unmaintainable Code[^]:
Never use i for the innermost loop variable. Use anything but. Use i liberally for any other purpose especially for non-int variables. Similarly use n as a loop index.
|
|
|
|
|
lol! I think they were using that as the coding standards document!
|
|
|
|
|
You just don't understand. If the variable was named count you would have a point. Here, the programmer was helping the poor computer with its communications skill. Hence naming the variable that the computer uses to count from its own perspective - "I Count" Please do not read this signature.
|
|
|
|