This document provides essential coding tips for beginners, emphasizing the importance of practice, problem-solving, and seeking help when needed. It covers various programming techniques such as debugging, writing clear code, using variables, and the significance of comments. Additionally, it advises on the use of test cases and the importance of maintaining clean code without unused elements.
This document provides essential coding tips for beginners, emphasizing the importance of practice, problem-solving, and seeking help when needed. It covers various programming techniques such as debugging, writing clear code, using variables, and the significance of comments. Additionally, it advises on the use of test cases and the importance of maintaining clean code without unused elements.
• Practice, practice, practice • You will get much faster • If you are stuck, ask for help Learning to Program • Recognizing mistakes • Reading code • Problem solving • Writing code Programming Note • If you are confused • Set a breakpoint see what it does • Step through the code • Ask yourself, is it doing what I expected? • Why or why not? If you are not sure what you expect • Valid!! • Write out what you want to happen in code • Find the inconsistency in your code and understanding • Ask yourself in a comment • Make the best guess • Mention you are guessing Tracing and Asserts • Use Debug.WriteLine() in regular code • Use Console.WriteLine() in tests • Use Debug.Assert() in regular code • Use Assert.IsTrue or Assert.AreEqual in tests projects Reversing the Direction • A problem solving trick is to reverse the direction that we loop over stuff • Look for a “counter example” as opposed to proving something is true Consider the Test Cases • Make them explicit • Don’t solve every problem right away • Sometimes code is “good enough” • That is where documentation is important Use Braces • If statements and loops don’t require curly braces • However, it can make code easier to read and avoid errors Use Variables • While learning, break complex expressions down into smaller ones • Assign sub-expressions to variables • Yes your code is longer, but easier to find mistakes • You can also debug easier Comments • Don’t put too many • Don’t state the obvious • They are for you and the reader • Tell us something useful • Code should speak for itself Don’t Leave Unused Code in a File • It can be confusing to yourself and others For Note: • Don’t monkey with the loop index What was • 0xFFul - hexadecimal number 255, typed as a 64 bit unsigned number (long) • 123.45f – single precision floating point number • TIP: When using the “var” declaration hover the mouse over the var