Differences between revisions 1 and 2
Revision 1 as of 2004-12-30 15:29:46
Size: 1771
Editor: pcp07851501pcs
Comment:
Revision 2 as of 2005-01-03 01:45:37
Size: 3741
Editor: pool-68-160-34-147
Comment:
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:

== Improved default value logic for Dictionaries ==

 * The setdefault() method is badly named and poorly designed. In a typical call, d.setdefault.(k, []).append(v), the list may be unnecessarily instantiated and discarded on every call. At a minimum, default value should be a new empty list instead of None: d.setdefault(k).append(v).

 * A more versatile idea is to realize that defaults generalize to the whole dictionary instead of an individual lookup. A call to setdefault would then change the whole dictionary's behavior when a key is not found::

    counts = {}
    counts.setdefault(value=0)
    for elem in data:
        counts[elem] += 1

    index = {}
    index.setdefault(function=list)
    for pageno, page in enumerate(pages):
        for line in page:
            for word in line.split():
                 index[word].append(line)

== Better boolean logic ==

The and/or operators should only return boolean values. This makes their use less error-prone, less prone to abuse,
and more closely match other languages. Also, it will simplify the underlying bytecode which currently inserts
many ''POP_TOP'' instructions to complete conditionals. The need to insert these instructions also results in extra
code paths and jump instructions. Overall, the language will become more intuitive, more reliable, simpler, and
faster.

== Disallow calling class methods from instances ==

Calling with a instance is almost never what you want. When it is done, the results are not especially readable the code
suggests that it is doing something that it isn't: {'a'=1}.fromkeys('poof') # what happened to 'a'?


== Simplify the syntax for raising exceptions ==

 * Eliminate string exceptions entirely.
 * Alway require instantation. IOW, prefer ''raise ValueError(dat)'' to ''raise ValueError, dat''.
 * Require that all exceptions subclass from ''Exception''.
 * Have ''Exception'' be a new-style class

Other syntax ideas and feature ideas for Python 3.0.

TableOfContents()

Optional Static Typing / Adaptation

Lambda / Anonymous Methods / Closures

Suggested syntaxes:

".." Sequences, Custom Infix Operators

Improved default value logic for Dictionaries

  • The setdefault() method is badly named and poorly designed. In a typical call, d.setdefault.(k, []).append(v), the list may be unnecessarily instantiated and discarded on every call. At a minimum, default value should be a new empty list instead of None: d.setdefault(k).append(v).
  • * A more versatile idea is to realize that defaults generalize to the whole dictionary instead of an individual lookup. A call to setdefault would then change the whole dictionary's behavior when a key is not found
    • counts = {} counts.setdefault(value=0) for elem in data:
      • counts[elem] += 1
      index = {} index.setdefault(function=list) for pageno, page in enumerate(pages):
      • for line in page:
        • for word in line.split():
          • index[word].append(line)

Better boolean logic

The and/or operators should only return boolean values. This makes their use less error-prone, less prone to abuse, and more closely match other languages. Also, it will simplify the underlying bytecode which currently inserts many POP_TOP instructions to complete conditionals. The need to insert these instructions also results in extra code paths and jump instructions. Overall, the language will become more intuitive, more reliable, simpler, and faster.

Disallow calling class methods from instances

Calling with a instance is almost never what you want. When it is done, the results are not especially readable the code suggests that it is doing something that it isn't: {'a'=1}.fromkeys('poof') # what happened to 'a'?

Simplify the syntax for raising exceptions

  • Eliminate string exceptions entirely.
  • Alway require instantation. IOW, prefer raise ValueError(dat) to raise ValueError, dat.

  • Require that all exceptions subclass from Exception.

  • Have Exception be a new-style class

Python3.0Suggestions (last edited 2010-05-16 23:17:52 by modemcable054)

Unable to edit the page? See the FrontPage for instructions.