in Go, to format Error strings use fmt.Errorf or fmt.Sprintf to create error strings that are clear, concise, and informative. Include relevant details, such as the operation that failed or the specific values involved.
handling errors properly really saves debugging times
#tips #golang
func openFile(filename string) (io.Reader, error) {
file, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("failed to open file %s: %w", filename, err) // Wrap the error with context
}
return file, nil
}handling errors properly really saves debugging times
#tips #golang
A sniperβs dream FINAL VERSION || Khapiter.boy.s
MegaSaverBot
here's the full version of the song btw πΏ AI song artists be rocking
π1
A constant struggle, a ceaseless battle to bring success from inhospitable surroundings, is the price of all great achievements.
have a great day y'all βοΈ
β€1
ForwardingServiceRepositoryImpl (Archive)
She did it
ofc congrats to Jo. this guy is the reason i started a channel. he and @gugutlogs finally made it π
π₯11
hey mates π so i've been working on a site where anyone can learn and reference Golang materials. Here's the site link:
https://gopher-notes.netlify.app/
Gopher Notes is an archive of Go notes from different resources. I reviewed and edited each part so that the material is up-to-date.
Features:
- Clear and Concise Notes: so you actually retain the info (no more forgetting what a 'defer' statement does lol)
- Exercises that'll test your coding skills
- Bookmark Feature that'll let you bookmark any topic
- Wrapping Up Sections: Additionally, I included this section for every topic that is covered.
If you're starting out in Go or want quick references, check it out. Plus it's totally open-source (giving it a star is appreciated lol). Let's build some awesome Go stuff together! π
[GitHub Repo]
#MyProjects #GopherNotes #golang #resources
https://gopher-notes.netlify.app/
Gopher Notes is an archive of Go notes from different resources. I reviewed and edited each part so that the material is up-to-date.
Features:
- Clear and Concise Notes: so you actually retain the info (no more forgetting what a 'defer' statement does lol)
- Exercises that'll test your coding skills
- Bookmark Feature that'll let you bookmark any topic
- Wrapping Up Sections: Additionally, I included this section for every topic that is covered.
If you're starting out in Go or want quick references, check it out. Plus it's totally open-source (giving it a star is appreciated lol). Let's build some awesome Go stuff together! π
[GitHub Repo]
#MyProjects #GopherNotes #golang #resources
π₯27π2
Mira
hey mates π so i've been working on a site where anyone can learn and reference Golang materials. Here's the site link: https://gopher-notes.netlify.app/ Gopher Notes is an archive of Go notes from different resources. I reviewed and edited each part soβ¦
the bandwidth usage literally sky-rocketed π₯ glad that it turned out to be useful for people
π₯4
make nested conditionals one-dimensional! use early returns from a function rather than if/else chains. this is essential not only in the aspect of Go, but also in any language.
take a look at the following code snippet:
the above code adds cognitive load for someone who's reading ur code (the number of entities they need to think about is a lot, so they might be lost in ur code).
but take a look at the more idiomatic approach to the code:
it uses early returns (guard clauses) and provide a linear approach to logic trees
#tips #code
@Mi_Ra_Ch
take a look at the following code snippet:
func isValidPassword(password string) bool {
isValid := true
if len(password) < 8 {
isValid = false
} else {
if !containsUppercase(password) {
isValid = false
} else {
if !containsLowercase(password) {
isValid = false
} else {
if !containsNumber(password) {
isValid = false
}
}
}
}
return isValid
}
func containsUppercase(str string) bool {
// ... implementation ...
}
func containsLowercase(str string) bool {
// ... implementation ...
}
func containsNumber(str string) bool {
// ... implementation ...
}the above code adds cognitive load for someone who's reading ur code (the number of entities they need to think about is a lot, so they might be lost in ur code).
but take a look at the more idiomatic approach to the code:
func isValidPassword(password string) bool {
if len(password) < 8 {
return false
}
if !containsUppercase(password) {
return false
}
if !containsLowercase(password) {
return false
}
if !containsNumber(password) {
return false
}
return true
}
func containsUppercase(str string) bool {
// ... implementation ...
}
func containsLowercase(str string) bool {
// ... implementation ...
}
func containsNumber(str string) bool {
// ... implementation ...
}it uses early returns (guard clauses) and provide a linear approach to logic trees
#tips #code
@Mi_Ra_Ch
the JPEG-XL team at Google is teaming up with Firefox to make browsing experience safer and smoother.
why should you care? they're replacing the heavy decoder (100k+ lines of C++) with a lighter one built in Rust. this means faster load times and a more secure experience for all image-heavy sites (especially if you're like me who spends time on image-heavy sites). less bloat, more speedβit's a win a win! hope it gets shipped
#JPEGXL
@Mi_Ra_Ch
why should you care? they're replacing the heavy decoder (100k+ lines of C++) with a lighter one built in Rust. this means faster load times and a more secure experience for all image-heavy sites (especially if you're like me who spends time on image-heavy sites). less bloat, more speedβit's a win a win! hope it gets shipped
#JPEGXL
@Mi_Ra_Ch
ahh internet so bad rn cant even work. gotta be coz of national exam. good luck for everyone tho π
β€4
no offense to @DaveDumps but when it comes from the guy itself, you gotta accept the fate π hope OpenSUSE has improved a lot since then
hope you had a great new year β¨ for some of us it was just another Wednesday. but ngl the Doro Wet was π
this year i've decided to put pentest a little bit aside and focus more on computer networks and development side. will be sharing lots of cool stuff here. thanks for sticking around lol. may you be overflown by blessings this year π
this year i've decided to put pentest a little bit aside and focus more on computer networks and development side. will be sharing lots of cool stuff here. thanks for sticking around lol. may you be overflown by blessings this year π
β‘6π4β€2
APL (which stands for "A Programming Language" btw) was invented back in the 60s by this dude Kenneth E. Iverson. It's known for its super-concise syntax, which is basically like a bunch of symbols that make a program.
Here's how you'd do some basic stuff in APL:
Go took inspiration from APL's "Iota" operator (represented by
What's Up with "Iota"?
Iota basically means "a tiny bit" in Greek. In APL,
Go's slice notation (using
Why Should You Care?
APL might not be the "coolest" language on the block, but it's important for understanding how array manipulation works in a lot of modern languages. It's like the grandparent of all the cool kids. Next time you're working with arrays in Go, give a shout-out to APL.
Here are some other cool APL features that influenced other programming languages:
Reduction:
Rank:
Here's how you'd do some basic stuff in APL:
2 + 3 β Simple addition, you already knew this one
5 β Output
A β 1 2 3 4 β Assign vector A (like an array)
B β 5 6 7 8 β Another vector B
A + B β Add corresponding elements
6 8 10 12 β Output
A Γ B β Matrix multiplication (assuming A and B are matrices)
β ...Output would depend on the actual matrix values
A β.Γ B β Outer product
β Output: matrix with all possible combinations
Go took inspiration from APL's "Iota" operator (represented by
β³). Iota's all about generating sequences of numbers, which is super helpful when you're working with arrays.What's Up with "Iota"?
Iota basically means "a tiny bit" in Greek. In APL,
β³n gives you a vector of numbers from 1 to n. So, β³5 would be like 1 2 3 4 5. Go's slice notation (using
: to extract parts of an array) is like a tribute to APL's Iota. It's all about making array manipulation easier and more intuitive. package main
import "fmt"
func main() {
arr := []int{1, 2, 3, 4, 5}
fmt.Println(arr[1:3]) // Output: [2 3]
}
Why Should You Care?
APL might not be the "coolest" language on the block, but it's important for understanding how array manipulation works in a lot of modern languages. It's like the grandparent of all the cool kids. Next time you're working with arrays in Go, give a shout-out to APL.
Here are some other cool APL features that influenced other programming languages:
Reduction:
+/A sums all elements in the array A.Rank:
β΄A returns the shape of the array A.something i came to realize these days, everyone tells you "Life is short"; but only few of em reminds you that there's an eternal life waiting for ya. in fact, the phrase "Life is short" is behind all my worst decisions, but i think it's important to enjoy life while still you got the time. this doesn't mean you should live carelessly either. you gotta be able to think of the eternal life, and evaluate your actions; "Are my actions worthy of the eternal life?"
β€8