Skip to content

Archive / page 67

All articles

Every practical article from the Nalar archive, newest first.

Software Engineering 06 Sep 2026 7 min read

Using Guard Clauses to Keep Control Flow Flat

A function often starts simple and becomes difficult to read as conditions accumulate. One check wraps another, the main work moves several indentation levels to the right, and a developer must remember which conditions are still true while reading the code. A guard clause handles a case that should stop or divert the current operation near the point where that case becomes known. Instead of wrapping the normal path in another conditional, the function deals with the exceptional, invalid, or inapplicable case and exits that path early.

Database 06 Sep 2026 12 min read

Use SQLite WITHOUT ROWID for Composite Primary Keys

A table with a composite primary key often looks straightforward in SQL: two or more columns together identify one row. In SQLite, however, the storage layout depends on whether the table is an ordinary rowid table or a WITHOUT ROWID table. That difference matters when the natural key is already the identity you use for nearly every lookup. An ordinary SQLite table normally keeps a hidden integer rowid as its storage key and implements a non-integer or composite PRIMARY KEY with a separate unique index. A WITHOUT ROWID table instead makes the declared primary key the key of the table’s main B-tree.

Artificial Intelligence 06 Sep 2026 10 min read

Use Best-of-N Sampling to Spend More Compute at Inference

A language model can produce several plausible answers to the same prompt. That variability is often treated as noise, but it can also be used deliberately: generate multiple candidates, evaluate them, and return the strongest one. This pattern is called best-of-N sampling. Instead of trusting one generation, the system samples N responses and uses a scoring rule to select one. The extra samples spend more compute at inference time in exchange for more opportunities to find a good response.

Cybersecurity 06 Sep 2026 10 min read

Turn Security Requirements Into Invariants

Security requirements often begin as broad statements: “users must not read other users’ records,” “disabled accounts must not create new sessions,” or “a refund must require approval.” These statements describe the desired outcome, but they do not yet tell a developer where the rule must hold or what code should make it true. That gap matters. A rule enforced in one screen can be bypassed by another API path. A check performed before a state change can become stale before the write completes. A background worker may operate under different assumptions from the request that queued its job. The result is not necessarily a missing security feature; it is often a security property that was never made precise enough to enforce consistently.

Cybersecurity 06 Sep 2026 9 min read

Treat Request Hosts as Untrusted Input

Web applications often need to know their own public hostname. A framework may expose it as request.host, a reverse proxy may forward it in a header, and application code may use it to build an absolute URL. That is convenient, but it can quietly turn request-controlled data into a security decision. If an application accepts an arbitrary request host and later places that value into a password-reset link, redirect, cache entry, or routing decision, an attacker may be able to make trusted application output point at an unintended host. The exact consequence depends on where the value is used, but the underlying mistake is the same: treating a routing identifier supplied with a request as if it were trusted configuration.

Cybersecurity 06 Sep 2026 10 min read

Treat CORS as a Browser Read Permission

A browser application often needs to call an API on another origin. The first time this fails, Cross-Origin Resource Sharing (CORS) can look like a networking obstacle: the request reached the server, the server returned data, yet JavaScript cannot read the response. That view leads to a dangerous fix—making the CORS policy broad until the error disappears. CORS is better understood as a browser-enforced read permission. Your server uses HTTP response headers to tell a browser which other origins may expose a response to their JavaScript. If a sensitive API grants that permission too broadly, code running on an unintended website may be able to read data in a user’s browser context. If the policy is too narrow, legitimate frontends stop working.

Artificial Intelligence 06 Sep 2026 9 min read

Token and Sequence Biases for LLM Decoding

Sometimes an LLM produces generally good text but makes one narrow decoding choice too often. Perhaps a domain-specific abbreviation should be preferred, a deprecated product name should be discouraged, or a particular token must not appear in generated text. Changing temperature is a poor fit for this problem because temperature affects the whole next-token distribution. Retraining a model is usually excessive when the desired change is local. Token and sequence biases provide a narrower tool: modify selected prediction scores during decoding while leaving the model parameters unchanged.

Artificial Intelligence 06 Sep 2026 10 min read

Steer Language Models by Editing Hidden Activations

Prompting changes what a language model reads. Fine-tuning changes its parameters. There is another, more experimental way to influence generation: change the model’s internal activations while it runs. This technique is commonly called activation steering or activation engineering. A simple version measures how hidden representations differ between examples that express opposite properties, turns that difference into a steering vector, and adds a scaled version of the vector during inference. The model weights stay unchanged.

Artificial Intelligence 06 Sep 2026 10 min read

Stabilize Neural Network Evaluation with Exponential Moving Average Weights

A neural network’s final training step is not necessarily its most useful checkpoint. Stochastic optimization keeps moving the parameters as it follows noisy mini-batch gradients, so two nearby checkpoints can behave slightly differently even when training is otherwise healthy. An exponential moving average (EMA) of model weights gives you a second set of parameters that changes more smoothly. Instead of evaluating only the latest training weights, you maintain a weighted history in which recent weights matter most and older weights gradually fade away.

Tech 06 Sep 2026 8 min read

Sleep vs Hibernate: What Happens to Your Laptop

Closing a laptop lid often makes the screen go dark without actually shutting the computer down. Open it again and your apps may return almost immediately, still showing the same documents and browser tabs. A laptop can also offer a hibernate option that preserves your session while using even less power. Sleep and hibernate both let you continue where you left off, but they preserve that working state differently. The difference explains why sleep usually resumes quickly, why a sleeping laptop can still lose battery charge, and why hibernate takes longer to enter and leave.

Cybersecurity 06 Sep 2026 9 min read

Serve User Uploads as Untrusted Content

Accepting a file is only half of an upload feature. The other half is deciding what happens when someone retrieves that file. A file that was harmless while sitting in object storage can become a security problem when a browser receives it from your application’s origin. If the response is interpreted as active content, the uploaded bytes may gain privileges that the uploader should never have had. Even files that are meant only for download can expose other users when authorization, response metadata, or storage boundaries are wrong.

Artificial Intelligence 06 Sep 2026 11 min read

Sequence Parallelism for Lower Transformer Activation Memory

Large transformer training can run out of accelerator memory even after the model’s weights are split across several devices. The reason is easy to miss: tensor parallelism can shard expensive matrix multiplications while some intermediate activations remain replicated on every worker in the tensor-parallel group. Sequence parallelism removes part of that replication. For operations that work independently on each token, it partitions activations along the sequence dimension so each tensor-parallel worker keeps only a slice of the tokens. The workers temporarily reconstruct or reduce data where the tensor-parallel computation requires communication, then return to sequence-sharded activations.

Cybersecurity 06 Sep 2026 12 min read

Separate Public Errors from Diagnostic Details

An application fails while processing a request. The easiest implementation is often to return the exception message to the caller. That feels helpful during development because the response explains exactly what went wrong. In production, the same detail can expose information that the caller did not previously know: filesystem paths, database structure, dependency names, internal service addresses, object identifiers, configuration values, or fragments of sensitive input. A stack trace can reveal even more about how the application is assembled.

Cybersecurity 06 Sep 2026 11 min read

Separate Human and Service Identities

A developer needs a background job to read from an internal API. The fastest solution may be to reuse the developer’s own account, save its credential in the job, and move on. That shortcut quietly joins two different security problems. A human account is designed around a person’s login, employment, recovery, and interactive authentication. A service identity is used by software that runs without a person present. When one identity is forced to serve both roles, permissions become harder to limit, credentials are harder to rotate, and logs can no longer clearly tell whether an action came from a person or an automated workload.

Cybersecurity 06 Sep 2026 9 min read

Rotate Encryption Keys Without Losing Access to Data

Encrypting stored data creates a second problem that is easy to overlook: the application must keep the right decryption key available for as long as the protected data still needs to be read. If an application replaces an encryption key and immediately deletes the old one, existing ciphertext may become permanently unreadable. If it never replaces keys, one long-lived key can accumulate more data and more operational exposure than intended. A practical design needs to support both change and continuity.

Cybersecurity 06 Sep 2026 9 min read

Rotate API Credentials Without Breaking Services

Long-lived API credentials create an awkward security trade-off. Keeping one credential forever avoids deployment work, but extends the useful lifetime of any copy that is exposed. Replacing it abruptly reduces that lifetime, but can also break every client that still uses the old value. The practical solution is not simply to “rotate more often.” It is to design the authentication system so a credential can be introduced, adopted, verified, and retired without requiring one perfectly synchronized change.

Artificial Intelligence 06 Sep 2026 10 min read

Rotary Position Embeddings in Transformers

A Transformer attention layer needs to know more than which tokens are present. Order matters: dog bites man and man bites dog contain the same words but express different relationships. Yet the dot products used by self-attention do not inherently know whether two token representations came from adjacent positions or opposite ends of a sequence. Rotary position embedding, usually shortened to RoPE, adds position information by rotating parts of the query and key vectors before their attention scores are computed. The useful consequence is subtle: each token receives a transformation based on its absolute position, while the dot product between two transformed vectors depends on their relative position.

Cybersecurity 06 Sep 2026 11 min read

Review Access Before Privileges Become Permanent

Access control can be correct on the day a permission is granted and still become risky later. A developer changes teams but keeps access to an old production project. A contractor finishes an engagement while a group membership remains active. A service account stops using a privileged operation, but its role is never reduced. None of these cases requires a broken authorization check. The system may enforce every permission exactly as configured. The problem is that the configured access no longer matches the current need.

Cybersecurity 06 Sep 2026 10 min read

Require Reauthentication Before Sensitive Actions

A user can remain signed in for hours or days, which is useful for ordinary work. The same convenience becomes risky when that old session is enough to change a password, add a new authenticator, reveal a recovery secret, or perform another action with lasting security impact. The problem is simple: a valid session proves that authentication happened earlier; it does not prove that the legitimate user is still in control now. A session may be open on an unattended device or may have been copied by an attacker. If every account change trusts the session equally, possession of that session can become enough to take over the account permanently.

Software Engineering 06 Sep 2026 9 min read

Replacing Branching with Lookup Tables

A chain of conditionals is not automatically a design problem. Sometimes each branch expresses genuinely different behavior, and an if or switch is the clearest way to show it. But another kind of branching appears when the logic is identical in every branch and only a value changes. That distinction matters. If the program is repeatedly asking, “Which constant belongs to this case?”, the conditionals are acting as a hand-written lookup mechanism. A lookup table can make the relationship explicit: keys represent cases, values represent the data associated with them.

Software Engineering 06 Sep 2026 8 min read

Replacing Behavior Switches with Polymorphism

A switch statement is not a design problem by itself. When a program has a small, stable set of cases, one explicit conditional can be easier to read than a hierarchy of types. Trouble starts when the same type distinction controls behavior in several places. Adding one new case then means finding every switch that knows about that type. Missing one produces a system where the new case works in some operations but not others.

Software Engineering 06 Sep 2026 8 min read

Reducing Temporal Coupling in APIs

Some APIs look simple because each method is simple. The difficulty appears only when you try to use them: one method must run before another, initialization must happen at exactly the right time, and an innocent-looking call fails because an earlier step was missed. This kind of order dependency is called temporal coupling. Two operations are temporally coupled when their correctness depends on when or in what order they happen. Some ordering is inherent to the problem, but hidden ordering makes code harder to understand, test, and change.

Artificial Intelligence 06 Sep 2026 10 min read

Reduce Transformer Inference with Early Exits

A transformer classifier normally spends the same number of layers on every input. A straightforward support ticket and an ambiguous one both travel through the entire network, even when an intermediate representation may already contain enough information for the easy case. Early exiting changes that fixed-compute rule. It adds prediction points inside the model and lets sufficiently confident inputs stop before the final layer. Harder inputs continue through more layers. The result is input-dependent computation: the model can reduce average work without forcing every request to use a smaller network.

Artificial Intelligence 06 Sep 2026 11 min read

Reduce Transformer Inference Cost with Early Exiting

A transformer classifier normally spends the same number of layers on every input. A clear support request and an ambiguous one both pass through the entire network, even when an intermediate representation already contains enough information to classify the easy case correctly. Early exiting changes that fixed-compute rule. It attaches prediction heads to intermediate layers and lets an input stop once a chosen exit rule considers the prediction sufficiently reliable. Easy inputs can use less computation, while harder inputs continue through deeper layers.