New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add convenient status function to set statusCode using method chaining #980

Merged
merged 1 commit into from Feb 15, 2015

Conversation

Projects
None yet
3 participants
@MartinNowak
Contributor

MartinNowak commented Feb 11, 2015

No description provided.

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Feb 13, 2015

Member

I'm still a bit undecided with regards to method chaining in D. In contrast to C++ we have with, for example, which is not much longer:
with (res) { status = HTTPStatus.notFound; writeBody("not found"); }
res.status(HTTPStatus.notFound).writeBody("not found");
well, actually writing it out is even shorter in this case ;)
res.status = HTTPStatus.notFound; res.writeBody("not found");

In this specific case, this would also duplicate trivial functionality which most of the time has a bad cost/benefit ratio in the long term due to API clutter. But there is already a precedent with URLRouter, so I'm not completely sure how to go about this. But maybe we could instead add another writeBody overload? res.writeBody(HTTPStatus.notFound, "not found");

Member

s-ludwig commented Feb 13, 2015

I'm still a bit undecided with regards to method chaining in D. In contrast to C++ we have with, for example, which is not much longer:
with (res) { status = HTTPStatus.notFound; writeBody("not found"); }
res.status(HTTPStatus.notFound).writeBody("not found");
well, actually writing it out is even shorter in this case ;)
res.status = HTTPStatus.notFound; res.writeBody("not found");

In this specific case, this would also duplicate trivial functionality which most of the time has a bad cost/benefit ratio in the long term due to API clutter. But there is already a precedent with URLRouter, so I'm not completely sure how to go about this. But maybe we could instead add another writeBody overload? res.writeBody(HTTPStatus.notFound, "not found");

@etcimon

This comment has been minimized.

Show comment
Hide comment
@etcimon

etcimon Feb 13, 2015

Contributor

I personally prefer method chaining when there's 3 or more methods in an object, which need to be used sequentially as many times, like when populating an object, but in a state machine kind of way. The typing is fast and smooth with an IDE that supports auto-completion.

In this case, the fact that you'd usually return afterwards would prompt for another function like res.exit(HTTPStatus, string);. It mimics the php exit function and would be implemented by throwing a CustomHTTPStatus error possibly (with respects to the current API) :-p Maybe a exit(HTTPStatus, Path) version of the method could support reading the html from an error file.

Contributor

etcimon commented Feb 13, 2015

I personally prefer method chaining when there's 3 or more methods in an object, which need to be used sequentially as many times, like when populating an object, but in a state machine kind of way. The typing is fast and smooth with an IDE that supports auto-completion.

In this case, the fact that you'd usually return afterwards would prompt for another function like res.exit(HTTPStatus, string);. It mimics the php exit function and would be implemented by throwing a CustomHTTPStatus error possibly (with respects to the current API) :-p Maybe a exit(HTTPStatus, Path) version of the method could support reading the html from an error file.

@MartinNowak

This comment has been minimized.

Show comment
Hide comment
@MartinNowak

MartinNowak Feb 15, 2015

Contributor

It mimics the php exit function and would be implemented by throwing a CustomHTTPStatus error possibly (with respects to the current API) :-p Maybe a exit(HTTPStatus, Path) version of the method could support reading the html from an error file.

Don't abuse exceptions for control flow, but what I want is a single statement to do return res.writeBody("foo", HTTPStatus.notFound). The overload sounds like a good idea.
Updated.

Contributor

MartinNowak commented Feb 15, 2015

It mimics the php exit function and would be implemented by throwing a CustomHTTPStatus error possibly (with respects to the current API) :-p Maybe a exit(HTTPStatus, Path) version of the method could support reading the html from an error file.

Don't abuse exceptions for control flow, but what I want is a single statement to do return res.writeBody("foo", HTTPStatus.notFound). The overload sounds like a good idea.
Updated.

s-ludwig added a commit that referenced this pull request Feb 15, 2015

Merge pull request #980 from MartinNowak/status
add convenient status function to set statusCode using method chaining

@s-ludwig s-ludwig merged commit c528601 into vibe-d:master Feb 15, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@MartinNowak MartinNowak deleted the MartinNowak:status branch Feb 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment