Learning π·πΌββοΈπ·πΌββοΈ
Coding in General
- Use βthisβ to make it obvious what youβre referring to in a method.
- Be consistent in the way you access stuffβ¦ e.g. pick one of βWays[0]β or βWays.First()β and stick to it (donβt swap between them).
Note βWays.First()β returns an object reference that does allow you to update data within it.
- Aim is to make the code as easy to read as possible
Don't include extra names in enums. e.g. DeviceConfig.~~Config~~Unspecified is better written as DeviceConfig.Unspecified
Properties in class should be Captialised
Raise exceptions as soon as they occur.
Functions
Naming
Consider the return types in the name. e.g. use GetCentreID() rather than GetCentre() if you are returning the ID of the object rather than the object.
Also consider exactly what the function is doing.
Returning
Avoid multiple returns in different places in a method. Various exit points not seen as a good thing. Be a bit Dijkstra about it all.
Changing incoming parameters for output
Avoid changing parameters that are passed into a function. Better to return a new value that change a value.
Refactoring
This is kind of my refactoring checklist (it's a work in progress!π)
- Overview of code
- Reformat code
- spaces between methods
- spaces in methods
- position of braces
- Clean up 'using' code block
Remove extra 'using' declarations
Right click on the using block at the top of the file and select 'Organize Usings' -> 'Remove and Sort'
Handy Hints and Shortcuts
VMs
- In Windows 10 - use CMD + Space to change keyboard region. Very handy when you need a #, if you aren't using a Win UK keyboard. (also in Win 10, use WinKey and . to bring up the emoticon panel)
VS2010
Shortcut Autocomplete - Tab + Tab Shortcut Format Code - Ctrl + E , D
VSCode (mac)
Shortcut Duplicate line Shift + Alt + Down (mac & win) Shortcut Multiple cursors (column) Cmd + Alt (mac) Ctrl + Alt (win)) Shortcut Multiple cursors (separate) Alt + mouse click (mac & win)
VB
Shortcut View Object Browser - F2 Shortcut Go Back - Ctrl + Shift + F2