in reply to Re^2: Can someone please write a *working* JSON module
in thread Can someone please write a *working* JSON module

I get all my json tools from the software that I've replicated of bliako's. Part of "tribal knowledge" is to know that M. Lehmann has left the fold. I wish there were a way to have perl know which modules are un-maintained, but one man's bug is another's feature.

I can't say: I have never used the debugger

How is it possible that you have never used the debugger?

  • Comment on Re^3: Can someone please write a *working* JSON module

Replies are listed 'Best First'.
Re^4: Can someone please write a *working* JSON module
by bliako (Abbot) on Oct 28, 2021 at 09:02 UTC

    I use gdb for debugging C code but for Perl I just put print statements here and there.

Re^4: Can someone please write a *working* JSON module
by eyepopslikeamosquito (Archbishop) on Oct 28, 2021 at 11:35 UTC

    > How is it possible that you have never used the debugger?

    See also: on Debuggers (posted earlier this year in response to ... Aldebaran I see! :)

    Oh well, it seems debuggers and exception handling, also discussed in this thread, are topics people tend to hold strong opinions on that are most unlikely to change.

Re^4: Can someone please write a *working* JSON module (Perl's Debugger)
by LanX (Saint) on Oct 28, 2021 at 11:50 UTC
    > How is it possible that you have never used the debugger?

    As always definition matters.

    perl -de0 is more than just a debugger.

    ... it's also Perl's main REPL, it's pretty good for ad hoc testing and interactive demos.

    I use it regularly for that.

    Others even use it as a Perl Shell, because it's very customizable.

    Personally I almost never use it for debugging my own code ( i.e. Breakpoints, Watch-expressions, etc), because I have a unit-test mixed with debug output strategy (mostly Data::Dump 's dd and pp)

    But it is very valuable when analyzing monolithic foreign code (e.g. B::Deparse)

    Now perl -de0 is commonly known as "The Debugger" , which is causing reactions.

    Unfortunately "people with strong opinions" here have a Pavlov reflex to demonstrate their ignorance.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      As always definition matters. perl -de0 is more than just a debugger. ... it's also Perl's main REPL, it's pretty good for ad hoc testing and interactive demos. I use it regularly for that.

      I've seen your posts from (what are we gonna call it?) output in perl -de0 mode for years now, and they've mostly been over my head. Only recently have I discovered that I have a REPL too. I could have replicated your REPL.

      Others even use it as a Perl Shell, because it's very customizable.

      Can you elaborate?

      But it is very valuable when analyzing monolithic foreign code (e.g. B::Deparse)

      I would extend that to foreign code in general. I can't understand and integrate others' code into mine without it, whilst working alone. The number of keystrokes I save using the debugger is immeasurable. With successive use of save/source, it's like a trail in the forest and can even tell a story, and it's one you keep telling until you get out of the forest. I worked a little harder on a modifed script from bliako, and I'm able to point out places in code as perl -de0 sees it, and I can get into the nitty-gritty of execution. I'll repost the 2020 perl -de0 demonstration by Ricardo Signes, for reference. I place sources and debugger output in readmore tags:

      Q1) What makes my Log4perl section a signature? This version is from parv, and I like that it gives me line numbers, but I don't see code for that. (?)

      Q2) How would I turn the above script into "monolithic" foreign code?

      Q3) Does Data::Roundtrip cover the same ground that JSON::XS did? I can't disambiguate what XS means.

      Q4) What operator is this? I believe it takes my global value of 1 for $debug and makes it zero:

      268==>      $debug //= 0;

      Q5) Finally, reading all around these issues, I found this one-liner and was wondering if this would fall under the umbrella of what "the debugger" might be. What is happening with this command?

      $ perl -Mre=debug -e "/just|another|perl|hacker/" Compiling REx "just|another|perl|hacker" ~ tying lastbr BRANCH (11) to ender END (15) offset 4 Final program: 1: TRIEC-EXACT[ahjp] (15) <just> <another> <perl> <hacker> 15: END (0) stclass AHOCORASICKC-EXACT[ahjp] minlen 4 Freeing REx: "just|another|perl|hacker" $

      Thx for your comment

        Q4) What operator is this? I believe it takes my global value of 1 for $debug and makes it zero

        It is the defined-or-equals operator. It assigns the RHS to the LHS only if the LHS is undefined. It is listed in perlop along with all the other operators.


        🦛

        Q3) Does Data::Roundtrip cover the same ground that JSON::XS did? I can't disambiguate what XS means.

        Data::Roundtrip requires the JSON distribution. When used, the JSON module will load JSON::XS if it is available to your interpreter, and the pure perl JSON::PP if not. JSON::PP has been in core since ~5.14, so this functionality is very handy instead of just having your script fall over if JSON::XS isn't installed.

        XS simply means that there are components to the software that are compiled, therefore in most cases making much of its functionality much, much faster.

        One of my distributions, Bit::Manip is an XS based module, but I also have a pure perl version (Bit::Manip::PP) for those who can't or don't want to compile software. Here's a benchmark script between the two, and the results. The C/XS version is ~394% faster than the pure perl version:

        use warnings; use strict; # performs a benchmark between this XS # version and the PP version use Benchmark qw(timethese cmpthese); use Bit::Manip; use Bit::Manip::PP; my $do = $ARGV[0]; timethese(1000000, { 'c' => 'c', 'p' => 'p', } ); cmpthese(1000000, { 'c' => 'c', 'p' => 'p', } ); sub c { Bit::Manip::bit_set(65535, 0, 8, 0xFF); } sub p { Bit::Manip::PP::bit_set(65535, 0, 8, 0xFF); } __END__ Benchmark: timing 1000000 iterations of c, p... c: 3 wallclock secs ( 3.35 usr + 0.00 sys = 3.35 CPU) @ 29 +8507.46/s (n=1000000) p: 17 wallclock secs (16.58 usr + 0.00 sys = 16.58 CPU) @ 60 +313.63/s (n=1000000) Rate p c p 60606/s -- -80% c 299401/s 394% --

        Aldebaran++ that's really cool addition you got there!

        Q2) How would I turn the above script into "monolithic" foreign code?

        Turn your additions into a sub (a subroutine aka function) which will be a complete black box. It will take some inputs, and return some outputs (print if you must but don't forget to return all you need to return to the caller so that your sub is useful). For example:

        sub func { my ($event, @planet_names) = @_; # read in parameters supplied by call +er as in func($xyz) # check that we have some names and that event contains the fields we +need # return undef on error. # caller must check if received undef! return undef unless @planet_names; return undef unless exists $event->{epoch}; ... my %returned_planets = (); for my $a_planet_name (@planet_names){ my $planet = Astro::Coords->new( planet => $name ); ... $returned_planets{$a_planet_name} = $planet; } # return to the caller results as a hashref # I always use refs for params and results. others may not. return \%returned_planets; } # end of my function # example use my $ret = func($anevent, "venus", "saturn"); die "func() failed" unless defined $ret; # and now do what you like with the results.

        I am referring to the code you presented above about here:

        for my $event (@events) { my $epoch = parse_event($event); my ( $MoonPhase, $MoonIllum, $MoonAge, $MoonDist, $MoonAng, $SunDist +, $SunAng ) = phase($epoch);

        Then build some test cases to test your sub. Edge cases (e.g. empty planet names, wrong names) and also cases you know the result. And you are good to go :)

        Todo: at this stage it is a prototype. When final, we can turn this into OO, with $event being a class. But that's much later.

        Let me know how you convert your additions into a sub.

        Q3) Does Data::Roundtrip cover the same ground that JSON::XS did? I can't disambiguate what XS means.

        It's just a wrapper around many great modules to implement things like json2perl, perl2yaml with (hopefully correct) unicode suppprt. Don't worry about it. But you can safely replace it with calls to JSON's decode() etc. (which, as stevieb said, switches between XS or PP depending what is installed on your system) so that you have one less dependency.

        BTW, I think you also provided me with an answer as to why I never use the debugger :)

        bw, bliako

      Now perl -de0 is commonly known as "The Debugger" , which is causing reactions.
      Unfortunately "people with strong opinions" here have a Pavlov reflex to demonstrate their ignorance.

      My personal Pavlov reflex kicks in when someone tries to save his own efforts on the cost of others. Primarily with highly misspelled or misformatted text targeted to a larger audience.

      But almost equally this is the case with examples given here that require an unnecessary effort to reproduce. This includes "debugger sessions". The simplest modifiable thing to reproduce is a runnable perl script. Anything else I regard as laziness.

      Greetings,
      -jo

      $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
        > Anything else I regard as laziness.

        Well I've probably produced 100 times more code for this board than you, and you - whoever you think you are - call me lazy.

        > given here ...

        Seems like you can't even link properly

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery