News for hackers. Stuff that matters.
Re:Python adopts a 12-month release cycle by dragonwriter on Saturday November 02, 2019 @04:40AM (#21426561)
> The other part I don't get is the religious insistence against not implementing something like a "switch" statement.

Off the top of my head, something like a switch, but more general and a function rather than a statement:

  def switch(key, opts_dict, *, default):
    return opts_dict.get(key, default)()
or, if key is of a comparable but non-hashable type:

  def switch(key, opts_list, *, default):
    return next(
      (o[1] for o in opts_list if o[0] == key), 
      default
    )()
I can think of other simple variations to do exactly what is wanted in other situations; it's easy enough to code a specific tool for the situation with what Python gives you that, in the situations where a chained set of if/else isn't what is called for, it's trivial to whip up something tailored to the specific need. C doesn't have dicts or iterators or first-class functions in the base language (at least, with convenient syntax), so it needs special syntax to cover a much smaller space than what Python conveniently handles without special syntax dedicated to the problem.

There are no comments on this comment yet.