Skip to content

Instantly share code, notes, and snippets.

@JakubNei
Last active December 11, 2017 20:24
Show Gist options
  • Save JakubNei/3de3c20b8b8b8fc3f9e8708b170585b1 to your computer and use it in GitHub Desktop.
Save JakubNei/3de3c20b8b8b8fc3f9e8708b170585b1 to your computer and use it in GitHub Desktop.

General way of working

Merge only working code.

If you are unsure, ask.

If you are stuck for over 1 hour, ask (anyone).

If you can prevent a duplicated code or file, do so.

If you can avoid static, do so.

If you can prevent implicit coversions & implicit operators, do so.

If you see a bug -> fix it, or make new Bug task -> throughtfuly describe how to reproduce it.

If you see something in need of improvement -> improve it or make new Improvement task -> throughtfuly describe it.

Know when to use CDNs, your site might be used behind firewall with restricted access to internet.

If there is some hidden hard to understand meaning of variable name or method, do write comments.

Follow the Boy Scout Rule: "Always leave the campground cleaner than you found it." -> "Always check a code in cleaner than when you checked it out."

Coding conventions

Name into prefix issue: https://gist.github.com/aeroson/b313b00225db30931b1320d87de61662

C#

See http://www.dofactory.com/reference/csharp-coding-standards Properties in PascalCasing Fields in camelCasing

float.Parse

float.Parse & double.Parse depends on current thread culture, use CultureInfo.InvariantCulture if possible. can cause parsing issues and exceptions on systems with different default culture

Take extra care

Beware of types and their sizes: can't use short to store data that short can't hold.

C#

type min max bits
short -32,768 32,767 16
ushort 0 65,535 16
int -2,147,483,648 2,147,483,647 32
uint 0 4,294,967,295 32
long -9,223,372,036,854,775,808 9,223,372,036,854,775,807 64
ulong 0 18,446,744,073,709,551,615 64

Encoding issues: UTF8 vs UTF7 vs Windows etc... (Example: DB update script, after every à an „ was inserted due to different encodings)

Similar characters. (Example: I was looking for ,, but it was actually „)

Renaming/adding/removing properties/fields can cause:

  • reflection based automapper to cease working
  • reflection dependant code to cease working -> Don't use reflection if you don't have to.

If refactoring, take super extra care that you kept original functionality (this causes the greatest number of bugs).

If something is licensed, check for license in server side code and only then do it, optionally check for license in client side JavaScript, the JavaScript might break because server will not do it.

Numbers

  • float can cause pain, know why and where
  • numbers divison: the divisor can be 0

Testing

XML parsing: test that the code will work if XML file has more values (not just one).

MySql columns, make sure they have default values, in case new row is being inserted without the column

Nullable<>: assume it will have no value

HTML

  • click all buttons, make sure they work correctly (Save, Cancel) (Cancel resets the form)
  • HTML checkboxes don`t send anytihing if unchecked, send their value if checked, value must be nonempty

Regexps

Run all regexps in https://regex101.com/ understand them, make sure they are correct. example of incorrectly escaped space in regex: var regExp = new RegExp('^[-\s-a-zA-Z0-9]$'); // doesnt work, if we use "s" regexp fails var regExp = new RegExp('^[-\s-a-zA-Z0-9]$'); // the \s is meant to be space, so it should have been \s

Think about edge case scenarios

Prefixed or sufixed spaces, make sure to Trim().

Overly long or short strings.

Think about (min, one, zero, multiple, max) use case scenarios (concurrent users, files, database entries, phone numbers, addresses, ..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment