Skip to content

Archive / page 75

All articles

Every practical article from the Nalar archive, newest first.

Artificial Intelligence 04 Sep 2026 8 min read

Weight Decay in Neural Network Training

A neural network can keep reducing its training loss while learning parameter values that generalize poorly. Weight decay is one way to regularize training: it applies a small pressure that shrinks selected parameters as optimization proceeds. The idea sounds similar to adding an L2 penalty to the loss, and for plain stochastic gradient descent the two can be made equivalent by matching their scaling. With adaptive optimizers such as Adam, however, adding an L2 penalty to the gradient and directly decaying the weights are not generally the same operation. That distinction is why optimizers such as AdamW use decoupled weight decay.

Software Engineering 04 Sep 2026 10 min read

Versioning Contracts, Not Just Releases

A version number is useful only when its consumers can make a decision from it. Suppose a library changes from 2.4.1 to 2.5.0. A developer considering the upgrade wants to know something practical: can existing code keep working, or must it change? The answer does not come from how much code the maintainer edited. It comes from whether the release changed a contract that consumers depend on. That contract includes more than function names. It can include accepted inputs, returned values, error behavior, configuration, file formats, command-line options, extension points, and other observable behavior that the project promises to preserve.

Cybersecurity 04 Sep 2026 8 min read

Verify Dependency Integrity Before Installation

A dependency declaration such as library = 2.4.1 tells a package manager which release you intend to use. It does not, by itself, prove that the bytes being installed are the same bytes you previously reviewed, tested, or approved. That distinction matters when dependencies cross a trust boundary. Packages may come through registries, mirrors, caches, proxies, build systems, or internal artifact stores. If unexpected bytes are accepted somewhere along that path, a familiar package name and version can create false confidence.

Python 04 Sep 2026 8 min read

Use Slotted Dataclasses When Object Shape Is Fixed in Python

Python dataclasses reduce boilerplate for record-like classes, but their instances are still ordinary Python objects by default. Declared fields normally live in an instance dictionary, and new attributes can be attached later. That flexibility is useful until the model is supposed to have a fixed shape. Coordinates, parsed records, configuration snapshots, protocol messages, and other compact value objects often have a known set of fields. When many such objects exist, keeping dynamic per-instance attribute storage may also be unnecessary.

Database 04 Sep 2026 10 min read

Use Partial Indexes to Index the Rows You Actually Query

A normal database index contains an entry for every table row that qualifies for the indexed columns. That is often appropriate, but some applications repeatedly query only a small, stable subset of a table. Consider a task table where most tasks eventually become completed or archived, while the application dashboard mainly reads current open tasks. A full index on project_id keeps index entries for historical rows even though those rows are rarely part of the hot query path.

Artificial Intelligence 04 Sep 2026 9 min read

Use Padding Masks for Variable-Length Transformer Batches

Transformer inputs rarely have identical lengths. One sentence may contain 8 tokens while another contains 30, yet efficient training and inference usually process multiple sequences in rectangular tensors. The usual solution is to add padding tokens to shorter sequences until their shapes match. Padding solves the shape problem but creates a semantic one: the added positions are not real input. If the model treats them like ordinary tokens, they can influence attention, pooling, and training loss. A padding mask tells the computation which positions are valid and which exist only to make the batch rectangular.

Artificial Intelligence 04 Sep 2026 11 min read

Use Label Smoothing Without Hiding Classification Mistakes

A classifier trained with ordinary cross-entropy is usually given a hard target: the correct class has probability 1, and every other class has probability 0. For a three-class example: cat dog bird 1.0 0.0 0.0 That target is simple and often appropriate. But it also asks the model to keep increasing the correct-class logit relative to the others even after the prediction is already very confident.

Python 04 Sep 2026 9 min read

Use functools.singledispatch for Type-Based Extension Points in Python

A function often starts with one input type and later grows branches for several related types. The first version may be straightforward: def render(value): if isinstance(value, str): ... elif isinstance(value, list): ... elif isinstance(value, dict): ... As the number of supported types grows, this function becomes the place where every extension must be added. The branches mix dispatch logic with the behavior for each type, and independently maintained modules cannot add support without editing the central function.

Database 04 Sep 2026 12 min read

Use EXISTS and NOT EXISTS for Relationship Checks in SQL

Many SQL queries do not actually need data from a related table. They only need to answer a yes-or-no question: Does this customer have at least one paid order? Is this project missing an active owner? Does any inventory row satisfy this product requirement? A common first attempt is to join the tables and then remove duplicates. That can work, but it makes the query produce more rows than the problem requires and then asks a later operation to repair the result.

Artificial Intelligence 04 Sep 2026 8 min read

Use Dropout Without Breaking Neural Network Inference

A neural network can fit its training data well while performing poorly on new examples. One way to reduce this kind of overfitting is dropout, a training technique that randomly removes some activations on each forward pass. The idea is simple, but one detail causes many implementation bugs: dropout is intentionally stochastic during training and normally disabled during inference. If those modes are confused, evaluation becomes noisy or predictions use the wrong activation scale.

Python 04 Sep 2026 10 min read

Use Decimal for Exact Base-10 Arithmetic in Python

A price of 0.10, a tax rate of 8.25%, and a total rounded to cents look like ordinary numbers. But the representation you choose determines which arithmetic rules your program actually follows. Python’s float is binary floating point. It is excellent for measurements, graphics, scientific calculations, and many other workloads where small approximation is expected. The problem appears when your domain requires values and rounding rules expressed in base 10.

Python 04 Sep 2026 10 min read

Use Callable-Sentinel Iteration for Chunked Reads in Python

Reading a file in chunks is a small problem that appears in many larger tasks: hashing uploads, copying large files, parsing binary records, compressing streams, and sending data without loading everything into memory. A common solution is a while loop that reads one chunk, checks for end-of-file, processes the chunk, and repeats. That loop is correct when written carefully, but Python has another standard-library pattern that expresses the same control flow as iteration:

Linux 04 Sep 2026 13 min read

Understand Memory-Mapped Files on Linux with mmap

Reading a file usually means calling read() and copying bytes into a buffer that your program manages. That model is explicit and works well for most file I/O. Linux offers another model with mmap(): map a file region into the process’s virtual address space, then access the file through ordinary memory loads and stores. That can simplify workloads such as random access into large files, shared file-backed state, indexes, and binary formats whose access pattern naturally looks like “read bytes at offset N.” It can also avoid an application-managed read buffer for those accesses.

Go 04 Sep 2026 9 min read

Understand Escape Analysis and Heap Allocations in Go

A Go program can create many values without you choosing whether each value lives on a goroutine stack or in heap memory. The compiler usually makes that decision for you. This becomes important when a hot path allocates more than expected. A small helper function may look harmless, yet a value it creates can outlive the function call and require heap storage. More heap allocation can mean more work for the garbage collector, but changing code blindly to avoid the heap can make a program harder to understand without producing a measurable benefit.

Cybersecurity 04 Sep 2026 11 min read

Treat Request Hostnames as Untrusted Input

A web application often needs to know which hostname a request targeted. That hostname helps route virtual hosts and can be useful when serving several domains. The security problem begins when the application treats the request hostname as if it were a trusted statement about its own public identity. If an unauthenticated client can influence that value, using it to build password-reset links, sign-in callbacks, canonical URLs, or other security-sensitive destinations can make the application generate URLs for a domain it does not control. Similar trust mistakes can also affect routing and caches.

Cybersecurity 04 Sep 2026 9 min read

Treat Deserialization as a Trust Boundary

Applications constantly turn bytes into useful values. A request body becomes a set of fields, a cached value becomes a record, or a message from a queue becomes a command. This conversion is called deserialization when the bytes represent a previously encoded data structure. The security problem begins when deserialization does more than recover inert data. Some serialization systems can reconstruct application-specific object types or trigger behavior while rebuilding an object graph. If an attacker can influence that serialized input, the parser may be asked to create types or invoke mechanisms that the application never intended to expose at that boundary.

Database 04 Sep 2026 10 min read

Traverse Hierarchical Data with Recursive SQL CTEs

Hierarchical data appears everywhere: employees report to managers, comments reply to other comments, folders contain folders, and categories form parent-child trees. The table structure is usually simple. The query is the hard part. A normal join follows a fixed number of relationships. A recursive common table expression, or recursive CTE, can follow the same relationship repeatedly until there are no more rows to visit. The key mental model is: start with an anchor set, repeatedly derive the next set from the previous one, then return the accumulated rows.

Software Engineering 04 Sep 2026 8 min read

Translating Errors at Abstraction Boundaries

A function can hide how data is stored and still leak the storage technology through every error it returns. When that happens, callers become coupled to details the abstraction was supposed to contain. Suppose an order service asks a repository to load an order. The repository promises to find orders; it does not promise that callers understand SQL drivers, HTTP clients, file formats, or whichever mechanism happens to sit underneath it. If a missing order appears as a driver-specific NoRows exception today and an HTTP 404 exception after a migration, callers must change even though the repository’s meaning did not.

Artificial Intelligence 04 Sep 2026 10 min read

Teacher Forcing in Autoregressive Models

An autoregressive model generates a sequence one element at a time. A language model predicts the next token from the tokens before it; a sequence model might similarly predict the next symbol, event, or value from an existing prefix. That creates a practical training question: when teaching the model to predict step 5, should the input contain the correct steps 1–4 from the dataset, or the model’s own earlier predictions?

Artificial Intelligence 04 Sep 2026 9 min read

Stop Neural Network Training at the Right Time with Early Stopping

Training a neural network for more steps usually gives the optimizer more opportunities to reduce training loss. That does not mean the resulting model will perform better on unseen data. After useful patterns have been learned, continued training can increasingly fit details that are specific to the training set. Early stopping turns this observation into a practical training rule: evaluate the model on held-out validation data during training, remember the best checkpoint, and stop when meaningful validation improvement has not appeared for long enough.

Artificial Intelligence 04 Sep 2026 9 min read

Stabilize Neural Network Evaluation with EMA Weights

Neural network training does not usually move parameters smoothly toward one final point. Mini-batch gradients are noisy, learning-rate schedules change step sizes, and later updates can move a model between nearby parameter settings with noticeably different validation results. That creates a practical question: should deployment use the parameters from one particular training step, or a smoothed version of several recent parameter states? An exponential moving average, or EMA, provides the second option. During training, it maintains a separate copy of the model parameters that changes more slowly than the actively optimized parameters. The optimizer still trains the ordinary model. The EMA copy is typically used for evaluation or inference.

Software Engineering 04 Sep 2026 10 min read

Snapshot Tests as Reviewed Contracts

Some outputs are easy to test with a few assertions. A price calculation can be checked against one number. A validation rule can be checked against one error code. Other outputs are structured and wide: a rendered document, a compiler diagnostic, a serialized configuration, or a formatted report may contain dozens of fields and lines. Writing an assertion for every detail can make the test harder to read than the behavior it protects.

Tech 04 Sep 2026 8 min read

Silent Mode vs Do Not Disturb: What Each Setting Changes

You silence your phone before a meeting, yet notifications still light up the screen. Another time, you turn on Do Not Disturb and an important call still gets through. Both can seem like failures if you expect these settings to do the same job. They usually do not. Silent mode mainly changes how alerts announce themselves, while Do Not Disturb controls which interruptions are allowed to reach you. Exact behaviour varies by phone and operating-system version, but this distinction is a useful way to understand the settings.