Category: Tech News

  • Why Variable Scoping Can Make or Break Your Data Science Workflow

    Why Variable Scoping Can Make or Break Your Data Science Workflow

    Clara Chong

    Let’s kick off 2025 by writing some clean code together

    Image by Swello from Unsplash

    When you’re deep in rapid prototyping, it’s tempting to skip clean scoping or reuse common variable names (hello, df!), thinking it will save time. But this can lead to sneaky bugs that break your workflow.

    The good news? Writing clean, well-scoped code does not require additional effort once you understand the basic principles.

    Let’s break it down.

    What is variable scope?

    Think of a variable as a container that will store some information. Scope refers to the region of your code where a variable is accessible.

    Scope prevents accidental changes by limiting where variables can be read or modified. If every variable was accessible from anywhere, you’ll have to keep track of all of them to avoid overwriting it accidentally.

    In Python, scope is defined by the LEGB rule, which stands for: local, enclosing, global and built-in.

    Scoping in Python, referred as LEGB (by author)

    Scoping in Python: LEGB rule

    Let’s illustrate this with an example.

    # Global scope, 7% tax
    default_tax = 0.07

    def calculate_invoice(price):
    # Enclosing scope
    discount = 0.10
    total_after_discount = 0

    def apply_discount():
    nonlocal total_after_discount

    # Local scope
    tax = price * default_tax
    total_after_discount = price - (price * discount)
    return total_after_discount + tax

    final_price = apply_discount()
    return final_price, total_after_discount

    # Built-in scope
    print("Invoice total:", round(calculate_invoice(100)[0], 2))

    1. Local scope

    Variables inside a function are in the local scope. They can only be accessed within that function.

    In the example, tax is a local variable inside apply_discount. It is not accessible outside this function.

    2. Enclosing scope

    These refer to variables in a function that contains a nested function. These variables are not global but can be accessed by the inner (nested) function. In this example, discount and total_after_discount are variables in the enclosing scope of apply_discount .

    The nonlocal keyword:

    The nonlocal keyword is used to modify variables in the enclosing scope, not just read them.

    For example, suppose you want to update the variable total_after_discount, which is in the enclosing scope of the function. Without nonlocal, if you assign to total_after_discount inside the inner function, Python will treat it as a new local variable, effectively shadowing the outer variable. This can introduce bugs and unexpected behavior.

    3. Global scope

    Variables that are defined outside all functions and accessible throughout.

    The global statement

    When you declare a variable as global inside a function, Python treats it as a reference to the variable outside the function. This means that changes to it will affect the variable in the global scope.

    With the global keyword, Python will create a new local variable.

    x = 10  # Global variable

    def modify_global():
    global x # Declare that x refers to the global variable
    x = 20 # Modify the global variable

    modify_global()
    print(x) # Output: 20. If "global" was not declared, this would read 10

    4. Built-in scope

    Refers to the reserved keywords that Python uses for it’s built-in functions, such as print , def , round and so on. This can be accessed at any level.

    Key concept: global vs nonlocal keywords

    Both keywords are crucial for modifying variables in different scopes, but they’re used differently.

    • global: Used to modify variables in the global scope.
    • nonlocal: Used to modify variables in the enclosing (non-global) scope.

    Variable shadowing

    Variable shadowing happens when a variable in an inner scope hides a variable from an outer scope.

    Within the inner scope, all references to the variable will point to the inner variable, not the outer one. This can lead to confusion and unexpected outputs if you’re not careful.

    Once execution returns to the outer scope, the inner variable ceases to exist, and any reference to the variable will point back to the outer scope variable.

    Here’s a quick example. x is shadowed in each scope, resulting in different outputs depending on the context.

    #global scope
    x = 10

    def outer_function():
    #enclosing scope
    x = 20

    def inner_function():
    #local scope
    x = 30
    print(x) # Outputs 30

    inner_function()
    print(x) # Outputs 20

    outer_function()
    print(x) # Outputs 10

    Parameter shadowing

    A similar concept to variable shadowing, but this occurs when a local variable redefines or overwrites a parameter passed to a function.

    def foo(x):
    x = 5 # Shadows the parameter `x`
    return x

    foo(10) # Output: 5

    x is passed as 10. But it is immediately shadowed and overwritten by x=5

    Scoping in recursive functions

    Each recursive call gets its own execution context, meaning that the local variables and parameters in that call are independent of previous calls.

    However, if a variable is modified globally or passed down explicitly as a parameter, the change can influence subsequent recursive calls.

    • Local variables: These are defined inside the function and only affect the current recursion level. They do not persist between calls.
    • Parameters passed explicitly to the next recursive call retain their values from the previous call, allowing the recursion to accumulate state across levels.
    • Global variables: These are shared across all recursion levels. If modified, the change will be visible to all levels of recursion.

    Let’s illustrate this with an example.

    Example 1: Using a global variable (not recommended)

    counter = 0  # Global variable

    def count_up(n):
    global counter
    if n > 0:
    counter += 1
    count_up(n - 1)

    count_up(5)
    print(counter) # Output: 5

    counter is a global variable shared across all recursive calls. It gets incremented at each level of recursion, and its final value (5) is printed after the recursion completes.

    Example 2: Using parameters (recommended)

    def count_up(n, counter=0):
    if n > 0:
    counter += 1
    return count_up(n - 1, counter)
    return counter

    result = count_up(5)
    print(result) # Output: 5
    • counter is now a parameter of the function.
    • counter is passed from one recursion level to the next, with it’s value updated at each level. The counter is not reinitialised in each call, rather, it’s current state is passed forward to the next recursion level.
    • The function is now pure — there are no side effects and it only operates within it’s own scope.
    • As the recursive function returns, the counter “bubbles up” to the top level and is returned at the base case.

    Best practices

    1. Use descriptive variable names

    Avoid vague names like df or x. Use descriptive names such as customer_sales_df or sales_records_df for clarity.

    2. Use capital letters for constants

    This is the standard naming convention for constants in Python. For example, MAX_RETRIES = 5.

    3. Avoid global variables as much as possible

    Global variables introduces bugs and makes code harder to test and maintain. It’s best to pass variables explicitly between functions.

    4. Aim to write pure functions where possible

    What’s a pure function?

    1. Deterministic: It always produces the same output for the same input. It’s not affected by external states or randomness.
    2. Side-effect-free: It does not modify any external variables or states. It operates solely within its local scope.

    Using nonlocal or global would make the function impure.

    However, if you’re working with a closure, you should use the nonlocal keyword to modify variables in the enclosing (outer) scope, which helps prevent variable shadowing.

    A closure occurs when a nested function (inner function) captures and refers to variables from its enclosing function (outer function). This allows the inner function to “remember” the environment in which it was created, including access to variables from the outer function’s scope, even after the outer function has finished executing.

    The concept of closures can go really deep, so tell me in the comments if this is something I should dive into in the next article! 🙂

    5. Avoid variable shadowing and parameter shadowing

    If you need to refer to an outer variable, avoid reusing its name in an inner scope. Use distinct names to clearly distinguish the variables.

    Wrapping up

    That’s a wrap! Thanks for sticking with me till the end.

    Have you encountered any of these challenges in your own work? Drop your thoughts in the comments below!

    I write regularly on Python, software development and the projects I build, so give me a follow to not miss out. See you in the next article 🙂


    Why Variable Scoping Can Make or Break Your Data Science Workflow was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.

    Originally appeared here:
    Why Variable Scoping Can Make or Break Your Data Science Workflow

    Go Here to Read this Fast! Why Variable Scoping Can Make or Break Your Data Science Workflow

  • Measuring The Execution Times of C Versus Rust

    Aaron Beckley

    Is C is faster than Rust? I had always assumed the answer to that question to be yes, but I recently felt the need to test my assumptions.

    Originally appeared here:
    Measuring The Execution Times of C Versus Rust

    Go Here to Read this Fast! Measuring The Execution Times of C Versus Rust

  • Wi-Fi 8: Stability, not speed, is the name of its game

    The last few major Wi-Fi releases have all been about getting the fastest possible connection. Wi-Fi 8 is about making sure that your connection is stable.

    Go Here to Read this Fast! Wi-Fi 8: Stability, not speed, is the name of its game

    Originally appeared here:
    Wi-Fi 8: Stability, not speed, is the name of its game

  • The Espresso 15 Pro is a compact version of our favorite portable monitor

    Kris Holt

    The Espresso 17 Pro is our favorite portable monitor. It delivers great image quality, has a rugged build, boasts built-in speakers and includes a touchscreen function. The only real trouble is that, with a 17-inch screen, it’s perhaps not as truly portable as it could be.

    Enter the Espresso 15 Pro.

    As you might have guessed, the latest model has a 15-inch display. This is the second Pro-level portable monitor from Espresso Displays. The company already has a 15-inch non-touch version, but as the name implies, this one’s geared toward professionals and business travelers who could do with more on-the-go screen real estate. 

    The Espresso 15 Pro, which was unveiled at CES 2025, has a resolution of 4K and 1,500:1 contrast. It’s said to display 1.07 billion colors with full coverage of the AdobeRGB color spectrum. The LCD panel is actually brighter than the 17-inch model at 550 nits versus the larger monitor’s 450 nits of peak brightness. It also has two USB-C inputs. On the downside, the refresh rate is limited to 60Hz.

    A MacBook alongside a portable monitor that's positioned vertically on a stand.
    Espresso Displays

    Along with MacOS and Windows devices, the Espresso 15 Pro works with iPhones, iPads and DeX-enabled Samsung Galaxy devices. It’s possible to use the Espresso Pen for notetaking on the touchscreen as well.

    Elsewhere, the Espresso 15 Pro will come with the brand’s new Stand+. The monitor magnetically attaches to the Stand+, which supports landscape and portrait orientations.

    Pricing and availability for the Espresso 15 Pro has yet to be revealed, though it’s slated to arrive in the coming months. Logic dictates that the price will fall somewhere in between the $299 Display 15 and $799 Espresso 17 Pro.

    This article originally appeared on Engadget at https://www.engadget.com/computing/the-espresso-15-pro-is-a-compact-version-of-our-favorite-portable-monitor-105237176.html?src=rss

    Go Here to Read this Fast! The Espresso 15 Pro is a compact version of our favorite portable monitor

    Originally appeared here:
    The Espresso 15 Pro is a compact version of our favorite portable monitor

  • The best wireless workout headphones for 2025

    Dana Wollman,Valentina Palladino

    Regardless of what kind of exercise you’re into, if you’re working out, you’ll want a pair of wireless workout headphones. They allow you to be free and untethered during a serious weight-lifting session, a 5K run, an hour at the skate park and everywhere in between where you’re moving and sweating a ton. There are dozens of great wireless headphones and wireless earbud options out there, but for exercise in particular, there are additional factors to consider before picking one up like water resistance, battery life and overall comfort.

    At Engadget, we’ve tested a bunch of fitness-ready headphones and earbuds to come up with our top picks, plus some advice to consider before you pick up a pair. All of our top picks below will work in and out of the gym, so you can invest in just one pair and make those your daily driver. If you’re primarily a runner, check out our list of best headphones for running.

    Before diving in, it’s worth mentioning that this guide focuses on wireless earbuds. While you could wear over-ear or on-ear headphones during a workout, most of the best headphones available now do not have the same level of durability. Water and dust resistance, particularly the former, is important for any audio gear you plan on sweating with or taking outdoors, and that’s more prevalent in the wireless earbuds world.

    Most earbuds have one of three designs: in-ear, in-ear with hook or open-ear. The first two are the most popular. In-ears are arguably the most common, while those with hooks promise better security and fit since they have an appendage that curls around the top of your ear. Open-ear designs don’t stick into your ear canal, but rather sit just outside of it. This makes it easier to hear the world around you while also listening to audio, and could be more comfortable for those who don’t like the intrusiveness of in-ear buds.

    Even if a pair of headphones for working out aren’t marketed specifically as exercise headphones, a sturdy, water-resistant design will, by default, make them suitable for exercise. To avoid repetition, here’s a quick primer on durability, or ingression protection (IP) ratings. The first digit you’ll see after the “IP” refers to protection from dust and other potential intrusions, measured on a scale from 1 to 6. The second refers to water resistance or even waterproofing, in the best cases. The ratings for water resistance are ranked on a scale of 1 to 9; higher numbers mean more protection, while the letter “X” means the device is not rated for protection in that regard.

    All of the earbuds we tested for this guide have at least an IPX4 rating, which means there’s no dust protection, but the buds can withstand splashes from any direction and are sweat resistant, but probably shouldn’t be submerged. For a detailed breakdown of all the possible permutations, check out this guide published by a supplier called The Enclosure Company.

    Active noise cancellation (ANC) is becoming standard on wireless earbuds, at least those above a certain price point. If you’re looking for a pair of buds that can be your workout companion and serve you outside of the gym, too, noise cancelation is a good feature to have. It makes the buds more versatile, allowing you to block out the dull roar of your home or office so you can focus, or give you some solitude during a busy commute.

    But an earbud’s ability to block out the world goes hand-in-hand with its ability to open things back up should you need it. Many ANC earbuds also support some sort of “transparency mode,” or various levels of noise reduction. This is important for running headphones because exercising outdoors, alongside busy streets, can be dangerous. You probably don’t want to be totally oblivious to what’s going on around you when you’re running outside; adjusting noise cancelation levels to increase your awareness will help with that. Stronger noise cancelation might be more appealing to those doing more indoor training if they want to block out the dull roar of a gym or the guy exaggeratingly lifting weights next to you.

    All of the Bluetooth earbuds we tested have a battery life of six to eight hours. In general, that’s what you can expect from this space, with a few outliers that can get up to 15 hours of life on a charge. Even the low end of the spectrum should be good enough for most athletes and gym junkies, but it’ll be handy to keep the buds’ charging case on you if you think you’ll get close to using up all their juice during a single session.

    You’ll get an average of 20 to 28 extra hours of battery out of most charging cases and all of the earbuds we tested had holders that provided at least an extra 15 hours. This will dictate how often you actually have to charge the device — as in physically connect the case with earbuds inside to a charging cable, or set it on a wireless charger to power up.

    In testing wireless workout headphones, I wear them during every bit of exercise I do — be it a casual walk around the block, a brisk morning run or a challenging weight-lifting session. I’m looking for comfort arguably most of all, because you should never be fussing with your earbuds when you should be focusing on working out. In the same vein, I’m cognizant of if they get loose during fast movements or slippery when I’m sweating. I also use the earbuds when not exercising to take calls and listen to music throughout the day. Many people will want just one pair of earbuds that they can use while exercising and just doing everyday things, so I evaluate each pair on their ability to be comfortable and provide a good listening experience in multiple different activities.

    While I am also evaluating sound quality, I’m admittedly not an audio expert. My colleague Billy Steele holds that title at Engadget, and you’ll find much more detailed information about audio quality for some of our top picks in his reviews and buying guides. With these headphones for working out, however, I will make note of related issues if they stood out (i.e. if a pair of earbuds had noticeably strong bass out of the box, weak highs, etc). Most of the wireless workout headphones we tested work with companion apps that have adjustable EQ settings, so you’ll be able to tweak sound profiles to your liking in most cases.

    Jabra announced it will exit the consumer earbuds business, which is disappointing considering the company has made excellent headphones for working out. Our top picks include two Jabra models and we feel comfortable recommending them still because Jabra plans to support its current earbuds for “several years.” However, we’re constantly testing new buds and reassessing our top picks, so we’ll update this list accordingly in the future.

    The Apple AirPods Pro have an IP54 rating, which protects them from brief encounters with dust and splashes. While that’s more dust protection than many other earbuds we tested, it’s the same level of water resistance that most exercise-specific competitors have. We generally like the AirPods Pro, but the Beats Fit Pro offer many of the same features and conveniences (namely good transparency mode and the H1 chip), with a design that’s more appropriate for working out.

    The Powerbeats Pro are a good alternative to the Beats Fit Pro if you’re a stickler for a hook design. However, they cost $50 more than the Fit Pro (although they often hover around $180) and don’t offer any significant upgrades or additional features aside from their design. They’re also quite old at this point (launched in 2019) and it appears Beats is putting more effort into upgrading and updating its newer models rather than this model.

    The Soundcore AeroFit Pro is Anker’s version of the Shokz OpenFit, but I found it to be less secure and not as comfortable as the latter. The actual earbuds on the AeroFit Pro are noticeably bulkier than those on the OpenFit, which caused them to shift and move much more when I was wearing them during exercise. They never fell off my ears completely, but I spent more time adjusting them than I did enjoying them.

    The most noteworthy thing about the Endurance Peak 3 is that they have the same IP68-rating that the Jabra Elite 8 Active do, but they only cost $100. But, while you get the same protection here, you’ll have to sacrifice in other areas. The Endurance Peak 3 didn’t blow me away when it came to sound quality or comfort (the hook is more rigid than those on my favorite buds of a similar style) and their charging case is massive compared to most competitors.

    This article originally appeared on Engadget at https://www.engadget.com/audio/headphones/best-wireless-workout-headphones-191517835.html?src=rss

    Go Here to Read this Fast! The best wireless workout headphones for 2025

    Originally appeared here:
    The best wireless workout headphones for 2025

  • Loreal’s latest device promises to help find out how well your skin responds to ingredients like retinol

    Steve Dent

    If you’ve ever been confused about the vast array of skincare products on the market and exactly which ones are right for you, L’Oréal claims to have the answer. For CES 2025, the company introduced a gadget called the Cell BioPrint that can biochemically analyze your skin and provide advice on how to make it look younger. 

    The company partnered with a startup called NanoEntek, a Korean manufacturer that develops microfluidic lab-on-a-chip technology. To use the system, you place a facial strip on your cheek, then transfer it over to a buffer solution. That is then loaded into a Cell BioPrint cartridge, which is in turn inserted into the machine for analysis. While that’s being processed, the device also takes images of your face and has you fill out a short questionnaire around skin concerns and aging. All of that takes just five minutes, the company says. 

    In an interview with Engadget, Loreal’s Guive Balooch said that the skin strip can be applied near the jawline, and that even if someone has sunscreen on, it won’t affect the results. 

    Once the data is crunched using something L’Oréal calls proteomics, Cell BioPrint can provide advice on how to improve your skin’s appearance. It can suggest how well you may respond to certain ingredients like retinol, and predict potential cosmetic issues like dark spots or enlarged pores before they become visible. 

    It all sounds good and reasonably science-based, but L’Oréal didn’t cite any peer-reviewed studies that may prove the machine’s efficacy. Still, it seems like a good time for such a product as skincare awareness has blown up of late thanks in part to Covid, influencers and Sephora. That has generated in a lot of new information (and misinformation), allowing L’Oréal to come in and save the day using science to hypothetically fix your issues. 

    In any case, the BioPrint machine won’t be available for consumers just yet, and to be clear, the first iteration of the device isn’t meant for at-home use. It’s slated to start pilot tests in stores in Asia sometime in 2025, but so far, there’s no firm launch date or price. Balooch indicated it would follow a similar rollout pattern to the company’s other tech launches in the past, by appearing first at the counters in flagship stores for one of L’Oréal’s luxury brands. Over time, it may make its way to more mainstream segments.

    This article originally appeared on Engadget at https://www.engadget.com/general/loreals-latest-device-promises-to-help-find-out-how-well-your-skin-responds-to-ingredients-like-retinol-090300942.html?src=rss

    Go Here to Read this Fast!

    Loreal’s latest device promises to help find out how well your skin responds to ingredients like retinol

    Originally appeared here:

    Loreal’s latest device promises to help find out how well your skin responds to ingredients like retinol