The hardest problem in computer science...

Steve D'Aprano steve+python at pearwood.info
Sat Jan 7 02:34:16 EST 2017


On Sat, 7 Jan 2017 12:03 am, Steve D'Aprano wrote:

> The second hardest problem in computer science is cache invalidation.
> 
> The *hardest* problem is naming things.

Thanks everyone who answered, but I think some of you misunderstood my
question. I know that the individual characters themselves are called some
variation of "line drawing characters", or "box drawing characters". But
the important part of the question was given by the Python code:

> XXX = namedtuple("XXX", "vline tee corner")
> 
> default_YYY = XXX("│  ", "├─ ", "└─ ")
> bold_YYY = XXX("┃  ", "┣━ ", "┗━ ")
> ascii_YYY = XXX("|  ", "|- ", "+- ")
> 
> def draw_tree(tree, YYY=default_YYY):
>     ...
> 
> 
> but what do I call XXX and YYY?

After puzzling over this for three days, it suddenly hit me:

Theme = namedtuple("Theme", "vline tee corner")

DEFAULT = Theme("│  ", "├─ ", "└─ ")
BOLD = Theme("┃  ", "┣━ ", "┗━ ")
ASCII = Theme("|  ", "|- ", "+- ")
 
def draw_tree(tree, theme=DEFAULT):
    ...



Ethan's idea of "style" is also good.


Thanks for all your ideas!



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list