HNHacker News
TopNewBestAskShowJobs

raymondh

2,430 karma · joined February 9, 2010

Highlights:

  * CEO of Mutable Minds, Inc. (a training and consulting company)
  * Python Distinguished Service Award
  * Past Python Software Foundation (PSF) board member
  * Private pilot (single engine land and sailplanes)
  * Certified Public Accountant
  * Certified Internal Auditor
  * Python Core Developer
  * Husband to Rachel
  * Father to Matthew
Python training video series, "Modern Python: Big Ideas, Little Code" available for free to Safari On-line subscribers: https://www.oreilly.com/library/view/modern-python-livelessons/9780134743400/

Videos for conference presentations and keynotes can be found at: https://www.youtube.com/playlist?list=PLRVdut2KPAguz3xcd22i_o_onnmDKj3MA

Contributions to Python:

  * any()
  * all()
  * enumerate()
  * local mapping argument to exec() can be any mapping
  * filter() -- originally itertools.ifilter
  * frozenset()
  * map() -- originally itertools.imap
  * reversed()
  * sum() -- optimized and made more accurate
  * zip() -- originally itertools.izip
  * sorted()
  * set()
  * dict.fromkeys
  * dict.pop
  * float.as_integer_ratio
  * str.format_map
  * str.partition
  * str.rpartition
  * tuple.count
  * tuple.index
  * abc.ABC
  * antigravity.geohash 
  * bisect module -- key function support
  * calendar module -- various fixups
  * collections.ChainMap
  * collections.Counter
  * collections.OrderedDict
  * collections.deque
  * collections.namedtuple
  * contextlib.redirect_stderr
  * contextlib.redirect_stdout
  * contextlib.suppress
  * decimal module
  * difflib.context_diff
  * difflib.unified_diff
  * fractions.limit_denominator -- with Mark Dickinson
  * functools.cache
  * functools.cmp_to_key
  * functools.lru_cache
  * functools.total_ordering
  * heapq.heappushpop
  * heapq.merge
  * heapq.nlargest
  * heapq.nsmallest
  * itertools.accumulate
  * itertools.chain
  * itertools.chain.from_iterable
  * itertools.combinations
  * itertools.combinations_with_replacement
  * itertools.compress
  * itertools.count
  * itertools.cycle
  * itertools.dropwhile
  * itertools.filterfalse
  * itertools.groupby
  * itertools.islice
  * itertools.pairwise
  * itertools.permutations
  * itertools.product
  * itertools.repeat
  * itertools.starmap
  * itertools.takewhile
  * itertools.tee
  * itertools.zip_longest
  * json.AttrDict (later removed)
  * math.dist
  * math.fsum -- with Mark Dickinson
  * math.hypot -- improve algorithm and expanded to n-dimensional case
  * math.log -- added the "base" optional argument
  * math.prod -- implemented by Pablo Galindo
  * operator.attrgetter
  * operator.itemgetter
  * queue.LifoQueue
  * queue.PriorityQueue
  * queue.join
  * queue.task_done
  * random's MersenneTwister
  * random.SystemRandom
  * random._randbelow
  * random.binomialvariate
  * random.choices
  * random.sample
  * random.triangular
  * statistics.correlation -- added spearman rank correlation coefficient
  * statistics.fmean
  * statistics.geometric_mean
  * statistics.harmonic_mean -- added weights parameter
  * statistics.kde
  * statistics.kde_random
  * statistics.linear_regression -- added direct proportion option
  * statistics.mode -- fixed api
  * statistics.multimode
  * statistics.NormalDist
  * statistics.quantiles
  * statistics.variance/pvariance/stdev/pstdev -- correctly ounded
  * tokenize.untokenize
  * userdict.DictMixin -- eventually became ollections.MutableMapping
  * __slots__ can be a dictionary
Designer of:

  * key-functions
  * generator expressions
  * compact and ordered dictionaries
  * the peephole optimizer
  * __length_hint__ optimization
  * the thousands separator in string formatting
  * original proponent of exception chaining
  * original proponent of sending data and exceptions into enerators
  * eval-loop opcode prediction
Maintainer of:

  * the argparse module (successor to Steven Bethard)
  * the bisect module
  * the collections module
  * the collections.abc module
  * the decimal module
  * the heapq module
  * the itertools module
  * the queue module
  * the random module
  * the statistics module (with Steven D'Aprano) 
Author of:

  * Python How-to: Descriptor Guide
  * Python How-to: Sorting Techniques
  * Python tutorial: Looping Techniques
  * Python tutorial: Tour of the standard library
  * Python tutorial: Floating Point Arithmetic
  * Blog post: Super Considered Super
  * Whatsnew 3.1
  * Whatsnew 3.2
  * Whatsnew 3.8
Social media:

  * https://twitter.com/raymondh
  * https://rhettinger.wordpress.com/
  * https://www.facebook.com/raymondh
  * https://www.linkedin.com/in/raymondhettinger/
  * https://stackoverflow.com/users/1001643/raymond-hettinger
submissionscomments
raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
Wouldn't it have been better for the language itself to have made a decision rather than another group of people who are in the business of having strong, enforced decisions about what is allowed?

The language specifies that simple statements can be separated by semicolons. Black eliminates this part of the language, essentially overriding Guido's decision.

The language specifies that four different quoting characters are available. Black eliminates this part of the language, mandating double quotes in code and single quotes in a repr output, essentially overriding Guido's decision.

The language specifies that in-line comments can start anywhere on a line. Black eliminates the writer's option to line-up their comments vertically, essentially overriding Guido's language decision.

The language allows and PEP 8 encourages using whitespace to aid readers in reading mathematical expressions just like sympy and LaTex do: ``3x*2 - 2x +5``. Black eliminates this possibility and mandates equal spacing regardless of operator precedence: ``3 * x * 2 - 2 * x + 5``. Once again, this overrides Guido's judgment.

Wouldn't be better for Guido to decide what the language allows rather than have a downstream tool narrow the range of what is possible?

raymondh
·
·on Multiple assignment and tuple unpacking improve Python code readability (2018)
As I teacher, types.SimpleNamespace is wonderful for helping people bridge between their understanding of dicts (a fundamental) to classes/instances (a little less fundamental).

However, I almost never use SimpleNamespace in real code. Dicts offer extra capabilities: get, pop, popitem, clear, copy, keys, values, items). Classes/instances offer extra capabilities: unique and shared keys in distinct namespaces, instances knowing their own type, and an elegant transformation of method calls ``a.m(b, c)`` --> ``type(a).m(a, b, c)``. Dataclasses and named tuples have their advantages as well. In practice, it is almost never that case that SimpleNamespace beats one of the alternatives.

raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
People who respect the law and love sausage should never watch either of them being made ;-)

The referenced thread isn't Python's finest hour. A: "Hey, this feature is slightly inconvenient to implement in AST, let's kill it." B: "Many users haven't heard of this, so let's kill it." C: "I find it useful and there's not real advantage in killing it". A&B: "Okay, it's gone".

Really, you're better-off just enjoying a language that is mostly nice and mostly well-designed. Don't read the development threads. It will spoil the illusion.

raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
I also miss this capability. It was super helpful for working with 2-D or 3-D point vectors:

    lambda (x1, y1), (x2, y2):  return abs(x2 - x1) + abs(y2 - y1)
raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
IOW, the match/case tool can pattern match and destructure at the same time. Som uninterestingly, it is possible to do only one of those things:

Iterator unpacking:

    first, *middle, last = t
is similar to a match/case with a sequence pattern:

    match t:
        case first, *middle, last:
            ...
The former works for any iterable and the latter requires a sequence. The former raises an error for a non-iterable and the latter just skips the case for a non-sequence. Otherwise, they are similar.

However, arguing that one is a special case of the other misses the entire point of structural pattern matching. We would almost never substitute the latter for the former. They mostly live in different worlds because we use them and think about them much differently:

    # Something that would work but they we don't do
    for item in somedict.items():    
        match item:
            case [key, value]:
                 print(key.upper())
                 print(value)
                 print()
            case _:
                 raise RuntimeError('unexpected kind of item')

    # What we actually do
    for key, value in somedict.items(): 
        print(key.upper())
        print(value)
        print()
Sorry for the small rant, but I think this pedantic point isn't a useful line of thinking. That concepts and implementation have some overlap but should occupy a different concept maps in our brains — very much like the idea that dicts can do set-like things but that we're better off thinking about dicts as doing lookups and sets as doing uniquification, membership-testing, and set-to-set operations.
raymondh··on HackerRank (YC S11) DMCA'ed the SymPy Docs [fixed]
Thank you, this gives a lot of insight into what is going on. This one tells the whole story: https://github.com/github/dmca/blob/ea3736a0c4c9574e0c8cea06...
raymondh··on Boycott Numerical Recipes (2007)
The Python docs¹ include an implementation of Allen Downey's algorithm:

    from random import Random
    from math import ldexp

    class FullRandom(Random):

        def random(self):
            mantissa = 0x10_0000_0000_0000 | self.getrandbits(52)
            exponent = -53
            x = 0
            while not x:
                x = self.getrandbits(32)
                exponent += x.bit_length() - 32
            return ldexp(mantissa, exponent)
¹ https://docs.python.org/3/library/random.html#recipes
raymondh··on The Cult of Posits
What is the recommended latest equivalent of that document?
raymondh··on Python 3 Types in the Wild
Almost the entire purpose of frozensets was so that you could have sets of frozensets. It's the only way to have nested sets. Frozensets also work as dictionary keys.
raymondh··on Simple passwordless authentication for web projects
dang?
raymondh··on Neural nets are not “slightly conscious,” and AI PR can do with less hype
Phased locked loops are conscious. Whatever their goal, they constantly compare their actions with the external world, and constantly adapt their behavior. They are clearly self-aware and have complete OODA loop. Though some are simple organisms with only a few components; others implemented software are much more complex; perhaps, they even dream.
raymondh··on More intuitive partial function application in Python
Current solutions:

  >>> list(map(partial(pow, exp=3), range(10)))
  [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

  >>> list(map(lambda base: pow(base, 3), range(10)))
  [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

  >>> [pow(base, 3) for base in range(10)]
  [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
Proposed solution:

  list(map(bp.partial(pow)(bp._, 3), range(10))
ISTM the only time you come out a little ahead is if you know in advance that a function is going to be partialed (so you can decorate it), that you will need to partial arguments in other than a left to right fashion (otherwise a plain partial will suffice), that you won't use keyword arguments (the current partial works with keywords), and that you really dislike the lambda keyword (which neatly covers all cases from simple to complex without a new notation).

That said, this is a clever recipe. Kudos to the author for putting it together. I don't think it really rises to the level of "better" or "more intuitive", but it is an interesting experiment.

raymondh··on New atomic clock loses only one second every 300B years
300B years is impressive. I wonder how they overcame the problem of our sun turning into a red giant 5 billion years from now ;-)
raymondh··on Computer scientists prove why bigger neural networks do better
> The proof relies on a curious fact about high-dimensional geometry, which is that randomly distributed points placed on the surface of a sphere are almost all a full diameter away from each other.

That should be √2 × radius.

Looking out from the North Pole of hypersphere, almost all points lie near the equator, not the South Pole.

raymondh··on Ask HN: Is it worth it to learn C to better understand Python?
Python instructor and C programmer here:

No need to learn C to better understand Python. Almost any gain you would make could be had by reading or watching an overview of the internals.

raymondh··on Beancount: Double-entry accounting from text files
If you just started the service, carefully consider the name of the service. "Bean counter" is a disparaging term that is almost never a compliment.

The first paragraph of https://www.cfo.com/accounting-tax/2007/10/finance-in-histor... explains:

“Bean counting” has long been an insulting term for what finance professionals and accountants do. Often it’s been used to tar CFOs as transaction processors — a role largely relegated to the back office. What’s more, people like to use the phrase to ratchet up the pedestrian aspects of finance by tagging practitioners as “mere” bean counters or “little more than” bean counters or “simply” bean counters. Such clichés get tossed around a lot.

Per https://www.phrases.org.uk/meanings/bean-counter.html , "A disparaging term for an accountant, or anyone excessively concerned with statistical records or accounts."

raymondh··on Beancount: Double-entry accounting from text files
Accountant here: Recommend using Beancount with version control on your data so that you can take snapshots at various points in time.

The notion behind "accountants don't user erasers" is that like a blockchain, you're creating a trail of evidence. If all of the data is mutable all of the time, its evidentiary value is low (for example, the IRS gives more weight to "contemporary" evidence than to records constructed or altered after-the-fact).

Another reason to freeze, snapshot, or close your books is to not lose the support and detail behind any financial statements you've produced. Imagine getting a business loan based on your Balance Sheet and Income Statement but later being unable to reconstruct how those were produced.

Generally, accounting systems use a system of cumulative, immutable journal entries. If a mistake is made, then a reversing or adjusting entry is made.¹

There is merit to text based bookkeeping, but don't create a world that is so free form and mutable that it loses it meaning and connection with the real world.

¹ https://en.wikipedia.org/wiki/Adjusting_entries

raymondh··on A trick to have arbitrary infix operators in Python
This is a pretty cool recipe.

The precedence is determined by the overridden operator. In this case the "|" operator has low precedence.¹ For a high precedence operator, override "%" with __mod__ and __rmod__:

    4 |add| 5 %mul% 6 |add| 7    # mul happens before add
¹ https://docs.python.org/3/reference/expressions.html#operato...
raymondh··on Microsoft Launches Inclusive Spelling Tool
The underlying theory of Newspeak is that if something can’t be said, then it can’t be thought. -- George Orwell
raymondh··on QR code scammers hitting on-street parking in Texas cities
Can anyone with an understanding of cash transfers work explain how this is possible?

I cannot fathom how scammers get away with this. The police have the QR code, the URL, and the cash going out of one account into another. How is it possible that these people don't get caught and locked up immediately?

raymondh··on When they warn of rare disorders, these prenatal tests are usually wrong
Thank you for sharing this.
raymondh··on JPMorgan hit with $200M in fines for letting employees use WhatsApp
Accountants, traders, executives, bankers, etc all have strict rules designed to avoid the appearance of impropriety. However, it seems that members of congress are held to a much lower standard.
raymondh··on Fredrik Lundh has died
The effbot was an early mentor me. He had a brusque style, an excellent sense of design, and a wry wit. He thought deeply about programming problems and did not shy away from non-trivial tasks such as regular expressions. His ElementTree library humanized XML parsing and generation in Python.
raymondh··on Who is the most accurate world chess champion?
For historical human-to-human games, it would be more interesting to see how well players targeted with weaknesses of their opponents. That skill likely mattered more than absolute accuracy as measured by computers.
raymondh··on A Tale of Java Hash Tables
It's an acronym for "virtual retractable binary link", a concept well known to perturbation specialists.
raymondh··on A Tale of Java Hash Tables
If the OP has time, it might be nice to experiment with the hash table technique used by sets in Python. It has a variant of open addressing the runs several linear probes before jumping to another location in hash table.

The premise is that probing consecutive memory addresses is cheap because of cache locality and because the address computation is a simple increment. This should be cheaper than resolving hash collisions with additional random probes or by chasing linked list references to random memory locations for each link.

https://github.com/python/cpython/blob/f840398a5fd8741653c26...

raymondh··on Astrophysicists unveil glut of gravitational-wave detections
GW fanboy here. IIRC, additional detectors provide better ability to locate the GW source so that other telescopes can also capture an event. They also improve polarization measurements. The number of detectors doesn't determine the false positive rate which is just a user selected point on a receiver operating characteristic curve. In general, we get more pay off from improving detect sensitivity than from having more detectors (that's why GEO 600 was more useful for the tech it developed rather than its most recent observations).
raymondh··on Suppose I Wanted to Kill a Lot of Pilots (2020)
I mainly aspired to relate the thesis of the article to the origin story for the Raspberry Pi.

The only intended political statement was about the importance of small airfields.

raymondh··on Suppose I Wanted to Kill a Lot of Pilots (2020)
Tangent: Rather than killing pilots, work on preventing them from becoming pilots in the first place. Perhaps join neighborhood efforts to close all the small airports where people learn to fly.

Now apply the "reverse thinking" described in the article. To enable the development of more pilots, work on increasing the number of small airfields.

Apply this to your own world. What do you need to do to increase the pipeline of talent available to your company?

The origin story for the RaspberryPI is a prime example:

https://www.zdnet.com/article/we-thought-wed-sell-1000-the-i...

raymondh··on Facebook-owned sites were down
It is slow for me too.
← PreviousPage 3 of 11Next →