From D

Stargaming stargaming at gmail.com
Tue Jul 24 10:10:53 EDT 2007


On Tue, 24 Jul 2007 03:19:53 -0700, bearophileHUGS wrote:

> 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.

Sounds like a good thing to be but the arbitrary positioning doesnt make 
any sense. Additionally, I'd suggest 10**n in such cases (eg. 10**6).
 
> 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

Accepted. http://www.python.org/dev/peps/pep-3127/#abstract

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

Well, I think it's just better to recognize visually. If you read ``foo = 
"""...``, it's clear you can skip the next few lines because they're most 
likely a chunk of data, not program code. Single quotation mark makes 
clear this is just a very small token in the whole line. (Yes, there may 
be exceptions, there may be syntax highlighting.)

> 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).

Yea, that's a good idea -- fits into the current movement towards 
generator'ing everything. But (IIRC) this idea came up earlier and there 
has been a patch, too. A quick search at sf.net didn't turn up anything 
relevant, tho.

> Bye,
> bearophile

Regards,
Stargaming



More information about the Python-list mailing list