Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^6: Newline's creep in, while using Tie::File

by Bod (Parson)
on Nov 17, 2020 at 11:39 UTC ( [id://11123732]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Newline's creep in, while using Tie::File
in thread Newline's creep in, while using Tie::File

Can you honestly say you've never fat fingered a variable name or misremembered what you called a variable?

Of course not...that's a normal part of coding isn't it regardless of the technology.

The reason I have never added use strict; is not because of any ideological view. It is because when I learnt to use Perl in the early 1990's I did so out of necessity and by looking at a very limited pool of other people's code which either didn't include strictures or, if it did I didn't notice and found my code worked without it. Back then I didn't have internet access at home so couldn't look things up to learn best practice.

I have experimented with turning on use strict; and got frustrated at having to declare variables before use so ended up not bothering. It sort of slowed down the initial code development although, granted, it may well have speeded things up down the line had I persevered.

The reason I ask is because I have many, many lines of working Perl code in production and I know it would be beneficial for me to up my coding game. Not least because coding is not core to my business and it would make sense for me to employ a developer soon(ish). Improving how I code going forward and improving existing code will have to be part of that process.

Replies are listed 'Best First'.
Re^7: Newlines creep in, while using Tie::File
by hippo (Bishop) on Nov 17, 2020 at 12:04 UTC
    when I learnt to use Perl in the early 1990's I did so out of necessity and by looking at a very limited pool of other people's code which either didn't include strictures or, if it did I didn't notice

    That will be because it didn't exist in the language back then. I think it was around 5.002 when it was introduced.

    I have experimented with turning on use strict; and got frustrated at having to declare variables before use so ended up not bothering. It sort of slowed down the initial code development although, granted, it may well have speeded things up down the line had I persevered.

    I don't see why it would slow down initial code development at all. Could you explain more?

    FWIW, here is one of my recent nodes showing the benefit. And another one.


    🦛

      strict.pm was first included in Perl 5.0. warnings.pm came in 5.6.

        I'm still using ancient Perl but not that ancient...
        I'm using 5.16.003 dating from 2012 unfortunately

Re^7: Newline's creep in, while using Tie::File
by marto (Cardinal) on Nov 17, 2020 at 11:42 UTC

    "It sort of slowed down the initial code development"

    How much time did you save by not typing my, and how much time has been spent finding problems caused by a typo in a variable name?

      "How much time did you save by not typing my, and how much time has been spent finding problems caused by a typo in a variable name?"

      ^ That.

      I have typed out use strict; at least several hundred thousand times over my 20 years writing Perl, and if it saved me even just 10 minutes troubleshooting why a variable is being clobbered, or why a variable isn't updated as expected, I feel my efforts were worth it. Also, by forcing you to declare all variables, it makes it far easier at a glance to see where variables are designed to be scoped. Without declaration, it's hard to tell whether a variable is global or not without having to scroll through code. That's even more time saved.

      Of course, it is impossible to know how much time time I would have saved debugging had I used use strict; but I am convinced of the wisdom going forward...
Re^7: Newline's creep in, while using Tie::File
by Anonymous Monk on Nov 17, 2020 at 15:16 UTC
    I have experimented with turning on use strict; and got frustrated at having to declare variables before use so ended up not bothering. It sort of slowed down the initial code development although, granted, it may well have speeded things up down the line had I persevered.

    I used to feel the same way. It's true that not having to think about variable scope or initialization seems easier and faster at first, but those gains have costs like difficulty of debugging and the constant danger of undetected typos. Strict will help you think more about why your variables exist and what constitutes sane defaults. You will find yourself creating less variables and knowing more about how your program works. The default values of your variables then become very useful in determining the flow of your code. Trust the monks, strict is your friend!

      Trust the monks, strict is your friend!

      I'm convinced; I'm convinced...

      :D

Re^7: Newline's creep in, while using Tie::File
by bliako (Monsignor) on Nov 17, 2020 at 22:12 UTC

    A lot of example code (e.g. CPAN module's doc), for the sake of being brief avoid the use of strict.

    But even if the example code does not have use strict; and does not declare variables (e.g. my $xyz;), you should. Regarding the few exceptions where strict should **locally** be disabled because you want to do some hackery, then by all means zap the bastard as if it was a star-wars rogue (barhards? plenials? prole-lians? obviously not acquainted with the subject).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found