Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
In a Perl shoppe now. The product seems to have exactly the same level of technical debt and under/over designed issues that I've seen in Java and Python heavy solutions, but the language seems a good fit to focus on the data being managed. Even the newer PMs look at the code, so there don't seem to be many learning troubles.

Sadly some of the long tenured people are wrong on some of the details and reluctant to make improvements.

Adbot
ADBOT LOVES YOU

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

BattleMaster posted:

I don't like how it handles function arguments
It's rare to need to mess with prototypes in Perl, because there are few optimizations that result, but you get two basic approaches. Like shell scripts, arguments are positional, but they can be assigned individually:

code:

my ($ip,$count,$delay)=@_;

As programs grow into helpers and objects, it becomes much better to pass named lists:

code:

sub ping {
  my (%opt)=@_;
  $opt{count}//=4;
  ...
}

ping(ip=>'8.8.4.4',delay=>3);

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Ooo part of an RPM even. I haven't dinked with building RPMs in about ten years.

Bash takes a different mindset; it can be a fun exercise.

Here's a fun one I didn't know until recently. You know how sed has a range operator, such as /open/../close/d ? It bleeping exists in Perl as well. :clint: In list context the .. range operator generates the range, duh, but in scalar context it's a boolean flip-flop operator. You can even do !defined(blah) .. /regexp/ and similar things, multiple instances without collision (ie nested loops work).

:3:

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Random recent find, file test functions are automatically conjunctive. IE, these are the same:
code:

(-f $file) && (-w $file) && (-z $file)
(-f -w -z $file)

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
For some reason I've always split on newlines when using qx, which is silly since it automatically splits on the input record separator in list context.

code:

foreach my $line (split("\n",qx/blah/))
foreach my $line (qx/blah/)
Same, except the latter is more portable since the IRS follows the system.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

Startyde posted:

perl is awk++ (derogatory)

:chef:

https://perldoc.perl.org/perlvar posted:

Remember: the value of $/ is a string, not a regex. awk has to be better for something. :-)

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Durr

code:

$flag = "-cat";
print -$flag;
:agesilaus:

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
But this is the Perl thread, so we love Perl here. As with any language, you get to maintain crap code if you write crap code, but when you adopt better patterns you get to enjoy beautiful code.

Perl, as many like to point out, has more than one way to do things, so you are free to adopt a code organization and presentation that matches the needs of the project. Procedural? Yep. Class based? Yep. Functional? Yep. Loaded up with 75 libraries and three lines of code? Yeap, even that.

It's so straightforward - rather, conditions, loops, flow control, are "universal", duh - that I worked with TPMs who filed ticket requests with code details and references. I never saw that at the Python, Ruby, and Java shops. They couldn't even find the relevant code.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
It sounds perfectly acceptable, but likely represents poor planning, particularly when you find you need to do the same thing next week with slight variation.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
The Benchmark module has a subtle imperfection: It finds a baseline runtime for an empty eval based on the type of underlying tests but does so only once. Delays at that time may result in later runtimes being reported as negatives, particularly when using the direct timing functions (instead of cmpthese).

Obviously benchmarking comes with a ton of caveats, but it's common to build representative baselines, which themselves require statistical measurement. Reporting and subtracting that runtime is likely to make more sense when performance profiling compared to getting some tests with negative average runtimes.

I really like how easy it is to quickly benchmark in Perl but this was an interesting choice.

If you see some negative times when using the timing functions of Benchmark coupled with timediff, this is the likely culprit. It's much less likely that your clock is jumping backwards.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Tis interesting that pointers will always cause problems for programmers. One of the most frequent syntax questions I get from our software peeps is their confusion about accessing things in basic and object types. They get confused because there are lots of places in our code where people have chosen to use references and arrow dereferencing.

I get the impression that the mid engineers really don't know what's happening and are just trying things until it works. Sadly, but I still see lots of ahha moments when people are sharing examples, doing code reviews and the like.

It's amazing how consistent the original syntax is after all these years and language requests.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Actually measuring minor performance differences of this scale is very difficult and depends on the distribution of inputs, however, there is a different way to structure the pattern:

code:

/:.*\b22\b/

This is "find a literal 22 as a word that is somewhere after a colon". The backslash-b is a "word boundary" that automatically handles all non-letters-digits-or-underscores as well as the beginning and ending boundaries of the string. Also as there's known to be the single colon separating the IP from the port list, this pattern might make more intuitive sense because it shows that everything to the left of the colon doesn't matter.

If you want additional validation, the full list of ports, etc., then it changes, but this is still twice as fast as fully splitting the string.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

Hughmoris posted:

I was curious about performance of the different solutions. Anyone know best practices for benchmarking scripts in modern perl? I'm thinking I could generate a 1 GB file of IP addresses and ports, and benchmark the different solutions.
Use the Benchmark module, which should be included with most distributions. (Every mistake that you can make regarding benchmarking is possible to make here as well.)

Adbot
ADBOT LOVES YOU

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
Catastrophic backtracking is certainly possible, but happily much less likely in Perl because of the regexp optimizations. I remember being surprised how awful some of the libraries were in (popular languages) a few/five years ago.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply