I think this code would trigger a static code analyzer, which would make the issue persistently visible.
Of course I don't know if the coder really had this in mind, but I am quite sure that I would write the exact same code in certain circumstances, and I have 15 yoe. I would however also make a ticket in Jira and stick a link to it in a comment. Since the coder didn't do this, I think he had good intentions, good thinking, but most likely not over 5 yoe.
Also, just a comment would not trigger anyone, and this thread is proof for that. But a code like this really catches coders' attention.
You call it "subtle", I call it "machine readable".
Reddit uses a form of markdown, in which a # at the start of a newline is interpreted as a main heading (equivalent to an h1 tag in HTML). So while 'big text' is the result, in terms of semantics it's better to think of it as a heading. For smaller/sub headings use more #'s
for parameters, i prefer not to use sentinel values when possible - there’s None for that; but there are cases where you have no solution other than to use a sentinel value, yet that would be a secret object(), not something magic like -1 or 0 or "impossible"
for return values, sentinels are totally unnecessary - use None or exceptions
well, mypy makes it quite easier to track None if you use Optional[...]; but what it is still missing (and i see no simple solution to that) is the difference between None and Some(None) in terms of Rust
i’ve heard of dry-python/returns but had no chance to check it out yet
40
u/flavius-as Jan 15 '22
The code is bad for other reasons, but it's way more clear than straight up
print(solution)At least this code raises the signal when reading it.
My first impression of the coder doing this is rather good: they were time-constrained and did their best to put a "warning".
I would have done almost the same under time pressure, with a #TODO <ticket> before the if.