Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Subset of Perl language

by wanna_code_perl (Pilgrim)
on Jul 30, 2013 at 13:08 UTC ( #1047014=perlquestion: print w/ replies, xml ) Need Help??
wanna_code_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

For a personal "fun" project I've had rattling around for a long time: is there any way (or are there any existing projects) to implement a subset of Perl? More to the point, I'm thinking about an educational game for grade school kids to learn some basic programming concepts without, you know, BASIC. I don't need a super-secure hack-proof system--it's not that important. Mainly I just want to limit the students' ability to shoot themselves (and each other) in the foot, and also limit their access to cheat by taking liberties with namespaces and object innards. Off the top of my head, I'd want to eliminate or limit:

  • Filesystem access, pretty much all I/O except <> and the (s)print(f)/say family.
  • system, exec, fork, ``, etc.
  • IPC, including pipes, signals and sockets
  • syscall, POSIX, ...
  • Debugger, dump, deparse, tie, etc.
  • Read-only @INC, probably just disable or whitelist require/use/no as well.
  • package overrides, redefinitions (though I imagine _I_ will need to do a fair amount of that to accomplish many of the other goals on this list.
  • BEGIN, END, INIT, ... (probably)
  • Setting some perlvars
  • ... just for starters.

I realize I'll at the very least need a custom Perl installation, with many core modules removed, stubbed, or overridden. I imagine there are some compile flags that would help as well. Students would not have the ability to run their code directly; it would be saved in a web-based editor and run by a harness of my creation (so default pragmas, overrides, source filters, etc., can be taken care of). To limit the performance hit from the inevitable runaway loops (despite best efforts to detect and kill them), as well as provide a bit of partitioning, I'm thinking of just keeping several lightweight VMs running with finite resource limits, which would serve requests round-robin.

I'm sure I haven't thought of everything (and it certainly doesn't need to be perfect), but with any luck I'm closer to over-thinking this than under-thinking. Thoughts? Existing projects I haven't been able to find?

Comment on Subset of Perl language
Select or Download Code
Re: Subset of Perl language
by fglock (Vicar) on Jul 30, 2013 at 13:17 UTC

    how about the perlito5 compiler?

    it is also available as a plugin for the Farabi web-based Perl IDE

    Perlito5 - http://perlcabal.org/~fglock/perlito5.html

    Farabi - http://search.cpan.org/dist/Farabi

Re: Subset of Perl language
by daxim (Chaplain) on Jul 30, 2013 at 13:26 UTC

      Safe (and Opcode) looks great! I had no idea core Perl had that ability. That will easily facilitate much of what I need to do, and I can even set up different capabilities on the fly. Nice.

Re: Subset of Perl language (Safe::World)
by Anonymous Monk on Jul 30, 2013 at 13:27 UTC
Re: Subset of Perl language
by jfroebe (Vicar) on Jul 30, 2013 at 14:48 UTC

    You would be looking at creating an interpreter that works with code that looks like Perl. This is not a small task to do properly.

    Since the goal is to teach programming concepts, why not take a look at Scratch, a programming language for kids? It was designed at MIT and for ages 6+.

    Jason L. Froebe

    Blog, Tech Blog

Re: Subset of Perl language
by AnomalousMonk (Abbot) on Jul 30, 2013 at 16:43 UTC
    ... I just want to limit the students' ability to shoot themselves (and each other) in the foot ...

    A properly structured and maintained System Administrator/User system should prevent students shooting others in the foot, and shooting yourself in the foot is a learning experience!

    ... and also limit their access to cheat by taking liberties with namespaces and object innards.

    But "cheating" and "taking liberties" (also known as "playing") are part of the fun of learning — and often a royal road to enlightenment. All too soon will your students enter an academic or commercial environment (whether or not they seek to become professional programmers or engineers) in which Someone will constantly be watching over their shoulders to make sure they don't "take liberties." For now, let them have a chance to enjoy learning.

    So don't bother. Just set up effective user firewalls, give them Perl, let them go nuts. You may be quite pleasantly surprised!

    (I'm assuming the kids are about 10 years and up. Younger than that, something like jfroebe's suggestion may be more appropriate than Perl.)

      A properly structured and maintained System Administrator/User system should prevent students shooting others in the foot, and shooting yourself in the foot is a learning experience!

      Oh, I agree. Securing the system from a bunch of kids is relatively easy (but I've learned to never underestimate the tenacity of a fifth grader who wants to beat his friends in some kind of real or imagined competition). And, yes, shooting oneself in the foot is educational, although often painful. The main point here is to provide an environment with a limited number of pitfalls that will lead to needless frustration.

      For example, nothing I teach them will ever be solved with shell commands, but I can pretty much guarantee someone would accidentally type print `which cat is your favorite?` and be intensely confused by what /bin/cat has to do with anything. To my mind, it would be a much less frustrating experience to get a syntax error (or at least an I'm sorry, Dave. I'm afraid I can't do that.) pointing to that line. I fully believe a little frustration can stimulate learning, but a lot of frustration combined with pretty much no clue what's going on, can lead to rather significant detachment. Yep, that's life, but fifth-graders are still developing a lot of those personal skills, and even among adults, getting thrown into the deep end before even learning the doggy paddle (be that figuratively or literally) is often counter-productive. Of course this is more developmental psychology than Perl, but hopefully it helps illuminate my motivations for wanting to throttle the kids' frustration level.

      But "cheating" and "taking liberties" (also known as "playing") are part of the fun of learning and often a royal road to enlightenment.

      Also agreed (emphatically!). While I of course try to project positive values re: honesty and cheating, I also don't step in to stop it unless there's a very good reason to do so. Game playing is a relatively safe (and efficient!) way to experience both sides of the social consequences of dishonesty, the rush of thinking you got away with it, and the crushing embarrassment and anger of getting caught (or finding out you've been bamboozled). In the context of what I'm currently proposing, there will be ways to "cheat"--some of them deliberate on my part. I just want to be able to limit what they can and can't get away with.

      Thanks for the insightful comments! I agree with them. If any of this seemed contrary, it's just me trying to elaborate a bit on some of the deeper motivations behind this project.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1047014]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-21 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls