Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Volker Dobler
On Thursday, 9 November 2023 at 18:35:38 UTC+1 Viktoriia Kapyrina 
Yelizarova wrote:

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


Except that almost all implementations of array_intersect
either have strange edge case (NaNs), have unintuitive semantics
(function equality), are awkward to use (callback/predicate hell)
or are dangerous to use (hidden runtime explosion).

The _simple_ cases are simple, but these are _simple_ and
stuff like array_intersect  don't provide much benefit here.

V.

-- 
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/c11f4276-c802-4adb-b72d-7040dab317e8n%40googlegroups.com.


[go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread ahuigo
Instead of reflect library. I'd like to recommend this generic 
library https://github.com/samber/lo.

It's very convenient than reflect, and I've been using it for a long time.

If you are not familiar about how to use it, ask GPT4(GPT3.5 does't know it)
On Friday, June 20, 2014 at 4:47:38 PM UTC+8 小菜 wrote:

>
> I  think in Golang, Array, Slice, and Map , all of them are very difficult 
> to use。
>
> For example, I want to check whether an element in the array, get all 
> the map key, or the map value into slice,
>
> With two slice,  intersection or union, the Slice sort, map sort, I found 
> that the operation has no official function support, there is no 
> official  package, so it is very difficult to use, not a 
> standard, efficient way.
>
> Perhaps Golang should like PHP/Python built-in some common operations,  
> Programming 
> language is used to solve practical problems。
>
>
> Reference resources.
>
> Http://us1.php.net/manual/en/ref.array.php 
> 
>
>
>
>- array_change_key_case 
> — 
>Changes the case of all keys in an array
>- array_chunk  — 
>Split an array into chunks
>- array_column  — 
>Return the values from a single column in the input array
>- array_combine 
> — Creates an 
>array by using one array for keys and another for its values
>- array_count_values 
> — 
>Counts all the values of an array
>- array_diff_assoc 
> — 
>Computes the difference of arrays with additional index check
>- array_diff_key 
> — Computes 
>the difference of arrays using keys for comparison
>- array_diff_uassoc 
> — 
>Computes the difference of arrays with additional index check which is 
>performed by a user supplied callback function
>- array_diff_ukey 
> — Computes 
>the difference of arrays using a callback function on the keys for 
>comparison
>- array_diff  — 
>Computes the difference of arrays
>- array_fill_keys 
> — Fill an 
>array with values, specifying keys
>- array_fill  — 
>Fill an array with values
>- array_filter  — 
>Filters elements of an array using a callback function
>- array_flip  — 
>Exchanges all keys with their associated values in an array
>- array_intersect_assoc 
> — 
>Computes the intersection of arrays with additional index check
>- array_intersect_key 
> — 
>Computes the intersection of arrays using keys for comparison
>- array_intersect_uassoc 
> — 
>Computes the intersection of arrays with additional index check, compares 
>indexes by a callback function
>- array_intersect_ukey 
> — 
>Computes the intersection of arrays using a callback function on the keys 
>for comparison
>- array_intersect 
> — Computes 
>the intersection of arrays
>- array_key_exists 
> — Checks 
>if the given key or index exists in the array
>- array_keys  — 
>Return all the keys or a subset of the keys of an array
>- array_map  — 
>Applies the callback to the elements of the given arrays
>- array_merge_recursive 
> — 
>Merge two or more arrays recursively
>- array_merge  — 
>Merge one or more arrays
>- array_multisort 
> — Sort 
>multiple or multi-dimensional arrays
>- array_pad  — 
>Pad array to the specified length with a value
>- array_pop 

Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Mike Schinkel
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.


Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Viktoriia Kapyrina Yelizarova
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/efbffb73-7ef1-43aa-bac0-07bde66ddbf4n%40googlegroups.com.