1 of 11

Chapter 1 common mistakes

2 of 11

Naming

  • Methods are verbs
  • Variables are nouns

Bad Good

3 of 11

Variables declaration

  • Do not declare all local variable at the same place
  • Declare them as close as possible to where you use them

Bad Good

4 of 11

Commit messages

  • Do not declare all local variable at the same place
  • Declare them as close as possible to where you use them

Bad Good

5 of 11

Reading error messages in tests

  • Tests are all about expectations and actual output
  • Error starts with expectation
  • Error ends with actual result

Expected {1,10,0} but was {1,0}

Expected “Failed calculating…”

But was “”�

6 of 11

Blocks of code with comments

  • Don’t write blocks of code with comments
  • Instead, refactor it to step functions
  • Code should speak for itself

Bad

Good

7 of 11

Blobs of code or blanks. Bad

  • Some students didn’t put any blank lines
  • Some put a blank line after every line of code
  • Both choices are bad

8 of 11

Good blanks

  • Tightly related code should be condense
  • Loosely related code should be separated by a blank

9 of 11

No code reuse

  • In homework 5 we had to implement the following:
    • InsertAt
    • InsertFirst
    • InsertLast
  • Most people had troubles realising that InsertFirst is almost the same as InsertAt(0)
  • Don’t repeat yourself (DRY)

10 of 11

Nesting

  • Some people would put a big chunk of code in if statement and another one if needed
  • However, you can work around this by returning in an inversed if

Good

Bad

11 of 11

PR reviews

Bad

Good

  • Please respond :)