This project introduces "SHORTY," a C++ utility that aims to make lambdas more concise. It achieves this by providing a macro-based system that replaces standard lambda syntax with a shorter, more symbolic representation. Essentially, SHORTY allows developers to define and use lambdas with fewer characters, potentially improving code readability in some cases by reducing boilerplate. However, this comes at the cost of relying on macros and introducing a new syntax that deviates from standard C++. The project documentation argues that the benefits in brevity outweigh the costs for certain use cases.
Steve Losh's "Teach, Don't Tell" advocates for a more effective approach to conveying technical information, particularly in programming tutorials. Instead of simply listing steps ("telling"), he encourages explaining the why behind each action, empowering learners to adapt and solve future problems independently. This involves revealing the author's thought process, exploring alternative approaches, and highlighting potential pitfalls. By focusing on the underlying principles and rationale, tutorials become less about rote memorization and more about fostering genuine understanding and problem-solving skills.
Hacker News users generally agreed with the "teach, don't tell" philosophy for giving feedback, particularly in programming. Several commenters shared anecdotes about its effectiveness in mentoring and code reviews, highlighting the benefits of guiding someone to a solution rather than simply providing it. Some discussed the importance of patience and understanding the learner's perspective. One compelling comment pointed out the subtle difference between explaining how to do something versus why it should be done a certain way, emphasizing the latter as key to fostering true understanding. Another cautioned against taking the principle to an extreme, noting that sometimes directly telling is the most efficient approach. A few commenters also appreciated the article's emphasis on avoiding assumptions about the learner's knowledge.
The blog post "What makes code hard to read: Visual patterns of complexity" explores how visual patterns in code impact readability, arguing that complexity isn't solely about logic but also visual structure. It identifies several patterns that hinder readability: deep nesting (excessive indentation), wide lines forcing horizontal scrolling, fragmented logic scattered across the screen, and inconsistent indentation disrupting vertical scanning. The author advocates for writing "calm" code, characterized by shallow nesting, narrow code blocks, localized logic, and consistent formatting, allowing developers to quickly grasp the overall structure and flow of the code. The post uses Python examples to illustrate these patterns and demonstrates how refactoring can significantly improve visual clarity, even without altering functionality.
HN commenters largely agree with the article's premise that visual complexity hinders code readability. Several highlight the importance of consistency in formatting and indentation, noting how deviations create visual noise that distracts from the code's logic. Some discuss specific patterns mentioned in the article, like deep nesting and arrow anti-patterns, offering personal anecdotes and suggesting mitigation strategies like extracting functions or using guard clauses. Others expand on the article's points by mentioning the cognitive load imposed by inconsistent naming conventions and the helpfulness of visual aids like syntax highlighting and code folding. A few commenters offer alternative perspectives, arguing that while visual complexity can be a symptom of deeper issues, it isn't the root cause of hard-to-read code. They emphasize the importance of clear logic and good design over purely visual aspects. There's also discussion around the subjective nature of code readability and the challenge of defining objective metrics for it.
Refactoring, while often beneficial, should not be undertaken without careful consideration. The blog post argues against refactoring for its own sake, emphasizing that it should be driven by a clear purpose, like improving performance, adding features, or fixing bugs. Blindly pursuing "clean code" or preemptive refactoring can introduce new bugs, create unnecessary complexity, and waste valuable time. Instead, refactoring should be a strategic tool used to address specific problems and improve the maintainability of code that is actively being worked on, not a constant, isolated activity. Essentially, refactor with a goal, not just for aesthetic reasons.
Hacker News users generally disagreed with the premise of the blog post, arguing that refactoring is crucial for maintaining code quality and developer velocity. Several commenters pointed out that the article conflates refactoring with rewriting, which are distinct activities. Others suggested the author's negative experiences stemmed from poorly executed refactors, rather than refactoring itself. The top comments highlighted the long-term benefits of refactoring, including reduced technical debt, improved readability, and easier debugging. Some users shared personal anecdotes about successful refactoring efforts, while others offered practical advice on when and how to refactor effectively. A few conceded that excessive or unnecessary refactoring can be detrimental, but emphasized that this doesn't negate the value of thoughtful refactoring.
The author argues that Knuth's vision of literate programming, where code is written for humans within a narrative explaining its logic, hasn't achieved mainstream adoption because it fundamentally misunderstands the nature of programming. Rather than a linear, top-down process suitable for narrative explanation, programming is inherently exploratory and iterative, involving frequent refactoring and restructuring. Literate programming tools force a rigid structure onto this fluid process, making it cumbersome and ultimately counterproductive. The author proposes "exploratory programming" as a more realistic approach, emphasizing tools that facilitate quick exploration, refactoring, and visualization of code relationships, allowing understanding to emerge organically from the code itself.
Hacker News users discuss the merits and flaws of Knuth's literate programming style. Some argue that his approach, while elegant, prioritizes code as literature over practicality, making it difficult to navigate and modify, particularly in larger projects. Others counter that the core concept of intertwining code and explanation remains valuable, but modern tooling like Jupyter notebooks and embedded documentation offer better solutions. The thread also explores alternative approaches like docstrings and the use of comments to generate documentation, emphasizing the importance of clear and concise explanations within the codebase itself. Several commenters highlight the benefits of separating documentation from code for maintainability and flexibility, suggesting that the ideal approach depends on the project's scale and complexity. The original post is criticized for misrepresenting Knuth's views and focusing too heavily on superficial aspects like tool choice rather than the underlying philosophy.
Summary of Comments ( 14 )
https://news.ycombinator.com/item?id=43629380
HN users largely discussed the potential downsides of Shorty, a C++ library for terser lambdas. Concerns included readability and maintainability suffering due to excessive brevity, especially for those unfamiliar with the library. Some argued against introducing more cryptic syntax to C++, preferring explicitness over extreme conciseness. Others questioned the practical benefits, suggesting existing lambda syntax is sufficient and the library's complexity outweighs its advantages. A few commenters expressed mild interest, acknowledging the potential for niche use cases but emphasizing the importance of careful consideration before widespread adoption. Several also debated the library's naming conventions and overall design choices.
The Hacker News post discussing the "shorty" C++ header for terser lambdas generated a moderate amount of discussion, mostly focused on the potential downsides and alternatives to the approach.
Several commenters expressed concern over the readability and maintainability of code using
shorty
. One commenter argued that while brevity can be good, excessive terseness can harm readability, especially for those unfamiliar with theshorty
syntax. They suggested that the potential gains in character count are outweighed by the increased cognitive load required to understand the code. Another user echoed this sentiment, pointing out that C++ is already a complex language, and adding more cryptic syntax likeshorty
further exacerbates the issue. They questioned the real-world benefit, suggesting that saving a few keystrokes is not worth the potential confusion.The discussion also touched upon the potential for namespace pollution and name clashes. One commenter pointed out the risk of unintended consequences when using generic short names like those provided by
shorty
, especially in larger projects. They suggested that more descriptive lambda names, even if longer, are generally preferable for clarity.Alternatives to
shorty
were also proposed. One user mentioned using an editor snippet or macro to achieve similar brevity without introducing new syntax. Another suggested leveraging existing C++ features likeauto
and structured bindings to simplify code without sacrificing readability. A commenter highlighted the benefits of refactoring complex logic into separate functions, thereby reducing the need for lengthy lambdas in the first place. They argued this approach often leads to more organized and understandable code.A few comments briefly acknowledged the potential usefulness of
shorty
in specific, limited contexts, such as competitive programming or code golfing, where character count is paramount. However, the general consensus seemed to be that for most practical applications, the potential drawbacks ofshorty
outweigh its benefits. There was a clear preference for maintaining code clarity and readability over achieving extreme terseness.