Skip to content

Return statements are optional #176

@apblack

Description

@apblack

A student wrote in a report on a homework, where I asked for comments about Grace:

I just realized that majority of the hardships that I had with reading grace code at the beginning of this class (it has gotten better) is due to the lack of return statements in the given code ( I know Grace has this statement and I use it). I think return statements are some kind of visual cues that help us skim the code faster and help us spatially understand the code. Or, in the worst case, we have this expectation to see a return at the end, and not seeing it there slowed/confused me.

In contrast, @KimBruce Kim Bruce wrote:

I think it is bad style to write return result at the end of a method. It should just be result. I teach my students that return is there only to change the flow of control — e.g., in the middle of a method you determine the answer in an intermediate result and can return immediately.

I have sympathy with both of these points of view, and also with Michael Koening's principle that there should be just a single way of doing things.

It seems that whatever we choose, we can't win.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions