Half a croissant, on a plate, with a sign in front of it saying '50c'
h a l f b a k e r y
Superficial Intelligence

idea: add, search, annotate, link, view, overview, recent, by name, random

meta: news, help, about, links, report a problem

account: browse anonymously, or get an account and write.

user:
pass:
register,


                                                   

Please log in.
Before you can vote, you need to register. Please log in or create an account.

Python dynamic online functions

  (+6, -1)
(+6, -1)
  [vote for,
against]

What if by typing a special prefix, you can quickly use premade/'user editable' code from a general snippet database (e.g. a wiki in codebank.python.org). Which when the script is run, it quickly downloads the script as needed, and interprets it as if it was a function.

What this means, is that scripts are kept smaller, and more compact, as any needed functions are simply downloaded from the wiki. (and also any updates and fixes can be found there, along with the function's help page.)

Coding time is also cut down, as people are more inclined to use ready made code that is collectively used. And if you want to make it offline proof, it won't be too hard to create a 'compile' setting, that downloads and integrate all the scripts from the wiki into the script being 'compiled'.

Applications: Best used for webapps.

Syntax form may look like this:

_##_pow(10,3) - finds the first code for 'pow'

_#v1.2#_pow(10,3) - finds a specific version of 'pow'

_#HASH:ndkafeik#_pow(10,3) - enforced specific version of 'pow' by hash function for security purpose.

-----

Note: you might want to also create a local cache, for functions that are downloaded. So that you can use it offline, and allow other similar program to use it.

mofosyne, Aug 24 2010

ChinesePython http://en.wikipedia.../wiki/ChinesePython
[Spacecoyote, Aug 26 2010]

Colt Python http://www.imfdb.or...7e/Coltpython25.jpg
My mother's first purse gun... [normzone, Aug 26 2010]

[link]






       I know this is baked somewhere, but I can't remember what it's called.
Spacecoyote, Aug 24 2010
  

       Interesting and potentially full of security holes.   

       That being said, I'd recommend the syntax of   

       from ##pow#1.2 import pow   

       Or, better yet   

       from ##example.com/snippets#pow1.2 import pow   

       ...   

       as the syntax so that you can get done with your online portion at the import statement.   

       Whitespace-fluffed bun for the concept
cowtamer, Aug 24 2010
  

       _##_pinin(10,3), _##_fjords(10,3)
zen_tom, Aug 24 2010
  

       Would make for fragile code. Your program could be absolutely bullet proof, unit tested to within an inch of its life, working fine for two years, and then develop a bug because of something some guy somewhere on the internet did. And if you think it's hard to deal with dependency hell by hand, just try writing software robust enough to handle it automatically at runtime.   

       I'll say this much in support of the idea, though: if you're going to do this, Python is the right language for it. Another way of looking at this -- not what you mean, I realize, but which I find attractive -- is as an idea designed to give software engineers nightmares: like Brainf*ck or the "comefrom" statement.
mouseposture, Aug 24 2010
  

       What makes Python the best language for this? Wouldn't Perl be just as good?   

       To do it with Perl, one would simply need to define a subroutine named "AUTOLOAD" that fetches the desired snippets over the internet and uses eval() to turn them from text into code.   

       To avoid nightmarish security holes, one could use the Safe module. There are still security holes, because Safe isn't perfect, but they're not so large you could drive a bus through them. (The security holes are pet door sized -- some contortionist skills required.)   

       Fragility might be an issue, but if the internet code snippets are maintained by individuals with ownership over those snippets, and those individuals wrote them for the purposes of helping their fellow programmers, it's unlikely that the code snippets would be "upgraded" without first doing some backward compatibility tests.   

       Incidentally, this vaguely similar to how Perl programs which depend on other people's Perl modules... well, except that those other people's modules are downloaded (typically from CPAN) when the program in question is installed, instead of on the fly.
goldbb, Aug 25 2010
  

       Would be great for cases where the drop-dead ship deadline is before the specs are written.   

       Like tax software, for example.
lurch, Aug 25 2010
  

       [goldbb] What I had in mind is this: Python makes a fetish of having nearly everything happen at run time, even some things, like binding identifiers to executable code, where you might not expect that. This makes it easy to intercept function calls at runtime for purposes of doing what this idea suggests. I think you'd create stub objects with custom __call__ methods (or write a factory for such objects). Those methods would invoke wget or curl or somesuch.   

       However, maybe Perl also does these things at runtime, but without making so much fuss about it. Haven't done much with Perl for a long time, but my impression was: *any* feature that the practical programmer might find convenient is already built in, *especially* if the theoreticians think it's a bad idea.   

       I agree with the rest of what you say, namely (as I paraphrase it) that this'll need something very like a package management system and a codebase specially organized for this purpose. As for the 'Safe' module, won't the 'taint' marker infect pretty much your entire program?
mouseposture, Aug 25 2010
  

       Some Perl packages with large numbers of subroutines are designed so that each of those subs is only compiled when it's first called, and kept in memory thereafter. This is done because it's not to uncommon for a Perl program to load a package only to use one or two subroutines from it. There's no point in wasting time compiling any subroutine that's not going to actually be used, and there's no way to know that a subroutine *will* be used, until the program actually goes and tries to use it.   

       Of course, while the packages themselves *could be* downloaded at runtime, they normally aren't... that would be silly.   

       As for perl's Safe module:   

       Data returned from code evaluated in a Safe isn't automatically marked with the taint flag.   

       Even if it were, taint can be removed from any string, by performing regular expression matching on that string and then getting (untainted) bits and pieces from $1, $2, etc.
goldbb, Aug 25 2010
  

       For one thing, Python's developers seem to be more open to drastic "enhancement" than Perl's.
Spacecoyote, Aug 25 2010
  

       Another thing this kind of approach would be fantastic for, is when you want to make a competitor to matlab.   

       You know how big matlab is? About a few gigs big.   

       And while all the functions matlab has is important. I highly doubt we often touch all of them in one program. If python maths (though, srly, their matrix notation plainly sucks, matlab syntax is more intuitive)   

       With this approach, you can store all the useful mathematical function into the clouds, and simply retrieve it as needed. And if you developed something cool, e.g. a better differentiation function, then you can simply upload it to the server for others to use as well as yourself.
mofosyne, Aug 25 2010
  

       OK I don't get it. how will waiting to connect with an exterior server to download a tiny piece of code speed page load time? This is going around your ass to get to your elbow. As for the other benefits I don't see any. If you want your scripts to be corrupted and frequently cause slow loading and page hangs then host them on a wiki (13kb OutRef'ed to a public server? WTF!)
WcW, Aug 25 2010
  

       Spacecoyote, is there anything in Python that's as drastic as Lingua::Romana::Perligata?
goldbb, Aug 25 2010
  

       Yes, [goldbb]. [link]
Spacecoyote, Aug 26 2010
  

       WcW, I'm not saying that this will save speed time in processing power. I'm saying this will cut down development time.   

       This is because, it cuts down the number of time people have to reengineer, a specific function that someone else have probably already did in their own programs.   

       To make it even better, this approach would make web scripting more wiki-like. This is since, these casual programmers won't have to deal too much with 'dependencies' and can use ready made functions to 'just get the damnn job done'. Hence sites which allows users to create online scripts will benefit from it.   

       hopefully this approach to programming will help make casual programming more of a lego game, rather than a mechanics nightmare.
mofosyne, Aug 26 2010
  

       //casual programming// I'll concede my own criticism (and others' too, I think) boils down to saying that this would only work for casual programming. I'd define "casual" in this instance as something quick & dirty that will run only once or twice and not be maintained. I'd bet a lot of programming falls in that category.
mouseposture, Aug 26 2010
  

       Actually you are onto something. But I propose a modification. You don't want your code dependent on the website all the time. As others have mentioned it causes problems for performance and for security. How about a compromise. Make your quick and dirty design "online" and then once ready to roll out, run a "get-dependencies" command that will look for all the dependencies, and store them in a local library cache.
That will give you the best of both worlds. Because bringing the libraries ahead of time is a huge time waster. Sometimes you'll find that the library doesn't do what you thought it did, so it never gets actually included in the code. Once it does, so sure bring it in locally.
ixnaum, Aug 26 2010
  

       So you mean, have a external program that when activated, scans the code, and preloads all the web based functions? (you distribute it with the code as well)   

       If its a massive file, wouldn't it take a while to download all the functions?
mofosyne, Aug 28 2010
  

       And since functions are likely to be reused by multiple programs, it would be good to have a common local offline cache.
mofosyne, Aug 28 2010
  

       Strange sites lying on servers distributing functions is no basis for a system of programming.
MaxwellBuchanan, Aug 28 2010
  

       [Max], Sounds like a cellular mechanism. :-)
wjt, Aug 30 2010
  

       Max, what about Sourceforge, CPAN, JSAN , and other online sources of code and coding tools?   

       Spacecoyote, that's not a Chinese language plugin for Python, it's a complete reimplementation of Python, written in C, using Chinese language keywords and Python syntax. It's a replacement for Python, not an add-on.   

       If you have Perl, and want to write programs in Latin, simply using the Lingua::Romana::Perligata package from within Perl will allow you to do it. You don't need to compile anything from C, since the package is written in entirely in Perl.   

       If one desired to write Perl using Chinese language names and keywords, that too would be possible with Perl, without needing to create a separate Chinese Language version of Perl. You'd need to write a translating package, of course, but the translator would be written in Perl, just as Lingua::Romana::Perligata is.
goldbb, Aug 31 2010
  

       [goldbb] One could write such a translator for Python in Python, but it's more a Perl thing to do. Pythonistas would consider that a stinging indictment of Perl. Now, if you want something that's that's truly more possible in Perl than in Python, I'd nominate: poetry that parses without errors.
mouseposture, Aug 31 2010
  

       //Max, what about Sourceforge, CPAN, JSAN , and other online sources of code and coding tools? //   

       Indeed, but what about Monty Python and the Holy Grail?
MaxwellBuchanan, Aug 31 2010
  
      
[annotate]
  


 

back: main index

business  computer  culture  fashion  food  halfbakery  home  other  product  public  science  sport  vehicle