It has a more conventional builder-style API that may answer the complaints of those wishing for a more straightforward way to write loops.
413 karma · joined March 31, 2007
It has a more conventional builder-style API that may answer the complaints of those wishing for a more straightforward way to write loops.
(delete-selection-mode 1)
(transient-mark-mode 1) ; enabled by default in emacs 23+
you can mark a region and press delete or backspace (or start typing replacement text) to delete the region without affecting the kill ring.Here is an emacs function I use, which does the reverse of the refactoring in the screencast. I use it by marking an expression and typing M-x extract-variable, which asks me what I want to call the variable. It then replaces the expression with the variable I named and puts "<varname> = <expression>" into the kill buffer. I navigate to where I want to define the variable and type C-y to yank, which completes the refactoring. It's a useful tool for breaking apart deeply nested code, pulling out constants to make things configurable, and improving the readability of long lines.
(defun extract-variable ()
"Micro-refactoring: replace the region with a variable and save an
assignment statement in the kill ring. After calling this function, find a
good destination for the assignment and yank."
(interactive)
(let ((var-name (read-string "Variable name: ")))
(kill-region (region-beginning) (region-end))
(kill-append " = " t)
(kill-append var-name t)
(unless (eq major-mode 'python-mode)
(kill-append ";" nil))
(insert var-name)))Here's a demo with source (PHP):
If this is the case, is there any good example of REST? I have yet to see a web service API that does not require one to read the docs to do URL construction, which violates the HATEOAS principle. The only examples I know of where HATEOAS is satisfied are HTML forms, as I mentioned, Atom feeds, and OpenSearchDescription. None of these are elaborate APIs (or APIs at all) where one would even need to consider something like XML-RPC.
I think HTML forms are a perfect example of REST, since they supply the client with all necessary information to build the next request, and URLs do not need to be constructed manually. The way 302s are used to redirect to the newly-created resource makes web browsers behave more RESTfully, since they prevent reloads from resubmitting POST requests. This is a very common practice today, and I would consider it one of the best examples of REST done right, and yet it uses a different HTTP response code than the proposed standard of 201 Created.
All I'm trying to do is show that there are at least two codes, 201 and 302, that properly RESTful services might return, to support my argument that response codes are not uniform across all REST services.
At least with real object-oriented programming you can come up with your own method names.