Thursday 1 September 2022

another python super-feature!

I'm perplexed and lost. I cannot do anything like passing a primitive (and otherwise "mutable") variable by reference, in order to change it. Just because I want it that way - clear and simple, almost simplistic. Context: in my main function I'm operating on pairs of files, for input and output; the simplest way I can think about it is

1. Parse the program's arguments, check if they are correct/valid/etc.
2. call split w.r.t. '=' on each other, take second part, strip() ("The shoe! Give us the shoe!" - 2 stupid dogs)
3. Give input and output files their names.
4. Use these inside my main function; perhaps check if the input file exists and that writing output wouldn't erase some existing file.

The simplest way that works, and is clumsy already, is to create an empty list, fill it when 3. is completed with two file names and later use list[0] and list[1] to re-create the filenames, once. Code smell if I ever saw one. Yes, a dictionary would be more self-descriptive and simple, if you use it once and don't have to keep its keys consistent throughout the code...

On SO and elsewhere I'm told to wrap the thing in a class, or use globals. Isn't it just silly that you have to complicate things so much, to do something that basic? To me it certainly is.

Perhaps globals is the solution here, but I'm not familiar with these. As with extern in C/C++. Someone wise told me that global variables suck and I agree and try to avoid them whenever I can. The mirage of carelessly copied & pasted COMMON blocks in an F-77 code (held in a single file, around 40 kB, their other code was around 300 kB) is still too fresh. Hardly anyone doing the copy-paste stuff cared if the copied variable names had been the minimal set that was needed by some function or subroutine.

Perhaps I will have this script rewritten to C#. At least there is that ref keyword which does exactly what I want done here ... 

Oh, almost forgot to mention: the weird syntax for their string.join, just lol:

delimiter.join(list or tuple or whatever of str)

No comments:

Post a Comment