Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Senko Rašić

November 24, 2012
Tweet

More Decks by Senko Rašić

Other Decks in Programming

Transcript

  1. 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
  2. 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