0% found this document useful (0 votes)
0 views

cs321-winter-2023-lecture-5-coding-tips

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.

Uploaded by

mbielawski21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

cs321-winter-2023-lecture-5-coding-tips

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.

Uploaded by

mbielawski21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CODING TIPS

First Pieces of Advice


• 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

You might also like