Latest articles

430 new today · 7,327 articles · from 241 blogs

Lea Verou··Lea Verou

jQuery considered harmful

AI summaryThe author argues that while jQuery was instrumental in advancing the Web, most developers today no longer need it since modern browsers natively support the functionality it provided. Beyond redundancy, the core problem is that jQuery's wrapper objects get mixed with native DOM elements and NodeLists, making code confusing, prone to defensive $() wrapping, and extremely difficult to understand or refactor, effectively locking codebases into jQuery. The author proposes a pragmatic approach: avoid using jQuery directly in your own code, reclaim the $ variable with jQuery.noConflict() for lightweight selector helpers, and consider alternatives like Zepto if you prefer the jQuery API.

Preshing on Programming··Jeff Preshing

You Can Do Any Kind of Atomic Read-Modify-Write Operation

AI summaryThe article explains that C++11's atomic library provides several read-modify-write (RMW) operations, and that compare_exchange_weak (compare-and-swap) is the essential primitive from which any custom atomic RMW operation—such as a fetch_multiply—can be implemented via a CAS loop. It demonstrates that CAS loops can combine multiple computation steps, or even multiple variables packed into a single 32- or 64-bit integer (e.g., as a bitfield), into one atomic, lock-free operation. However, it cautions that the C++11 standard doesn't guarantee lock-free behavior, so developers should verify compiler and platform support, such as for std::atomic, std::atomic, or pointer specializations on x86, x64, or ARMv7.

Preshing on Programming··Jeff Preshing

Safe Bitfields in C++

AI summaryThe article presents a macro-based technique for defining 'safe bitfields' in C++, implemented with unions and class templates so that every operation—such as assignment, increment/decrement, and packed array indexing—is checked with runtime asserts to catch out-of-range values during development. It explains how the macros expand into a union whose members share a common initial sequence, which the C++ standard permits for standard-layout types, making the approach legal and free of undefined behavior. Since compilers inline the hidden function calls, the resulting machine code is as efficient as manual bit twiddling.

Sara Soueidan··Sara Soueidan

A Primer To Background Positioning In CSS

AI summaryThis article provides a deep dive into CSS's background positioning properties, illustrated with visual explanations and examples. It covers lesser-known features such as edge offset values, which allow a background image to be positioned relative to any edge—not just top and left—using a length value for the offset. The article aims to teach readers all about these capabilities and more.

Preshing on Programming··Jeff Preshing

Semaphores are Surprisingly Versatile

AI summaryThe article demonstrates that semaphores, though invented by Dijkstra in the early 1960s, are surprisingly versatile building blocks in multithreaded programming: using only semaphores and atomic operations, one can implement lightweight mutexes, auto-reset event objects, read-write locks, a solution to the dining philosophers problem, and a lightweight semaphore with partial spinning. The author describes a reusable 'box office/bouncer' pattern in which an atomic counter at the 'box office' makes decisions in userspace while the semaphore acts as the 'bouncer' managing waiting threads, allowing these primitives to avoid expensive system calls and optionally spin briefly before sleeping in the kernel. All implementations are provided as portable C++11 source code on GitHub, including a Semaphore class that maps to native semaphores on Windows, MacOS, iOS, Linux and other POSIX environments.

Sara Soueidan··Sara Soueidan

Building a Circular Navigation with SVG

AI summaryThe article explains why SVG is better suited than CSS for building circular navigation menus, as SVG's semantic, interactive shape elements avoid the hacky transformations and browser inconsistencies of the CSS approach. It gives an overview of how to draw menu sectors using the SVG element, covering the line and arc commands, coordinate calculations with polar-to-cartesian conversion, and rotating the sectors with SVG's native transformations. It also briefly describes positioning icons within the sectors using and elements.

Sara Soueidan··Sara Soueidan

Extending the Color Cascade with the CSS currentColor Variable

AI summaryThis article explains the benefits of using variables in CSS style sheets, a practice familiar to those who use preprocessors like Sass or LESS. It provides an overview of why variables are so popular and useful, with a particular focus on introducing the currentColor variable.

Lea Verou··Lea Verou

Awesomplete: 2KB autocomplete with zero dependencies

AI summaryFrustrated by the HTML5 element's browser inconsistencies and lack of customizability, and finding existing autocomplete scripts too bloated and often jQuery-dependent, the author wrote their own widget called Awesomplete. The widget is extremely lightweight—under 1.5KB minified and gzipped—with zero dependencies, and it works in IE9 (sorta), IE10+, Chrome, Firefox, Safari 5+, and Mobile Safari. It's available on GitHub with documentation, and while it may not suit complex needs out of the box, it's designed to be hackable and extensible.

Sara Soueidan··Sara Soueidan

Better SVG Fallback and Art Direction With The picture Element

AI summaryThe article explains how the HTML element offers a better, mostly JavaScript-free way to serve SVG foreground images with fallbacks for non-supporting browsers and to apply art direction by loading different images based on media queries, compared to the traditional approach that requires JavaScript solutions like Modernizr. It shows how to use the , , srcset, and sizes attributes to provide fallbacks at various resolutions and to serve smaller or cropped SVGs on smaller screens. Since browser support for is still incomplete, the author recommends the Picturefill polyfill, including a conditional-comment workaround for IE9.

Sara Soueidan··Sara Soueidan

Compositing And Blending In CSS

AI summaryThis article explains compositing and blending in CSS, introducing the concepts of source and destination elements, Porter Duff compositing operations, and how 16 available blend modes determine how overlapping colors interact. It covers two main properties: background-blend-mode, which blends an element's background layers with each other and its background color, and mix-blend-mode, which blends an element with content in its backdrop. The author describes each blend mode's effect and provides an interactive demo to help users experiment and pick the right mode, since results are often hard to predict.

Sara Soueidan··Sara Soueidan

Useful SVGO[ptimization] Tools

AI summaryThe article introduces SVGOMG, a new GUI for the SVGO SVG optimization tool built by Jake Archibald, which lets users select optimizations and see a live preview of the result, addressing SVGO's previous lack of preview and its risk of breaking animated or scripted SVGs. It also overviews other SVGO tools and plugins for different workflows, including Adobe Illustrator (SVG NOW), Inkscape, Sketch (SVGO Compressor), a drag-and-drop GUI, Grunt/Gulp plugins, and an OS X folder action, while noting precautions such as disabling the removeViewBox optimization and backing up files when originals are replaced.

Sara Soueidan··Sara Soueidan

Tips For Optimizing SVG Delivery For The Web

AI summarySVGs are a valuable asset in responsive web design, but like any image format, they must be properly optimized to avoid negatively impacting page performance. The article outlines several steps that developers can take to ensure they deliver well-optimized SVG resources for the web.

Sara Soueidan··Sara Soueidan

An Overview Of SVG Sprite Creation Techniques

AI summaryThis article, written for 24Ways, provides an overview of three techniques for creating SVG sprites as an icon system that can replace icon fonts. It also examines several available tools that can automate sprite creation and provide fallback support.

Preshing on Programming··Jeff Preshing

C++ Has Become More Pythonic

AI summaryThe article argues that modern C++, particularly C++11 and C++14, has adopted many features that give it a distinctly Pythonic flavor, such as range-based for loops, type deduction with auto, tuples, uniform initialization, lambda expressions, and parameter packs. The author compares each of these C++ additions to their earlier Python counterparts, raising the question of whether Python directly influenced C++ or whether both languages simply converged on similar useful constructs. Ultimately, the author muses that Python's reputation as a friendly, approachable language may have rubbed off on C++, and asks readers whether the new features make C++ simpler and more expressive.

Preshing on Programming··Jeff Preshing

Fixing GCC's Implementation of memory_order_consume

AI summaryThe article documents a bug in GCC 4.9.2's implementation of C++11's memory_order_consume, where the AArch64 compiler neither promotes consume to acquire (the 'heavy' strategy) nor preserves dependency chains (the 'efficient' strategy), allowing out-of-thin-air values like 0xbadf00d to be read in violation of the standard. The author demonstrates the bug with an example, applies Andrew Macleod's patch that conservatively promotes memory_order_consume to memory_order_acquire early in compilation, and verifies the resulting assembly uses the acquire-semantics ldar instruction. Notably, the PowerPC backend does not exhibit the bug because its machine description files treat consume like acquire, whereas AArch64's treat it like relaxed, and the article closes by discussing the uncertain future of memory_order_consume in the C++ standard.

Preshing on Programming··Jeff Preshing

How to Build a GCC Cross-Compiler

AI summaryThis article provides a step-by-step tutorial for building a GCC cross-compiler targeting AArch64 (64-bit ARM) on a Debian Linux system, starting from source packages including Binutils, GCC, Linux kernel headers, Glibc, and supporting libraries like MPFR, GMP, and MPC. It explains how the components depend on each other, details seven sequential build steps (from cross-assembler tools through the standard C and C++ libraries), and covers troubleshooting build errors. The author also mentions an alternative C library called Newlib for embedded targets and provides a bash script on GitHub to automate the entire build process.

Preshing on Programming··Jeff Preshing

How to Install the Latest GCC on Windows

AI summaryThis article provides a step-by-step guide for installing the latest GCC compiler on Windows by building it from source within the Cygwin environment, enabling access to modern C++14 features like generic lambdas that are missing from Visual Studio Express and older system compilers. The process involves installing Cygwin, adding the required packages, downloading and compiling GCC with time-saving configure options, and then testing the new compiler with a C++14 program. The author also notes that native GCC compilers from the MinGW-w64 project offer an alternative that doesn't require Cygwin.

Sara Soueidan··Sara Soueidan

Styling and Animating SVGs with CSS

AI summaryThe article, written for Smashing Magazine, explains how CSS can be used to style and animate SVGs in much the same way as HTML elements. It is a modified transcript of a talk the author gave at CSSconf EU and From the Front, covering the prerequisites and techniques for working with CSS in SVG.

Preshing on Programming··Jeff Preshing

My Multicore Talk at CppCon 2014

AI summaryThe author recounts attending CppCon 2014 and giving a talk on how Ubisoft Montreal develops games for multicore, explaining that their game engines build on three common threading patterns and use custom concurrent objects optimized with atomic operations similar to C++11's low-level atomic library. Notable attendees like Michael Wong and Lawrence Crowl, who authored the C++11 atomic operations section, chimed in during the talk. The author also offers corrections, clarifying that Microsoft's x86 compiler treats volatile variables specially (explaining the absence of compiler reordering bugs) and proposing an assert-based macro to help enforce single-threaded usage of lock-free data structures.

Sara Soueidan··Sara Soueidan

A Guide to SVG Animations (SMIL)

What the title says: a complete guide to SVG animations derived from the SMIl specification. The extensive guide features a lot of demos and goes over the animations syntax, covering almost everything you need to know to get started with SV