From D

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Jul 24 06:19:53 EDT 2007


There are various things I like about the D language that I think
Python too may enjoy. Here are few bits (mostly syntactical ones):

1) (we have discussed part of this in the past) You can put
underscores inside number literals, like 1_000_000, the compiler
doesn't enforce the position of such underscores, so you can also put
them like this: 1_00_000. You can put them in literals of decimals,
binary, hex, etc. I think it's quite useful, because when in Python
code I have a line like:
for i in xrange(1000000):
I need some time to count the zeros, because the lower levels of my
visual systems can't count/group them quickly (perceptually). While in
a syntax like:
for i in xrange(1_000_000):
my eyes help me group them at once.


2) Base 2 number literals, and base 2 "%b" printing with the writefln.
Base-2 numbers are less common in Python code, but once in a while I
use them. For example:
import std.stdio;
void main() {
  auto x = 0b0100_0011;
  writefln("%b", x);
  writefln("%.8b", x);
  writefln(x);
}
Prints:
1000011
01000011
67


3) All string literals are multi line. So you can write:
a = "how are
you";
There's no need for """ """.


4) With D I have created an xsplit() generator, and from my tests it's
quite faster than the split(), expecially if the string/lines you want
to split are few hundred chars long or more (it's not faster if you
want to split very little strings). So I think Python can enjoy such
string method too (you can probably simulate an xsplit with a regular
expression, but the same is true for some other string methods too).

Bye,
bearophile




More information about the Python-list mailing list