Roads of Code

Travels in the Land of Computer Programming

Let Every Pixel Count – Drop def and class Keywords from Python

In the spirit of letting every pixel count, why do we not drop the def and class keywords from Python? I am not proposing it, but just wondering about it.

Python has discarded the braces {} and the semicolons as used in the C-programming language, but has added the def keyword. In C, a function is defined like this:

add_numbers(){
    x = 74;
    y = 86;
    return x + y;
}

In Python, like this:

def add_numbers():
    x = 74
    y = 86
    return x + y

Why not copy that good idea from C and define it like this in Python:

add_numbers():
    x = 74
    y = 86
    return x + y

Of course, there would be the problem of how to distinguish between class definitions and function definitions. One solution would be to make the format of the class and function names significant for the interpreter, e.g. the interpreter could require that:

  • classes be written in PascalCase, that
  • funtions be written in camelCase, and that
  • variables be written in lowercase with words separated by underscores.

To distinguish between function and variable names that have only one word, function names should always end with a capital letter.

Here is an example:

PoliceDog(): # Class
    hair_color = 'black' # Variable with two words in name

    findContraband(): #Function
        return True

    barK(): # Function with one word in name
        return 'noise'

The difference between a statement with a function definition header and a function call is the presence or absence of the colon.

About these ads

3 Responses to Let Every Pixel Count – Drop def and class Keywords from Python

  1. Swartskaap February 17, 2011 at 8:29 PM

    Ons Afrikaners kan darem code!
    Good gaan!

  2. Francis M. Walls January 27, 2013 at 6:48 PM

    Public function and variable names in X Windows are upper and lowercase words, with no underscores.

  3. Humberto Holland June 16, 2013 at 3:35 PM

    Multivalued functions of a complex variable have branch points . For the nth root and logarithm functions, 0 is a branch point, for the arctangent functions, the imaginary units i and −i are branch points.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: