@@ -290,18 +290,18 @@ Dynamic typing
290
290
Python is said to be dynamically typed, which means that variables
291
291
do not have a fixed type. In fact, in Python, variables are very
292
292
different from what they are in many other languages, specifically
293
- strongly-typed languages: variables are not a segment of the computer's
294
- memory where some value ir written, they are 'tags' or 'names' pointing
293
+ strongly-typed languages. Variables are not a segment of the computer's
294
+ memory where some value is written, they are 'tags' or 'names' pointing
295
295
to objects. It is therefore possible for the variable 'a' to be set to
296
296
the value 1, then to the value 'a string', then to a function.
297
297
298
- The dynanic typing of Python is often considered as a weakness, and indeed
299
- it can lead to complexities and to hard-to-debug code, where something
298
+ The dynamic typing of Python is often considered to be a weakness, and indeed
299
+ it can lead to complexities and hard-to-debug code. Something
300
300
named 'a' can be set to many different things, and the developer or the
301
- maintainer need to track this name in the code to make sure it has not
301
+ maintainer needs to track this name in the code to make sure it has not
302
302
been set to a completely unrelated object.
303
303
304
- Some guidelines allow to avoid this issue:
304
+ Some guidelines help to avoid this issue:
305
305
306
306
- Avoid using variables for different things.
307
307
@@ -323,9 +323,8 @@ Some guidelines allow to avoid this issue:
323
323
def func ()
324
324
pass # Do something
325
325
326
- Using short functions or methods helps writing good code for many
327
- reasons, one being that their local scope is clearer, and the risk
328
- of using the same name for two unrelated things is lowered.
326
+ Using short functions or methods helps reduce the risk
327
+ of using the same name for two unrelated things.
329
328
330
329
It is better to use different names even for things that are related,
331
330
when they have a different type:
@@ -340,14 +339,14 @@ when they have a different type:
340
339
341
340
There is no efficiency gain when reusing names: the assignments
342
341
will have to create new objects anyway. However, when the complexity
343
- grows are each assignment are separated by other lines of code, including
344
- 'if' branches and loops, it becomes harder to acertain which type is the
345
- variable at hand .
346
-
347
- Some coding practices, like functional programming, even recommend to never re-assign a variable, which
348
- is done in Java with the keyword final. Python do not have such a keyword,
349
- and it would be against its philosophy anyway, but it may be a good
350
- discipline to avoid setting more than once any variable , and it helps
342
+ grows and each assignment is separated by other lines of code, including
343
+ 'if' branches and loops, it becomes harder to ascertain what a given
344
+ variable's type is .
345
+
346
+ Some coding practices, like functional programming, recommend never reassigning a variable.
347
+ In Java this is done with the ` final ` keyword . Python does not have a ` final ` keyword
348
+ and it would be against its philosophy anyway. However, it may be a good
349
+ discipline to avoid assigning to a variable more than once, and it helps
351
350
in grasping the concept of mutable and immutable types.
352
351
353
352
Mutable and immutable types
0 commit comments