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 ...
user avatar
29 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 ...
user avatar
  • 24k
25 votes

When "How To Ask" is too subtle

The validateTitle method takes a titleField, and then extracts titleField.value as ...
user avatar
  • 107k
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 ...
user avatar
  • 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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 8,418
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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 25k
11 votes

Using sounds in Java

Layout Calling .setSize() with fixed dimensions isn't portable. For example, this is what happens on Mac OS X: Instead, call ...
user avatar
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. ...
user avatar
11 votes

Too-high / too-low guessing game in Swing

Create a new Actionlistener class and add it to all Buttons: ...
user avatar
  • 297
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 ...
user avatar
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 ...
user avatar
  • 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 ...
user avatar
  • 24k
10 votes

Using sounds in Java

You can clean up the repetition by moving the ActionListener's code into a custom class, like this: ...
user avatar
  • 107k
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 ...
user avatar
8 votes
Accepted

Simple event management system

I was expecting this to be hard as, from what I've read, most people don't create their own Actually, there are more people who create event emitters than you think. I'm one of them, and here's my ...
user avatar
  • 24.8k
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: ...
user avatar
  • 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: ...
user avatar
  • 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! ...
user avatar
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. ...
user avatar
  • 30.7k
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. ...
user avatar
  • 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: ...
user avatar
  • 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, ...
user avatar
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 ...
user avatar
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. ...
user avatar
  • 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 <...
user avatar
  • 5,553

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