Monday, 13 July 2026

React 18 Automatic Batching: A Senior Developer Brain Teaser

The React 18 Batching Brain Teaser That Stumps Seniors

The React 18 Brain Teaser That Stumps Seniors

If you have been writing React for more than a few years, your brain is likely hardwired to expect certain behaviors from the rendering engine. But React 18 introduced a massive fundamental change under the hood that quietly broke how many of us model state updates in our heads.

Let’s test your knowledge of modern React rendering mechanics. Assuming this app is running in standard production mode (no StrictMode double-invocations), take a look at the component below.

The Challenge

When the component mounts, and the user clicks the "Trigger" button exactly once, what will be logged to the console from start to finish?

import { useState, useRef } from 'react';

export default function App() {
  const [count, setCount] = useState(0);
  const renders = useRef(0);
  
  renders.current++;
  console.log(`Render ${renders.current}: ${count}`);

  const handleClick = () => {
    // First batch
    setCount(c => c + 1);
    setCount(c => c + 1);
    
    // Second batch
    setTimeout(() => {
      setCount(c => c + 1);
      setCount(c => c + 1);
    }, 0);
  };

  return <button onClick={handleClick}>Trigger</button>;
}

Trace the state updates and the Event Loop in your head. Do you have your answer? Drop your guess in the comments below before you expand the solution!

Click here to reveal the output and explanation

The Correct Output:

Render 1: 0
Render 2: 2
Render 3: 4

Why does this happen?

If you guessed Render 3: 3 and Render 4: 4 at the end, you are thinking in React 17!

Here is exactly how the React 18 rendering engine processes this:

  • Render 1 (Mount): The component mounts, renders.current becomes 1, and count is 0.
  • The Click (Synchronous): React has always batched state updates inside standard React event handlers. The first two setCount calls are bundled together. React waits for the synchronous code to finish, applies both increments, and triggers exactly one render. (Logs Render 2: 2).
  • The Timeout (Asynchronous): In React 17, state updates inside promises, timeouts, or native event handlers were not batched. They would trigger a re-render for every single setState call.
  • React 18 Automatic Batching: React 18 introduced Automatic Batching. Now, React batches state updates no matter where they happen. When the macro-task (the setTimeout) executes, React intelligently batches the two internal setCount calls together just like it did in the synchronous event handler. It waits for the callback to complete, applies both increments, and triggers just one final render. (Logs Render 3: 4).

Bonus tip: If you ever actually need the old React 17 behavior to force the DOM to paint between updates inside a timeout, you now have to explicitly wrap your state updates in flushSync() from react-dom.

Python Question: ID-PY28302

The Classic Python Bug: Do You Know Your Default Arguments?

The Classic Python Bug: Do You Know Your Default Arguments?

Here is a tricky bug that almost every Python developer has written at least once in their career. It tests an intermediate concept that is crucial for writing clean, bug-free code—especially when you start dealing with complex data pipelines or web frameworks.

Take a look at the function below. Without running the code in your IDE, try to figure out what the exact output of the three print statements will be.

The Challenge

def add_employee(name, team=[]):
    team.append(name)
    return team

# Let's hire some folks!
dev_team = add_employee("Alice")
design_team = add_employee("Bob", [])
marketing_team = add_employee("Charlie")

# What gets printed?
print(f"Devs: {dev_team}")
print(f"Design: {design_team}")
print(f"Marketing: {marketing_team}")

Do you have your answer? Drop your guess in the comments below before you check the solution! Bonus points if you can explain exactly why it behaves this way.

Click here to reveal the output and explanation

The Output:

Devs: ['Alice', 'Charlie']
Design: ['Bob']
Marketing: ['Alice', 'Charlie']

Why does this happen?

In Python, default arguments are evaluated only once at the time the function is defined, not every time the function is called.

  • Because team=[] is a mutable object (a list), that exact same list in memory is reused for every function call that doesn't explicitly provide a second argument.
  • Alice is added to this default list.
  • Bob gets his own isolated team because we explicitly passed in a brand new, empty list [] during his function call.
  • Charlie is passed without a second argument, so Python uses the default list again—which already has Alice sitting inside it!

The Fix: Always use None for mutable default arguments!

def add_employee(name, team=None):
    if team is None:
        team = []
    team.append(name)
    return team

Did you get it right? Let me know in the comments below!

Python Question: ID-PY28301

Think You Know Python? The Class Variable Brain Teaser That Trips Up Seniors

I love a good brain teaser, and this one has tripped up surprisingly experienced Python developers. It touches on a core concept of the language that is easy to forget when you are moving fast.

Take a look at the Python snippet below. Without running the code in your IDE, try to figure out what the exact output of the three print statements will be.

The Challenge

class Developer:
    skill_level = 1
    languages = []

class FrontendDev(Developer):
    pass

class BackendDev(Developer):
    pass

# Let's make some changes
FrontendDev.skill_level = 2
FrontendDev.languages.append('JavaScript')

BackendDev.skill_level = 3
BackendDev.languages.append('Python')

Developer.languages.append('SQL')

# What gets printed?
print(f"Dev: {Developer.skill_level}, {Developer.languages}")
print(f"Front: {FrontendDev.skill_level}, {FrontendDev.languages}")
print(f"Back: {BackendDev.skill_level}, {BackendDev.languages}")

Do you have your answer? Drop your guess in the comments below before you check the solution! Bonus points if you can explain why it behaves this way.


The Solution

🚨 Click here to reveal the output and explanation

The Output:

Dev: 1, ['JavaScript', 'Python', 'SQL']
Front: 2, ['JavaScript', 'Python', 'SQL']
Back: 3, ['JavaScript', 'Python', 'SQL']

Why does this happen?

It comes down to how Python handles mutable vs. immutable class variables:

  • Integers are immutable: When we assign FrontendDev.skill_level = 2 and BackendDev.skill_level = 3, Python creates entirely new attributes in the specific namespaces of the FrontendDev and BackendDev classes. It does not overwrite the parent Developer.skill_level, which safely remains 1.
  • Lists are mutable: The languages list is defined at the class level on Developer. Because FrontendDev and BackendDev inherit from Developer and don't explicitly overwrite the list with a brand new assignment (e.g., FrontendDev.languages = []), calling .append() on the children modifies the exact same list object residing in the parent class's memory space.

Therefore, all three .append() calls are adding strings to the exact same underlying list, while the integers remain isolated to their respective child classes.

Did you get it right? Let me know in the comments!

Srinivasa Mangapuram - Official Trailer

Srinivasa Mangapuram - Official Trailer




from Entertainment - Videos - The Times of India https://ift.tt/WPJtAdl

Delhi Jantar Mantar Protest Latest Updates (July 2026)

As the Monsoon Session of Parliament approaches, New Delhi's historic protest site, Jantar Mantar, has once again become the epicenter of intense political and social mobilization. Here is the latest update on the two major demonstrations shaping the capital's current landscape.

1. The Education Reform & CJP Sit-In

The ongoing protest led by the Cockroach Janta Party (CJP) and founder Abhijeet Dipke has entered a critical phase. Staged continuously since June 20, the demonstration targets alleged structural irregularities within the national examination system—most notably the NEET-UG 2026 controversy and CBSE grading discrepancies.

The protestors are demanding the immediate resignation of Union Education Minister Dharmendra Pradhan and a ₹1 crore compensation package for the families of students who tragically died by suicide following the exam disputes.

⚠️ Health Update: Sonam Wangchuk's Hunger Strike

Climate activist Sonam Wangchuk, who joined the student-led agitation on June 28 with an indefinite hunger strike, is facing severe health risks. Entering his 15th day of fasting, medical reports indicate a total weight loss of 7.8 kg and fluctuating blood pressure. Members of the All India Students' Association (AISA) also continue their hunger strike alongside him in solidarity.

Escalating Tensions & Parliament March

  • Infrastructure Cutoffs: CJP leaders have publicly alleged that authorities attempted to disperse the crowds by cutting off electricity lines and blocking water access to the public restrooms at the protest site.
  • Broadening Alliances: A steady stream of opposition political leaders, economists, and prominent public intellectuals have visited Jantar Mantar to back the students' demands.
  • The Next Step: The CJP has officially called for a massive, peaceful March to Parliament on July 20, timed precisely to coincide with the opening day of the Monsoon Session.

2. The Upcoming J&K Statehood Demonstration

Simultaneously, a massive political storm is brewing for July 20. The National Conference (NC), alongside key alliance partners from the INDIA bloc, is organizing a major demonstration at Jantar Mantar to demand the immediate restoration of statehood and constitutional safeguards for Jammu and Kashmir.

Current Status and Friction Points

  • Permit Hurdles: J&K Chief Minister Omar Abdullah recently expressed frustration, claiming that official security and police clearances for the Jantar Mantar gathering are being deliberately delayed by authorities to suppress the mobilization.
  • United Opposition Support: The CPI(M) and several other regional political factions have formally declared their participation, turning this into a joint opposition front.
  • Counter-Protests Planned: In response to the Delhi rally, the BJP has announced a parallel series of counter-protests across various districts in Jammu and Kashmir on July 20, focusing on local development and employment generation.

Key Flashpoints to Watch (July 20)

Movement Core Demand Key Action
CJP & Students NEET-UG Inquiry & Minister Resignation Peaceful March to Parliament
National Conference & INDIA Bloc Restoration of J&K Statehood Joint Opposition Rally at Jantar Mantar

Stay tuned for live updates as the situation develops in the national capital.

Sunday, 12 July 2026

Momo - Official Teaser​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Momo - Official Teaser​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​




from Entertainment - Videos - The Times of India https://ift.tt/kbdu6Mc

Thamizh Murugan - Official First look

Thamizh Murugan - Official First look




from Entertainment - Videos - The Times of India https://ift.tt/JhwqcG6