Sometimes I suggest to add things to the language (like adding some set
methods to dicts), but I've seen that I tend to forget the meaning of
six set/frozenset operators:
s & t s &= t
s | t s |= t
s ^ t s ^= t
My suggestion is to remove them, and keep them only as explicit
non-operator versions (.symmetric_dif ference(), .update(),
..intersection_ update(), etc). But maybe now it's too much late to
remove them... Maybe someone gentle can explain me the advantage of
having/keeping them.
Thank you,
Bearophile 6 1968
<be************ @lycos.com> wrote: Sometimes I suggest to add things to the language (like adding some set methods to dicts), but I've seen that I tend to forget the meaning of six set/frozenset operators:
s & t s &= t s | t s |= t s ^ t s ^= t
My suggestion is to remove them, and keep them only as explicit non-operator versions (.symmetric_dif ference(), .update(), .intersection_u pdate(), etc). But maybe now it's too much late to remove them... Maybe someone gentle can explain me the advantage of having/keeping them.
Helen:~ alex$ python2.4 -mtimeit -s's1=s2=set()' 's1&s2'
1000000 loops, best of 3: 0.929 usec per loop
Helen:~ alex$ python2.4 -mtimeit -s's1=s2=set()' 's1.intersectio n(s2)'
1000000 loops, best of 3: 1.28 usec per loop
Besides avoiding the need for a name look-up, and thus extracting a tiny
speed-up of about 0.35 microseconds or so, I can't think of advantages
for the infix operator form (but then, I can't think of any advantages
for type *int* having the same operators, with bitwise-logic semantics,
rather than placing them only in some library module).
I still vaguely hope that in 3.0, where backwards incompatibiliti es can
be introduced, Python may shed some rarely used operators such as these
(for all types, of course). As long as the operators are there for
ints, it makes sense to have them apply to sets as well, of course.
Alex be************@ lycos.com wrote: Sometimes I suggest to add things to the language (like adding some set methods to dicts), but I've seen that I tend to forget the meaning of six set/frozenset operators:
s & t s &= t s | t s |= t s ^ t s ^= t
My suggestion is to remove them, and keep them only as explicit non-operator versions (.symmetric_dif ference(), .update(), .intersection_u pdate(), etc). But maybe now it's too much late to remove them... Maybe someone gentle can explain me the advantage of having/keeping them.
&, |, and ^ are Python's standard operators for AND, OR, and XOR. they
make as much sense for sets as they do for bitpatterns...
</F>
Alex Martelli <al***@mail.com cast.net> wrote: I still vaguely hope that in 3.0, where backwards incompatibiliti es can be introduced, Python may shed some rarely used operators such as these (for all types, of course).
I hope there is no serious plan to drop them. There is nothing wrong in having
such operators, and I wouldn't flag bit operations as "rarely used". They are
very common when calling C-based API and other stuff. I know I use them very
often. They have a clear and well-understood meaning, as they appear identical
in other languages, including the widely-spread C and C++.
Giovanni Bajo
Giovanni Bajo <no***@sorry.co m> wrote: Alex Martelli <al***@mail.com cast.net> wrote:
I still vaguely hope that in 3.0, where backwards incompatibiliti es can be introduced, Python may shed some rarely used operators such as these (for all types, of course).
I hope there is no serious plan to drop them. There is nothing wrong in having such operators, and I wouldn't flag bit operations as "rarely used". They are very common when calling C-based API and other stuff. I know I use them very often. They have a clear and well-understood meaning, as they appear identical in other languages, including the widely-spread C and C++.
Well, C and C++ don't have unbounded-length integers, nor built-in sets,
so the equivalence is slightly iffy; and the precedence table of
operators in Python is not identical to that in C/C++. As for frequency
of use, that's easily measured: take a few big chunks of open-source
Python code, starting with the standard library (which does a lot of
"calling C-based API and other stuff") and widespread applications such
as mailman and spambayes, and see what gives.
But the crux of our disagreement lies with your assertion that there's
nothing wrong in having mind-boggling varieties and numbers of
operators, presumably based on the fact that C/C++ has almost as many.
I contend that having huge number of operators (and other built-ins)
goes against the grain of Python's simplicity, makes Python
substantially harder to teach, and presents no substantial advantages
when compared to the alternative of placing that functionality in a
built-in module (possibly together with other useful bit-oriented
functionality, such as counts of ones/zeros, location of first/last
one/zero bit, formatting into binary, octal and hexadecimal, etc).
As for "serious plans", it's been a while since I checked PEP 3000, but
I don't think it addresses this issue one way or another -- yet.
Alex
Alex Martelli wrote: I still vaguely hope that in 3.0, where backwards incompatibiliti es can be introduced, Python may shed some rarely used operators such as these (for all types, of course). I hope there is no serious plan to drop them. There is nothing wrong in having such operators, and I wouldn't flag bit operations as "rarely used". They are very common when calling C-based API and other stuff. I know I use them very often. They have a clear and well-understood meaning, as they appear identical in other languages, including the widely-spread C and C++.
Well, C and C++ don't have unbounded-length integers, nor built-in sets, so the equivalence is slightly iffy; and the precedence table of operators in Python is not identical to that in C/C++.
The equivalence was trying to make a point about the fact that bitwise
operators are not an uncommon and obscure operator like GCC's "<?=" (so-called
"update minimum") operator. "&" reads as "and" to English readers, "|" reads as
"or" in regular expression. It's not something weird we have come up with just
by sticking a couple of symbols together.
As for frequency of use, that's easily measured: take a few big chunks of open-source Python code, starting with the standard library (which does a lot of "calling C-based API and other stuff") and widespread applications such as mailman and spambayes, and see what gives.
I grepped in a Python application of mine (around 20k lines), and I found about
350 occurrences of ^, | and &, for either integers or builtin sets.
But the crux of our disagreement lies with your assertion that there's nothing wrong in having mind-boggling varieties and numbers of operators, presumably based on the fact that C/C++ has almost as many.
When exactly did I assert this? I am just saying that an infix operator form
for bitwise or, and, xor is very useful. And once we have them for integers,
using them for sets is elegant and clear. Notice also that a keyword-based
alternative like "bitand", "bitor", "bitxor" would serve well as a replacement
for the operators for integers, but it would make them almost useless for sets.
I contend that having huge number of operators (and other built-ins) goes against the grain of Python's simplicity,
We agree on this.
makes Python substantially harder to teach, and presents no substantial advantages when compared to the alternative of placing that functionality in a built-in module (possibly together with other useful bit-oriented functionality, such as counts of ones/zeros, location of first/last one/zero bit, formatting into binary, octal and hexadecimal, etc).
Such a module would be very useful, but I believe it's orthogonal to having an
infix notation for common operations. We have a string module (and string
methods), but we still have a couple of operators for strings like "+".
--
Giovanni Bajo
Hi Bearophile,
Nah, you don't want to change 'em. I can remember 'em just fine :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: GianGuz |
last post by:
Global new and delete operators can be overloaded to suite particulars
needs. Typically they are overloaded to insert useful debugging/trace
informations. What I would to discuss here concerns the possibility of
overload these operators not at the global level namespace but
into different program namespaces.
For instances:
#include<iostream>
using namespace std;
|
by: KL |
last post by:
I am working on a school assignment, so please don't tell me the
solution. I just want some direction.
I am supposed to overload the >, <, ==, !=, >=, and <= operators using
bool. I am having a bit of a problem in seeing what needs to happen
here. I am just not sure how I do this. Will the overloading function
recognize a < and a usual <? Do I do an
IF (a.letters < b.letters){
return true
}
|
by: Michael B. |
last post by:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.
Of course, I speak only of features in the spirit of C; something like
object-orientation, though a nice feature, does not belong in C.
Something like being able to #define a #define would be very handy,
though, e.g:
#define DECLARE_FOO(bar) #define...
|
by: raju |
last post by:
hi
can we compare two integers without using relational operators (== != <
<= > >=)
thanks
rajesh s
|
by: Syanide |
last post by:
here's a bit info for you fellas:
eg.. you have Square classes u wanna add
public static int operator+ (Square s1, Square s2)
{
// your code here
}
comparision operators..
| |
by: fctk |
last post by:
hello,
i have some questions.
1) do constant expressions include string literals? for example, is
"hello, world" a constant expression?
2) int i = 0; is the equal sign the assignment operator or is it only a
symbol? (i think the last one is correct)
|
by: naknak4 |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will implement all three techniques as
programs. In these programs, as well as solving the problem, you will
also measure how long the program takes to run. The programs are worth
80% of the total mark. The final 20% of the marks are awarded for a...
|
by: Carl Banks |
last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this
is just talk.)
Not many people are bit-fiddling these days. One of the main uses of bit
fields is flags, but that's not often done in Python because of keyword
arguments and dicts, which are lot more versatile. Another major use,
talking to hardware, is not something oft done in Python either.
It seems like this occasional usage wouldn't justify having built-in...
|
by: Tony Johansson |
last post by:
Hello!
I think that this text is complete enough so you can give me an explanation
what they mean with it.
I wonder if somebody understand what this means. It says the following :
"You can't overload assignment operator, such as +=, but these operator use
their simple counterpart, such as +, so you don't have to worry about that.
Overloading + means that += will function as expected.
The = operator is included in this -- it makes little...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |