Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I was given the following feedback:

functions are not defined for stepwise refinement, and functions are not defined and are called instead of repetitive code.

I am not sure exactly what is meant by that...

## Importing turtle to 'draw' the fractal images ##
from turtle import *

def draw_fractal(initial_state, target, replacement, num_replacements, \
             length, angle):

    ## Set result (also known as initial output ) to the inital state##

    result = initial_state

    ## Incorporating the number of replacements into the formula as to ensure
    ## that each fractal image will replace as many times as the test
    ## run states ##
    for i in range(num_replacements):
        ## Replacing the 'target' with the replacement' and also stating the
        ## replacements for Island Lakes Question ##
        result = result.replace(target, replacement).replace('f', 'ffff')

    ## Set the speed of turtle to be the fastest and eliminate the tracer ##
    speed('fastest')
    tracer(0)


    for command in result:
        if command == target:
            ## Turtle moves forward by the length given to us in the test runs ##
            forward(length)
        elif command == '+':
            ## Turtle turns right at the angle given to us in the test runs ##
            right(angle)
        elif command == '-':
            ## Turtle turns left at the angle given to us in the test runs ##
            left(angle)
        elif command == 'f':
            ## Pulls the pen up, turtle moves forward by the length given to us in
            ## the test runs and the pen is put back down ##
            up()
            forward(length)
            down()
share|improve this question
1  
Claire, this code is not working, as it is not properly indented. Please re-format. – ThomasH May 29 '11 at 9:25
Is this all the code in question? – Winston Ewert May 29 '11 at 13:35

2 Answers

functions are not defined for stepwise refinement, and functions are not defined and are called instead of repetitive code.

Was this like a supervisor's remark on a print-out?! - Let's take it piecewise, from the back:

  • "[functions] are called instead of repetitive code" - This makes sense in general. If you find yourself typing the same code fragment multiple times, put it into an own function and call this instead. - But: In the code that you provided I see no repetition. Do you? Could this refer to the draw_fractal function itself, to motivate it, as it avoids repeating this code in the places where you call it?!

  • "functions are not defined" - Are you sure the not is correct here? Without it, the sentence would make much more sense: "functions are defined and are called instead of repetitive code". - Check that with your supervisor.

  • "functions are not defined for stepwise refinement" - Mh, that's a tough one. Again, I don't see stepwise refinement in the code you posted. It's rather straight forward, working on its arguments, bring them into shape, then using them to do the real work. Again, could this refer to the places where this function is called, rather than the function itself? Or is it referring to the "refinement" of the arguments? - One idea might be putting the arguments-scrubbing into an own function, so you get a separation of a function preparing the arguments, and another using them. But that also seems a bit artificial, especially when you have to do both actions always toegether.

share|improve this answer

My guess is that the grader wanted you to recursively define the function. Instead of doing all the replacements up front, you'd say something like:

if command == target:
    if num_replacements > 0:
        draw_fractal(replacement, target, replacement, num_replacements -1, length, angle)
    else:
        forward(length)

This example may be incorrect, since I haven't tested it and don't fully understand the requirements, but hopefully it points you in the right direction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.