31 votes
Accepted

When "How To Ask" is too subtle

String.includes() is part of the experimental ECMAScript 6 language proposal. Therefore, you cannot rely on it being available in browsers. On browsers that do ...
30 votes
Accepted

Use of Async/Await for EventHandlers

The things to consider when it comes to async event handlers are: Exceptions thrown for the handler might be rethrown on the UI ...
  • 24.1k
26 votes

When "How To Ask" is too subtle

The validateTitle method takes a titleField, and then extracts titleField.value as ...
  • 110k
22 votes

Updating dimensions when focus is lost from any of 9 columns

I don't do C# so pardon the syntax, but you should be able to reduce the amount of code by using a for loop over a string array with your column names. Again I don't do C# but in Java you could do ...
  • 16.4k
20 votes
Accepted

One-shot events in C#

Other answers are great, but this is really re-inventing the wheel. What you are looking for is the observer pattern. .NET has great in-built capabilities with observer through ...
  • 3,753
16 votes

When "How To Ask" is too subtle

I'm surprised to see that nobody else has mentioned this but you forgot one thing: THERE IS A BUG IN MY CODE is an accepted title, while there is a bug in my code is not. You really should ...
15 votes
Accepted

Updating dimensions when focus is lost from any of 9 columns

A shorter version would be to create an anonymous array in the if statement combined with a collection initializer where you will add all of the column names and ...
  • 8,438
13 votes

One-shot events in C#

For me this whole idea smells like a bad design. I don't like having this logic hidden in the event sender. If I see an event and I subscribe to it I really expect to be called each time that actions ...
  • 606
13 votes

When "How To Ask" is too subtle

A couple of small things: "use strict"; Seeing as you want all of your functions to use strict mode, just put it at the top of the file instead. (Note that only ...
12 votes
Accepted

Event Listener and Publisher

I've got a few small points about this code and then I have some other points regarding your design. I'll try to discuss your design in perspective to game-development (where I am completely ...
  • 25.1k
11 votes

Too-high / too-low guessing game in Swing

Create a new Actionlistener class and add it to all Buttons: ...
  • 297
11 votes
Accepted

Using sounds in Java

Use MIDI Why play a WAV file, when you could synthesize the tones using MIDI? The tones can be played with indefinite length. You wouldn't need to distribute supplementary files with the program. ...
11 votes
Accepted

Fourteen buttons with hover effects

You can actually do this entirely in CSS with no need for JavaScript. You just have to switch to using background-image instead of an image within the anchor and ...
11 votes
Accepted

JPaint (Java painting app)

The code is damn long, so just a few notes: Use initializer expressions like private JRadioButton setRed = new JRadioButton("Red", true); Use static factory ...
  • 13.4k
11 votes

Type-Safe Event System

C# events are type-safe. The common (and recommended) pattern is to use EventHandler<T>, where T is a custom type deriving ...
  • 24.1k
10 votes

Fourteen buttons with hover effects

You shouldn't be using images for text, nor should you be using JavaScript at all. The images aren't semantically relevant; they are just for styling. By using text, you'll make your site workable ...
8 votes

"Function Buffer" to avoid triggering an event handler too frequently

As mentioned in the comments, this is usually called "debouncing." A simpler and easier-to-use approach would be something like this: ...
  • 4,531
8 votes

One-shot events in C#

Unrelated to your main question, but for thread safety, it's recommended you take a local copy of the event, like so: ...
  • 5,167
8 votes
Accepted

Toggling between radio buttons

The trick here is to create an inner class. Something I've started doing recently is to create a method that returns the interface you want! ...
8 votes

Copy Cell on Worksheet_Change event if some criteria is met

Indent everything one level inside of the Sub...End Sub block. Go one more inside of If blocks and loops. ...
  • 30.8k
8 votes
Accepted

Yet another event dispatcher in c++11

Start/Stop You should consider calling these from your constructor/destructor so that the thread is ready when constructed and automatically stopped when destroyed. It would make is easier to use. ...
  • 16.4k
7 votes

Messy handler for multiple touch events in a game

You can easily make the code more readable by breaking the large method into three smaller ones. My suggestion: ...
  • 17k
7 votes

Too-high / too-low guessing game in Swing

A few things: You are overusing public static, all those variables should instead be private and not static. Whenever you can, ...
7 votes
Accepted

ECS Event/Messaging implementation

My suggestions: Move type_count from being a public member type_count plays an important role in the event manager. Making ...
  • 3,484
7 votes

WinForm Calculator

If you're going to put a try catch in an else, you should probably wrap it in braces: else { try { ... } catch { ... } } You don't need ...
7 votes
Accepted

Paint rectangles to canvas using mouse

Don't load the same resource repeatedly I don't have much time to give a full review but I can point out one big thing that I saw while looking through the code. ...
  • 16.4k
7 votes

CheckChanged event readability

Before thinking I didn't read well, I didn't want to rewrite everything: the final edit is at the bottom of the answer, but please read everything to understand it all. :) If the code inside the <...
  • 5,553
7 votes
Accepted

Finger painting code

The first thing that strikes me as odd about your code is having the four single-character variables to represent color components. I would rather see a single ...
  • 25.2k
7 votes
Accepted

Python Event Dispatcher

Checking items in dictionnary There is no need to call keys when checking for dictionnary membership. Much like there is no need of ...

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