6

Before you try to do something, make sure you can do nothing

 1 year ago
source link: https://devblogs.microsoft.com/oldnewthing/20230725-00/?p=108482
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Before you try to do something, make sure you can do nothing

RaymondChen_5in-150x150.jpg

Raymond Chen

July 25th, 20236 18

When building a new thing, a good first step is to build a thing that does nothing. That way, you at least know you are starting from a good place. If I’m building a component that performs an action, I’ll probably do it in these steps:

  • Step zero is to write a standalone program to perform the action. This ensures that the action is even possible.
  • Once I have working code to perform the action, I write a component that doesn’t perform an action. That at least makes sure I know how to build a component.
  • Next, I register the component for the action, but have the Invoke method merely print the message “Yay!” to the debugger without doing anything else. This makes sure I know how to get the component to run at the proper time.
  • Next, I fill in the Invoke method with enough code to identify what action to perform and which object to perform it on, print that information to the debugger, and return without actually performing the action. This makes sure I can identify which action is supposed to be done.
  • Finally, I fill in the rest of the Invoke method to perform the action on the desired object. For this, I can copy/paste the already-debugged code from step zero.

Too often, I see relatively inexperienced developers dive in and start writing a big complex thing: Then they can’t even get it to compile because it’s so big and complex. They ask for help, saying, “I’m having trouble with this one line of code,” but as you study what they have written, you realize that this one line of code is hardly the problem. The program hasn’t even gotten to the point where it can comprehend the possibility of executing that line of code. I mutter to myself, “How did you let it get this bad?”

Start with something that does nothing. Make sure you can do nothing successfully. Only then should you start making changes so it starts doing something. That way, you know that any problems you have are related to your attempts to do something.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK