Hot answers tagged

8 votes
Accepted

Digital clock with Python Tkinter

To start, it's crucial that you stop creating a brand new label ten times a second. Just modify the existing one. Also, this is so simple that a class is not called for. Move as much as possible away ...
user avatar
  • 47.8k
6 votes

Python analog clock with turtle - runs slow

Avoid import *; there's only a few symbols you need from turtle. There's a lot of repetition in your hand logic. Consider factoring out a class that does the common ...
user avatar
  • 47.8k
6 votes
Accepted

Time duration conversion with units

Avoid defining your own constants There's no need to use your own constants for the duration of a millisecond, second, minute and so on; just use the right ...
user avatar
  • 32.3k
6 votes

Time duration conversion with units

Looks pretty good; these comments are mainly nitpicking: Error messages should be streamed to std::cerr, not std::cout. Whilst ...
user avatar
  • 57.6k
5 votes

Timer for event throttling

Using the following function to test, 62% of your CPU usage is used by DateTime.Now and 15% by Timer.Change ...
user avatar
  • 2,247
4 votes

Simple stop watch class

Silently ignoring a method call when it has been done in an invalid state should never be the correct approach. Calling start() when the stop watch has already been ...
user avatar
4 votes
Accepted

A priority based timer using priority queue

any corner cases that I forgot to take into account No error handling e.g.: malloc() may return NULL. any design approach that ...
user avatar
3 votes

Retry a callback function n times until success

Super short review; Pure nitpicking, but to me, you try the first time, and retry afterward. This means that a retry of 3 would guarantee up to 4 calls. I would not create ...
user avatar
  • 32.4k
3 votes

Python analog clock with turtle - runs slow

I found the correct way to optimize your code: the drawing code takes some time, so you should not wait 1 full second, but only wait until the time elapsed from the start of the loop is one second: <...
user avatar
  • 27k
3 votes

A priority based timer using priority queue

Code structure There are three important components here Priority queue Scheduler Timer Scheduler picks up timer based on priority queue and fires. Should priority queue know about details of Timer? ...
user avatar
  • 379
3 votes

Simple stop watch class

As mentioned in the comments, startTime is more sensible than startDate in testing, I found ...
user avatar
  • 47.8k
2 votes

Simple stopwatch in C

I think it's surprising that timeAdd() and timeDiff() return their results by both return value and out-parameter. I recommend ...
user avatar
  • 57.6k
2 votes

A priority based timer using priority queue

There seems to be some confusion between this struct: ...
user avatar
  • 57.6k
2 votes

Simple stop watch class

From the design perspective - have you considered making the class a pure function? I'd see its api like (keeping naming similar): ...
user avatar
  • 255
2 votes
Accepted

Simple stop watch class

For a library class, JavaDocs should be given (well, here the interface is so small and well-named that one can easily guess the tasks of the methods, but anyway). As already said, the ...
user avatar
2 votes

Simple stop watch class

A broader view of development scenario, skip it for a narrow approach of code reviewing. The code snippet from one of the answers to this question could be a unit test that is an easy maintainable ...
user avatar
2 votes
Accepted

Leaky Bucket Algorithm with no Queue

Create a type alias for the clock you want to use Things become more maintainable and easier to write if you create a type alias for the clock, like so: ...
user avatar
  • 32.3k
2 votes
Accepted

Program to check if a window is opened or not during some time interval

I would probably start by defining a function named require or something on that order: ...
user avatar
  • 33.2k
1 vote

Python analog clock with turtle - runs slow

Waiting 1 second at a time will never work well. The time in between sleep calls is not counted, so every tick will be slightly longer than 1 second, no matter what you do. Instead you should track ...
user avatar
1 vote

Simple stop watch class

to measure time without the need to deal with details of a time library could be achieved following the Single-responsibility principle factoring out the conversion from nano seconds to a different ...
user avatar
1 vote

Simple stop watch class

By the way is implemented the timing can be achieved in two steps: instantiate and start the timing thus it might worth addressing thread safeness that could be achieved in terms of listed ...
user avatar
1 vote

Safe Windows API Timers for Excel

This is a pet peeve of mine: s = s & "Public Sub Init(ByRef hWnd As LongPtr _" & n I hate large blocks of code with this type of concatenation. ...
user avatar
  • 4,028
1 vote

Simple stop watch class

Update to question update: After updating the question most of the requirements exploratory answer is obsolete. Following up the updates there might be alternative solutions, although arguable from K....
user avatar
1 vote
Accepted

watchdog for c++11

Move Event and TimeEvent inside class Timer These types are just implementation details of ...
user avatar
  • 32.3k

Only top scored, non community-wiki answers of a minimum length are eligible