@@ -132,7 +132,7 @@ from django.http import HttpRequest, HttpResponse
132132from words_app.logic import calculate_points
133133
134134def view (request : HttpRequest) -> HttpResponse:
135- user_word: str = request.GET [' word' ] # just an example
135+ user_word: str = request.POST [' word' ] # just an example
136136 points = calculate_points(user_word)
137137 ... # later you show the result to user somehow
138138
@@ -148,20 +148,20 @@ def _award_points_for_letters(guessed: int) -> int:
148148
149149Awesome! It works, users are happy, your logic is pure and awesome.
150150But, later you decide to make the game more fun:
151- let's make the minimal accoutable letters thresshold
151+ let's make the minimal accoutable letters threshold
152152configurable for an extra challenge.
153153
154154You can just do it directly:
155155
156156``` python
157- def _award_points_for_letters (guessed : int , thresshold : int ) -> int :
158- return 0 if guessed < thresshold else guessed
157+ def _award_points_for_letters (guessed : int , threshold : int ) -> int :
158+ return 0 if guessed < threshold else guessed
159159```
160160
161161The problem is that ` _award_points_for_letters ` is deeply nested.
162- And then you have to pass ` thresshold ` through the whole callstack,
162+ And then you have to pass ` threshold ` through the whole callstack,
163163including ` calculate_points ` and all other functions that might be on the way.
164- All of them will have to accept ` thresshold ` as a parameter!
164+ All of them will have to accept ` threshold ` as a parameter!
165165This is not useful at all!
166166Large code bases will struggle a lot from this change.
167167
@@ -177,7 +177,7 @@ from django.http import HttpRequest, HttpResponse
177177from words_app.logic import calculate_points
178178
179179def view (request : HttpRequest) -> HttpResponse:
180- user_word: str = request.GET [' word' ] # just an example
180+ user_word: str = request.POST [' word' ] # just an example
181181 points = calculate_points(user_words)(settings) # passing the dependencies
182182 ... # later you show the result to user somehow
183183
@@ -187,15 +187,15 @@ from typing_extensions import Protocol
187187from returns.context import RequiresContext
188188
189189class _Deps (Protocol ): # we rely on abstractions, not direct values or types
190- WORD_THRESSHOLD : int
190+ WORD_THRESHOLD : int
191191
192192def calculate_points (word : str ) -> RequiresContext[_Deps, int ]:
193193 guessed_letters_count = len ([letter for letter in word if letter != ' .' ])
194194 return _award_points_for_letters(guessed_letters_count)
195195
196196def _award_points_for_letters (guessed : int ) -> RequiresContext[_Deps, int ]:
197197 return RequiresContext(
198- lambda deps : 0 if guessed < deps.WORD_THRESSHOLD else guessed,
198+ lambda deps : 0 if guessed < deps.WORD_THRESHOLD else guessed,
199199 )
200200```
201201
0 commit comments