Senko Rašić
November 24, 2012
290

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

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)
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. class Board(Model):
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,
def test_invalid_move_not_accepted():
test_player, -1, -1)
Unit testing – u praksi

8. 2) Pregled koda

9. Coop (ne PVP), peer review

10. You Are Not Your Code

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

12. 3) Automatizirani build

13. Hvala na pažnji