Singular irregularities

An irregularity is a shape or rule violation. It supposes that objects are built according to rules but there are exceptional cases that don’t really fit or do at least violate our expectations of the building law. An irregularity is singular if the building law is violated in a single case.

The best known example in Python is the syntax of tuples:

()                          # empty tuple
(arg)                       # parenthesized expression - no tuple!
(arg,)                      # tuple with one element
(arg1, arg2, ...)           # tuple with many arguments

Another more recent example is the set syntax in Python 3 which requires an ambiguity resolution involving an empty set and an empty dict:

{}                          # empty dict!
set()                       # empty set !
{arg}                       # set with one element
{arg1, arg2, ...}           # set with many elements

Some people suggested to drop parentheses around arguments in function calls. This leads to an ambiguity between a function object and function call without arguments. In order to resolve it one might introduce another singular irregularity:

func                      # object !
func arg1 arg2...         # function call with arguments
func()                    # function call
func(arg1, arg2, ...)     # function call with arguments

Are singular irregularities design mistakes or are they acceptable trade offs for avoiding verbosity and/or the introduction of even more syntax?

This entry was posted in General. Bookmark the permalink.

3 Responses to Singular irregularities

  1. I believe that in the first case of tuples, the irregularity should be () (empty tuple!) rather than the parenthesized expression without a comma. After all, it’s not the parentheses that define the tuple, it’s the comma operator: adict[x,y]= 1,2,3; in the previous expression, there are two tuples and no parentheses.

  2. Jon Harrop says:

    Design flaw, IMHO.

    OCaml has similar one where “type a = A of int * int” is different from “type a = A of (int * int)” because the former is a variant type constructor with two arguments whereas the latter is a constructor with one argument that is a tuple. Senseless…

  3. I’d say they’re a mistake if they could’ve been avoided.

Comments are closed.