On Thu, 24 Jun 2021 at 07:20, Hamza Ahmad <office.hamzaah...@gmail.com>
wrote:

> HI George,
>
> > I really don't see the point of these functions.
>
> These functions provide a clearer semantics for their usage.


Are they though? The naming doesn't convey anything as pointed out by Kamil.



> Substr,
> as Sara has mentioned, can be an alternative to these functions. Does
> it make clear that substr returns the either ends of a string? No,
> substr returns a part of a string, not ends. Although both mean
> similar, and substr can be used in absence of these functions, saying
> so is not linguisticly true!
>

This is factually wrong, the first/last n characters of a string IS a
substring of the original string. And by that logic left and right are
actually linguistically incorrect due to languages being read Right to Left
or Top to Bottom.


> If these functions are added, one can make sense of what these
> functions actually do, without involving extra thought process.
> Furthermore, it will help code readers decode their purpose at the
> cognitive level, and that will provide with a faster understanding of
> the code. Therefore, Microsoft is using AI to design a clearer
> language to aid human minds understand quickly. I don't know how your
> mind functions, but allow me to explain my thought process. When I see
> substr, my mind says it is going to be a part of string from x offset
> to y offset. Then, I look at the offsets, I learn that it is either
> going to be a left end or a right end. If these functions are added to
> PHP, programmers will have a clear idea of what is going on there
> using a single thought. You are free to accuse me of mixing both
> psychology and computer science.
>

A language, be that spoken or programming, provides you with building
blocks that you can combine to form larger constructs to express thoughts
or a logical operation. Here you are basically asking to add a whole new set
of half done constructions just because you didn't know a fundamental
aspect of the PHP language, which is that string offsets can be negative,
a fact that you can use broadly across the language.

Now, why did you not know this is a more interesting question to solve,
is it documentation? You never needed to do this before? etc.

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".

I'll indulge you in my thought process which plainly is, "oh I'm extracting
part of this string, oh this takes the first/last n bytes, fair enough",
contrast this with how you'd need to perform str_contains() previously
strpos($haystack, $needle) !== false
"Okay I'm looking to find if a needle is in a haystack here, ... wait,
am I because of the false? Ah no we're looking that it's just *somewhere*
in the haystack"
Which is fastly more complex and prone to logic errors if you need to
touch this segment, a substring on the other hand, is always a substring.


> Because the time is approaching, what do you all suggest whether this
> request requires an RFC?
>
> I thank you all for providing me with your opinions. I wish this
> thread leads a positive consensus.
>

Yes this requires an RFC, just by this thread alone you should realize
this is controversial, and I'll personally vote against it because there is
no advantage to have this in core at all.

Regards,

George P. Banyard

Reply via email to