Common code smells in C/C++ and how to fix them. Memory Leaks 1// ❌ Bad 2void process() { 3 int* data = new int[100]; 4 // ... use data ... 5 // forgot to delete! 6} 7 8// ✅ Good: Use RAII 9void process() { 10 std::vector<int> data(100); 11 // ... use data ... 12 // automatically cleaned up 13} 14 15// ✅ Good: …
Read MoreSecure coding practices for C/C++ applications. Buffer Overflow Prevention 1// ❌ Vulnerable 2char buffer[100]; 3gets(buffer); // Never use! 4sprintf(buffer, "%s", user_input); 5 6// ✅ Secure 7char buffer[100]; 8fgets(buffer, sizeof(buffer), stdin); 9snprintf(buffer, sizeof(buffer), "%s", user_input); …
Read MoreTools for checking vulnerabilities in C/C++ code. Valgrind 1# Install 2sudo apt install valgrind 3 4# Check memory leaks 5valgrind --leak-check=full ./program 6 7# Detailed output 8valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./program AddressSanitizer (ASan) 1# Compile with ASan 2gcc …
Read MoreCommon software antipatterns to avoid across all languages and architectures. God Object Problem: One class/module does everything. Example: 1class Application: 2 def connect_database(self): pass 3 def send_email(self): pass 4 def process_payment(self): pass 5 def generate_report(self): pass 6 def …
Read MoreCommon code smells to watch for during code reviews with examples and fixes. Long Methods Problem: Methods that do too many things are hard to understand, test, and maintain. 1// ❌ Bad: 200-line method doing everything 2function processOrder(order) { 3 // validate order 4 if (!order.id) throw new Error("Invalid …
Read MoreComprehensive checklist for developers before submitting a pull request. Code Quality 1□ Code follows project style guide and conventions 2□ No commented-out code (remove or explain why it's there) 3□ No debug statements (console.log, print, etc.) 4□ No TODO comments without issue references 5□ Variable and …
Read MoreCommon code smells in Go and how to fix them. Ignoring Errors 1// ❌ Bad 2result, _ := doSomething() 3 4// ✅ Good 5result, err := doSomething() 6if err != nil { 7 return fmt.Errorf("failed: %w", err) 8} Not Using defer 1// ❌ Bad 2file, err := os.Open("file.txt") 3if err != nil { 4 return err 5} 6data, …
Read MoreSecure coding practices for Go applications. SQL Injection Prevention 1// ❌ Vulnerable 2username := r.FormValue("username") 3query := fmt.Sprintf("SELECT * FROM users WHERE username = '%s'", username) 4db.Query(query) 5 6// ✅ Secure 7username := r.FormValue("username") 8query := …
Read MoreTools for checking vulnerabilities in Go code. Govulncheck 1# Install 2go install golang.org/x/vuln/cmd/govulncheck@latest 3 4# Check current module 5govulncheck ./... 6 7# JSON output 8govulncheck -json ./... Gosec 1# Install 2go install github.com/securego/gosec/v2/cmd/gosec@latest 3 4# Scan project 5gosec ./... 6 7# …
Read MoreCommon code smells in Haskell and how to fix them. Partial Functions 1-- ❌ Bad: head can fail 2getFirst :: [a] -> a 3getFirst xs = head xs 4 5-- ✅ Good: Use Maybe 6getFirst :: [a] -> Maybe a 7getFirst [] = Nothing 8getFirst (x:_) = Just x Not Using Pattern Matching 1-- ❌ Bad 2processResult :: Either String Int …
Read MoreSecure coding practices for Haskell applications. SQL Injection Prevention 1-- ❌ Vulnerable 2import Database.PostgreSQL.Simple 3getUserBad :: Connection -> String -> IO [User] 4getUserBad conn username = 5 query_ conn $ fromString $ "SELECT * FROM users WHERE username = '" ++ username ++ …
Read MoreTools for checking vulnerabilities in Haskell code. Cabal Outdated 1# Check outdated dependencies 2cabal outdated 3 4# Update dependencies 5cabal update 6cabal install --only-dependencies HLint 1# Install 2cabal install hlint 3 4# Run on project 5hlint src/ 6 7# Apply suggestions 8hlint src/ --refactor …
Read MoreCommon code smells in Python and how to fix them. Mutable Default Arguments 1# ❌ Bad: Mutable default argument 2def append_to_list(item, my_list=[]): 3 my_list.append(item) 4 return my_list 5 6print(append_to_list(1)) # [1] 7print(append_to_list(2)) # [1, 2] - Unexpected! 8 9# ✅ Good: Use None as default 10def …
Read More