Pythonicity
Pythonicity
pythonicity | pīˈTHänisədē | noun the quality of being Pythonic
Categories
All
(21)
core
(1)
graphql
(5)
interviews
(4)
puzzles
(5)
style
(6)
Order By
Default
Title
Date - Oldest
Date - Newest
Author
GraphQL cursors
Contrarian view on cursor-based pagination.
graphql
GraphQL documentation recommends cursor-based pagination, and it has subsequently become a popular standard.
Jun 9, 2024
A. Coady
Packaging rundown
Companion guide to the Python packaging tutorial.
core
This is not an overview of packaging, nor a history of the tooling. The intended audience is an author of a simple package who merely wants to publish it on the package index…
May 12, 2024
A. Coady
GraphQL root fields
There is no such thing as a “root field”.
graphql
There is a common - seemingly universal - misconception that GraphQL root fields are somehow special, in both usage and implementation. The better conceptual model is that…
Apr 12, 2024
A. Coady
Composition vs. inheritance
Contrarian view on composition over inheritance.
style
The conventional wisdom is to prefer composition over inheritance. More specifically to use delegation over single inheritance.
Nov 18, 2023
A. Coady
Decorator overuse
Decorators versus blocks and partial functions.
style
Decorators are a beloved feature of Python, but like any good thing can be overused. The key is acknowledging that decorators are just functions.
Mar 4, 2023
A. Coady
GraphQL nulls
Litany against nulls.
graphql
The myths and misconceptions regarding null behavior in GraphQL are epic. Even the spec is wrong.
Feb 24, 2023
A. Coady
GraphQL coroutines
GraphQL resolvers should have been coroutines.
graphql
This is how the GraphQL documentation introduces execution, as a hierarchy of resolvers:
Feb 20, 2023
A. Coady
Random Selection
Generate random numbers efficiently.
interviews
Random selection utilities used to be common in interviews. Less so in Python circles because of the builtin
random
module. Still advanced examples may come up. First is a…
Jan 2, 2023
A. Coady
Primes
Generate prime numbers.
interviews
An old interview challenge is to generate prime numbers or check if a number is prime. No advanced mathematics needed, just variants on the Sieve of Eratosthenes. Starting…
Jul 10, 2021
A. Coady
Hardest Logic Puzzle Ever
How to solve the Hardest Logic Puzzle Ever programmatically.
puzzles
Three gods A, B, and C are called, in no particular order, True, False, and Random. True always speaks truly, False always speaks falsely, but whether Random speaks truly or…
Jan 1, 2021
A. Coady
GraphQL - ORM
GraphQL is the new ORM.
graphql
REST and ORMs are both infamous for:
Jul 6, 2020
A. Coady
Closing files
Contrarian view on closing files.
style
It has become conventional wisdom to always explicitly close file-like objects, via context managers. The google style guide is representative:
Jul 5, 2020
A. Coady
Mutable defaults
Contrarian view on mutable default arguments.
style
The use of mutable defaults is probably the most infamous Python gotcha. Default values are evaluated at definition time, which means mutating them will be persistent across…
Jun 28, 2020
A. Coady
Water pouring
How to solve the water pouring puzzle programmatically.
puzzles
Given two jugs of capcity of 3 and 5 liters, acquire exactly 4 liters in a jug. Assume an unlimited water supply, and that jugs can only be filled or emptied, i.e., no…
Jun 14, 2020
A. Coady
Coin balance
How to solve the coin balance puzzle programmatically.
puzzles
Given a balance and a set of coins, which are all equal in weight except for one, determine which coin is of different weight in as few weighings as possible.
Jun 7, 2020
A. Coady
Hat puzzle
How to solve the Hat puzzle programmatically.
puzzles
Ten-Hat Variant
Jan 11, 2020
A. Coady
Split an Iterable
Split an iterable into equal sized chunks.
interviews
A common task and interview question, with many variants. It’s frequently asked and answered in a way that’s suboptimal and only handles one specific case. The goal here is…
Dec 28, 2019
A. Coady
Accumulator
A Paul Graham classic, the accumulator function.
style
As an illustration of what I mean about the relative power of programming languages, consider the following problem. We want to write a function that generates accumulators–…
May 28, 2018
A. Coady
Map and Filter
Contrarian view on
map
and
filter
.
style
Although PEP 8 is silent on the topic, it’s become recommended in many Python circles to eschew
map
and
filter
in favor of generator expressions or list comprehensions. For…
Mar 31, 2018
A. Coady
Fizz Buzz
The infamously simple FizzBuzz problem.
interviews
Reportedly a high percentage of programmer applicants can’t solve this quickly.
Mar 25, 2018
A. Coady
Cheryl’s Birthday
How to solve the Cheryl’s Birthday puzzle programmatically.
puzzles
As with the pytudes solution, the goal is to solve the puzzle in code. A different approach is taken here though, for simplicity and extensibility.
Mar 20, 2018
A. Coady
No matching items