←back to thread

Perl's decline was cultural

(www.beatworm.co.uk)
393 points todsacerdoti | 4 comments | | HN request time: 0.202s | source
1. darrenf ◴[] No.46176020[source]
> [TIMTOWTDI] literally means 'there is more than one way to do it in Perl' - and you can perhaps infer from that that there's little to no reason to do it using anything else

Not my experience at all, FWIW. For me, and the vast majority of Perl devs I’ve worked with over the past 30 years, TIMTOWTDI absolutely means some of the “ways to do it” don’t involve Perl, and that’s not only OK but expected. Of course Perl isn’t the be all/end all. It’s a lot of fun though!

(I’m a majority Perl coder to this day, it’s my favourite language by far. Hell, I even find it readable and easy/fun to debug)

replies(1): >>46177861 #
2. writtiewrat ◴[] No.46177861[source]
How popular was/is monkeypatching in Perl?
replies(2): >>46183770 #>>46184293 #
3. darrenf ◴[] No.46183770[source]
Very. I use `Test::MockModule` (not just in tests) or `Sub::Override` or `Class::Method::Modifiers` a lot, according to convention/style or as I see appropriate — but there are, of course, tons more ways to do it.
4. sivoais ◴[] No.46184293[source]
It is possible to do so, but it stands out in a way such that most people aren't doing it using direct language features unless necessary. If you have `strict` and `warnings` enabled, which is recommended, then the interpreter can give runtime warnings or compile-time errors if you try to manipulate the symbol table or redefine a function. If you still want to use those on a case-by-case basis, you have to turn off those pragmas within a scope. So there are built-in ways the language discourages using them arbitrarily.

In tests, you can use monkeypatching as a quick way to mock, but typically, you use modules that wrap up the functionality and make it cleaner. The mocks get cleaned up on scope exit.

There are also more principled ways of having composable behavior, such as <https://metacpan.org/pod/Class::Method::Modifiers> (advice/method combination).

There is another approach that takes advantage of the variety of scoping approaches Perl has. If one uses `local`, it indicates the use of dynamic scope rather than the standard `my` lexical scope. This can be used for things like setting an environment variable temporarily and automatically reverting it when leaving the scope. But this is not common.