Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

#Code improvements

Code improvements

#Design improvements

Design improvements

#Code improvements

#Design improvements

Code improvements

Design improvements

added 6 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155

Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code to make sure the correct types are used. For example, here would be your connect function with type hints. Note the added import from typing, which has common types like List, Dict, and Tuple.

  1. For performance, queries that at ranare executed "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.

Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code. For example, here would be your connect function with type hints. Note the added import from typing, which has common types like List, Dict, and Tuple.

  1. For performance, queries that at ran "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.

Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code to make sure the correct types are used. For example, here would be your connect function with type hints. Note the added import from typing, which has common types like List, Dict, and Tuple.

  1. For performance, queries that are executed "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.
added 10 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155

I would recommend using the string .format()string .format() method instead of +'ing strings together. For example:

def check_user_exists(nameuser_name: str) -> bool:
 query = "SELECT id FROM users WHERE name = ?"
 cursor.execute(query, nameuser_name)
 # etc.

I would recommend using the string .format() method instead of +'ing strings together. For example:

def check_user_exists(name: str) -> bool:
 query = "SELECT id FROM users WHERE name = ?"
 cursor.execute(query, name)
 # etc.

I would recommend using the string .format() method instead of +'ing strings together. For example:

def check_user_exists(user_name: str) -> bool:
 query = "SELECT id FROM users WHERE name = ?"
 cursor.execute(query, user_name)
 # etc.
added 49 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155
Loading
added 49 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155
Loading
added 677 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155
Loading
added 677 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155
Loading
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155
Loading
lang-py

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