in reply to Re^3: Ordering of parameters - Re^9: Converting Unicode
in thread Converting Unicode
But I cannot imagine the mess I'd be in by trying to create a unique hash for every subroutine just to accommodate its particular requirements for incoming variables. I think I'd rather have a single hash with all of them than to have the nightmare of so many hashes that were hard to keep track of.Post your code somewhere. I remember you hate the idea of putting code on github but put it somewhere because I wanna see it. We gotta see the function that uses fifty different parameters every time it's called. You keep talking about it but we (apparently) can't help without seeing the code itself.
Being unable to use references/dereferences, etc. (like what is a "hashref"...I just don't get it), Raku's named parameters is a wonderful way of keeping things concrete without layers of so-called abstraction.Here, since you think Raku will solve all your problems where Perl cannot, here's an example of Raku's named parameters:
sub distance(:$from, :$to) { $from - $to } say distance(from => 30, to => 10);
That's taken directly from https://course.raku.org/essentials/functions/named-parameters/. Here's one of a few ways that could be written in Perl (this example is core 5.36 or better):
use 5.36.0; sub distance(%args) { $args{from} - $args{to} } say distance(from => 30, to => 10);
The two snippets behave the same way. If you can understand one, surely you can understand the other. In fact, because you're using a hash reference in the perl version, you can pass along only the variables you need and not all 50. For example, you can do say distance(from => 30, to => 10, extra => 'yeah');, or say distance(from => 30);, or even say distance( ); and the logic in that function can do different things based on the incoming named parameters. See?
I'm thinking you should take a break from writing code for a while and wrap your mind around basic OOP concepts though. In Perl, Raku, or any other language. The more you write about it, the more I'm convinced that's the solution you're looking for.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Ordering of parameters - Re^9: Converting Unicode
by bliako (Abbot) on Dec 22, 2023 at 07:19 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |