Hi Vicktoriia,

Go has reflection:  https://pkg.go.dev/reflect

And in its various packages it also has many (though not all) of the types 
of functions mentioned above that PHP has:

   - https://pkg.go.dev/slices & https://pkg.go.dev/golang.org/x/exp/slices
   - https://pkg.go.dev/maps & https://pkg.go.dev/golang.org/x/exp/maps
   - https://pkg.go.dev/strings
   - https://pkg.go.dev/sort
   
Go does not have equivalent functions for working with PHP-style arrays 
because it does not support PHP style arrays. Few other languages (any?) 
do, in part I think because they are weird, and likely hard to make 
performant. But in Go you can simulate them with `map[any]any` I think.

Before Go, I spent around a decade working in PHP. After about 6 months I 
never wanted to work in PHP again.  One of the reasons PHP has so many 
array functions is that you cannot make low-level data manipulation 
functions performant, such as working character by character, or executing 
many loops. So PHP *needs* to have them in its standard library in order to 
be usable.

Go OTOH handles low-lever data manipulation performantly, so there is not 
nearly as much need to have every conceivable array operation in the 
standard library like there is in PHP.  Over the five years I've been 
coding in Go the Go team has added many functions to the standard library, 
including many of those from the links I included above. 

So It is quite possible the Go team will add a function to create an 
intersection and a union of slices to the standard lib at some point. And 
this is especially true since Generics are a recent addition and their 
inclusion allows functions to apply to many different data types. This 
means there is now arguable benefit for the Go team to add some of the 
functionality they are missing when compared to PHP.

But even if they do not, it would be trivial to write many of them and add 
them to your own package of functions, publish them to GitHub, and then 
they would also be just an import statement away.

If you are new to Go, allow yourself to get to know it for several months 
before judging it.  If you are anything like me, you will come to 
appreciate Go by leaps and bounds more than working with PHP. #fwiw

-Mike 

On Thursday, November 9, 2023 at 12:35:38 PM UTC-5 Viktoriia Kapyrina 
Yelizarova wrote:

> Well, reflection is one of the things I love in language and it is a 
> "must".  
>  On the other hand, the automation is exactly what common libraries do, I 
> can not find any reason to make a loops if they are repeated actions which 
> might be implemented in general library.  array_intersect is a common 
> example of automation. It makes no sense to right it again and again as it 
> is common operation which works the same way. 
> On Sunday, June 22, 2014 at 12:08:50 AM UTC+3 Milan P. Stanic wrote:
>
>> On Fri, 2014-06-20 at 04:57, Larry Clapp wrote: 
>> > I don't know PHP, but from what I've seen of it, it looks a lot like 
>> Perl. 
>> > I know Perl fairly well. 
>> > 
>> > One of the key differences between Perl and Go (and possibly PHP and 
>> Go) is 
>> > that Go has structs and Perl has only hashes (as far as named data 
>> > structures)[1]. It's very important to not try to write Perl in Go 
>> (i.e. 
>> > duplicating your Perl hashes in Go hashes, etc), but write more native, 
>> > idiomatic Go, that takes full advantage of Go's structs and other 
>> native 
>> > data structures. 
>>
>> From my PoV main difference is that the Go is strongly typed while most 
>> 'scripting' languages (Perl, PHP, Python etc.) are untyped (weak typed 
>> or whatever) and I don't like to argue what typing means). 
>> [...] 
>>
>> -- 
>> Best regards 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/315dcbb3-cf56-45d6-a4d7-57691209d6b9n%40googlegroups.com.

Reply via email to