We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Code that write itself.
Page Index Toggle Pages: 1
Code that write itself. (Read 674 times)
Code that write itself.
Jan 26th, 2009, 4:09pm
 
I have a good understanding of scripting (actionscript mainly), but i moving into OOP programming and picking things up as I go.

I was just curious, as a concept. Can code be written that rewrites itself on the fly?

I imagine this would be very complicated, but as concept does even make sense.

Just an odd thought really.
Re: Code that write itself.
Reply #1 - Jan 26th, 2009, 4:38pm
 
Not sure this thought is as "odd" as it might seem (if I got your point right, that is): While doing rather "low-level" development using, say, some sort of assembler language, writing code that modifies itself is a pretty common and straightforward approach of doing things in an "elegant" way (and a source of severe pain eventually if not done right... Wink ). In some "newer" languages (Ruby, Groovy, ...), there also are rather strong "metaprogramming" concepts which, put as "straightforward" as possible, allow for dynamic modification or generation of code at application runtime. Look at [1] as a quick example... or is that not what you meant? Smiley

Cheers,
Kristian

[1] http://www.fiascode.com/programming/groovy-metaprogramming-adding-behavior-dynamically/
Re: Code that write itself.
Reply #2 - Jan 26th, 2009, 5:24pm
 
Thanks, i'll have a read of that.
Re: Code that write itself.
Reply #3 - Jan 26th, 2009, 5:59pm
 
Yeh, I think metaprogramming and generative programming are areas I need to read into.

I found some other areas here.
http://en.wikipedia.org/wiki/Self-modifying_code
http://en.wikipedia.org/wiki/Self-interpreter
http://en.wikipedia.org/wiki/Self-replication
Re: Code that write itself.
Reply #4 - Jan 27th, 2009, 4:52am
 
LISP is all you need.

Re: Code that write itself.
Reply #5 - Jan 27th, 2009, 5:05am
 
Lisp/scheme is the best way to get into that, in my opinion. Its also great in that it really make a person a better programmer. You really learn to think outside the box and abstractly.
Re: Code that write itself.
Reply #6 - Jan 27th, 2009, 4:47pm
 
if what is you want is the ability to code dynamically at runtime, then check out beanshell.org for a java interpreter in java - you can then build up strings of java code, interpret and run them, interop'ing with your "hard" code.
Re: Code that write itself.
Reply #7 - Jan 28th, 2009, 11:18am
 
OgreProgrammer wrote on Jan 27th, 2009, 5:05am:
Lisp/scheme is the best way to get into that, in my opinion. Its also great in that it really make a person a better programmer. You really learn to think outside the box and abstractly.


I partly agree. Though LISP is both a great way of giving you "another point of view" and eventually a horrid pain to deal with if you're used to other languages / environments, I think this "thinking-outside-the-box" virtually applies to any additional programming language one deals with in course of everyday programming as most languages (just looking at things like Groovy, Scala, Ruby, Python, Haskell, Erlang, Eiffel, ...) do introduce fewer or more things making them unique, interesting and worth considering for one problem or the other, and be that just for the sake of curiosity and "unleashing" ones thoughts which (at the very least as soon as you earn a living doing software development) tend to be tied to a given language and environment rather closely at times... even though it might not get you anywhere as some paradigms may not easily be applicable to the tool you are professionally using (see closures in Java... Wink ).
Cheers,
K.
Re: Code that write itself.
Reply #8 - Jan 28th, 2009, 11:22am
 
davbol wrote on Jan 27th, 2009, 4:47pm:
if what is you want is the ability to code dynamically at runtime, then check out beanshell.org for a java interpreter in java - you can then build up strings of java code, interpret and run them, interop'ing with your "hard" code.


You also might replace beanshell with any other language allowing for dynamically loading and executing code into Java applications. Support for scripting languages (most notably, I guess, Groovy, JRuby and Jython) is one of the more interesting features about Java SE 6, providing both benefit and threts (-> (me) trembles at the idea of java applications being capable of loading and executing arbitrary, human-modifiable code at runtime... :> ). The idea of automatically generating such scripts in a simple string-based fashion however seems tempting indeed... gonna give this a try. Smiley
K.
Re: Code that write itself.
Reply #9 - Feb 3rd, 2009, 4:26pm
 
Thinking im running before i can walk on this one, but its an interesting thought!
Page Index Toggle Pages: 1