Path: csiph.com!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Mild Shock Newsgroups: comp.lang.javascript Subject: Re: Statement-Continuation Rule Date: Thu, 22 Feb 2024 11:37:52 +0100 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 22 Feb 2024 10:37:52 -0000 (UTC) Injection-Info: solani.org; logging-data="495021"; mail-complaints-to="abuse@news.solani.org" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.18.1 Cancel-Lock: sha1:OOh+lV9LRc4IZNJXzDgoLOoEKYY= In-Reply-To: X-User-ID: eJwFwQkBACAIBLBKAscXBwX6R3BTMbLnMDXo6kYODCwsu5ReOjTsZ7AI7bLuQ324EX5vuQcSy2GvKa9ofT14FRM= Xref: csiph.com comp.lang.javascript:124089 Looks like an instance of method chaining style https://en.wikipedia.org/wiki/Method_chaining It is heralded as something powerful: Method chaining is a powerful programming pattern that allows you to call multiple methods on an object in a single line of code. It enhances code readability and conciseness by eliminating the need for intermediate variables or repeated method calls. In this blog post, we'll explore method chaining in Python, explain it using a simple example, discuss its use cases, and conclude with its benefits. https://nikhilakki.in/understanding-method-chaining-in-python But I have my doubts. Its also related to so called Fluent Interfaces. When you design APIs so that they support method chaining: https://en.wikipedia.org/wiki/Fluent_interface So called builders often exhibit a fluent interfrace. I recently had a revelation, that many builders are rather cheaters, for example I thought the appropriate thing to do would be: builder = builder.header(key, value); So the fluent interface would give me a new version of the build, with each method chaining call. Just like the replaceAll gives a new string. But this is often not the case, it would require that all headers are copied somehow. So we find in the implementation of header() that it just returns this, and the method chaining works with a side effect: public HttpRequestBuilderImpl header(String name, String value) { checkNameAndValue(name, value); headersBuilder.addHeader(name, value); return this; } So method chaining might not always satisfied the same expectations about being a more "functional" approach. Lawrence D'Oliveiro schrieb: > Is this valid code? > > function escape_html(s) > { > return s > .replaceAll("&", "&") /* always do first, rest can be in any order */ > .replaceAll("\"", """) > .replaceAll("<", "<") > .replaceAll(">", ">") > .replaceAll("\t", " ") > .replaceAll("\n", " ") > } /*escape_html*/ >