Re: [whatwg] Confusion about node1.replace(node2)
Bjoern Hoehrmann derhoe...@gmx.net writes: * Glen Huang wrote: When someone says A replace B, I get the impression that B is no longer in effect and A is the new one. So when I do `node1.replace(node2)`, I can’t help but feel node2 is replaced with node1, which is the opposite of what the spec specifies. To illustrate this, imagine some team sports game where the coach jells Jane, replace John!, in other words, `Jane.replace(John)`. It is clear that Jane is instructed to take the position of John. To elaborate on this a bit: “Jane.replace(John)” takes Jane as the first (implicit) argument and John as the second (explicit), so I read it like “replace Jane and John”. This may look ambiguous – until you remember who is instructed to to the replacement, namely Jane. -- Nils Dagsson Moskopp // erlehmann http://dieweltistgarnichtso.net
Re: [whatwg] Confusion about node1.replace(node2)
Thank you for the quick fix. On Jan 14, 2015, at 5:37 PM, Anne van Kesteren ann...@annevk.nl wrote: On Mon, Jan 12, 2015 at 1:15 PM, Glen Huang curvedm...@gmail.com wrote: So yeah, replaceWith looks pretty good. Thanks: https://github.com/whatwg/dom/commit/b7563aaf0864c8d104d18c36a9eda036c5205131 -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
On Mon, Jan 12, 2015 at 1:15 PM, Glen Huang curvedm...@gmail.com wrote: So yeah, replaceWith looks pretty good. Thanks: https://github.com/whatwg/dom/commit/b7563aaf0864c8d104d18c36a9eda036c5205131 -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
On Sat, Jan 10, 2015 at 2:14 PM, James M. Greene james.m.gre...@gmail.com wrote: jQuery is famous (and sometimes infamous, depending on who you talk to) for its API brevity and yet we still chose longer names for these scenarios: `replaceWith` and `replaceAll` (even including All in the latter to clarify that it operates on the entire context set, not just the first element). Dojo uses the same method names as well for their NodeList implementation: `replaceWith` and `replaceAll`. Thanks, that's compelling. Is it a problem for anyone if we rename replace to replaceWith? -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
Just realize that reversing the algorithm won’t work for node.replace(nodes), where nodes contains multiple nodes. So yeah, replaceWith looks pretty good. On Jan 12, 2015, at 8:07 PM, Anne van Kesteren ann...@annevk.nl wrote: On Mon, Jan 12, 2015 at 12:03 PM, Glen Huang curvedm...@gmail.com wrote: Or, the current algorithm of replace could be reversed, which should eliminate such confusion. I think as James said that would leave the confusion. And given the precedent in libraries, replaceWith() seems good. -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
Or, the current algorithm of replace could be reversed, which should eliminate such confusion. On Jan 12, 2015, at 6:41 PM, Anne van Kesteren ann...@annevk.nl wrote: On Sat, Jan 10, 2015 at 2:14 PM, James M. Greene james.m.gre...@gmail.com wrote: jQuery is famous (and sometimes infamous, depending on who you talk to) for its API brevity and yet we still chose longer names for these scenarios: `replaceWith` and `replaceAll` (even including All in the latter to clarify that it operates on the entire context set, not just the first element). Dojo uses the same method names as well for their NodeList implementation: `replaceWith` and `replaceAll`. Thanks, that's compelling. Is it a problem for anyone if we rename replace to replaceWith? -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
On 2015-01-11 03:58, Bjoern Hoehrmann wrote: * Glen Huang wrote: When someone says A replace B, I get the impression that B is no longer in effect and A is the new one. So when I do `node1.replace(node2)`, I can't help but feel node2 is replaced with node1, which is the opposite of what the spec specifies. To illustrate this, imagine some team sports game where the coach jells Jane, replace John!, in other words, `Jane.replace(John)`. It is clear that Jane is instructed to take the position of John. I could not be able to use a better example to show A replaces B. Excellent. --- Delfi Ramirez My digital signature [1] +34 633 589231 del...@segonquart.net [2] twitter: delfinramirez IRC: segonquart Skype: segonquart [3] http://segonquart.net [4] http://delfiramirez.info [5] Links: -- [1] http://delfiramirez.info/public/dr_public_key.asc [2] mail:%20del...@segonquart.net [3] skype:segonquart [4] http://segonquart.net [5] http://delfiramirez.info
Re: [whatwg] Confusion about node1.replace(node2)
On Mon, Jan 12, 2015 at 12:03 PM, Glen Huang curvedm...@gmail.com wrote: Or, the current algorithm of replace could be reversed, which should eliminate such confusion. I think as James said that would leave the confusion. And given the precedent in libraries, replaceWith() seems good. -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
On Mon, Jan 12, 2015 at 7:15 AM, Glen Huang curvedm...@gmail.com wrote: Just realize that reversing the algorithm won’t work for node.replace(nodes), where nodes contains multiple nodes. So yeah, replaceWith looks pretty good. On Jan 12, 2015, at 8:07 PM, Anne van Kesteren ann...@annevk.nl wrote: On Mon, Jan 12, 2015 at 12:03 PM, Glen Huang curvedm...@gmail.com wrote: Or, the current algorithm of replace could be reversed, which should eliminate such confusion. I think as James said that would leave the confusion. And given the precedent in libraries, replaceWith() seems good. -- https://annevankesteren.nl/ Yeah, libraries seem to have proven this out - unless there is a really compelling reason to violate this, replaceWith seems to be what it should be called. +1 to that. -- Brian Kardell :: @briankardell :: hitchjs.com
Re: [whatwg] Confusion about node1.replace(node2)
* Glen Huang wrote: When someone says A replace B, I get the impression that B is no longer in effect and A is the new one. So when I do `node1.replace(node2)`, I can’t help but feel node2 is replaced with node1, which is the opposite of what the spec specifies. To illustrate this, imagine some team sports game where the coach jells Jane, replace John!, in other words, `Jane.replace(John)`. It is clear that Jane is instructed to take the position of John. -- Björn Höhrmann · mailto:bjo...@hoehrmann.de · http://bjoern.hoehrmann.de D-10243 Berlin · PGP Pub. KeyID: 0xA4357E78 · http://www.bjoernsworld.de Available for hire in Berlin (early 2015) · http://www.websitedev.de/
Re: [whatwg] Confusion about node1.replace(node2)
And since methods operate on the object they are invoked upon I think the name is clear enough. The fact replace() is a method operating on an object doesn’t clarify the intention in this case,because the confusion here is that it’s unclear whether the object is having others take its place, or is itself trying take others’ place, and from the general meaning of the english word “replace”, it actually implies the latter. The general preference is brevity over precision. In most cases, I favor brevity too, but when it starts to raise confusion, especially it’s implying the opposite of what it’s actually trying to do, brevity should no longer be a priority, IMHO.
Re: [whatwg] Confusion about node1.replace(node2)
On Sat, Jan 10, 2015 at 8:26 AM, Glen Huang curvedm...@gmail.com wrote: Do you think it would be worthwhile to change to a name that states the intention a bit clearer? The general preference is brevity over precision. And since methods operate on the object they are invoked upon I think the name is clear enough. -- https://annevankesteren.nl/
Re: [whatwg] Confusion about node1.replace(node2)
I have to agree with Glen on this one. Using `node1.replace(node2);` makes me expect that `node1` will be replacing by `node2`. jQuery is famous (and sometimes infamous, depending on who you talk to) for its API brevity and yet we still chose longer names[1] for these scenarios: `replaceWith` and `replaceAll` (even including All in the latter to clarify that it operates on the entire context set, not just the first element). Dojo uses the same method names[2] as well for their NodeList implementation: `replaceWith` and `replaceAll`. If not renamed, `ChildNode#replace` will probably need to be added to my personal list DOM APIs that I'm always doubtful of how to use despite years of off-and on usage... along with, e.g. `ParentNode#insertBefore` and `ParentNode#insertAfter` for their parameter order. [1]: http://api.jquery.com/category/manipulation/dom-replacement/ [2]: http://dojotoolkit.org/api/1.10/dojo/NodeList.html Sincerely, James Greene On Jan 10, 2015 3:56 AM, Glen Huang curvedm...@gmail.com wrote: And since methods operate on the object they are invoked upon I think the name is clear enough. The fact replace() is a method operating on an object doesn’t clarify the intention in this case,because the confusion here is that it’s unclear whether the object is having others take its place, or is itself trying take others’ place, and from the general meaning of the english word “replace”, it actually implies the latter. The general preference is brevity over precision. In most cases, I favor brevity too, but when it starts to raise confusion, especially it’s implying the opposite of what it’s actually trying to do, brevity should no longer be a priority, IMHO.