[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] PyQt documentation where PyQt function is not same as Qt C++ function
From:       Kyle Altendorf <sda () fstab ! net>
Date:       2017-11-29 18:51:55
Message-ID: 3875b3f8f9265b043a7f2e4e8f8bee68 () fstab ! net
[Download RAW message or body]

On 2017-11-28 04:01, J Barchan wrote:
> I now understand why PyQt has to use these "tuple" returns in places.  
> I may not be a fan of the way Python has to do this, but at least I now 
> know what to look for in function declarations (non-const & references) 
> which will make me need to check the signature, instead of it appearing 
> simply "random" to me!

Perhaps your distaste for Python's approach is mostly based on being 
used to something else like C++?

Python passes everything by reference.  Further, every name is a 
reference.  The difference is that some objects are immutable (strings, 
tuples, ints, and more) and so even though the receiving function 
references the original object it would be unable to change it in those 
cases.

Perhaps if you explain why you prefer passing in variables to receive 
the results of multiple return values (as C++ requires) we could help 
you understand better.

   int cplusplusFunc(int anInput, int &secondOutput, int &thirdOutput);

   int first, second, third;
   first = cplusplusFUnc(second, third)

vs.

   def pythonFunc(anInput):
       return 1, anInput + 2, 3

   first, second, third = pythonFunc(42)

Looking at that, do you still feel that the C++ approach is more clear?  
Seems to me that Python nicely distinguishes inputs from output (and 
yes, technically there is a single return value, a tuple, but it is so 
easily packed and unpacked that that fact is not an issue).

This may also be relevant to understanding Python:
   https://nedbatchelder.com/text/names1.html

Cheers,
-kyle
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic