4 ms·
The pipe operator example omits the typical way you would write this code in any language: simply by introducing temporary variables or by shadowing. The url p
by dgb23 11mo ago
The pipe operator example omits the typical way you would write this code in any language: simply by introducing temporary variables or by shadowing.
The url parse example is not being compared to the builtin parse_url function that is just as easy to use.
- RobAley 11mo agoParse_url isn't standards compliant, often fails with relative url's and most importantly only parses urls, not uris (with the exception of file://). I also find it's syntax clunkier than the new uri(), but that's just personal preference. The pipe operator is indeed just syntactical sugar (and the article links to another article specifically about it which does cover the case of temporary variables), but with the coming partial function application feature it (in my opinion) will make easier to read/reason chains of code than temporary variables or nested function calls.
- duskwuff 11mo agoparse_url() also had no generate_url() counterpart - sure, it could (sometimes) split a URL into its components, but there was no safe way to modify those components and glue them back into a string. The new URI class solves that.