Roads of Code
Travels in the Land of Computer Programming
Let Every Pixel Count – Drop def and class Keywords from Python
Posted by on November 5, 2010
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.
Ons Afrikaners kan darem code!
Good gaan!
Public function and variable names in X Windows are upper and lowercase words, with no underscores.
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.