Perl (Raku) Programming Leftovers

-
To Hardcode, or Not to Hardcode: That Is the (Unit) Test-ion
So, first of all, let me agree whole-heartedly with Tom’s final statement there: “We tolerate a lot more repetition, and factor it out sparingly.” Absolutely good advice. The only problem is that, as I noted previously on my Other Blog, we humans have a tendency to want to simplify things in general, and rules and “best practices” in particular. I don’t think that Tom was saying “always hardcode everything in your unit tests!” ... but I think some people will read it that way nonetheless. I would like to make the argument that this is a more nuanced topic, and hopefully present some reasons why you want to consider this question very carefully.1
For an example of how hardcoding the right answers for all your unit tests can be taken too far, imagine a system where you need to test several scripts that produce output. One simple way would be to run the scripts and capture the output, then examine that output very carefully, once. Once you’ve verified by hand that the output is good, you save said output to a file. Now all your unit test has to do is run the script, generate new output, diff against the Last Known Good output, and throw a fit if there are any differences. Easy peasy.
-
Increasing Perl's Visibility
Perl has some really great community websites. But a drawback to this is that the Perl community is centred around a few domain names, which means that it isn't as visible as some other languages. Most projects use github for development and CPAN for distribution, and outside those sites, they don't have much online presence.
One thing I think might help spread Perl around the web would be if different Perl projects had their own websites.
-
Preallocating scalars
I'm using the fabulous FFI::Platypus to interface to a C routine which uses caller-allocated buffers to return data. While FFI::Platypus transparently translates Perl arrays to C arrays and back, the buffers are used only to return data, so I only need the C-to-Perl conversion and not the Perl-to-C conversion.
The first step is to efficiently allocate a buffer of a given size in Perl (the last step, converting the retuned data in the buffer to Perl, is done straightforwardly with unpack).
-
Perl Weekly Challenge 046: Cryptic Message & Is the Room Open?
-
Perl Weekly Challenge 46: Garbled Message and Room Open
-

- Login or register to post comments
Printer-friendly version- 2023 reads
PDF version
More in Tux Machines
- Highlights
- Front Page
- Latest Headlines
- Archive
- Recent comments
- All-Time Popular Stories
- Hot Topics
- New Members
digiKam 7.7.0 is released
After three months of active maintenance and another bug triage, the digiKam team is proud to present version 7.7.0 of its open source digital photo manager. See below the list of most important features coming with this release.
|
Dilution and Misuse of the "Linux" Brand
|
Samsung, Red Hat to Work on Linux Drivers for Future Tech
The metaverse is expected to uproot system design as we know it, and Samsung is one of many hardware vendors re-imagining data center infrastructure in preparation for a parallel 3D world.
Samsung is working on new memory technologies that provide faster bandwidth inside hardware for data to travel between CPUs, storage and other computing resources. The company also announced it was partnering with Red Hat to ensure these technologies have Linux compatibility.
|
today's howtos
|








.svg_.png)
Content (where original) is available under CC-BY-SA, copyrighted by original author/s.

Recent comments
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago