Mohamed Idris
@hnooz
Tips by @hnooz
Unwrap errors type-safely with errors.AsType (Go 1.26)
GOerrors.AsType[E] (Go 1.26) is a generic, type-safe version of errors.As. It returns the matched error and a boolean ins…
Sandbox filesystem access to a directory with os.Root (Go 1.24)
GOos.Root (Go 1.24) confines all file operations to a directory: Open, Create, Stat, and friends resolve relative to the…
Write custom iterators with range-over-func (Go 1.23+)
GOGo 1.23 lets functions of type iter.Seq[V] be consumed by for range. You return a function that calls yield for each el…
Use b.Loop() for accurate benchmarks (Go 1.24)
GOb.Loop() (Go 1.24) is the new benchmark loop. Beyond being cleaner than for i := 0; i < b.N; i++, it keeps setup outsid…
Track tool dependencies in go.mod with tool directives (Go 1.24)
GOGo 1.24 tracks executable dependencies with tool directives in go.mod, retiring the old tools.go blank-import hack. go…
Attach request-scoped metadata with the Context facade so it flows into logs and jobs
LARAVELThe Context facade (Laravel 11+) stores key/value data for the current request that's automatically added to every log…
Turn N+1 queries into errors in development with preventLazyLoading()
LARAVELCalled in a service provider, this throws a LazyLoadingViolationException whenever a relation is accessed without being…
Lock down outbound HTTP in tests with preventStrayRequests()
LARAVELHttp::fake() alone lets un-matched requests fall through to the real network, which makes tests flaky and slow and can…
Auto-delete stale records with the Prunable trait instead of a custom command
LARAVELAdd Prunable and a prunable() query, and model:prune (scheduled) deletes matching rows in chunks — no bespoke cleanup c…
Use whenLoaded() in API resources to avoid firing queries during serialization
LARAVELReferencing $this->posts directly in a resource lazy-loads the relation for every model when it wasn't eager-loaded — a…
Throw IntrinsicException for expected errors to skip Nest's auto-logger
NESTJSNestJS 11 added IntrinsicException: throwing it bypasses the framework's automatic error logging while still propagatin…
Validate and convert date query params at the boundary with ParseDatePipe
NESTJSNestJS 11 ships ParseDatePipe, which validates an incoming date string and hands your handler a real Date. Parsing date…
Skip the HTTP layer for workers and CLI with createApplicationContext()
NESTJScreateApplicationContext() boots the DI container without starting an HTTP server. For cron jobs, queue consumers, and…
Keep the SWC builder (default in Nest 11) for ~20x faster builds
NESTJSNest 11 defaults to the Rust-based SWC compiler, which is dramatically faster than tsc for builds and dev restarts. SWC…
Configure a strict global ValidationPipe to strip unknown fields and coerce DTOs
NESTJSwhitelist: true removes any property not declared with a validation decorator — your defense against mass-assignment, s…
Push 'use client' to leaf components and pass server data down as props
NEXTEverything in the App Router is a Server Component until you add 'use client', and that directive taints the whole subt…
Remember GET route handlers are uncached by default since Next.js 15
NEXTNext.js 15 flipped the default: GET route handlers and the client router cache are no longer cached unless you opt in.…
Invalidate exactly what changed with revalidateTag/revalidatePath after writes
NEXTAfter a mutation, invalidate the specific cache entries it affected rather than forcing a broad refresh or client reloa…
Use Server Actions for internal mutations instead of hand-rolled API routes
NEXTServer Actions run mutation logic on the server and can be called directly from a <form action> or a client handler — n…
Stream slow sections with loading.tsx and Suspense instead of blocking the route
NEXTA route-level loading.tsx wraps the page in a Suspense boundary so the shell streams immediately while data loads. Wrap…
Cache expensive server routes at the edge with defineCachedEventHandler
NUXTNitro's defineCachedEventHandler wraps a server route with stale-while-revalidate caching backed by your configured sto…
Set per-route rendering strategy with routeRules instead of restructuring code
NUXTrouteRules applies a rendering mode per URL pattern in config, so marketing pages prerender, content pages use ISR, and…
Give useAsyncData an explicit key to control dedup and caching
NUXTuseAsyncData dedups and caches by key. Without an explicit key Nuxt derives one from the call site, which can collide w…
Share state across components with useState, never a module-level ref, on SSR
NUXTOn the server a module-level ref is created once and shared by every request, so one user's cart can leak into another'…
Use useFetch in setup and $fetch in handlers to avoid double-fetching
NUXTuseFetch is the SSR-aware wrapper: it runs during server render, serializes the result into the payload, and hydrates o…
Prefer asymmetric visibility over readonly when a class mutates its own state
PHPpublic private(set) (PHP 8.4) makes a property readable from anywhere but writable only inside the class. readonly forb…
Chain methods directly off constructors in PHP 8.4
PHPPHP 8.4 allows new Foo()->method() without wrapping the instantiation in parentheses. It's a small ergonomic win that r…
Add #[\Override] in PHP 8.3 to catch broken method overrides at compile time
PHP#[\Override] (PHP 8.3) tells the engine you intend to override a parent or interface method. If no matching method exis…
Use property hooks in PHP 8.4 to compute and validate without getter methods
PHPPHP 8.4 lets a property define get/set hooks inline, so computed and validated values no longer need a separate method…
Type your class constants in PHP 8.3 to lock the contract across subclasses
PHPPHP 8.3 added type declarations for class, interface, and enum constants. Without a type, a subclass could override a c…
Let the React Compiler memoize instead of hand-writing useMemo/useCallback
REACTThe React Compiler analyzes your components and automatically memoizes values and callbacks at build time, following th…
Drop forwardRef in React 19 and accept ref as a normal prop
REACTReact 19 lets function components receive ref as a regular prop, so forwardRef is no longer required for the common cas…
Handle form mutations with built-in pending and error state via useActionState
REACTuseActionState wraps an async action and returns the last result, the action to bind to a <form action>, and a pending…
Read promises and context conditionally with the use() hook
REACTReact 19's use() unwraps a promise or reads context, and unlike the Rules of Hooks it can be called conditionally or in…
Show instant UI with useOptimistic and auto-revert on failure
REACTuseOptimistic renders an expected next state immediately while the real async action runs, then reconciles to the true…
Pass inline async handlers with async closures and the AsyncFn traits (Rust 1.85)
RUSTRust 1.85 stabilized async closures (async || { ... }) and the AsyncFn/AsyncFnMut/AsyncFnOnce traits. These let higher-…
Use native async fn in traits and drop the async-trait crate
RUSTSince Rust 1.75, async fn works directly in traits (via return-position impl Trait), giving you static dispatch with ze…
Flatten guard clauses with let ... else
RUSTlet ... else binds a pattern or diverges — the else block must return, break, continue, or panic, so control flow leave…
Future-proof public types with
RUST#[non_exhaustive] on a public enum or struct forces downstream crates to include a wildcard arm when matching, and bloc…
Control impl Trait lifetime capture precisely with use<> (Rust 2024)
RUSTIn the Rust 2024 edition, return-position impl Trait captures every in-scope generic and lifetime by default. That's us…
Replace modelValue/update boilerplate with defineModel() for v-model
VUEdefineModel() returns a writable ref wired to the parent's v-model, collapsing the modelValue prop plus update:modelVal…
Cancel stale async work in watchers with onWatcherCleanup()
VUERegistered inside the watcher callback, onWatcherCleanup runs before the next invocation and on stop. It removes the ma…
Destructure props with native defaults in Vue 3.5, but pass a getter to watch
VUEStabilized in 3.5: destructured variables from defineProps compile to props.count on access, so they stay reactive and…
Generate hydration-safe unique IDs with useId() for accessibility
VUEuseId() produces IDs that are stable and identical across server render and client hydration, so label/for and aria-des…
Use useTemplateRef() for typed template refs instead of string-matched refs
VUEVue 3.5 resolves template refs by key at runtime, so the type is inferred and you drop the ref(null) declaration that h…
Want to contribute? Submit a tip →