Skip to content

Archive / page 52

All articles

Every practical article from the Nalar archive, newest first.

Go 10 Sep 2026 7 min read

Compare Go Slices with Custom Equality Using slices.EqualFunc

Two slices can represent the same information without being directly comparable element by element. One side might contain structs while the other contains strings. Text may need case-insensitive comparison. IDs may arrive in different concrete types even though your application treats them as the same value. When equality depends on a rule rather than Go’s == operator, slices.EqualFunc puts that rule in one place and handles the slice traversal for you.

Go 10 Sep 2026 6 min read

Compare Go Slices Lexicographically with slices.Compare

Sometimes equality isn’t enough. You may need to order version components, compare path segments, choose which byte sequence comes first, or sort records by a slice-valued key. Writing that comparison by hand is straightforward, but the prefix case and the meaning of the return value are easy places to introduce small bugs. For slices whose element type is ordered, slices.Compare provides the standard lexicographic comparison directly. It compares elements from left to right and, when all shared elements match, treats the shorter slice as smaller.

Software Engineering 10 Sep 2026 8 min read

Command-Query Separation: Make Side Effects Visible

Command-Query Separation: Make Side Effects Visible A method named getNextInvoiceNumber() looks like a read. If calling it also increments the stored number, logging it twice can change application behavior. A debugger expression can consume a value. A harmless-looking retry can advance state again. The problem isn’t mutation by itself. Software has to change state. The problem is making a caller guess whether asking for information also changes something. Command-query separation is a design principle that reduces this ambiguity. A query returns information without changing observable state. A command changes state and doesn’t need to return domain information about that change. This article shows how that distinction makes APIs easier to reason about, where the rule is useful, and where forcing it creates more complexity than it removes.

Go 10 Sep 2026 5 min read

Combine Go Slices with slices.Concat

Combining several slices often starts as a tiny append expression and ends with an ownership question: did the result reuse one of the input backing arrays, and can a later append or mutation affect data another part of the program still uses? Since Go 1.22, slices.Concat gives this operation a direct standard-library form. It combines multiple slices into a new slice, which is especially useful when the result should be treated as its own collection rather than as an extension of one input.

Software Engineering 10 Sep 2026 12 min read

Choosing Sociable or Solitary Unit Tests

Choosing Sociable or Solitary Unit Tests A unit test fails after a harmless refactor. The production behaviour is still correct, but the test expected an internal collaborator to receive exactly three calls. Elsewhere, a different unit test passes even though two real classes no longer work together, because both sides were replaced with mocks. Both tests are isolated in some sense, yet they give poor feedback for different reasons. The useful question isn’t simply whether unit tests should use mocks. It is where the test boundary should be.

Go 10 Sep 2026 6 min read

Check Slice Predicates in Go with slices.ContainsFunc

Sometimes you don’t need the matching element or its position. You only need to answer a yes-or-no question: does this slice contain anything that satisfies a condition? For that case, slices.ContainsFunc is more direct than writing an index loop or calling slices.IndexFunc and comparing its result with -1. It accepts a predicate, checks elements in order, and returns as soon as one matches. What slices.ContainsFunc does The function accepts any slice element type because the predicate decides what counts as a match:

Tech 10 Sep 2026 8 min read

Can Motorcycle Vibrations Damage a Phone Camera?

A phone mounted on a motorcycle handlebar may look perfectly secure while its camera is experiencing thousands of small movements. For many phones, ordinary movement is expected. Some camera modules even contain moving parts designed to compensate for it. The concern is a different kind of motion: sustained, high-amplitude vibration in particular frequency ranges. Repeated exposure can interfere with or degrade delicate camera mechanisms in some phones, especially systems that physically move lens or sensor components for stabilization or focusing.

Go 10 Sep 2026 9 min read

Build Lazy Iterators in Go with iter.Seq

A Go API that returns a slice is pleasantly simple, but a slice isn’t always the right contract. Sometimes the caller only needs the first matching value. Sometimes producing each value requires work. Sometimes the complete result could be large enough that building it up front is wasteful. Go 1.23 gives those APIs a standard alternative: iter.Seq. It represents a sequence that produces values on demand and works directly with a for range loop. The useful part isn’t just new syntax. An iter.Seq can hide a container’s representation, avoid an intermediate result slice, and stop producing values as soon as the caller stops iterating.

Go 10 Sep 2026 7 min read

Build Go Maps from Iterators with maps.Collect

An iterator is a convenient way to produce key-value pairs without deciding up front where they’ll be stored. Eventually, though, an API may need an ordinary map. Writing the collection loop yourself is straightforward, but Go 1.23 gives that boundary a standard name: maps.Collect. maps.Collect consumes an iter.Seq2, stores each yielded pair in a newly allocated map, and returns that map. It’s a small helper, but it makes ownership clear: the sequence produces data; Collect creates the destination.

Cybersecurity 10 Sep 2026 8 min read

Bound Decompression Before Processing Untrusted Data

A compressed request or uploaded archive can look harmless when its byte count is small. The server may discover a very different workload after decompression: far more output bytes, memory use, disk writes, or nested work than the original input suggested. That gap matters whenever an attacker can supply compressed data. If the application limits only the compressed input size, a small request can still force expensive expansion and exhaust resources needed by other users. The defensive goal is not to guess which compressed files are malicious. It is to put a hard boundary around the work the application is willing to perform.

Cybersecurity 10 Sep 2026 12 min read

Bind OAuth Callbacks to the Login That Started Them

An OAuth callback can look valid even when it belongs to the wrong browser interaction. The authorization server may have issued a real code, the redirect URI may be correct, and the code exchange may succeed. Yet if the client cannot tell whether this browser actually started that authorization flow, it can attach the wrong external identity or authorization to the current session. This is a form of cross-site request forgery at the OAuth callback. In a login flow, one possible consequence is login CSRF: a victim can end up signed into the client as an account associated with someone else. The details vary by application, but the defensive question stays the same: does this callback belong to a login transaction that this user agent started?

Go 10 Sep 2026 6 min read

Append Iterator Values to Go Slices with slices.AppendSeq

An iterator is convenient while data is flowing through a pipeline, but sooner or later you may need those values in a slice. If you already have a destination slice, collecting the iterator separately and then appending it creates an unnecessary intermediate step. Go 1.23 added slices.AppendSeq for exactly this boundary. It consumes an iter.Seq, appends each yielded value to an existing slice, and returns the resulting slice. What slices.AppendSeq does The function has a compact signature:

Tech 09 Sep 2026 8 min read

Why Your Screen Can Stay On While Video Is Playing

Set a phone or laptop to turn its screen off after a few minutes, then start a video. The display may stay on for the entire program even though you never touch the device. At other times, the same screen-timeout setting works exactly as expected. The difference is that a screen timeout is usually an idle rule, not an unconditional countdown. A device can treat active video playback as a reason to keep the display awake. Understanding that distinction makes screen-timeout behavior much less mysterious and helps when a screen turns off too soon—or refuses to turn off when you expect it to.

Tech 09 Sep 2026 8 min read

Why Your Phone Compass Can Point the Wrong Way

A maps app can know where you are yet show your direction incorrectly. The location marker may be on the right street while its direction indicator points sideways, rotates while you stand still, or seems to face the wrong way. That is possible because location and direction are different measurements. A phone can estimate its position from satellite navigation, Wi-Fi, mobile networks, and other information, while its compass heading depends heavily on sensing the magnetic field around the device.

Tech 09 Sep 2026 7 min read

Why Your Laptop Fan Can Keep Running After You Close Apps

You finish a video call, close your browser and other visible apps, yet your laptop fan keeps spinning. It can seem as though the computer is working hard for no reason. The key is that the fan does not respond directly to how many windows are open. It responds to the laptop’s need for cooling. Heat already inside the machine can take time to leave, and software can continue doing work even when no application window is visible.

Tech 09 Sep 2026 8 min read

Why Your Computer Can Open the Same File in Different Apps

Double-click a photo, document, or audio file and your computer usually opens it in one particular app. Install another suitable app, however, and the same file may now have several programs that can open it. You can often choose one app for a single occasion or make it the new default. This can be confusing because the file and the app seem tightly connected. In reality, they are separate. The file contains data in a particular format, while the operating system keeps rules about which installed app should normally handle that kind of file.

Tech 09 Sep 2026 7 min read

Why Wired Headphones Can Work While the Microphone Does Not

You plug a wired headset into a phone, laptop, controller, or adapter. Music plays normally through both earpieces, but a call or recording app still uses the device’s built-in microphone—or records no useful sound at all. That combination can seem contradictory. If the headphones work, surely the cable and plug must be connected correctly. The missing piece is that headphone audio and microphone audio travel through separate electrical connections. A connection can support the speakers without supporting the microphone, and a partial compatibility problem can affect one function while leaving the other apparently normal.

Tech 09 Sep 2026 9 min read

Why SSDs Can Slow Down When They Are Nearly Full

A solid-state drive can still have free space and yet become less consistent at writing data as it fills up. You might notice a large file transfer slowing down, an installation taking longer than expected, or a heavily used computer feeling less responsive when storage is almost exhausted. The reason is not simply that an SSD has to “search harder” for empty space. Flash storage has rules about how data can be written and erased. When plenty of unused space is available, the drive has more flexibility to work within those rules. When little space remains, that work can become more complicated.

Tech 09 Sep 2026 7 min read

Why Some PDFs Have Selectable Text and Others Do Not

Two PDF files can look almost identical on screen but behave very differently. In one, you can highlight a sentence, search for a name, or copy a paragraph. In another, dragging across the same-looking words selects nothing at all. The difference is usually not the PDF extension itself. A PDF is a container that can hold several kinds of page content, including actual text and images. A page that looks like printed text may therefore contain computer-readable characters, a picture of those characters, or a combination of both.

Tech 09 Sep 2026 8 min read

Why Phone Notifications Can Arrive Late

A message can reach your phone instantly one moment and appear several minutes late the next. Sometimes several notifications arrive together as soon as you wake the screen or open an app. It is tempting to blame the notification setting itself, but a notification is the end of a longer delivery path. The service has to detect new information, send it toward your phone, the phone has to receive it, and software has to decide how to present it.

Tech 09 Sep 2026 8 min read

Why Files With Numbers in Their Names Can Sort in an Unexpected Order

You create files named photo-1, photo-2, and photo-10, then sort the folder by name. You expect 1, 2, 10. In some apps that is exactly what you get. In others, photo-10 may appear before photo-2. Nothing is necessarily wrong with the files. The difference comes from what sorting by name means to the software doing the sorting. A program can compare filenames as text, or it can recognise runs of digits as numbers and compare their numerical values. Those two rules can produce different orders from the same names.

Tech 09 Sep 2026 9 min read

Why Fast Motion Can Leave Trails on a Screen

A screen can have a high refresh rate and still show a faint trail behind a moving cursor, dark text, or a fast object in a game. This effect is often called ghosting or smearing. It can make motion look less clear even when the animation itself is running smoothly. The key idea is that refreshing the screen and changing each pixel are related but different jobs. A display may receive a new image on time while some pixels are still moving toward the brightness or colour that the new image requires.

Tech 09 Sep 2026 8 min read

Why Display Scaling Changes Text Size Without Changing Resolution

A high-resolution laptop or monitor can have plenty of pixels and still show text that feels uncomfortably small. Increasing display scaling often fixes that problem, yet the screen can continue running at the same resolution. That seems contradictory until you separate two ideas: how many physical pixels the display has and how large the operating system chooses to draw interface elements. Display scaling changes the second one. Understanding that distinction helps when setting up a new monitor, connecting displays with different pixel densities, or deciding whether lowering resolution is really the right way to make things easier to read.

Tech 09 Sep 2026 8 min read

Why Bluetooth Audio Can Lag Behind Video

Bluetooth headphones can sound perfectly normal with music yet make a video feel wrong when a speaker’s lips move before you hear the words. The same delay can be more obvious in a game, where a sound may arrive after the action that caused it. This happens because wireless audio is not sent directly from an app to your ears in one instant. The sound passes through several processing and transmission stages, and each can add a small amount of time. Some devices can hide much of that delay during ordinary video playback, but they cannot compensate equally well in every situation.