Home / Companies / New Relic / Blog / November 2014

November 2014 Summaries

2 posts from New Relic

Filter
Month: Year:
Post Summaries Back to Blog
Ruby's begin-end block control structure is often overlooked but can have unexpected effects when combined with conditionals like `if`, `while`, and `until`. When used alone, a begin-end block doesn't change the behavior of the code. However, when paired with these conditionals, it can alter the execution path of the program. In one example, using a while loop with a false condition resulted in the code within the begin-end block being executed, despite the conditional checking for falseness. This demonstrates Ruby's do-while construct, which checks the post-condition after processing the body of the loop. The behavior can be surprising and may lead to confusion among developers unfamiliar with this syntax.
Nov 13, 2014 1,041 words in the original blog post.
This blog post, the first in a series on "Weird Ruby," explores the peculiar and often counterintuitive behaviors of the Ruby programming language, particularly the use of begin-end blocks and their interaction with conditionals. The author, inspired by insights gained from speaking at the Keep Ruby Weird conference, aims to offer an alternative perspective on these behaviors rather than just listing surprising Ruby code samples. The post illustrates that while standalone begin-end blocks do not change code behavior, when combined with constructs like while, they can lead to unexpected results due to Ruby's do-while loop construct. This loop allows the code within the begin-end block to execute at least once before checking the condition, a behavior that even the language's creator, Matz, has expressed regret over, suggesting a more intuitive loop-break construct. The author encourages readers to engage with Ruby's TracePoint feature for deeper exploration, while cautioning against its use in production environments due to potential performance issues.
Nov 13, 2014 1,124 words in the original blog post.