4 ms·
Golang gets zero points from me because function receivers are declared between func and the name of the function. God ai hate this design choice and boy am I g
by eptcyka 2y ago
Golang gets zero points from me because function receivers are declared between func and the name of the function. God ai hate this design choice and boy am I glad I can use golsp.
- alienchow 2y agoI very rarely use literal grep at all. Perl grep is my standard goto. For functions: grep -P '^func funcName\(' For methods: grep -P '^func [^)]+\) methodName\('
- aadhavans 2y agoWhat about piped grep statements? grep func | grep functionName
- medstrom 2y agoIs it just hard to get used to, or does it fundamentally make something more difficult?
- ljm 2y agoCan’t say I’ve ever had an issue with it, but it does get a bit wild when you have a function signature that takes a function and returns one, unless you clear it up with some types. func (s *Recv) foo(fn func(x any) err) func bar(y any) (*Recv, err) As an exaggerated example. Easy to parse but not always easy to read at a glance.
- kragen 2y agothis thread is about using `grep` to find things, and this subthread is specifically about how the `func` keyword in golang makes it easy to distinguish the definition of a function from its uses, so yes, because `grep 'func lart('` will not find definitions of `lart` as a method. you might end up with something like `grep 'func .*) *lart('` which is both imprecise and enough noise that you will not want to type it; you'll have to can it in a script, with the associated losses of flexibility and transparency
- alienchow 2y agoFor functions: grep -P '^func funcName\(' For methods: grep -P '^func [^)]+\) methodName\(' Hope that helps.
- kragen 2y agothanks, that definitely looks better! pcre is kind of working against you here tho; i assume you're invoking it out of habit
- alienchow 2y agoI am actually unaware of downsides of PCRE. Could you explain? I hardly ever use literal grep nowadays.
- kragen 2y agooh, i mean that instead of grep -P '^func [^)]+\) methodName\(' you could say grep 'func [^)]*) methodName(' which is a bit less typing however, i have to admit that i sort of ensnared myself in my own noose here by being too clever! i forgot that grep's regexp dialect only supports + if you \ it, and it took me six tries to figure out why i wasn't getting any grep hits. there's a lot to be said for the predictability and consistency of pcre!
- kiitos 2y agoNo need for any func, you can just grep '\) methodName\('
- kragen 2y agogrep: Unmatched ) or \) but your main point might be right; the few non-method matches to (pcre) '\)\s*\w+\s*\(' in /usr/share/go-1.19 seem to be uncommon things like this: static void __attribute__ ((constructor)) sigsetup(void) { void poison() __attribute__ ((weak)); C3 = -(R + I) // ADD(5,6) NEG(-5,-6)
- eptcyka 2y agoI have to always add wildcards between func and the function name, because I can never know how the other developer has decided to specify the name of the receiver. This will always be a problem as far as grepping with primitive tools that don't parse the language.
- medstrom 2y agoFYI, many people use thin wrappers like this, it's still a primitive tool that doesn't parse the language, but it can handle that problem: https://jumpshare.com/s/zMENBSr2LwwauJVjo1wS https://jumpshare.com/s/zMENBSr2LwwauJVjo1wS (GIF)
- sethammons 2y agoI search ") myFunc" to find member functions. It would be nice to search "c myFunc", but a parentheses works
- db48x 2y agoYea, that was my workaround for Go as well. Go both gains and loses points here.
- executesorder66 2y agoHow many God AI's have expressed their hate for this design? /s
- kazinator 2y agoReceivers are utterly idiotic. Like how could anyone with two working brain cells sign off on something like that? If you don't want OOP in the language, but want people to be able to write thing.function(arg), you just make function(thing, arg) and thing.function(arg) equivalent syntax.
- db48x 2y agoI completely agree with that.
- Pxtl 2y agoC# did this for extension methods and it Just Works. You just add the "this" keyword to a function in a pure-static class and you get method-like calling on the first param of that function.
- kazinator 2y agoIf the function has to be modified in any way in order to grant permission to be used that way, then it is not quite "did this". Equivalent means that there is no difference at the AST level between o.f(a) and f(o, a), like there is no difference in C among (a + i), a[i], i[a] and (i + a). However, a this keyword is way better than making the programmers fraction off a parameter and move it to the other side of the function name.
- tczMUFlmoNk 2y agoA search term here is "Uniform Function Call Syntax", as present in (e.g.) D: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax