Programming Helper: Get Code with Loops & Conditionals

  • Thread starter Thread starter Bartholomew
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around the concept of developing a program that can assist in writing or debugging code, particularly focusing on loops and conditional structures in Java. Participants explore the feasibility of such a tool, its potential efficiency gains, and the challenges involved in creating it.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant proposes a program that could "guess" the desired code based on input-output examples, suggesting it could use evolutionary computing.
  • Another participant humorously suggests that the original poster should write a program that writes code for them.
  • A participant clarifies that they envision a debugging tool that suggests code alterations based on desired variable values at specific times.
  • One suggestion involves creating a comprehensive table of inputs and outputs for the program to reference, although this is challenged as impractical due to the required human effort.
  • Another participant argues that while a table approach is a last resort, the tool should prioritize shorter, effective code constructs.
  • Some participants debate the sufficiency of providing limited input-output examples for effective pattern recognition by a computer.
  • One participant cites a past example of a program that used evolutionary computing to control a prosthetic thumb, arguing that it demonstrates a computer's capability to generate code given sufficient data.
  • Counterarguments are raised regarding the limitations of computers in making intelligent inferences from small data sets, emphasizing the complexity of programming compared to simpler tasks.
  • Another participant mentions the simplicity of programs compared to real-world systems, suggesting that the linear nature of programming could simplify the task of generating code.
  • Concerns are expressed about the computational intensity required for a computer to understand complex interactions among multiple variables.

Areas of Agreement / Disagreement

Participants express a mix of agreement and disagreement regarding the feasibility and efficiency of a code-generating tool. Some support the idea, while others raise concerns about the practicality and limitations of such an approach. The discussion remains unresolved with multiple competing views on the topic.

Contextual Notes

Participants highlight limitations related to the amount of input data required for effective pattern recognition and the complexity of programming tasks. There are also discussions about the need for clear relationships between variables to aid in code generation.

Bartholomew
Messages
527
Reaction score
0
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?
 
Computer science news on Phys.org
Hey good idea.. In fact why don't you write a program that writes code for you! :smile: :cool:
 
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:
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.
 
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.
 
Bartholomew said:
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.

Then why don't you just say x = whatever where you want that variable to take on that "certain value"
 
Bartholomew said:
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.

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.
 
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.
 
Bartholomew 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)

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
 
  • #10
Bartholomew said:
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.

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.
 
  • #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:
  • #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.
 
  • #13
Bartholomew said:
Programs tend to be much simpler than real-world systems. They tend to be linear and they are always very clear-cut.

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.

Bartholomew said:
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.

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?
 
  • #14
A computer would have to only look at very small portions of the program to do any useful reasoning.

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.
 
  • #15
Bartholomew said:
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.

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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
15
Views
12K
  • · Replies 18 ·
Replies
18
Views
3K
Replies
11
Views
4K
  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 10 ·
Replies
10
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K