Tri koraka do boljeg koda

Tri koraka do boljeg koda

[Croatian] Svi smo mi rockstar ninja developeri sa mad skilzima, ali, priznajmo, često nam se zaleti da napišemo stvarno loš komad koda. Predavanje će opisati tri tehnike kojima možemo smanjiti ili bar što prije otkriti te slučajeve: pisanje unit testova, review koda i automatizirano buildanje aplikacije. Navest ću naša iskustva u uvođenju svake od ovih stavki – na koje smo probleme naišli, koliko smo zadovoljni rezultatima, a na čemu još moramo poraditi.

382b18eebb1386e80ff7e20fd1eb784e?s=128

Senko Rašić

November 24, 2012
Tweet

Transcript

  1. Tri koraka do boljeg koda

  2. Dobar Kod – web aplikacije po mjeri

  3. 1) Unit testing

  4. Testiranje aplikacija

  5. def double(x): return 2 * x def test_that_doubling_works(): assert double(5)

    == 10 Unit testing – u teoriji
  6. def play(request, board_id): board = Board.objects.get(id=board_id) x = request.GET['x'] y

    = request.GET['y'] if x < 0 or x >= 3 or y < 0 or y >= 3: return render_to_response(“invalid_move.html”) move = Move(player=request.user, board=board, x=x, y=y) Board.moves.add(move) player_moves = Board.moves.filter( player=request.player) if winning(player_moves): return render_to_response(“winner.html”) elif Board.moves.count() == 9: return render_to_response(“tie.html”) else: return redirect(“next_player.html”) Čušpajz
  7. None
  8. class Board(Model): def add_move(self, player, x, y): if not (0

    <= x < 3 and 0 <= y < 3): Raise ValueError(“invalid move”) if self.moves.filter(x=x, y=y).exists(): Raise ValueError(“position taken”) return self.moves.create(board=self, player=player, x=x, y=y) def test_valid_move_accepted(): assertNotRaises(ValueError, board.add_move, test_player, 0, 0) def test_invalid_move_not_accepted(): assertRaises(ValueError, board.add_move, test_player, -1, -1) Unit testing – u praksi
  9. None
  10. 2) Pregled koda

  11. None
  12. Coop (ne PVP), peer review

  13. You Are Not Your Code

  14. Branch, Code, Pull Req, Review, Merge

  15. 3) Automatizirani build

  16. None
  17. None
  18. None
  19. None
  20. Hvala na pažnji