# if statement

A programming statement that conditionally executes one or more statements based on the value of a Boolean or logical expression, with optional else or elsif branches.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Rivet split one Jev question into six

DevFeed: [Rivet split one Jev question into six](<https://devfeed.tech/articles/rivet-split-one-jev-question-into-six-146090.md>)

Original publisher: [Read original article](<https://jevdaily.com/issues/2026-11-19>)

Author: Jev Daily

Published: 2026-11-19T17:00:00Z

Content type: article

Language: en

Sources: [Jev Daily](<https://devfeed.tech/sources/jev-daily.md>)

Topics: [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [built-with-it](<https://devfeed.tech/tags/built-with-it.md>), [classifier](<https://devfeed.tech/tags/classifier.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [engineers](<https://devfeed.tech/tags/engineers.md>), [gemini](<https://devfeed.tech/tags/gemini.md>), [jev](<https://devfeed.tech/tags/jev.md>), [question](<https://devfeed.tech/tags/question.md>), [results](<https://devfeed.tech/tags/results.md>), [split](<https://devfeed.tech/tags/split.md>), [support](<https://devfeed.tech/tags/support.md>), [the-case-against](<https://devfeed.tech/tags/the-case-against.md>), [ticket](<https://devfeed.tech/tags/ticket.md>), [writing-criteria](<https://devfeed.tech/tags/writing-criteria.md>)

### AI overview

Rivet found that Jev classified ticket severity poorly when asked to choose SEV1-SEV4 in one step. Asking three yes/no questions--whether the issue is down, blocked, or broken--and ranking the answers with simple if-statements produced a working classifier. Nathan Flurry says Rivet built its support system with Rivet and Jev, reducing time to resolve hard engineering tickets to 5h 1m; human engineers still staff support, with models assisting. The excerpt also notes that Rivet had previously used Plain, which Flurry called its best attempt so far.

### Source excerpt

Nathan Flurry says Rivet asked Jev for a ticket's severity in one question and got mediocre results, then got a working classifier by asking three yes/no...

## Representative Line: Terning White as a (Style)Sheet

DevFeed: [Representative Line: Terning White as a (Style)Sheet](<https://devfeed.tech/articles/representative-line-terning-white-as-a-style-sheet-141923.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/terning-white-as-a-style-sheet>)

Author: Remy Porter

Published: 2026-11-18T06:30:00Z

Content type: article

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [PHP](<https://devfeed.tech/topics/php.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [boolean](<https://devfeed.tech/tags/boolean.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [developer](<https://devfeed.tech/tags/developer.md>), [development](<https://devfeed.tech/tags/development.md>), [easy](<https://devfeed.tech/tags/easy.md>), [examples](<https://devfeed.tech/tags/examples.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [helpdesk](<https://devfeed.tech/tags/helpdesk.md>), [idea](<https://devfeed.tech/tags/idea.md>), [pattern](<https://devfeed.tech/tags/pattern.md>), [php](<https://devfeed.tech/tags/php.md>), [processing](<https://devfeed.tech/tags/processing.md>), [regular](<https://devfeed.tech/tags/regular.md>), [representative-line](<https://devfeed.tech/tags/representative-line.md>), [shouldn-t](<https://devfeed.tech/tags/shouldn-t.md>), [style](<https://devfeed.tech/tags/style.md>), [support](<https://devfeed.tech/tags/support.md>), [tasks](<https://devfeed.tech/tags/tasks.md>), [team](<https://devfeed.tech/tags/team.md>), [templating](<https://devfeed.tech/tags/templating.md>)

### AI overview

The excerpt's finding is that `$bgc = $tno ? '#FFFFFF' : '#FFFFFF';` contains an unnecessary ternary: both outcomes assign the same color, and `$tno` is a numeric value that may be zero but should not determine formatting. The excerpt says the condition was typed directly, rather than generated by a template or preprocessing step.

### Source excerpt

Years ago, Stefan's company was short handed, especially on the developer team. But they had a large hell-desk support team. And at some point, someone had the genius idea: "PHP is easy for anyone to learn, and so our helpdesk folks should have no problem. Let's hand them development tasks." Which meant Stefan inherited lots of lines which look like this: $bgc = $tno ? '#FFFFFF' : '#FFFFFF'; Unlike many examples of this pattern, this is not the result of a pre-processing or templating step generating a conditional where both branches are the same value. Someone actually typed this. Also, notably, the variable $tno holds a numeric value, not a boolean, and is never null. It sometimes is zero, which is false, but zero is just a regular value it might hold, and thus it shouldn't get any special formatting. In short, the ternary shouldn't be here, not just because both branches are the same thing, but because there shouldn't logically be any branching at all. [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more.

## Learn With Mentor AI: Working Through a Coding Exercise

DevFeed: [Learn With Mentor AI: Working Through a Coding Exercise](<https://devfeed.tech/articles/learn-with-mentor-ai-working-through-a-coding-exercise-130366.md>)

Original publisher: [Read original article](<https://realpython.com/mentor-ai-coding-exercise/>)

Author: Bartosz Zaczyński

Published: 2026-11-12T14:00:00Z

Content type: tutorial

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [Learning](<https://devfeed.tech/topics/learning.md>), [Code Challenge](<https://devfeed.tech/topics/code-challenge.md>), [AI Chat](<https://devfeed.tech/topics/ai-chat.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [3](<https://devfeed.tech/tags/3.md>), [about](<https://devfeed.tech/tags/about.md>), [after](<https://devfeed.tech/tags/after.md>), [ai](<https://devfeed.tech/tags/ai.md>), [ai-answers](<https://devfeed.tech/tags/ai-answers.md>), [ai-chat](<https://devfeed.tech/tags/ai-chat.md>), [all](<https://devfeed.tech/tags/all.md>), [coding](<https://devfeed.tech/tags/coding.md>), [exercise](<https://devfeed.tech/tags/exercise.md>), [failed](<https://devfeed.tech/tags/failed.md>), [hints](<https://devfeed.tech/tags/hints.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [instead](<https://devfeed.tech/tags/instead.md>), [learn](<https://devfeed.tech/tags/learn.md>), [learn-how-to](<https://devfeed.tech/tags/learn-how-to.md>), [mentor](<https://devfeed.tech/tags/mentor.md>), [python](<https://devfeed.tech/tags/python.md>), [test](<https://devfeed.tech/tags/test.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

The tutorial demonstrates using Real Python's Mentor AI to debug a coding exercise while keeping the learner responsible for the solution. In "Fix the Sticky Default List," a mutable `[]` default is shared across calls; changing it to `None` and creating a list only when `starter_list is None` fixes that bug while preserving a caller's explicitly passed empty list. The tutorial walks through running tests, asking why a specific test failed, requesting hints and examples, checking predictions, reviewing the solution, explaining the fix back, and taking a quiz. Mentor AI can see the exercise code and test results without requiring them to be pasted into chat. Access requires a signed-in Real Python membership with Mentor AI; the exercise is members-only, and a free seven-day trial is mentioned.

### Source excerpt

Learn how to use Mentor AI on a Real Python coding exercise. Ask why a test failed, get hints instead of the answer, and check your understanding.

## How I Fold Thirty Reports of the Same Event Into One Story

DevFeed: [How I Fold Thirty Reports of the Same Event Into One Story](<https://devfeed.tech/articles/how-i-fold-thirty-reports-of-the-same-event-into-one-story-130188.md>)

Original publisher: [Read original article](<https://hackernoon.com/how-i-fold-thirty-reports-of-the-same-event-into-one-story?source=rss>)

Author: Lavneet Sharma

Published: 2026-11-12T07:30:15Z

Content type: tutorial

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [implementation](<https://devfeed.tech/topics/implementation.md>), [AI Integration Strategies](<https://devfeed.tech/topics/ai-integration-strategies.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [code comments](<https://devfeed.tech/topics/code-comments.md>)

Tags: [2026](<https://devfeed.tech/tags/2026.md>), [ai](<https://devfeed.tech/tags/ai.md>), [ai-model](<https://devfeed.tech/tags/ai-model.md>), [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [atom](<https://devfeed.tech/tags/atom.md>), [bridging](<https://devfeed.tech/tags/bridging.md>), [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [comment](<https://devfeed.tech/tags/comment.md>), [cosine](<https://devfeed.tech/tags/cosine.md>), [counts](<https://devfeed.tech/tags/counts.md>), [embeddings](<https://devfeed.tech/tags/embeddings.md>), [event](<https://devfeed.tech/tags/event.md>), [guard](<https://devfeed.tech/tags/guard.md>), [links](<https://devfeed.tech/tags/links.md>), [machine-learning](<https://devfeed.tech/tags/machine-learning.md>), [merge](<https://devfeed.tech/tags/merge.md>), [news](<https://devfeed.tech/tags/news.md>), [nlp](<https://devfeed.tech/tags/nlp.md>), [programming](<https://devfeed.tech/tags/programming.md>), [publisher](<https://devfeed.tech/tags/publisher.md>), [reports](<https://devfeed.tech/tags/reports.md>), [rss](<https://devfeed.tech/tags/rss.md>), [software-engineering](<https://devfeed.tech/tags/software-engineering.md>), [story](<https://devfeed.tech/tags/story.md>)

### AI overview

Hushread groups coverage through one-way links from each new article to at most one earlier article from the previous 12 hours, using a default cosine-similarity threshold of 0.92. A bridging article once fused unrelated stories; the guard now allows a merge only if the smaller story has at most 8 articles or the stories' centres have similarity of at least 0.72. Trending counts distinct normalized publishers, not syndicated articles, and requires 5 publishers. AI-written Stories appear after either a burst of 8 publishers with at least 4 reports in the busiest hour, or broader coverage of 15 publishers with at least 3 reports in that hour. Reports are attributed and linked to originals. Stories close after 48 quiet hours or 7 days, then may join a continuing thread under separate similarity thresholds. The author says thresholds were tuned on a 14-day backfill.

### Source excerpt

How an RSS reader folds thirty reports of one event into a single story: embedding links, a merge guard, publisher counts and corroboration bars.

## CodeSOD: Next Month

DevFeed: [CodeSOD: Next Month](<https://devfeed.tech/articles/codesod-next-month-131106.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/next-month>)

Author: Remy Porter

Published: 2026-11-12T06:30:00Z

Content type: news

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [billing](<https://devfeed.tech/tags/billing.md>), [bug](<https://devfeed.tech/tags/bug.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [net-9](<https://devfeed.tech/tags/net-9.md>)

### AI overview

A billing bug canceled all bills due in January because the code compared only the month numbers of `next_bill_date` and `end_date`, ignoring the year. When December began, January's month number was greater than or equal to the account's ending month, so the code cleared and saved those billing dates. The team could reconstruct the dates without restoring a backup, but an unknown number of customer billing periods had been canceled and required a history check.

### Source excerpt

One of Sean's colleagues left Initech on good terms. It caused no small amount of surprise that the very next day their billing system started failing. The billing system which the colleauge had worked on. No one truly suspected foul play, it was just a weird coincidence. Still, billing blowing up was a 5 alarm fire, so everyone was throwing every idea out about what could be the cause. Late in the evening, after staring at the code for many hours, Sean found this: if item.next_bill_date.month >= end_date.month item.next_bill_date = nil item.save else ... end If the month of the next billing date is greater than the last billing date for this account, wipe the billing date and update the item. It's worth noting that Sean's co-worker's last date happened to be the end of November, and billing started blowing up on the 1st of December. You'll also note this is checking just the month and not any other part of the date, like, oh, I don't know, the year? While this bug could happen to any bill, it was blowing up in December because every bill's ending month was greater than or equal to January. So this code canceled all the bills due in January. The good news was that they could reconstruct the correct next billing dates without having to restore from a backup. The bad news is that some unknown number of billing periods had been canceled for some of their customers, and someone was going to have to check the history. Sean reached out to his former co-worker to politely thank them for an early Christmas present. "At least I understand our billing code better," Sean writes. [Advertisement] Plan Your .NET 9 Migration with Confidence Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

## Hardware-Aware Conditional Code in Android Apps

DevFeed: [Hardware-Aware Conditional Code in Android Apps](<https://devfeed.tech/articles/hardware-aware-conditional-code-in-android-apps-113486.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2611.00296>)

Author: Marco Alecci, Jordan Samhi, Li Li, Tegawend\\'e F. Bissyand\\'e, Jacques Klein

Published: 2026-11-03T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Software Engineering](<https://devfeed.tech/sources/arxiv-software-engineering.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [Static code analysis](<https://devfeed.tech/topics/static-code-analysis.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-apps](<https://devfeed.tech/tags/android-apps.md>), [apis](<https://devfeed.tech/tags/apis.md>), [availability](<https://devfeed.tech/tags/availability.md>), [code](<https://devfeed.tech/tags/code.md>), [computer-science](<https://devfeed.tech/tags/computer-science.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [cs-se](<https://devfeed.tech/tags/cs-se.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [llm-assisted](<https://devfeed.tech/tags/llm-assisted.md>), [memory](<https://devfeed.tech/tags/memory.md>), [resource-management](<https://devfeed.tech/tags/resource-management.md>), [runtime](<https://devfeed.tech/tags/runtime.md>), [statement](<https://devfeed.tech/tags/statement.md>), [study](<https://devfeed.tech/tags/study.md>), [taxonomy](<https://devfeed.tech/tags/taxonomy.md>), [tiering](<https://devfeed.tech/tags/tiering.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

A static analysis of 50,000 Android apps found that 95% of successfully analyzed apps contain at least one conditional whose logic depends on hardware-related APIs, averaging 74 such statements per app. The researchers extracted conditions and branch code, then used LLM-assisted open coding to classify their purposes. The identified uses include checking feature availability, adapting the UI, detecting emulators, grouping devices into tiers, and managing resources. The study frames these findings as evidence that hardware-dependent logic is widespread; the supplied text does not describe the individual categories in further detail.

### Source excerpt

arXiv:2611.00296v1 Announce Type: new Abstract: Android OS runs on a highly diverse set of devices, spanning entry-level phones and flagships with substantially different hardware characteristics, including memory capacity, processors, displays, cameras, and sensors. Through APIs, apps can query device information at runtime, such as memory, hardware features, and manufacturer, among other device properties, allowing developers to execute different code paths on different devices. Existing studies cover only specific compatibility bugs or brand-specific behavior; however, the broader use of hardware information in app logic has not been comprehensively explored. We address this question with a large-scale empirical study of hardware-related if statements in Android apps. We statically analyze 50,000 apps to identify the if statements whose conditions depend on the values of hardware-related APIs, and extract their conditions together with the code of their branches. Our results show that 95% of successfully analyzed apps contain at least one such statement, with an average of 74 per app, which suggests that hardware-related logic is widespread. We then apply an LLM-assisted open-coding process to the extracted code to build a structured taxonomy of the purposes behind hardware-related conditional code. The resulting characterization shows that developers use hardware information for feature availability checks, UI adaptation, emulator detection, device tiering, and resource management, among others.

## Python while Loops: Repeating Tasks Conditionally

DevFeed: [Python while Loops: Repeating Tasks Conditionally](<https://devfeed.tech/articles/python-while-loops-repeating-tasks-conditionally-99122.md>)

Original publisher: [Read original article](<https://realpython.com/python-while-loop/>)

Author: Leodanis Pozo Ramos

Published: 2026-10-24T14:00:00Z

Content type: tutorial

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [iteration](<https://devfeed.tech/topics/iteration.md>), [Python](<https://devfeed.tech/topics/python.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [infinite](<https://devfeed.tech/tags/infinite.md>), [iteration](<https://devfeed.tech/tags/iteration.md>), [loops](<https://devfeed.tech/tags/loops.md>), [python](<https://devfeed.tech/tags/python.md>)

### AI overview

Python's `while` loop repeats its indented body while its condition is true, making it useful when the number of iterations depends on a changing condition or is unknown. The tutorial shows how to update loop state, use `break` to exit and `continue` to skip the rest of one iteration, and use `else` for code that runs after natural termination without a break. Examples include waiting for a file, reading input until a sentinel value, processing items from a list, and retrying a connection. A `while True` loop can model continuous monitoring or a do-while pattern, but needs appropriate exit conditions; faulty conditions or state updates can cause unintended infinite loops. For iterating over a known collection, the text recommends `for` loops.

### Source excerpt

Master indefinite iteration with Python while loops: build simple and complex loops, use break and continue, and handle infinite loops.

## The Merge: What if your 'if-statements' could think?

DevFeed: [The Merge: What if your 'if-statements' could think?](<https://devfeed.tech/articles/the-merge-what-if-your-if-statements-could-think-79691.md>)

Original publisher: [Read original article](<https://coderabbit.ai/blog/the-merge-typesafe-jev-smart-if-statements>)

Author: Hendrik Krack

Published: 2026-10-01T00:00:00Z

Content type: article

Language: en

Sources: [CodeRabbit](<https://devfeed.tech/sources/coderabbit.md>)

Topics: [AI interaction best practices](<https://devfeed.tech/topics/ai-interaction-best-practices.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [AI-assisted coding](<https://devfeed.tech/topics/ai-assisted-coding.md>), [Code review](<https://devfeed.tech/topics/code-review.md>), [Pull Request](<https://devfeed.tech/topics/pull-request.md>), [AI for customer service automation](<https://devfeed.tech/topics/ai-for-customer-service-automation.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [api](<https://devfeed.tech/tags/api.md>), [aws-lambda](<https://devfeed.tech/tags/aws-lambda.md>), [batching](<https://devfeed.tech/tags/batching.md>), [classification](<https://devfeed.tech/tags/classification.md>), [code-review](<https://devfeed.tech/tags/code-review.md>), [coding-agents](<https://devfeed.tech/tags/coding-agents.md>), [decision-models](<https://devfeed.tech/tags/decision-models.md>), [docker](<https://devfeed.tech/tags/docker.md>), [drop-in](<https://devfeed.tech/tags/drop-in.md>), [english](<https://devfeed.tech/tags/english.md>), [featured](<https://devfeed.tech/tags/featured.md>), [if](<https://devfeed.tech/tags/if.md>), [jev](<https://devfeed.tech/tags/jev.md>), [typesafe](<https://devfeed.tech/tags/typesafe.md>)

### AI overview

Jev is TypeSafe's decision model for classification, scoring, and routing: it takes application state plus typed questions and returns a defined choice, rubric score, or yes/no probability, avoiding generated text that software must parse. Allie Laabs says it can fit existing LLM-based classification tasks and branching decisions that are difficult to specify mathematically; it is not a replacement for general language models. Jev answers questions independently in parallel, so asking potentially relevant follow-up questions in one request can avoid resending state. A TypeSafe cookbook reports a 13-question batch was 12.2 times cheaper and 10 times faster than separate calls, with unchanged answers. Laabs says coding agents often need a review rule to bundle calls that send the same state. TypeSafe reports $0.042 per million input tokens and 70-500 ms response times, while noting its latency tests were near West Coast servers. Its known-limitations page warns that injected instructions or persuasive text in the state can shift classifications, so low-confidence answers need fallback paths and action-authorizing decisions require care.

### Source excerpt

TypeSafe's Allie Laabs explains how to find Jev-shaped problems in your code, why you should ask every question up front, and why coding agents still need help getting it right.

## TypeScript enums and falsy values

DevFeed: [TypeScript enums and falsy values](<https://devfeed.tech/articles/typescript-enums-and-falsy-values-52575.md>)

Original publisher: [Read original article](<http://www.jackfranklin.co.uk/blog/typescript-enums-0-values/>)

Published: 2024-11-17T00:00:00Z

Content type: article

Language: en

Sources: [Jack Franklin](<https://devfeed.tech/sources/jack-franklin.md>)

Topics: [TypeScript](<https://devfeed.tech/topics/typescript.md>), [enum](<https://devfeed.tech/topics/enum.md>), [union types](<https://devfeed.tech/topics/union-types.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [Null-Safety](<https://devfeed.tech/topics/null-safety.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [boolean](<https://devfeed.tech/tags/boolean.md>), [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [condition](<https://devfeed.tech/tags/condition.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [enum](<https://devfeed.tech/tags/enum.md>), [enums](<https://devfeed.tech/tags/enums.md>), [function](<https://devfeed.tech/tags/function.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [members](<https://devfeed.tech/tags/members.md>), [null](<https://devfeed.tech/tags/null.md>), [number](<https://devfeed.tech/tags/number.md>), [return](<https://devfeed.tech/tags/return.md>), [status](<https://devfeed.tech/tags/status.md>), [string](<https://devfeed.tech/tags/string.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [value](<https://devfeed.tech/tags/value.md>), [values](<https://devfeed.tech/tags/values.md>)

### AI overview

A numeric TypeScript enum starts at 0 by default, and JavaScript treats 0 as falsy. When a function returns an enum value or null, `if (status)` therefore mistakes the first enum member for "not logged in." The text recommends checking `status !== null`, or assigning enum members nonzero numeric values or nonempty strings so truthiness checks do not reject a valid status. It also notes that the issue can pass TypeScript compilation and mentions the TypeScript ESLint `strict-boolean-expressions` rule as a possible aid.

### Source excerpt

I recently lost an evening to debugging a subtle issue which highlights a potential pitfall in the interaction between TypeScript enums and "falsy" values in JavaScript. Let's look at a scenario that illustrates this problem: Spot the Bug Consider the following code where a function returns either an enum value or null depending on whether a user is logged in: const enum Status { Inactive, Active, Pending, } function getUserStatus(user?: User): Status | null { if (!user) { // No user is logged in. return null } return user.status() } function checkUserStatus(user?: User): void { const status = getUserStatus(userId) if (status) { console.log('User has a valid status:', status) } else { console.log('The user is not logged in.') } } What's the Issue? JavaScript has a concept of truthy and falsy values. In conditional statements, values that are considered falsy are treated as false. The list of falsy values in JavaScript include: false 0 "" (empty string) null undefined NaN This means that if(0) {} is always false in JavaScript. Now we can look at the default values assigned to enum members in TypeScript. As the TypeScript documentation states, when initializing enum values, the default values are numeric and start from 0. These two enums are equivalent: const enum Status { Inactive = 0, Active = 1, Pending = 2, } const enum Status { Inactive, Active, Pending, } This means that if an enum member is assigned the value 0, it will behave like false in any condition where truthiness is evaluated rather than explicitly checking for the null value. Solving with explicit checks To avoid this bug, explicitly check for null instead of relying on truthy checks: function checkUserStatus(user?: User): void { const status = getUserStatus(user) if (status !== null) { console.log('User has a valid status:', status) } else { console.log('The user is not logged in.') } } Solving with explicit enum values Alternatively, because each number in JavaScript that is not 0 is considered truth

## isBooleanTooLongAndComplex

DevFeed: [isBooleanTooLongAndComplex](<https://devfeed.tech/articles/isbooleantoolongandcomplex-23853.md>)

Original publisher: [Read original article](<http://testing.googleblog.com/2024/04/isbooleantoolongandcomplex.html>)

Author: Google Testing Bloggers (noreply@blogger.com)

Published: 2024-04-25T13:14:00Z

Content type: tutorial

Language: en

Sources: [Google Testing Blog](<https://devfeed.tech/sources/google-testing-blog.md>)

Topics: [Variable](<https://devfeed.tech/topics/variable.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [abstractions](<https://devfeed.tech/tags/abstractions.md>), [boolean](<https://devfeed.tech/tags/boolean.md>), [business-logic](<https://devfeed.tech/tags/business-logic.md>), [code](<https://devfeed.tech/tags/code.md>), [code-health](<https://devfeed.tech/tags/code-health.md>), [complex](<https://devfeed.tech/tags/complex.md>), [expression](<https://devfeed.tech/tags/expression.md>), [tott](<https://devfeed.tech/tags/tott.md>), [yiming-sun](<https://devfeed.tech/tags/yiming-sun.md>)

### AI overview

For hard-to-read Boolean conditions, extracting the whole expression into a named variable may not make its logic clear. The excerpt recommends grouping related details into intermediate Booleans with meaningful names, so the final condition combines well-defined qualities without mixing `&&` and `||`. This can improve readability without changing business logic. Hiding the condition in a separate method is another option; the excerpt notes that guard clauses and early returns can make intermediate states easier to follow. The supplied excerpt ends partway through that method example.

### Source excerpt

This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By Yiming Sun You may have come across some complex, hard-to-read Boolean expressions in your codebase and wished they were easier to understand. For example, let's say we want to decide whether a pizza is fantastic: // Decide whether this pizza is fantastic. if ((!pepperoniService.empty() || sausages.size() > 0) && (useOnionFlag.get() || hasMushroom(ENOKI, PORTOBELLO)) && hasCheese()) { ... } A first step toward improving this is to extract the condition into a well-named variable: boolean isPizzaFantastic = (!pepperoniService.empty() || sausages.size() > 0) && (useOnionFlag.get() || hasMushroom(ENOKI, PORTOBELLO)) && hasCheese(); if (isPizzaFantastic) { ... } However, the Boolean expression is still too complex. It's potentially confusing to calculate the value of isPizzaFantastic from a given set of inputs. You might need to grab a pen and paper, or start a server locally and set breakpoints. Instead, try to group the details into intermediate Booleans that provide meaningful abstractions. Each Boolean below represents a single well-defined quality, and you no longer need to mix && and || within an expression. Without changing the business logic, you've made it easier to see how the Booleans relate to each other: boolean hasGoodMeat = !pepperoniService.empty() || sausages.size() > 0; boolean hasGoodVeggies = useOnionFlag.get() || hasMushroom(ENOKI, PORTOBELLO); boolean isPizzaFantastic = hasGoodMeat && hasGoodVeggies && hasCheese(); Another option is to hide the logic in a separate method. This also offers the possibility of early returns using guard clauses, further reducing the need to keep track of intermediate states: boolean isPizzaFantastic() { if (!hasCheese()) { return false; } if (pepperoniService.empty() && sausages.size()

## An opinionated guide on how to make your Kotlin code fun to read and joy to work with

DevFeed: [An opinionated guide on how to make your Kotlin code fun to read and joy to work with](<https://devfeed.tech/articles/an-opinionated-guide-on-how-to-make-your-kotlin-code-fun-to-read-and-joy-to-work-with-25931.md>)

Original publisher: [Read original article](<https://proandroiddev.com/an-opinionated-guide-on-how-to-make-your-kotlin-code-fun-to-read-and-joy-to-work-with-caa3a4036f9e?source=rss-7a8d96da8cb6------2>)

Author: Gabor Varadi

Published: 2021-02-15T06:16:05Z

Content type: tutorial

Language: en

Sources: [Gabor Varadi](<https://devfeed.tech/sources/stories-by-gabor-varadi-on-medium.md>)

Topics: [Code quality](<https://devfeed.tech/topics/code-quality.md>), [scope function](<https://devfeed.tech/topics/scope-function.md>), [Safe-Call Operator](<https://devfeed.tech/topics/safe-call-operator.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [code beautification](<https://devfeed.tech/topics/code-beautification.md>), [pretty printing](<https://devfeed.tech/topics/pretty-printing.md>), [smart cast](<https://devfeed.tech/topics/smart-cast.md>), [constructor](<https://devfeed.tech/topics/constructor.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [code-style](<https://devfeed.tech/tags/code-style.md>), [guide](<https://devfeed.tech/tags/guide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [style](<https://devfeed.tech/tags/style.md>)

### AI overview

The guide favors Kotlin code whose intent and types stay easy to read as code evolves. Put constructor properties on separate lines when there are multiple arguments, use named lambda parameters in multi-line or chained expressions, and name multiple callback lambdas. Reserve `let` for simple assignments or returns; avoid using it as general control flow or replacing `if`/`else` with `x?.let {} ?: run {}`. Prefer early returns with the Elvis operator when there is no alternate branch, explicit return types on public non-override functions, `val` where mutation is unnecessary, and non-null parameters when null is not meaningful. Use named data classes rather than positional decomposition or tuple return types when fields carry distinct meanings. The author also recommends read-only `List` types instead of exposing mutable list types, built-in collection operations instead of equivalent loops, and choosing function types, `fun interface`, or regular interfaces according to whether callbacks need a name or multiple methods. These are presented as style recommendations, with some preferences explicitly personal or situational.

### Source excerpt

I've been meaning to write this article in a while. Hopefully, the following tips and style recommendations (in no particular order) will help you write better Kotlin! Let's get on with it, shall we? For 2 or more constructor arguments, prefer not to keep the properties on the same line as the class name in the constructor definitionclass MyClass( val a: A, val b: B, ): MyParentClass(a, b), MyInterface { // ... } This format is preferable, because when adding the 3rd argument, important bits (such as a possible base class or interface) can appear too far on the right side of the screen. Listing them one after the other (including the trailing comma since 1.4.21+) allows for better readability and extensibility (reducing the chance of causing merge conflicts with future code changes, for example). Prefer to use the scoping function 'let' only in assignments or return statements, but NOT as general control flow, or a "quick rename to 'it'" Oftentimes, Kotlin code tends to do something like this: fun myMethod(nullableA: A?) { nullableA?.let { // no it.x() // no it.y() // no it.z() // no } } (Note: in a method like this, A? could be replaced with A to take advantage of typed nullability, this is just an example.) To allow better maintainability and readability, we should instead prefer to only use ?.let { in simple assignments, or return statements, but not as general control flow. For example, the following chain is easy to understand: val protoClass = savedInstanceState?.getByteArray("protoValue") ?.let { ProtoClass.parseFrom(it) } However, in this case, ?.let { is part of an assignment. Also, while ?.let { can be chained with a ?: to provide a default value (especially in combination with takeIf) it shouldn't be used to execute side-effects (also is more suitable for that). In fact, it needs to be said: x?.let {} ?: run {} is NOT a general purpose replacement for if-else statements and null-checks, and should never be used in this particular format for that purpose!

## Swift's Guard Statement for Kotlin

DevFeed: [Swift's Guard Statement for Kotlin](<https://devfeed.tech/articles/swift-s-guard-statement-for-kotlin-25890.md>)

Original publisher: [Read original article](<https://medium.com/swlh/swifts-guard-statement-for-kotlin-967ba580443f?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-12-07T21:55:37Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [statement](<https://devfeed.tech/tags/statement.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

Swift's `guard` exits early when a condition fails, keeping subsequent code outside nested checks. The excerpt shows Kotlin alternatives: use `toIntOrNull()` with `?: run` or an `if`/`else` that returns from the function; both work when a function return is available. For reusable guarded blocks, it proposes throwing a custom exception from `otherwise` and catching it in an inline `guarded` wrapper, with `Nothing` indicating that `otherwise` does not return. A later variant makes the failure action optional and uses an extension `guard` to check a Boolean while returning the original value. The author notes that these are approximations built from Kotlin features, not an official language keyword, and that the optional failure action differs from Swift's required `else`.

### Source excerpt

https://unsplash.com/photos/znMu0Enj_Gw Even if you live on the Kotlin side of things maybe once in a while you also check Swift code. If you do, you probably noticed how similar both languages are. To me, Kotlin looks more concise but I'm also biased as I work with Kotlin daily. On the other hand, Swift has some great features too. One is the guard keyword, a really nice tool Swift developers have that we are missing. Can we bring it to Kotlin? What is guard? guard is used to exit a block of code early, if a given condition is not met. This way all the code following the guarded variable can be safely executed. Let's look at an example where we do some calculation but only if the given input can be converted into an integer: func printResultFor(input: String) -> Void { guard let result = Int(input) else { println("input was not an integer") return } // function continues with valid int print("result: ", 100 * result)} Of course, simple code like this could be written with the standard if/else statements! But the power of guard becomes apparent when many of these statements are used in succession. Written in a traditional way this can easily lead to a hell of nested ifs where you make sure everything is safe in the innermost block when all the if are true. Take a simple sign up flow for example, where the customer needs to enter user, password, and their age for validation. We have to make sure those are not nil or empty and check for a valid age. func submit(usernameText: String?, passwordText: String?, ageText: String?) { guard let username = usernameText, !username.isEmpty else { print("username is not set or blank") return } guard let password = passwordText, !password.isEmpty else { print("password is not set or blank") return } guard let ageString = ageText else { print("age is not set") return } guard let age = Int(ageString), age > 18 else { print("age not valid") return } // all values are checked and valid here register(username, password, age)} Here the r

## The --var: ; hack to toggle multiple values with one custom property

DevFeed: [The --var: ; hack to toggle multiple values with one custom property](<https://devfeed.tech/articles/the-var-hack-to-toggle-multiple-values-with-one-custom-property-52124.md>)

Original publisher: [Read original article](<https://lea.verou.me/2020/10/the-var-space-hack-to-toggle-multiple-values-with-one-custom-property/>)

Author: Lea Verou

Published: 2020-10-12T00:00:00Z

Content type: article

Language: en

Sources: [Lea Verou's blog](<https://devfeed.tech/sources/lea-verou-s-blog.md>)

Topics: [Web Development](<https://devfeed.tech/topics/web-development.md>), [User interface design](<https://devfeed.tech/topics/ui-design.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [concatenation](<https://devfeed.tech/topics/concatenation.md>)

Tags: [all](<https://devfeed.tech/tags/all.md>), [allowed](<https://devfeed.tech/tags/allowed.md>), [apply](<https://devfeed.tech/tags/apply.md>), [background](<https://devfeed.tech/tags/background.md>), [blog](<https://devfeed.tech/tags/blog.md>), [border](<https://devfeed.tech/tags/border.md>), [box](<https://devfeed.tech/tags/box.md>), [but](<https://devfeed.tech/tags/but.md>), [button](<https://devfeed.tech/tags/button.md>), [call](<https://devfeed.tech/tags/call.md>), [can](<https://devfeed.tech/tags/can.md>), [code](<https://devfeed.tech/tags/code.md>), [color](<https://devfeed.tech/tags/color.md>), [css](<https://devfeed.tech/tags/css.md>), [css-variables](<https://devfeed.tech/tags/css-variables.md>), [custom](<https://devfeed.tech/tags/custom.md>), [hack](<https://devfeed.tech/tags/hack.md>), [multiple](<https://devfeed.tech/tags/multiple.md>), [original](<https://devfeed.tech/tags/original.md>), [property](<https://devfeed.tech/tags/property.md>), [tips](<https://devfeed.tech/tags/tips.md>), [toggle](<https://devfeed.tech/tags/toggle.md>), [values](<https://devfeed.tech/tags/values.md>), [var](<https://devfeed.tech/tags/var.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

The excerpt describes a CSS custom-property toggle: set a variable used in `var()` fallbacks to `initial` to activate the fallback values, or to whitespace (`--foo: ;`) to leave surrounding declarations unchanged. This can append or enable values across properties and rules using one variable, such as styling a raised button. The technique only supports appending values or choosing a whole value versus `initial`; it cannot express arbitrary alternatives such as red versus white backgrounds. The author notes readability concerns and suggests comments or named constants like `--ON` and `--OFF`. A proper CSS `if()` is described as a future alternative under discussion.

### Source excerpt

What if I told you you could use a single property value to turn multiple different values on and off across multiple different properties and even across multiple CSS rules? What if I told you you could turn this flat button into a glossy skeuomorphic button by just tweaking one custom property --is-raised, and that would set its border, background image, box and text shadows in one fell swoop? How, you may ask? The crux of this technique is this: There are two custom property values that work almost everywhere there is a var() call with a fallback. The more obvious one that you probably already know is the initial value, which makes the property just apply its fallback. So, in the following code: background: var(--foo, linear-gradient(white, transparent)) hsl(220 10% 50%); border: 1px solid var(--foo, rgb(0 0 0 / .1)); color: rgb(0 0 0 var(--foo, / .8)); We can set --foo to initial to enable these "fallbacks" and append these values to the property value, adding a gradient, setting a border-color, and making the text color translucent in one go. But what to do when we want to turn these values off? Any non-initial value for --foo (that doesn't create cycles) should work. But is there one that works in all three declarations? It turns out there is another value that works everywhere, in every property a var() reference is present, and you'd likely never guess what it is (unless you have watched any of my CSS variable talks and have a good memory for passing mentions of things). Intrigued? It's whitespace! Whitespace is significant in a custom property. When you write something like this: --foo: ; This is not an invalid declaration. This is a declaration where the value of --foo is literally one space character. However, whitespace is valid in every CSS property value, everywhere a var() is allowed, and does not affect its computed value in any way. So, we can just set our property to one space (or even a comment) and not affect any other value present in the declar

## Simple Rust Programming 01 - Checking The Existence of a Directory

DevFeed: [Simple Rust Programming 01 - Checking The Existence of a Directory](<https://devfeed.tech/articles/simple-rust-programming-01-checking-the-existence-of-a-directory-28322.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rust/2020/06/03/simple-rust-programs-01-checking-the-existence-of-a-directory.html>)

Author: Fuzzygroup

Published: 2020-06-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rust](<https://devfeed.tech/topics/rust.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [if expression](<https://devfeed.tech/topics/if-expression.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Learning](<https://devfeed.tech/topics/learning.md>)

Tags: [directory](<https://devfeed.tech/tags/directory.md>), [rust](<https://devfeed.tech/tags/rust.md>), [rust-programming](<https://devfeed.tech/tags/rust-programming.md>)

### AI overview

The excerpt shows a beginner Rust program that checks whether `/home` is a directory using `Path::new(path).is_dir()` to distinguish a presumed Linux environment from other systems. Its first attempt fails because variables declared inside the `if` and `else` blocks are out of scope after those blocks. Moving the choice into `get_env()` fixes the scope issue, but the function initially lacks a return type; declaring `-> &'static str` lets it return the string literals `"unix"` or `"other"` and lets `main` print the result. The author presents this as a learning example based on the assumption that Linux home directories are under `/home` and Mac home directories under `/Users`; the excerpt does not show a completed Mac-specific check.

### Source excerpt

So I'm at the very early learning stage of Rust, that stage where almost nothing you type in works. And this, for me, usually means "make the learning stick by writing it down". So here goes ... Note: I wrote this code using the Rust playground, a web based repl, which was invaluable. A Simple Program for Testing the Existence of a Directory I'm going to start with an assumption that I need to get the location of my input based on the type of the machine: either a Mac or a Linux box. Given that we know that a user's home directory exists in /home on Linux and /Users on Mac, this gives us an easy way to differentiate the two. Pass 1: Problems with Scopes use std::path::Path; fn main() { if path_exists("/home") { let environment = "unix"; } else { let environment = "other"; } println!("{}", environment); } fn path_exists(path: &str) -> bool { if Path::new(path).is_dir() { return true; } else { return false } } This program has a core problem - the environment variable isn't in scope: Compiling playground v0.0.1 (/playground) error[E0425]: cannot find value `environment` in this scope --> src/main.rs:11:20 | 11 | println!("{}", environment); | ^^^^^^^^^^^ not found in this scope The implication of this is that code within { } braces is a true local block and thus out of scope with what came before. The Ruby work around for something like this is to have an outer variable that "shadows" the name of the variable within the block and thus allows its value to pass out. Unfortunately Rust identifies that technique as a bug since the outer variable is never read. My refactor on this is to write a function which returns this. Pass 2: Problems with Return Types Here was my first pass at moving environment fetching into a function of its own. I got tired of typing environment so I moved to calling it my_env. use std::path::Path; fn main() { let my_env = get_env(); println!("{}", my_env); } fn get_env() { if path_exists("/home") { return "unix"; } else { return "other"; } } fn pat

## Linear Time Liveness Analysis

DevFeed: [Linear Time Liveness Analysis](<https://devfeed.tech/articles/linear-time-liveness-analysis-25069.md>)

Original publisher: [Read original article](<https://databasearchitects.blogspot.com/2020/04/linear-time-liveness-analysis.html>)

Author: Thomas Neumann (noreply@blogger.com)

Published: 2020-04-28T14:42:00Z

Content type: article

Language: en

Sources: [Database Architects](<https://devfeed.tech/sources/database-architects.md>)

Topics: [Programming Languages / Compilers](<https://devfeed.tech/topics/programming-languages-compilers.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [analysis](<https://devfeed.tech/tags/analysis.md>), [block](<https://devfeed.tech/tags/block.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [control](<https://devfeed.tech/tags/control.md>), [define](<https://devfeed.tech/tags/define.md>), [function](<https://devfeed.tech/tags/function.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [large](<https://devfeed.tech/tags/large.md>), [limit](<https://devfeed.tech/tags/limit.md>), [linear](<https://devfeed.tech/tags/linear.md>), [processing](<https://devfeed.tech/tags/processing.md>), [program](<https://devfeed.tech/tags/program.md>), [query](<https://devfeed.tech/tags/query.md>), [runtime](<https://devfeed.tech/tags/runtime.md>), [script](<https://devfeed.tech/tags/script.md>), [simple](<https://devfeed.tech/tags/simple.md>), [time](<https://devfeed.tech/tags/time.md>)

### AI overview

Generated functions with many overflow-check branches can make compilation scale dramatically worse than linearly: the excerpt reports GCC taking 34.99 seconds at 10,000 statements and over an hour at 100,000, while Clang fares better at -O0 but also becomes super-linear at -O1. The author identifies textbook liveness analysis, which propagates per-variable information across blocks, as a scaling problem. Their alternative examines the control-flow graph and extends a variable's lifetime across every path between its definition and use, including an entire loop when execution can wrap around before reaching the use. The excerpt ends as the loop-identification algorithm is introduced, so its full procedure and performance are not available.

### Source excerpt

Standard compiler are usually used with hand-written programs. These programs tend to have reasonably small functions, and can be processed in (nearly) linear time. Generated programs however can be quite large, and compilers sometimes struggle to compile them at all. This can be seen with the following (silly) demonstration script: import subprocess from timeit import default_timer as timer def doTest(size): with open("foo.cpp", "w") as out: print("int foo(int x) {", file=out) for s in range(size): p="x" if s==0 else f'l{s-1}' print (f'int l{s}; if (__builtin_sadd_overflow({p},1,&l{s})) goto error;', file=out) print(f'return l{size-1};error: throw;}}', file=out); start = timer() subprocess.run(["gcc", "-c", "foo.cpp"]) stop = timer() print(size, ": ", (stop-start)) for size in [10,100,1000,10000,100000]: doTest(size) It generates one function with n statements of the form "int lX; if (__builtin_sadd_overflow(lY,1,&lX)) goto error;" which are basically just n additions with overflow checks, and then measures the compile time. The generated code is conceptually a very simple, but it contains a lot of basic blocks due to the large number of ifs. When compiling with gcc we get the following compile times: n101001,00010,000100,000 compilation [s]0.020.040.1934.99> 1h The compile time is dramatically super linear, gcc is basically unable to compile the function if it contains 10,000 ifs or more. In this simple example clang fares better when using -O0, but with -O1 it shows super-linear compile times, too. This is disastrous when processing generated code, where we cannot easily limit the size of individual functions. In our own system we use neither gcc nor clang for query compilation, but we have same problem, namely compiling large generated code. And super-linear runtime quickly becomes an issue when the input is large. One particular important problem in this context is liveness analysis, i.e, figuring out which value is alive at which part of the program. The textb

## Ruby Madness - Right Hand If Statements and Syntax Error, Unexpected end-of-input, Expecting End

DevFeed: [Ruby Madness - Right Hand If Statements and Syntax Error, Unexpected end-of-input, Expecting End](<https://devfeed.tech/articles/ruby-madness-right-hand-if-statements-and-syntax-error-unexpected-end-of-input-expecting-end-28302.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2019/11/07/ruby-madness-right-hand-if-statements-and-syntax-error-unexpected-end-of-input-expecting-end.html>)

Author: Fuzzygroup

Published: 2019-11-07T00:00:00Z

Content type: article

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [syntax](<https://devfeed.tech/topics/syntax.md>), [Parsing](<https://devfeed.tech/topics/parsing.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [debugging](<https://devfeed.tech/tags/debugging.md>), [error](<https://devfeed.tech/tags/error.md>), [right](<https://devfeed.tech/tags/right.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

A Ruby syntax error reported only at end-of-file was caused by a subtle difference in a conditional append. The faulty line, `habits_with_feeds << if habit.has_feed?`, was corrected to `habits_with_feeds << habit if habit.has_feed?`. The author says `ruby -c` identified whether the file parsed, but not the useful error location; they isolated the problem by repeatedly cutting the file's code in half and rerunning the check. The excerpt notes that right-hand `if` syntax can shorten code, but in this case the alternative form triggered the confusing missing-`end` error.

### Source excerpt

The Eagle's Nest AirBnB Cabin on the Ohio River; One of my favorite places... Last night I was on a coding tear, that moment when the solution is just crystal clear. That situation where something you've struggled with for days / weeks / months and then it all comest together. The result of this was a whole bunch of code stuck in a single model and then this morning when I was ready to run it across the entire dataset, I got this crap: ruby -c app/models/habit.rb app/models/habit.rb:592: syntax error, unexpected end-of-input, expecting end I censored hate this error. Line 592 is the end of the class and that means that the ruby parser just blithely skipped to the end and really has no useful positional information for you. Note: If you're not familiar with ruby -c, it is a syntax checker that makes sure your file is parseable. Think of it as a poor man's lint. My usual approach to finding this error is to cut our half the code in the file and then re-run the ruby -c process. And then repeat that until you get this: ruby -c app/models/habit.rb Syntax OK And that's how I ended up finding the error but the error was ridiculously subtle. Here's the error: def self.with_feeds habits_with_feeds = [] Habit.active.each do |habit| habits_with_feeds << if habit.has_feed? end habits_with_feeds end And here's the corrected version of the method: def self.with_feeds habits_with_feeds = [] Habit.active.each do |habit| habits_with_feeds << habit if habit.has_feed? end habits_with_feeds end Now, this is subtle, so I'm going to just call it out. The issue was this line: habits_with_feeds << habit if habit.has_feed? versus habits_with_feeds << if habit.has_feed? Clearly, to the ruby parser, the lack of something being added to the array qualifies as a missing end. Yeah I get that but damn. I'm personally a huge fan of right hand if statements due to the reduction of 3 lines down to 1 but this is a case where they bit me hard. Sigh.

## Java switch - 4 wrongs don't make a right

DevFeed: [Java switch - 4 wrongs don't make a right](<https://devfeed.tech/articles/java-switch-4-wrongs-don-t-make-a-right-22009.md>)

Original publisher: [Read original article](<http://blog.joda.org/2019/11/java-switch-4-wrongs-dont-make-right.html>)

Author: Stephen Colebourne (noreply@blogger.com)

Published: 2019-11-04T20:32:00Z

Content type: opinion

Language: en

Sources: [Stephen Colebourne](<https://devfeed.tech/sources/stephen-colebourne.md>)

Topics: [conditionals](<https://devfeed.tech/topics/conditionals.md>), [enum](<https://devfeed.tech/topics/enum.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [complex](<https://devfeed.tech/tags/complex.md>), [design](<https://devfeed.tech/tags/design.md>), [expression](<https://devfeed.tech/tags/expression.md>), [fall](<https://devfeed.tech/tags/fall.md>), [java](<https://devfeed.tech/tags/java.md>), [project](<https://devfeed.tech/tags/project.md>), [project-amber](<https://devfeed.tech/tags/project-amber.md>), [return](<https://devfeed.tech/tags/return.md>), [switch](<https://devfeed.tech/tags/switch.md>)

### AI overview

The author argues that Java's planned switch upgrade adds complexity around the useful arrow-form switch expression. The classic switch can fall through when `break` is omitted, shares one variable scope across cases, and does not require `default`. The proposal adds four forms: classic and arrow syntax, each as a statement or expression. Arrow forms avoid fall-through; expressions must be exhaustive, while statement forms need not be. The author sees the classic-syntax expression as preserving fall-through risks and the arrow statement as allowing silent omissions, and questions whether orthogonality justifies both. They favor keeping only the arrow expression, allowing it to serve as a statement expression, and introducing `match` as its keyword. The excerpt also notes that switch expressions cannot return early or continue/break a loop.

### Source excerpt

The switch statement in Java is being changed. But is it an upgrade or a mess? Classic switch The classic switch statement in Java isn't great. Unlike many other parts of Java, it wasn't properly rethought when pulling features across from C all those years ago. The key flaw is "fall-through-by-default". This means that if you forget to put a break clause in each case, processing will continue on to the next case clause. Another flaw is that variables are scoped to the entire switch, thus you cannot reuse a variable name in two different case clauses. In addition, default clause is not required, which leaves readers of the code unclear as to whether a clause was forgotten or not. And of course there is also the key limitation - that the type to be switched on can only be an integer, enum or string. String instruction; switch (trafficLight) { case RED: instruction = "Stop"; case YELLOW: instruction = "Prepare"; break; case GREEN: instruction = "Go"; break; } System.out.println(instruction); The code above does not compile because there is no default clause, leaving instruction undefined. But even if it did compile, it would never print "Stop" due to the missing break. In my own coding, I prefer to always put a switch at the end of a method, with each clause containing a return to reduce the risks of switch. Upgraded switch As part of Project Amber, switch is being upgraded. But sadly, I'm unconvinced as to the merits of the new design. To be clear, there are some good aspects, but overall I think the solution is overly complex and with some unpleasant syntax choices. The key aim is to add an expression form, where you can assign the result of the switch to a variable. This is rather like the ternary operator (eg. x != null ? x : ""), which is the expression equivalent of an if statement. An expression form would reduce problems like the undefined variable above, because it makes it more obvious that each branch must result in a variable. The current plan is to add no

## The Four Languages You Must Know to Understand WordPress

DevFeed: [The Four Languages You Must Know to Understand WordPress](<https://devfeed.tech/articles/the-four-languages-you-must-know-to-understand-wordpress-121176.md>)

Original publisher: [Read original article](<https://wpshout.com/wordpress-programming-language/>)

Author: David Hayes

Published: 2019-03-05T15:15:14Z

Content type: article

Language: en

Sources: [Back-End Development - WPShout](<https://devfeed.tech/sources/back-end-development-wpshout.md>)

Topics: [WordPress](<https://devfeed.tech/topics/wordpress.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Learning](<https://devfeed.tech/topics/learning.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [Web platform](<https://devfeed.tech/topics/web-platform.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [back-end-development](<https://devfeed.tech/tags/back-end-development.md>), [css](<https://devfeed.tech/tags/css.md>), [development](<https://devfeed.tech/tags/development.md>), [front-end-development](<https://devfeed.tech/tags/front-end-development.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [languages](<https://devfeed.tech/tags/languages.md>), [learning](<https://devfeed.tech/tags/learning.md>), [php](<https://devfeed.tech/tags/php.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [wordpress](<https://devfeed.tech/tags/wordpress.md>), [wordpress-programming-language](<https://devfeed.tech/tags/wordpress-programming-language.md>), [wps](<https://devfeed.tech/tags/wps.md>), [wps-nf](<https://devfeed.tech/tags/wps-nf.md>)

### AI overview

WordPress development uses HTML and CSS as the markup and styling foundation, PHP for server-side WordPress behavior, and JavaScript for browser-side interactivity. The article recommends learning HTML and CSS first, then PHP: WordPress core, plugins, and classic themes primarily use PHP, and custom server-side features rely on it. Block themes can use HTML templates, but still run on WordPress's PHP engine. JavaScript is optional to get started and is useful for richer interactions; the block editor and some features, including the Interactivity API, require it. The article suggests learning JavaScript later, once PHP work exposes needs it cannot address.

### Source excerpt

Learning WordPress development starts with a lot of key questions, including this one: "What language is WordPress written in?" Another common one is "Should I learn PHP or JavaScript first?" WordPress programming languages is a big topic, but we'll cover all you need to get started. The answer to "What coding language does WordPress use?"... Read More "The Four Languages You Must Know to Understand WordPress

## Learn CMake's Scripting Language in 15 Minutes

DevFeed: [Learn CMake's Scripting Language in 15 Minutes](<https://devfeed.tech/articles/learn-cmake-s-scripting-language-in-15-minutes-21009.md>)

Original publisher: [Read original article](<https://preshing.com/20170522/learn-cmakes-scripting-language-in-15-minutes>)

Author: Jeff Preshing

Published: 2017-05-22T12:20:00Z

Content type: tutorial

Language: en

Sources: [Jeff Preshing](<https://devfeed.tech/sources/jeff-preshing.md>)

Topics: [CMake](<https://devfeed.tech/topics/cmake.md>), [Script](<https://devfeed.tech/topics/script.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>)

Tags: [cmake](<https://devfeed.tech/tags/cmake.md>), [language](<https://devfeed.tech/tags/language.md>), [learn](<https://devfeed.tech/tags/learn.md>), [scripting](<https://devfeed.tech/tags/scripting.md>)

### AI overview

CMake scripts use commands whose arguments are strings; variables are strings too, and unquoted semicolon-delimited variable references can expand into multiple arguments. The guide demonstrates running a script with `cmake -P`, setting variables, flow control, lists, and target properties. Its key scope distinctions are practical: functions have their own scope and can set caller variables with `PARENT_SCOPE`; macros share the caller's scope; `include` and `find_package` scripts run in the caller's scope, while `add_subdirectory` runs a `CMakeLists.txt` in a new scope. Targets remain visible across scopes, and their properties feed build pipeline generation. The guide covers syntax and the programming model rather than all built-in commands, and says generator expressions are outside its coverage.

### Source excerpt

As explained in my previous post, every CMake-based project must contain a script named CMakeLists.txt. This script defines targets, but it can also do a lot of other things, such as finding third-party libraries or generating C++ header files. CMake scripts have a lot of flexibility. Every time you integrate an external library, and often when adding support for another platform, you'll need to edit the script. I spent a long time editing CMake scripts without really understanding the language, as the documentation is quite scattered, but eventually, things clicked. The goal of this post is to get you to the same point as quickly as possible. This post won't cover all of CMake's built-in commands, as there are hundreds, but it is a fairly complete guide to the syntax and programming model of the language. Hello World If you create a file named hello.txt with the following contents: message("Hello world!") # A message to print ...you can run it from the command line using cmake -P hello.txt. (The -P option runs the given script, but doesn't generate a build pipeline.) As expected, it prints "Hello world!". $ cmake -P hello.txt Hello world! All Variables Are Strings In CMake, every variable is a string. You can substitute a variable inside a string literal by surrounding it with ${}. This is called a variable reference. Modify hello.txt as follows: message("Hello ${NAME}!") # Substitute a variable into the message Now, if we define NAME on the cmake command line using the -D option, the script will use it: $ cmake -DNAME=Newman -P hello.txt Hello Newman! When a variable is undefined, it defaults to an empty string: $ cmake -P hello.txt Hello ! To define a variable inside a script, use the set command. The first argument is the name of the variable to assign, and the second argument is its value: set(THING "funk") message("We want the ${THING}!") Quotes around arguments are optional, as long as there are no spaces or variable references in the argument. For example, I c

## NSWindow Global Hotkey

DevFeed: [NSWindow Global Hotkey](<https://devfeed.tech/articles/nswindow-global-hotkey-25378.md>)

Original publisher: [Read original article](<https://smileykeith.com/2013/01/03/nswindow-global-hotkey/>)

Author: Keith Smiley

Published: 2013-01-03T18:44:00Z

Content type: article

Language: en

Sources: [Keith Smiley](<https://devfeed.tech/sources/keith-smiley.md>)

Topics: [if statement](<https://devfeed.tech/topics/if-statement.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [avoid](<https://devfeed.tech/tags/avoid.md>), [blocks](<https://devfeed.tech/tags/blocks.md>), [global](<https://devfeed.tech/tags/global.md>), [hidden](<https://devfeed.tech/tags/hidden.md>), [hit](<https://devfeed.tech/tags/hit.md>), [if-statement](<https://devfeed.tech/tags/if-statement.md>), [ifs](<https://devfeed.tech/tags/ifs.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [return](<https://devfeed.tech/tags/return.md>), [solution](<https://devfeed.tech/tags/solution.md>), [solved](<https://devfeed.tech/tags/solved.md>), [value](<https://devfeed.tech/tags/value.md>), [window](<https://devfeed.tech/tags/window.md>)

### AI overview

The author reports that MASShortcut solved global hotkey handling, but toggling the app and its window remained problematic: after hiding the app, checks of `isActive` or window visibility appeared to be reevaluated and fell through to `else` branches, even with `return` statements. Their workaround was to track the initial active/open state with `NSNumber` booleans and use `else if` branches to decide whether to close and hide, show the window, or activate the app and bring the window forward. The excerpt presents this as the author's solution, without broader explanation of the behavior.

### Source excerpt

For quite a while I was having trouble dealing with a global show/hide hotkey for windows in Objective-C. Global hotkeys are already hard enough. Although MASShortcut has solved that. Yes I know of ShortcutRecorder but it's very dated (MASShortcut even uses blocks!). I found that once I had the shortcut working I was having a hard time dealing with opening and closing, showing and hiding the application. What seemed to happen was when the method was called and [[NSRunningApplication currentApplication] isActive] was evaluated in an if statement along with an else clause, if the application was hidden using [[NSApplication sharedApplication] hide:self]; it was reevaluated and it hit the else case. This also happened with an if statement checking if the window was already visible with [myWindow isVisible] even with return; statements inserted in appropriate places. My solution was adding NSNumbers acting as booleans to keep track of the value allowing me to avoid else statements altogether and use else ifs instead. - (void)showHideMainWindow { NSNumber *wasActive = @NO; if ([[NSRunningApplication currentApplication] isActive]) { wasActive = @YES; NSNumber *wasOpen = @NO; if ([self.window isVisible]) { wasOpen = @YES; [self.window close]; [[NSApplication sharedApplication] hide:self]; } else if (![wasOpen boolValue]) { [self.window makeKeyAndOrderFront:self]; } } else if (![wasActive boolValue]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; [self.window makeKeyAndOrderFront:self]; } }

## On native, single-input, multiple file uploads

DevFeed: [On native, single-input, multiple file uploads](<https://devfeed.tech/articles/on-native-single-input-multiple-file-uploads-51948.md>)

Original publisher: [Read original article](<https://lea.verou.me/2009/03/regarding-native-single-input-multiple-file-uploads/>)

Author: Lea Verou

Published: 2009-03-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [Lea Verou's blog](<https://devfeed.tech/sources/lea-verou-s-blog.md>)

Topics: [Web Development](<https://devfeed.tech/topics/web-development.md>), [browser](<https://devfeed.tech/topics/browser.md>), [WebKit](<https://devfeed.tech/topics/webkit.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [Internet Explorer](<https://devfeed.tech/topics/internet-explorer.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [blog](<https://devfeed.tech/tags/blog.md>), [browser](<https://devfeed.tech/tags/browser.md>), [browsers](<https://devfeed.tech/tags/browsers.md>), [bug](<https://devfeed.tech/tags/bug.md>), [development](<https://devfeed.tech/tags/development.md>), [feature](<https://devfeed.tech/tags/feature.md>), [feature-detection](<https://devfeed.tech/tags/feature-detection.md>), [features](<https://devfeed.tech/tags/features.md>), [file](<https://devfeed.tech/tags/file.md>), [files](<https://devfeed.tech/tags/files.md>), [flexible](<https://devfeed.tech/tags/flexible.md>), [forms](<https://devfeed.tech/tags/forms.md>), [html](<https://devfeed.tech/tags/html.md>), [input](<https://devfeed.tech/tags/input.md>), [js](<https://devfeed.tech/tags/js.md>), [min](<https://devfeed.tech/tags/min.md>), [multiple](<https://devfeed.tech/tags/multiple.md>), [native](<https://devfeed.tech/tags/native.md>), [news](<https://devfeed.tech/tags/news.md>), [opera](<https://devfeed.tech/tags/opera.md>), [properties](<https://devfeed.tech/tags/properties.md>), [safari](<https://devfeed.tech/tags/safari.md>), [select](<https://devfeed.tech/tags/select.md>), [standard](<https://devfeed.tech/tags/standard.md>), [uploads](<https://devfeed.tech/tags/uploads.md>), [webkit](<https://devfeed.tech/tags/webkit.md>), [webkit-bugs](<https://devfeed.tech/tags/webkit-bugs.md>)

### AI overview

The excerpt describes two native ways to allow multiple file selection in one file input: Safari 4's `multiple` attribute and Opera's Web Forms 2.0 `min`/`max` attributes. It gives feature checks for each and combines them by enabling whichever supported mechanism is detected, with a preferred workaround left for other browsers. The author recommends fallbacks where neither is supported. Safari 4's `multiple` property was not then exposed for detection; the excerpt says the WebKit team had fixed a reported bug and that support was expected in a later nightly build. Mozilla implementation is presented as pending a Bugzilla request.

### Source excerpt

If you are following the current news on web development, you probably heard that the new Safari 4 has a great feature: It natively allows the user to select multiple files via a single input control, if you specify a value for the attribute multiple: <input type="file" multiple> or, in XHTML: <input type="file" multiple="multiple" /> You might not know that Opera supported multiple file uploads for a while now, based on the earlier Web Forms 2.0 standard in a slightly different (and more flexible) format: <input type="file" min="1" max="9999″ /> Can we use those currently? Sure we can, but we should provide fallbacks for the other browsers. Using these features will put pressure on the other browser vendors to implement them as well and generally, native is always better. How can we find out whether the browser supports them? Opera Opera supports accessing those min and max properties as properties of the element. So, it's quite trivial to check whether Opera-style multiple inputs are supported: var supportsMin = (function(){ var fi = document.createElement('input'); fi.type = 'file'; return fi.min === '' && fi.max === ''; })(); Safari 4 In Safari 4 the check would be equally simple, if it supported accessing the multiple attribute as a property. Then we could easily check whether it's boolean and conclude that Safari-style multiple inputs are supported: var supportsMultiple = (function(){ var fi = document.createElement('input'); fi.type = 'file'; // The second check is probably redundant but what if in the future an implementor // decides to make the file inputs to handle multiple selections by default? // Yeah, it's not likely, but it's not entirely impossible. return fi.multiple === false || fi.multiple === true; })(); However, that's currently not the case. The good news are that I reported this as a bug today, and the Webkit team fixed it, so it will be possible in the next Webkit nightly! Combining the two You can easily combine these two together with the w