in reply to Re^6: Is there a problem with using barewords as filehandles ?
in thread Is there a problem with using barewords as filehandles ?
You may make your recommendations, and I will make my recommendations. What I strongly oppose is removing features from the language that touts TIMTOWTDI without very, very, very good reasons, and the arguments against bareword filehandles do not meet that bar in my view.
I have a significant background in C, where all variables must be declared and the compiler will always catch typos (unless the typo refers to another declared variable with a compatible type) but issues of scope are similar, although the available scopes and extents are different from those in Perl. I see Perl file-scope lexicals as equivalent to static variables declared at file scope in C. They can be a useful tool, and certainly are preferable in most cases to ordinary globals, which appear in a common namespace across all modules in a C program, but are still best avoided unless you really do need that variable to be in the static data segment — nearly all actual data should be dynamically allocated on the heap and pointers held in local variables or itself held in local variables. But Perl does not put all globals in a common namespace: Perl has packages, which C lacks. Perl "globals" are actually stored in those packages, and standard practice in Perl 5 is to limit the reach of a package to a single source file. Therefore, "globals" and file-scope lexicals actually have the same scope and the same risks.
I reject the seatbelt analogy for this reason. (And I personally always wear my seatbelt when driving.) From my view, this is more like an "Emperor's New Clothes" situation where people are wearing sashes (that look like seatbelts) and acting as if they are wearing seatbelts and getting upset when it is pointed out that the sashes do not actually anchor to the car. File-scope lexicals look like lexicals, but have effectively the same scope as globals. In terms of surprise action-at-a-distance, they carry the same risks.
This is not to say that lexical filehandles are completely useless at top-level, as you have mentioned before, code is often lifted out of a sub for presentation in a SSCCE, and lexical filehandles are (with rare exceptions) the only proper option in a sub, but file-scope lexicals walk like globals and quack like globals. They are not, therefore, chickens.
|
|---|