|
FF3.0: OK
IE7: bad
|
|
|
|
|
CSS Fail!
|
|
|
|
|
Found in production code:
The standardTimer is the number of minutes. The result is the number of millideconds (standardTimer * 60000)
// Specified delay... Start every xx minutes
System.TimeSpan duration = new System.TimeSpan(0, 0, standardTimer, 0);
DateTime dtStart = new DateTime();
dtStart = DateTime.Now + duration;
string sDate = dtStart.ToString();
// Calcul delay
string sCurrent = DateTime.Now.ToString("HH:mm:ss");
string sStart = dtStart.ToString("HH:mm:ss");
System.TimeSpan tsCurrent = System.TimeSpan.Parse(sCurrent);
System.TimeSpan tsStart = System.TimeSpan.Parse(sStart);
tsStart = tsStart - tsCurrent;
return (int)tsStart.TotalMilliseconds;
|
|
|
|
|
Nothing wrong with that code - perfectly good approach!
I particularly like the DateTime -> TimeSpan conversion via parse - classy.
I do however feel that he has missed an opportunity to save some code space:
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
TimeSpan duration = new TimeSpan(0, standardTimer, 0);
sw.Start();
System.Threading.Sleep(duration);
sw.Stop();
return sw.ElapsedMilliseconds;
Perhaps you should use this method instead?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Perhaps the coder thought it was necessary to convert a DateTime into a TimeSpan before subtracting to yield a TimeSpan? In fact, the difference between two DateTime values is a TimeSpan.
Not sure how to explain some of the other ugliness in the code, though. I can understand cases where one might want to e.g. calculate the number of milliseconds until the start of a minute 'n' minutes from now, but I'm unclear how any of the cases where this function wouldn't return StandardTimer*60000 would be useful.
|
|
|
|
|
Elegant or not, the code has a bug actually. It's using DateTime.Now in two places. Because the code is not saving that first value off to use later, it will be unreliable.
|
|
|
|
|
Andrew Rissing wrote: it will be unreliable
Yes, but you can rely on it to be unreliable.
|
|
|
|
|
Indeed. Lets just hope it doesn't become unreliable to rely on its unreliability.
|
|
|
|
|
it is a very mild form of unreliability, as you can perfectly predict when it will be shaky and when not.
I did mention it in my datetime compendium[^] though.
|
|
|
|
|
Nice little collection of useful DateTime snippets. I added that to my bookmarks. Thanks.
|
|
|
|
|
One of our users was sent to a client's site to upload some work files for review. She got a message that said something like:
This website requires an HTML 4.0 compliant web browser with Javascript enabled. You are using a browser version that does not meet these requirements. It is recommended that you use either Internet Explorer versions 5.5/6.x/7.x, or Netscape version 7.x. Refer to your browser's online help for specific instructions to enable Javascript.
Yet we are using IE 7 with JavaScript enabled. So I went digging through their page to see what triggered that message and found this little gem:
function browserSupported()
{
var agt=navigator.userAgent.toLowerCase();
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_nav62up = (is_nav && (is_major >= 5) && (is_minor >=5) && (agt.indexOf("gecko")!=-1) );
var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_ie55 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) );
var is_ie55up = (is_ie && ((!is_ie3 && !is_ie4 && !is_ie5) || is_ie55));
var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1) );
var is_ie6up = (is_ie && ((!is_ie3 && !is_ie4 && !is_ie5 && !is_ie55) || is_ie6));
var is_opera = (agt.indexOf("opera") != -1);
if (is_nav62up || is_ie55up || is_opera || is_ie6up || is_ie6)
{
return true;
}
return false;
}
Note the complete and utter lack of a check for "msie 7.0", let alone the horrible combination of and's and not's to set all those is_<browser> flags. -Greg
|
|
|
|
|
It seems some rookie has coded that script...
|
|
|
|
|
Wow, talk about how times change. I bet I could dig up a curses lib file that does the same thing for DEC VT-xxx terminals. Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
It took me about 20 minutes to work out what the heck this For/Next loop was doing. The programmer must not have heard of .Split.
It takes a key from an INI file (vkeys) and if it is formatted as such:
SERVICES = Service1, Service2, Service3, Service4 ...
it puts the list of services into an array for later use..
If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then
totallength = Len(vkeys(lval, 1))
For searchstring = 1 To totallength
tempcounter2 = tempcounter2 + 1
If Mid(vkeys(lval, 1), searchstring, 1) = "," Then
servicecount(X) = servicecount(X) + 1
nodeservices(X, servicecount(X)) = Mid(vkeys(lval, 1), _
tempcounter1, tempcounter2 - 1)
If Right(nodeservices(X, servicecount(X)), 1) = "," Then
nodeservices(X, servicecount(X)) = _
Left(nodeservices(X, servicecount(X)),_
(Len(nodeservices(X, servicecount(X))) - 1))
End If
tempcounter1 = searchstring + 1
tempcounter2 = 1
End If
If searchstring = totallength Then
nodeservices(X, (servicecount(X) + 1)) = Mid(vkeys(lval, 1),_
tempcounter1, tempcounter2 - 1)
End If
Next searchstring
servicecount(X) = servicecount(X) + 1
tempcounter2 = 1
End If
|
|
|
|
|
It's a horror right from the first line
If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then
...what about "Services"
|
|
|
|
|
Release 1.01: Added support for "Services".
|
|
|
|
|
Bug report: it fails with "serviceS". You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: Bug report: it fails with "serviceS".
Dear Mr./Ms. User,
We are currently offering support for "services", "Services", "SERVICES" (based on user skill - does not know about text formatting rules, knows about text formatting rules, does not know about CAPS LOCK key) and we plan to support "sERVICES" (for users who know formatting rules but forgot about CAPS LOCK key) in future releases.
As far as we see, "serviceS" is an anomaly and it should not be considered a bug.
Yours trully,
Programming Team Leader.I have no smart signature yet...
|
|
|
|
|
Development team answer:
This is not a bug. All key values must be uppercase.
We are simplifying the application so services and Services are no more supported, avoiding further errors.
In fact, the check is now:
If len(vkeys[lval, 0]) = 8 and Mid(lvkeys[lval, 0], 0, 1) = "S" and Mid(lvkeys[lval, 0], 1, 1) = "E" ... and so on.
(Note, I started to write this at the same time of the last post... I think our development team is having problems of communication... who the hell tought we must support other keywords?? ).
|
|
|
|
|
This is an excerpt from some sample code provided in the documentation for an EFT interface
decimal divider;
divider = 10*10*10;
divider = Decimal.Multiply(divider,10*10*10*10*10);
divider = Decimal.Multiply(divider,10*10*10*10*10);
divider = Decimal.Multiply(divider,10*10*10*10*10);
Blows my mind
|
|
|
|
|
Never mind casting - at least he didn't use a loop:
decimal tenE18 = 1;
for (int i = 0; i < 18; i++)
{
tenE18 *= 10;
}
Still, I think I will stick to the old-fashioned, boring way:
decimal d = 1E18M;
[edit]Got the number of zeros wrong, didn't I? Oops.[/edit]You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
modified on Wednesday, March 3, 2010 11:21 AM
|
|
|
|
|
|
test your code - it saves processing time, but raises debug time - if you are able to compile it
|
|
|
|
|
it might have a syntax error but you can do it this way.. you can refer algorithm by corman... n compare to given algo
for (int i = 0; i < 18; i++)
{
tenE18 *= 10;
}
this one will run for 18times.. for debuging also you have to go through this loop 18 times... then how can you say algo i gave takes more time to debug.. complexity of given algo is O(n) and complexity of algo i gave is O(lg(n))....modified on Wednesday, March 3, 2010 10:37 PM
|
|
|
|
|
chevu wrote: how can you say algo i gave takes more time to debug.. complexity of given algo is O(n)
O(n) and O(lg(n)) apply to execution time, not debugging time.
There are no formulas for debugging time; it depends on number of statements, decision points, readability of code, and initial number of bugs. Your code has more than 5 bugs, it will take you lots of time to find all of them. I suggest you try and fix and run it until the result is correct.
|
|
|
|