News for hackers. Stuff that matters.
Re:ECMAScript proposal: String.prototype.replaceAll by yepthatsreality on Saturday December 21, 2019 @04:13PM (#21853399)
Mmmmm...syntactic sugar...
Re:ECMAScript proposal: String.prototype.replaceAll by DDR0 on Saturday December 21, 2019 @04:40PM (#21853494)
Could you provide an example of what this desugars to? I'm not sure I understand.
Re:ECMAScript proposal: String.prototype.replaceAll by pier25 on Saturday December 21, 2019 @11:41PM (#21855226)
You can simply use string.replace() with a global regex.
Re:ECMAScript proposal: String.prototype.replaceAll by minitech on Sunday December 22, 2019 @04:10AM (#21856069)
Dynamic patterns require escaping, resulting in unnecessary complexity and overhead.
Re:ECMAScript proposal: String.prototype.replaceAll by sveingjoby on Saturday December 21, 2019 @05:35PM (#21853718)
Yes, you are (of course) able to replace all occurrences today. However, you either need to call replace multiple times or pollute your code with a regex. This would certainly improve the readability.
Re:ECMAScript proposal: String.prototype.replaceAll by pier25 on Saturday December 21, 2019 @11:42PM (#21855228)
Why would using regex pollute your code?
Re:ECMAScript proposal: String.prototype.replaceAll by Normal_gaussian on Sunday December 22, 2019 @12:06AM (#21855313)
It depends on who you ask; however the thinking is often:

* They can indicate poor parsing (ie can't read xml with regex) and failure to use programmatic methods (e.g parsing command output rather than making syscalls)

* regexes are very easy to write incorrectly without being obviously wrong

* regexes are often overkill for a direct match

* regexes invite people to make it more complex rather than restructure surrounding code

* regexs are comparatively more expensive than alternative code

* to work on the codebase you are now required to understand regex in general and this particular implementations quirks as well

I often use regexes, and I often choose not to use regexes.

Re:ECMAScript proposal: String.prototype.replaceAll by chrisseaton on Saturday December 21, 2019 @04:22PM (#21853437)
Not sure what you mean? This doesn't add or use any new syntax, let alone syntactic sugar. It's a new builtin method.