Considering migrating to Python from Visual Basic 6 for engineering applications

BartC bc at freeuk.com
Mon Feb 22 07:51:01 EST 2016


On 22/02/2016 11:16, Steven D'Aprano wrote:
> On Mon, 22 Feb 2016 12:16 am, BartC wrote:
>
> [...]
>>> No need for anyone to re-invent the
>>> wheel!  ;-)
>>
>> I keep seeing this in the thread. Python has all this capability, yet it
>> still requires a lot of fiddly code to be added to get anywhere near as
>> simple as this:
>>
>>     read f, a, b, c
>
> I can't say I really know what that means. My guess is that reads three
> things (a, b and c) from a file f, but what those things are (strings,
> binary blobs, floats, ints, something else?) is a mystery.

Yes, I mentioned that point. In the OP's language, the variables can be 
declared as a particular type; in Python they could perhaps be 
'declared' by first assigning with 0, 0.0 or "" for example. But that 
would need reference parameters to make use of tidily.

But even when declared, sometimes additional formatting info is needed 
(numbers might be in hex or binary for example).

> One of the major problems with output parameters is that it isn't obvious
> what is an output parameter and what isn't. When it comes to read, perhaps
> you can guess, but when it comes to arbitrary functions, who can tell what
> is output and what is input?
>
> fromaginate m, x, y, z, a, b
>
>
> Whereas a functional design makes it obvious: output is on the left of the
> assignment symbol, input is on the right.
>
> x, y, z = fromaginate m, a, b

Old-style /statements/ such as 'read' aren't functional. Then it is easy 
to specify that the parameters need to be l-values.

>>     readline(f, a, b, c)
>>
>> I can't see a straightforward way of making this possible while still
>> keeping a, b and c simple integer, float or string types (because
>> Python's reference parameters don't work quite the right way).
>
> Python doesn't have reference parameters.
>
> Please feel free to discuss further if you disagree, or want additional
> explanation.

Well, I've just finished reimplementing a language so that it uses 
CPython-like references for objects (not, however, for types such as 
small integers which stay as value types).

But that language retains the use of pointers which can be used /as well 
as/ references to provide pass-by-reference, even for integers.

Then it is possible to write a function which can be called like: 
readline(f,a,b,c) and which would update the caller's a,b,c variables.

Python can't do this, even with 100% reference objects. This is because 
most types are immutable and their values can be shared across unrelated 
variables. Try and change one of those, and all would be changed!

In any case, doing an assignment to a parameter just replaces its local 
value. Caller's data can only be changed via an in-place modification of 
the parameter, which I believe only works for lists.

(Maybe, something like this can be done with classes, but I did say you 
can't do it with simple types.)

-- 
Bartc


More information about the Python-list mailing list