Hi Flo, this is a great nugget of knowledge. The cmp package has escaped me until watching this video. One of golangs biggest mistakes in my opinion is the lack of a ternary operator resulting in either ugly code or complicated work arounds. My complicated weapon of choice up to now has been to use a third party package lo which provides functional programming features, one of which is a ternary function. However this could be replaced by using the cmp.Or that you so greatly describe in this presentation. I have hundreds of cases in my own projects that could be replaced using this technique, so thanks. (As good as the cmp.Or solution is, it is still a sub optimal solution in many cases, because all entries have to be evaluated first. If the golang team gave us a proper ternary operator then we wouldn’t have this problem 😤. I read their many foolish arguments about why they omit this feature on the grounds of simplicity, but by omitting it they greatly force us to write either crap or inefficient clumsy code. I just think now they don’t want to provide it because that would mean them having to admit they are wrong; especially when you consider the unnecessary complicated features they have given us, most recently the ability to iterate a function which I remember you describing in a recent video about the new features of golang version 1.23. I wrote my own iterators ages ago and I see no reason to replace mine with theirs)
Hi again Flo, I noticed a really nice feature that you’re using in your ide (vscode?) that I’m wondering how you achieve. When writing the code to invoke a function with a complicated signature I noticed that somehow as you type, the full signature is spit out into the editor window which you type over. How do you do this? Which plugin is responsible for this? I would appreciate it if you could share this as I have been in this situation many frustrating times and the way I do it is frankly prehistoric; I F2 the function name, then manually copy the signature and paste it back into my own code into a comment, then proceed from there. I need to stop dragging my knuckles along the floor as quite frankly then are getting pretty sore! Thanks in advance
I don't think I'll ever use this function. What if one of the functions return additional values or error? usually I do this func getPort(defaultPort string) string { port := getPortFromFlag() if port != "" { return port } port = os.Getenv("PORT") if port != "" { return port } port = getPortFromWhatever() if port != "" { return port } return defaultPort } and call that function in the main function. The cmp.Compare() function cool I guess, but the use case is really specific
Slice inside the function should be copied.. not just assigned pointer to the same "parameter" slice sorted := make([]employee, len(orig)) copy(sorted, orig) right?
@FloWoelki It feels as if VSCode was the standard today and everything else needed an explanation. So, why did you choose Zed, to whom would you recommend it and what did you do for it to work so well with Golang?
sorting use case was just brilliant. Complex logic portrayed with simpler example!
There was just some sort of beauty in it, right? :D
@@FloWoelki exactly bro
Great video Flo. Greetings from Egypt!
Thank you for watching! :) Greetings back!
Hi Flo, this is a great nugget of knowledge. The cmp package has escaped me until watching this video. One of golangs biggest mistakes in my opinion is the lack of a ternary operator resulting in either ugly code or complicated work arounds. My complicated weapon of choice up to now has been to use a third party package lo which provides functional programming features, one of which is a ternary function. However this could be replaced by using the cmp.Or that you so greatly describe in this presentation. I have hundreds of cases in my own projects that could be replaced using this technique, so thanks. (As good as the cmp.Or solution is, it is still a sub optimal solution in many cases, because all entries have to be evaluated first. If the golang team gave us a proper ternary operator then we wouldn’t have this problem 😤. I read their many foolish arguments about why they omit this feature on the grounds of simplicity, but by omitting it they greatly force us to write either crap or inefficient clumsy code. I just think now they don’t want to provide it because that would mean them having to admit they are wrong; especially when you consider the unnecessary complicated features they have given us, most recently the ability to iterate a function which I remember you describing in a recent video about the new features of golang version 1.23. I wrote my own iterators ages ago and I see no reason to replace mine with theirs)
Hi again Flo, I noticed a really nice feature that you’re using in your ide (vscode?) that I’m wondering how you achieve. When writing the code to invoke a function with a complicated signature I noticed that somehow as you type, the full signature is spit out into the editor window which you type over. How do you do this? Which plugin is responsible for this? I would appreciate it if you could share this as I have been in this situation many frustrating times and the way I do it is frankly prehistoric; I F2 the function name, then manually copy the signature and paste it back into my own code into a comment, then proceed from there. I need to stop dragging my knuckles along the floor as quite frankly then are getting pretty sore! Thanks in advance
I don't think I'll ever use this function. What if one of the functions return additional values or error?
usually I do this
func getPort(defaultPort string) string {
port := getPortFromFlag()
if port != "" {
return port
}
port = os.Getenv("PORT")
if port != "" {
return port
}
port = getPortFromWhatever()
if port != "" {
return port
}
return defaultPort
}
and call that function in the main function.
The cmp.Compare() function cool I guess, but the use case is really specific
I agree; it really depends on the specific use case. But overall, it would be nice to have additional syntactical sugar for your Go code.
Slice inside the function should be copied.. not just assigned pointer to the same "parameter" slice sorted := make([]employee, len(orig))
copy(sorted, orig) right?
what’s your ide and font? btw nice usecase. I think I might going to use that in future
Awesome stuff! :)
Generally, I do use Zed with the official GitHub theme. The GitHub theme is also available for vsc or nvim.
Would you consider a video on using zed with Golang?
@@HarmonicaTool sure. Do you have something specific in mind?
@FloWoelki It feels as if VSCode was the standard today and everything else needed an explanation. So, why did you choose Zed, to whom would you recommend it and what did you do for it to work so well with Golang?
@@HarmonicaTool interesting idea. Thanks I'll try to think of a possible video :)
nice explanation
Thank you for the feedback :)
nice video
Thank you :)