|
I understand.. but my point is will that read anything after first line as Object to read file is initiated EVERYTIME in loop
R A M
|
|
|
|
|
I can't tell from what is shown.
Is file a string, and BDTline opening said file?
or is file some kind of object (say a StreamReader), that has the file opened earlier on, and parses/returns a single line?
|
|
|
|
|
It breaks out of the loop with the first exception encountered, which is typically a System.IO.EndOfStreamException because the last line from which is read is always empty. And the normal way to leave that loop is exactly this exception. Every file read will cause three such lines in the log file (later on, the file is read another two times - it is certain that it has not changed between reads...). The next file causing another three lines in the log, and so on. When searching for the cause of a different error I was severely mislead by these messages.
|
|
|
|
|
This looks bad pratice to me, to break loop on exception, rather then actually detecting and comparing EOF character.
Ravi S
Coding is my birth-right and bugs are part of feature my code has!
_________________________________________
Me
Facebook
Twitter
|
|
|
|
|
Simply bad design and very poor naming conventions.
1) Call things what they are, nothing more, nothing less.
Class BDTLine should be BDTFile
line should be lines
.Read method should be .ReadLine (or should it be ReadBytes?)
Now when you look at the code you can see why it is loaded with problems.
2) BDTFile is an implementation nightmare for you or anyone else in the future.
2a) If the caller manages the loop, the class must expose a property to determine when to stop.
<br />
public bool EOF { <br />
get { return sr.Peek > -1; }
}<br />
<br />
_eof=((input=sr.ReadLine())==null)<br />
get { return _eof; }
2b) if the class manages the loop, either pass the lines reference or return the desired result from the Read method.
3) Finally there is no excuse for using do...while(true), period.
Dwayne J. Baldwin
|
|
|
|
|
Maybe it's just me, but using code that could cause an exception would mean that I'd rewrite it to not cause an exception. Why wouldn't you just do something like:
try
{
StreamReader sr = new StreamReader("TestFile.txt");
string data = sr.ReadToEnd();
string[] lines = data.Split(Environment.NewLine.ToCharArray());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|
|
A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:
bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
switch (moreThanOneModelTypes)
{
case true:
this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
goto default;
case false:
goto default;
default:
foreach (VehicleType vehicleType in vehicle.PossibleTypes)
{
this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
}
_fullVehicleModelTypeReload = false;
break;
}
So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.
|
|
|
|
|
The default in this is surely a marsterwork par excellance. I must have been misinformed, boolean=true|false|maybe.
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
You should applaud the genius for holding into account quantum mechanics!
|
|
|
|
|
|
Is this guy in his 50's, bald, close-set eyes? If it is, I used to work with him :shudder:.
|
|
|
|
|
one half of me is LMAO, the other half is straight faced and the rest is thinking if that can be incorporated in my own code.
...byte till it megahertz...
|
|
|
|
|
LOL @ three halves
Before .NET 4.0,
object Universe = NULL;
|
|
|
|
|
I have to ask - was there ever a case in which the default clause executed? Did the author honestly expect it to?
Bear in mind that Boole's wife was also a mathematician, and in her algebra there were three states: "true", "false", and "it depends..."
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Just found
Is it GPLed ?
Can I use this portion of code?
|
|
|
|
|
While that code snippet may indeed produce the desired effect it is one of the most convoluted ways I have seen of doing a simple task. See my sig.
You should tell that guy about the International Obfuscated C Code Contest (IOCCC[^])
Just because the code works, it doesn't mean that it is good code.
modified on Wednesday, August 25, 2010 2:40 PM
|
|
|
|
|
Okay, hello Coding Horrors!!! A while ago I stumbled upon this delightful piece of code, which appears in a much larger monster that is (thankfully) obsolete. This loop also has a number of shorter variants covering the case of 7, 6, 5, 4 etc cameras. It cracked me up in any case, and I'd like to share it. To this day, I haven't worked out whether the person who wrote it was a fool, a genius, or both!
Enjoy =)
if (pairCount>=28)
{
errBounce = FLOAT_MAX;
for (i1=0; i1<pairCount-14; i1++)
{
for (i2=i1+1; i2<pairCount-13; i2++)
{
for (i3=i2+1; i3<pairCount-12; i3++)
{
for (i4=i3+1; i4<pairCount-11; i4++)
{
for (i5=i4+1; i5<pairCount-10; i5++)
{
for (i6=i5+1; i6<pairCount-9; i6++)
{
for (i7=i6+1; i7<pairCount-8; i7++)
{
for (i8=i7+1; i8<pairCount-7; i8++)
{
for (i9=i8+1; i9<pairCount-6; i9++)
{
for (i10=i9+1; i10<pairCount-5; i10++)
{
for (i11=i10+1; i11<pairCount-4; i11++)
{
for (i12=i11+1; i12<pairCount-3; i12++)
{
for (i13=i12+1; i13<pairCount-2; i13++)
{
for (i14=i13+1; i14<pairCount-1; i14++)
{
for (i15=i14+1; i15<pairCount; i15++)
{
centroid[0] = (estBounce[i1][0] + estBounce[i2][0] + estBounce[i3][0] + estBounce[i4][0] + estBounce[i5][0] +
estBounce[i6][0] + estBounce[i7][0] + estBounce[i8][0] + estBounce[i9][0] + estBounce[i10][0] +
estBounce[i11][0] + estBounce[i12][0] + estBounce[i13][0] + estBounce[i14][0] + estBounce[i15][0])/15.0;
centroid[1] = (estBounce[i1][1] + estBounce[i2][1] + estBounce[i3][1] + estBounce[i4][1] + estBounce[i5][1] +
estBounce[i6][1] + estBounce[i7][1] + estBounce[i8][1] + estBounce[i9][1] + estBounce[i10][1] +
estBounce[i11][1] + estBounce[i12][1] + estBounce[i13][1] + estBounce[i14][1] + estBounce[i15][1])/15.0;
centroid[2] = (estBounce[i1][2] + estBounce[i2][2] + estBounce[i3][2] + estBounce[i4][2] + estBounce[i5][2] +
estBounce[i6][2] + estBounce[i7][2] + estBounce[i8][2] + estBounce[i9][2] + estBounce[i10][2] +
estBounce[i11][2] + estBounce[i12][2] + estBounce[i13][2] + estBounce[i14][2] + estBounce[i15][2])/15.0;
dis1 = PointDistance(centroid, estBounce[i1]);
dis2 = PointDistance(centroid, estBounce[i2]);
dis3 = PointDistance(centroid, estBounce[i3]);
dis4 = PointDistance(centroid, estBounce[i4]);
dis5 = PointDistance(centroid, estBounce[i5]);
dis6 = PointDistance(centroid, estBounce[i6]);
dis7 = PointDistance(centroid, estBounce[i7]);
dis8 = PointDistance(centroid, estBounce[i8]);
dis9 = PointDistance(centroid, estBounce[i9]);
dis10= PointDistance(centroid, estBounce[i10]);
dis11= PointDistance(centroid, estBounce[i11]);
dis12= PointDistance(centroid, estBounce[i12]);
dis13= PointDistance(centroid, estBounce[i13]);
dis14= PointDistance(centroid, estBounce[i14]);
dis15= PointDistance(centroid, estBounce[i15]);
dis = dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15;
if (dis<errBounce)
{
w1 = (dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w2 = (dis1+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w3 = (dis1+dis2+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w4 = (dis1+dis2+dis3+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w5 = (dis1+dis2+dis3+dis4+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w6 = (dis1+dis2+dis3+dis4+dis5+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w7 = (dis1+dis2+dis3+dis4+dis5+dis6+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w8 = (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w9 = (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w10= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w11= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis12+dis13+dis14+dis15)/(dis*14.0);
w12= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis13+dis14+dis15)/(dis*14.0);
w13= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis14+dis15)/(dis*14.0);
w14= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis13+dis15)/(dis*14.0);
w15= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis13+dis14)/(dis*14.0);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
errBounce /= 15;
}
|
|
|
|
|
Geoff Bolton wrote: To this day, I haven't worked out whether the person who wrote it was a fool, a genius, or both
Granted I only glanced at the code for, like, 1 minute, but I haven't figured it either!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I dont think that code will terminate
|
|
|
|
|
I'd like to see how this guy would create software to manage a global system. How many TiB would the source be?
|
|
|
|
|
The for() loops seem a rather verbose way of generating all 37,442,160 combinations of 15 pairs chosen from 28, but I wouldn't say they're necessarily horrible. If it is indeed necessary to enumerate all the combinations, nested 'for' loops seem a verbose but time-efficient way to do it. The w1..w15 calculations seem icky, though. Much better to compute the sum of dis1..dis15, and subtract one item from that computation.
|
|
|
|
|
Seems like a classic case for recursion to me...but I'm too tired to both trying to code it now...
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Auch! It is terrible. I'm sure this can be reduced to a O(n^2) complexity with a smart algorithm and some precalculations/caching. If not, a simple recursive method can do it.
Greetings - Jacek
|
|
|
|
|
My God. It looks like some of the old stuff lying around at my company.
|
|
|
|
|
Below is an HTML file. Try to guess which DIV will be invisible in IE, then scroll down to see why...
<html>
<head>
<title>WTF</title>
<style type="text/css">
div
{
filter: alpha(opacity = 100);
border-color: Green;
border-style: solid;
border-width: 1px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div style="background-color: #020509;"></div>
<div style="background-color: #02050A;"></div>
<div style="background-color: #02050B;"></div>
</body>
</html>
The middle DIV will be transparent because any element with the color #02050A that also has the filter set to an opacity (even if fully opaque) will appear transparent in IE8 (and probably other versions of IE).
|
|
|
|