HN
Today

Small Programming Tricks

This post highlights that significant engineering productivity often stems from mastering small, high-leverage programming tricks across various domains. It resonates with Hacker News's audience, who are always keen on efficiency gains and tooling mastery, sparking a lively debate on the enduring relevance of such 'nuggets of knowledge' in the age of AI. The discussion delves into specific tool alternatives, best practices for sharing knowledge, and even philosophical debates on coding paradigms like branch avoidance.

83
Score
59
Comments
#1
Highest Rank
19h
on Front Page
First Seen
Sep 16, 4:00 PM
Last Seen
Sep 17, 10:00 AM
Rank Over Time
1212345566679889111213

The Lowdown

The article "Small Programming Tricks" argues that a surprising amount of engineering productivity comes from knowing specific, small, high-leverage bits of knowledge that don't require extensive supporting infrastructure. These "nuggets" can significantly ease work, even if they seem obvious once learned.

Key examples of these tricks include:

  • Enhanced Terminal History: Using tools like fzf, atuin, or per-directory-history to upgrade ctrl + r functionality in the shell.
  • SQL Utilities: Performing SELECT statements without a FROM clause for quick tests, and using EXPLAIN ANALYZE in PostgreSQL/MySQL for performance insights.
  • Regular Expressions: Leveraging the \b word boundary assertion for precise pattern matching.
  • Metrics Bucketing: Applying Math.log10 to categorize metric values for better distribution analysis.
  • Modern JavaScript Features: Highlighting the utility of Array.flatMap, Object.entries, and Promise.withResolvers.
  • Node.js Performance: Utilizing https.Agent to maintain persistent connections and reduce latency for external requests.
  • Git Commands: Discovering git log -S pattern (the "git pickaxe") to find commits that added or removed specific strings, and git checkout - for quickly switching to the previous branch/commit.
  • Shell Tool Alternatives: Advocating for glob patterns (**/*.md) over find for many use cases and recommending ripgrep (rg) over grep/ack/ag for faster searching.
  • Zsh Configuration: Enabling advanced autocompletion features in zsh for a more efficient command-line experience.

The author extends this concept to company-specific knowledge, such as knowing the right person to ask or the correct command for a rolling restart. They suggest that senior engineers share these types of daily tips, emphasizing that even if only one out of ten is new, it could save significant time for someone.

Ultimately, the piece champions the continuous accumulation and sharing of these practical, often overlooked, insights as a crucial element of engineering growth and efficiency.

The Gossip

AI vs. Manual Mastery

A significant portion of the discussion revolves around the relevance of these 'manual' programming tricks in an era increasingly dominated by AI coding assistants. Some commenters argue that AI makes many of these specific tools and memorized commands obsolete, replacing them with agent orchestration or prompt engineering. Others contend that while AI is useful for scaffolding or as a 'smart reference,' it hasn't replaced the fundamental act of hand-coding, particularly for complex or greenfield projects, and that understanding the underlying tools remains crucial for debugging and critical thinking. They highlight that AI is a tool, not a replacement for deep technical knowledge.

Sharing Savvy Snippets

The author's suggestion of sharing daily tricks on Slack sparked a debate about the best approach to knowledge sharing within teams. Some found the idea potentially annoying, suggesting that such frequent, broad communication could create noise, especially if the tips were already widely known or perceived as self-promotion. Others strongly defended the practice, emphasizing that sharing insights fosters team growth and that even one new trick can be valuable. Alternative suggestions included dedicated channels or personal blogs for curating and sharing these useful snippets.

Terminal and Git Triumphs

Many comments delved into specific terminal and Git tricks, either endorsing the article's suggestions or offering their own favorites and nuanced perspectives. The `ctrl+r` terminal history search was a popular topic, with users recommending tools like `fzf`, `zhist`, or `zoxide` for enhanced functionality, while others preferred simpler methods like `fish` shell's built-in history. The recommendation to replace `find` with globs and `grep` with `ripgrep` also saw discussion, with some pointing out edge cases where `find` remains indispensable (e.g., large file sets) or expressing preference for older tools like `ag` due to specific filtering syntaxes.

Branching Bewilderment

One commenter's assertion to 'avoid branches' in programming evolved into a detailed, if sometimes abstract, discussion. Initial reactions expressed confusion or skepticism about how or why one would avoid such a fundamental programming construct. Subsequent comments clarified that this often refers to minimizing explicit conditional statements (`if/else`) through techniques like polymorphism, lookup tables, fuzzy logic, or specialized routines, aiming for cleaner, potentially more performant, and sometimes more readable code. However, there was also a counter-argument that explicitly branched code can often be clearer and easier to understand, questioning the intrinsic benefit of 'branchless' code for readability.