On Saturday 05 May 2007, Aahz wrote:
 > I'm with MAL and Fred on making literals immutable -- that's safe and
 > lots of newbies will need to use byte literals early in their Python
 > experience if they pick up Python to operate on network data.

Yes; there are lots of places where bytes literals will be used the way str 
literals are today.  buffer(b'...') might be good enough, but it seems more 
than a little idiomatic, and doesn't seem particularly readable.

I'm not suggesting that /all/ literals result in constants, but bytes literals 
seem like a case where what's wanted is the value.  If b'...' results in a 
new object on every reference, that's a lot of overhead for a network 
protocol implementation, where the data is just going to be written to a 
socket or concatenated with other data.  An immutable bytes type would be 
very useful as a dictionary key as well, and more space-efficient than 
tuple(b'...').

Whether there should be one type with a flag indicating mutability, or two 
separate types (as with set and frozenset), I'm not sure.  The later offers 
some small performance benefits, but I don't expect there's enough to really 
matter there.


  -Fred

-- 
Fred L. Drake, Jr.   <fdrake at acm.org>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to