user-pic

Belden

  • Commented on Dangling Definitions
    Properly formatted ternary statements have the advantages of being quickly scannable, and unlikely to grow warts. my $var = some-condition ? value1 : other-condition ? value2 : default-value; my $var = some-condition ? value1 : other-condition ? value2 : default-value;...
  • Commented on Please build this for me, yesterday!
    Is this harder than finding all of your desired asset files on disk: find /var/www -name '*.css' -o -name '*.png' -print | perl -pe 's,/var/www,,' > /tmp/my-assets And then grepping across your codebase for each of those files, recording which...
  • Commented on Prototype changes across Perl release boundaries
    I updated the implementation so it does take advantage of the (+) now :)...
  • Commented on Prototype changes across Perl release boundaries
    I'm not unaware of Module::Implementation. I didn't really care for the interface for this particular problem; I can shoehorn the module to do what I want: use strict; use warnings; package Hash::MostUtils::leach; use Module::Implementation; BEGIN { my $implementation; my %available...
  • Commented on Prototype changes across Perl release boundaries
    Oh, that's a fair question. It's an artifact of how I developed leach - first on a higher version of Perl, where the prototype was reported as +, and then fixing for a lower version of Perl. I must not...
  • Posted Prototype changes across Perl release boundaries to Belden

    At a previous employer, one of the things I ran into from time to time was the need to get the keys of a hash back out in the same order they were provided. Yes, Tie::IxHash exists to solve this problem: but it always felt like a heavy-weight…

  • Commented on Unicode and Passwords
    It's worth knowing that binmode($fh, ':encoding(UTF-8)') blows away $@. However, not all encoding layers for binmode() blow away $@. foreach my $layer (':raw', ':utf8', ':encoding(UTF-8)', ':encoding(utf8)') { eval { die $layer . "\n" }; binmode STDOUT, $layer; if ($@) {...
Subscribe to feed Recent Actions from Belden

  • Steven Haryanto commented on Dangling Definitions

    I don't fancy the term 'dangling definition'. Perhaps 'declaration without initial value' is better (albeit more boring)?

    And there are certainly cases where I want to declare a variable and let undef be its initial value.

    my $found_value;
    for (...) {
        if (some condition) {
            $found_value = blah;
            last;
        }
    }
    warn "Not found" unless defined($found_value);
    

    and so on.

  • rlauer commented on Dangling Definitions

    Unfortunately, I think there are times when leaving a variable undefined is really not what you want to do, so what you are left with is ambiguous code.

    Maybe:

    my $found_value = undef; # undef = not found

    IOW, explicit assignment vs implicit to indicate, yeah I really want that to be undef, although I'm not sure I like returning undef to indicate "not found".

    Even though it evaluates to false I might consider reserving undef to indicate something's not right, but not wrong enough to throw an exception and use other true and false values to indicate...true and…

  • Steven Haryanto commented on Dangling Definitions

    I'll admit my example is not the best there, but I do think doing 'my $foo = undef;' is redundant.

    What gain does it give you? Especially since you said that you do not want to use the 'undef' value and want to reserve it to signal something's wrong/incomplete.

    What gain does it give me? Since I always mean 'my $foo' to be 'my $foo = undef' in my code.

    BTW, if you reserve 'undef' to mean something's incomplete, how would you deal with getting undef from somewhere else (like return value from function) which means something fails, but not incomplete. Because the latt…

  • rlauer commented on Dangling Definitions

    Agreed.

    my $foo = undef;

    is redundant (and you wouldn't find that in my code) - however, my point was just that you are using undef as a specific signal for "not found" and it might be less ambiguous to explicitly set it rather than considering it simply as a variable definition.

    But your overall points are valid. I guess the horse is dead. ;-)

  • Nick Patch commented on Dangling Definitions

    The Perl 6 version of do/if is more natural:

    
    $x = do { if ($a) { $b } else { $c } };  # Perl 5
    
    

    $x = do if $a { $b } else { $c }; # Perl 6

    The difference is that do can take a statement instead of a block and the condition to the if statement doesn't require parens, which together makes for more readable code.

Subscribe to feed Responses to Comments from Belden

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is run by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.