Re: Introduce str_left/right In 8.1
| From: | Mike Schinkel | Date: | Thu, 24 Jun 2021 19:52:26 +0000 |
| Subject: | Re: Introduce str_left/right In 8.1 | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115131@lists.php.net to get a copy of this message | ||
> On Jun 24, 2021, at 8:04 AM, G. P. B. <george.banyard@gmail.com> wrote:
>
> Moreover, the fact that only a very restricted number of programming
> languages, which are some of the earliest languages ever, implement those
> functions should tell you something about programming language design
> as a whole, which is that many people came to the conclusion that a variant
> of substring is a better abstraction than "left/right".
It think the distinction is not so much that is earlier vs. later languages, but who the target
market is for the languages. For languages that offer left() and right() function the average
developer skill for developers proficient in those language tends to be lower than for languages
that do not have those functions, compared on a absolute scale to the most highly-skilled
professional developers, of course.
Erlang has left() and right() string methods, and it is not an earlier language.
R is not an early language and it has StrLeft() and StrRight() but R is a language targeting data
scientists instead of hard core programmers.
Visual Basic is not earlier, but it is based on early Basic. That said it has always targeted more
line-of-business programmers than professional programmers.
Excel, which is an end-users tool has LEFT() and RIGHT() functions.
Wikipedia actual has a really nice comparison of languages on string handling:
- https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)#left
<https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)#left>
- https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)#right
<https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)#right>
So a question to ask about PHP we could collectively answer is: Who is the target market for PHP?
If we collectively want to forsake lower-skilled developers then no, it would not make sense to
include str_left()/str_right() because few programming languages targeting more advanced developers
do.
OTOH if we do want to maintain approachability for lower-skilled developers and allow them easier
success experiences then adding functions like str_left()/str_right() make a lot of sense.
Maybe it would make sense to have the community identify and define who PHP's target user is,
and then put that as a stake in the ground? If that were agreed and explicitly stated on PHP.net
<http://php.net/> for reference, it sure could help stop a lot
of bikeshedding and heated debates among people with different visions for the future of PHP.
#justsaying
----
That said, many newer languages use the indexing operator to extract substrings of length 2 or more,
which PHP does not.
Given your comment about early languages are you amenable to adding a substring indexing syntax to
PHP for strings and arrays?
I quite like how Swift does it, but there are many others:
- Swift: https://stackoverflow.com/a/39677331/102699
<https://stackoverflow.com/a/39677331/102699>
- Go: https://www.dotnetperls.com/substring-go <https://www.dotnetperls.com/substring-go>
- Python: https://runestone.academy/runestone/books/published/thinkcspy/Strings/IndexOperatorWorkingwiththeCharactersofaString.html
<https://runestone.academy/runestone/books/published/thinkcspy/Strings/IndexOperatorWorkingwiththeCharactersofaString.html>
- Ruby: https://stackoverflow.com/a/4528091/102699
<https://stackoverflow.com/a/4528091/102699>
- F#: https://dotnetcodr.com/2017/02/18/creating-substrings-in-f/
<https://dotnetcodr.com/2017/02/18/creating-substrings-in-f/>
- D: https://stackoverflow.com/a/20570677/102699
<https://stackoverflow.com/a/20570677/102699>
- Mathematica: https://reference.wolfram.com/language/ref/StringTake.html
<https://reference.wolfram.com/language/ref/StringTake.html>
-Mike