Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming helper

  1. Dec 20, 2004 #1
    I'm writing a complicated Java program (for me, at least) and getting some bugs. I thought of something: why not have a program that can "guess" at the code you want if you step it through for test input and tell it what output you want at various stages? It could come up with likely code which would produce the answer you said and you would check to make sure. It would produce code as variations on simple looping and conditonal structures and if you wanted something more complicated (like for example if you wanted to use a library function) you would just write that line yourself and it would help fill in the blanks. Because looping and conditional structures are so predictable--if you had a human who looked at input and output with the information that they were built around loops and conditional structures, the human could probably figure out what was going on--I don't think it would be impractical to make a program that could do this. It could practically do it just by guessing--you could use evolutionary computing. Has someone already made this thing?
  2. jcsd
  3. Dec 20, 2004 #2
    Hey good idea.. In fact why dont you write a program that writes code for you!! :rofl: :cool:
  4. Dec 20, 2004 #3
    I guess I really mean more of a debugging tool than actually writing the program. I mean, like, say you have a variable that has to be kept at a certain value in various places in the code which otherwise works. You would tell the helper what you wanted the variable to be and at what times, and what information in general contributes to the variable being this value, and it would suggest alterations to your code that could produce the results you said.

    Edit: (reply to Anttech) Well, wouldn't it be an efficiency gain if you had programs that could mostly write other programs?

    (Of course, this might render many professional programmers obsolete... maybe not such a good idea to have it write everything)
    Last edited: Dec 20, 2004
  5. Dec 20, 2004 #4
    This is easy to do. Just build a big table that contains every possible input and the corresponding output. Then all your program has to do is read in the input, look up the output in the table and then write out the output.
  6. Dec 20, 2004 #5
    You might do that as a last resort but it would require a lot of human work to match inputs and outputs! The helper should suggest with greater priority the code constructs it finds that are shorter but still work, so it should not suggest the table approach often.
  7. Dec 20, 2004 #6
    Then why don't you just say x = whatever where you want that variable to take on that "certain value"
  8. Dec 20, 2004 #7
    If you don't supply the computer with all the inputs and outputs, then how is it supposed to know what works? You can't just give the computer a few samples and expect it to pick out a pattern. Even a human requires an enormous amount of information in order to perform useful pattern matching.
  9. Dec 20, 2004 #8
    Not true--for example, "find the pattern" puzzles usually only give you four or five numbers and from that you can figure out a likely pattern. Computers are fully capable of writing code given examples of what it should do. In fact, a few years ago I remember reading about a program that used evolutionary computing to write a program to control a prosthetic thumb. Of course, that one DID have a huge amount of input-output examples to work on, but that application dealt with "real-world" data. If all you want your computer to do for you is make appropriate basic looping/conditional statements, it probably wouldn't require as many examples.
  10. Dec 20, 2004 #9
    Depends on how "efficient" the program is that writes your programs.... Software Engineering is exactly that... You engineer solutions to a remite u are given.... Now for an application to do this for you is in the relms of AI...

    Most Debuggers will corect syntax for you AFAIK
  11. Dec 20, 2004 #10
    Only the most trivial of patterns can be determined from just a few inputs. And you certainly can't demonstrate that computers can make intelligent inferences from small amounts of data by citing an example that uses massive amounts of data to teach the system. And controlling a thumb is a relatively simple task compared to writing a program.

    There really aren't very many cases where people can figure out the solution to a problem given a small amount of information, so it certainly isn't reasonable to expect a computer program to do the same thing. There are a lot of times when people seem to solve a problem given only a few bits of information; but this is only possible because humans carry around a staggering amount of context information that computers don't understand.
  12. Dec 21, 2004 #11
    "They will invent self spelling wands before they..."Mr.Weasly(Harry Potter)

    As for the debugging idea.You can make some print statements or use the standard debbuger.
    I usually spend hours looking for logical errors in my code.
    Last edited: Dec 21, 2004
  13. Dec 22, 2004 #12
    The reason I mentioned the prosthetic thumb controller was that it actually did generate code. It wasn't just a neural net; it actually came up with a code solution.

    Programs tend to be much simpler than real-world systems. They tend to be linear and they are always very clear-cut. The task of finding a possible solution is further simplified because the programmer can point out necessary relations between the variables so that suggested solutions which do not incorporate those relations can be discarded.
  14. Dec 22, 2004 #13
    Parts of most programs are clear-cut and linear. Most programs as a whole are very non-linear and very fuzzy. A computer would have to only look at very small portions of the program to do any useful reasoning.

    You would most likely have to spend more time teaching the computer about the relationships between variables than you would have had to spend if you just wrote the program yourself.

    If you have a large number of variables than using the computer to solve the problem is too computationally intensive. The interactions are just too complex for the very linear computer to understand.

    If you have only a few variables then the amount of time it takes you to just type out the code should be negligible. How did you plan to make it easier to tell the computer about relations between variables instead of just writing code?
  15. Dec 23, 2004 #14
    Well, you'd be intended to point the computer in the direction of what lines are questionable.

    But I guess this would be most practical as a debugging tool rather than as a from-scratch program writer. You could say that such-and-such a variable has the wrong value at such-and-such a point and also at such-and-such a point, tell the computer what its values _should_ be at those points, and the computer would determine where it was modified and by what and generate possible ways to correct it while keeping mostly unmodified what you had already written. If the variable depends on the use of external functions, the programming helper could look at those functions just as it would look at any other code (except this code would be unalterable) and on the basis of that suggest ways to alter how you use them.
  16. Dec 23, 2004 #15
    That's a much more reasonable suggestion. I'm still not certain that such a program would really be helpful...I can't think of very many situations where something like that would have been useful to me...but it might have some uses in more specific applications.

    External functions would still be quite a problem, since there's no limit to the amount of side effects they can have. You would have to provide the program with assurances about what outside functions will and won't change.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook