Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Recursion

###Recursion II like recursion. But when I find myself trying to use it in Python I stop and reconsider. Using recursion in Python is possible, but doing so is usually an exercise in snake wrestling more than it is productive programming.

Magic Numbers

###Magic Numbers TheThe Danish alphabet has 29 letters. Icelandic has 32. Russian, 33. The length of the Latin alphabet, 26, is hard coded into the functions. These languages use characters that are not directly representable in ASCII. The code assumes that they are and hard codes the offset 97.

A => 1

###A => 1 PythonPython is zero indexed. Indexing the Latin alphabet from 1 is fighting against the language. I can follow your rationales for wrestling the snake. But I have to think too much about your rationales in order to understand your code. If you had created a Domain Specific Language in Python and then were writing your functions in that, 1-indexing would make sense. But your code is in Python. The biggest advantage of Python is that people know what to expect. They don't expect 1-indexing.

Data Architecture

###Data Architecture ZeroZero-indexing versus one-indexing is mostly a matter of not conceptually separating the internal data representation of your application from the external interface of the Google API. The architecture of your application is:

Naming

###Naming ConsiderConsider deserialize_column_name and serialize_column_name as the names of your functions because those are your functions' functions. Base 26 is not really the important part of how someone uses it. That the output is a letter is not really the important part. Those are implementation details of Google's API protocol that can be described in the DocStrings. People will have to read the DocString with the current names, anyway.

###Recursion I like recursion. But when I find myself trying to use it in Python I stop and reconsider. Using recursion in Python is possible, but doing so is usually an exercise in snake wrestling more than it is productive programming.

###Magic Numbers The Danish alphabet has 29 letters. Icelandic has 32. Russian, 33. The length of the Latin alphabet, 26, is hard coded into the functions. These languages use characters that are not directly representable in ASCII. The code assumes that they are and hard codes the offset 97.

###A => 1 Python is zero indexed. Indexing the Latin alphabet from 1 is fighting against the language. I can follow your rationales for wrestling the snake. But I have to think too much about your rationales in order to understand your code. If you had created a Domain Specific Language in Python and then were writing your functions in that, 1-indexing would make sense. But your code is in Python. The biggest advantage of Python is that people know what to expect. They don't expect 1-indexing.

###Data Architecture Zero-indexing versus one-indexing is mostly a matter of not conceptually separating the internal data representation of your application from the external interface of the Google API. The architecture of your application is:

###Naming Consider deserialize_column_name and serialize_column_name as the names of your functions because those are your functions' functions. Base 26 is not really the important part of how someone uses it. That the output is a letter is not really the important part. Those are implementation details of Google's API protocol that can be described in the DocStrings. People will have to read the DocString with the current names, anyway.

Recursion

I like recursion. But when I find myself trying to use it in Python I stop and reconsider. Using recursion in Python is possible, but doing so is usually an exercise in snake wrestling more than it is productive programming.

Magic Numbers

The Danish alphabet has 29 letters. Icelandic has 32. Russian, 33. The length of the Latin alphabet, 26, is hard coded into the functions. These languages use characters that are not directly representable in ASCII. The code assumes that they are and hard codes the offset 97.

A => 1

Python is zero indexed. Indexing the Latin alphabet from 1 is fighting against the language. I can follow your rationales for wrestling the snake. But I have to think too much about your rationales in order to understand your code. If you had created a Domain Specific Language in Python and then were writing your functions in that, 1-indexing would make sense. But your code is in Python. The biggest advantage of Python is that people know what to expect. They don't expect 1-indexing.

Data Architecture

Zero-indexing versus one-indexing is mostly a matter of not conceptually separating the internal data representation of your application from the external interface of the Google API. The architecture of your application is:

Naming

Consider deserialize_column_name and serialize_column_name as the names of your functions because those are your functions' functions. Base 26 is not really the important part of how someone uses it. That the output is a letter is not really the important part. Those are implementation details of Google's API protocol that can be described in the DocStrings. People will have to read the DocString with the current names, anyway.

Source Link
ben rudgers
  • 2.7k
  • 13
  • 23

There is a lot of sound advice in other answers, so I will only touch on aspects that I think are worth considering, but are not yet addressed (or that I misunderstood).

###Recursion I like recursion. But when I find myself trying to use it in Python I stop and reconsider. Using recursion in Python is possible, but doing so is usually an exercise in snake wrestling more than it is productive programming.

while_stmt ::= "while" expression ":" suite
 ["else" ":" suite]

On the other hand, the while statement is very similar conceptually. The syntactical differences from recursion are:

  1. The test is true when the inductive base case is false.
  2. The action on the base case comes at the end.

Other answers show examples of how to use while and it might be worth looking at them and trying "to see" them as recursive. It is probably worth using while instead of recursion if you plan to share Python code with other people because in the context of Python's community, recursive code is harder to understand.

###Magic Numbers The Danish alphabet has 29 letters. Icelandic has 32. Russian, 33. The length of the Latin alphabet, 26, is hard coded into the functions. These languages use characters that are not directly representable in ASCII. The code assumes that they are and hard codes the offset 97.

It may be the case that the Latin 26 character alphabet is hard coded into Google Sheets, now. If it is, that assumption should be made explicitly in one place so that maintenance will be easier if Google changes (or if there already is localization). Magic numbers are a "code smell". Sprinkling the same numbers throughout the code is another.

###A => 1 Python is zero indexed. Indexing the Latin alphabet from 1 is fighting against the language. I can follow your rationales for wrestling the snake. But I have to think too much about your rationales in order to understand your code. If you had created a Domain Specific Language in Python and then were writing your functions in that, 1-indexing would make sense. But your code is in Python. The biggest advantage of Python is that people know what to expect. They don't expect 1-indexing.

###Data Architecture Zero-indexing versus one-indexing is mostly a matter of not conceptually separating the internal data representation of your application from the external interface of the Google API. The architecture of your application is:

Deserialize from API -> Manipulate -> Serialize to API

The decision to use One-indexing is due to letting the data abstractions of Google's API leak into your Python code. It makes your code brittle and harder to reason about. Nobody should have to think about Google's API when looking at the internals of the Manipulateportion of the architecture. It is probably better if all your wrestling with Google's API happens in Deserialize and Serialize and Manipulate just works and make sense with zero knowledge of Google (or any other) API's.

###Naming Consider deserialize_column_name and serialize_column_name as the names of your functions because those are your functions' functions. Base 26 is not really the important part of how someone uses it. That the output is a letter is not really the important part. Those are implementation details of Google's API protocol that can be described in the DocStrings. People will have to read the DocString with the current names, anyway.

lang-py

AltStyle によって変換されたページ (->オリジナル) /