<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abhishak Bhatnagar</title>
    <description>The latest articles on Forem by Abhishak Bhatnagar (@kindssoul).</description>
    <link>https://forem.com/kindssoul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3124672%2F87bddb09-55d4-4bcd-b60e-ad273300e669.jpg</url>
      <title>Forem: Abhishak Bhatnagar</title>
      <link>https://forem.com/kindssoul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kindssoul"/>
    <language>en</language>
    <item>
      <title>How C++ Can Take Us to Mars and Back</title>
      <dc:creator>Abhishak Bhatnagar</dc:creator>
      <pubDate>Tue, 06 May 2025 06:22:04 +0000</pubDate>
      <link>https://forem.com/kindssoul/how-c-can-take-us-to-mars-and-back-27oo</link>
      <guid>https://forem.com/kindssoul/how-c-can-take-us-to-mars-and-back-27oo</guid>
      <description>&lt;p&gt;In the modern era of space exploration, software is as critical as rocket fuel. The spacecraft of the future—especially for interplanetary missions to Mars—won’t just be metal and circuits; they’ll be powered by millions of lines of highly reliable code. Among the top languages trusted for these missions is C++.&lt;/p&gt;

&lt;p&gt;Why? Because C++ offers the performance, precision, and control needed to build the mission-critical systems that must function without fail in the unforgiving vacuum of space.&lt;/p&gt;

&lt;p&gt;But C++ isn’t perfect. It comes with its own set of challenges—such as undefined behavior, memory issues, and hardware sensitivity. This article explores how C++ can not only take us to Mars and back, but also how its challenges can be solved with modern techniques, tools, and best practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why C++ Is Chosen for Space
&lt;/h2&gt;

&lt;p&gt;Before diving into the problems and solutions, let’s understand why C++ is still a favorite among aerospace engineers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10urbrx29oeaqgpbw7h0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10urbrx29oeaqgpbw7h0.png" alt="Image description" width="684" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Mars Mission Software Stack in C++
&lt;/h2&gt;

&lt;p&gt;A real Mars mission software system might include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Navigation System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Autonomous AI Decision Engine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Communication System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thermal &amp;amp; Life Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Diagnostics &amp;amp; Recovery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each component must be fast, fault-tolerant, and radiation-aware.&lt;/p&gt;

&lt;p&gt;Let’s now go module by module, write real C++ code, and examine the challenges and solutions for each.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Undefined Behavior Risks
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;br&gt;
C++ gives low-level control, but that means undefined behavior (UB) can occur if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory is accessed out of bounds&lt;/li&gt;
&lt;li&gt;Null pointers are dereferenced&lt;/li&gt;
&lt;li&gt;Integer overflows happen unchecked&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In space, UB could mean mission failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution: Use Static Analysis Tools + Safe Subsets of C++&lt;/strong&gt;&lt;br&gt;
Use tools like Clang-Tidy, CppCheck, or MISRA C++ guidelines&lt;/p&gt;

&lt;p&gt;Avoid dangerous constructs (e.g., raw pointers, uninitialized vars)&lt;/p&gt;

&lt;p&gt;Use modern C++11/14/17 features like constexpr, enum class, nullptr, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Safe use of enum class avoids accidental conversions
enum class ThrusterStatus { OFF, IDLE, FIRING };

void fireThruster(ThrusterStatus status) {
    if (status == ThrusterStatus::FIRING) {
        std::cout &amp;lt;&amp;lt; "Thruster is firing\n";
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Static analysis would catch any misuse like comparing ThrusterStatus to an integer.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Pointer Bugs and Memory Leaks
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;br&gt;
C++ allows direct memory access. This can lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory leaks&lt;/li&gt;
&lt;li&gt;Dangling pointers&lt;/li&gt;
&lt;li&gt;Double deletes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Memory bugs are very hard to debug in space, where logs may be delayed or unavailable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution: Use Smart Pointers + RAII (Resource Acquisition Is Initialization)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace new and delete with std::unique_ptr and std::shared_ptr&lt;/li&gt;
&lt;li&gt;Use std::vector instead of raw arrays&lt;/li&gt;
&lt;li&gt;Encapsulate resource handling in classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;memory&amp;gt;
#include &amp;lt;iostream&amp;gt;

class Sensor {
public:
    Sensor() { std::cout &amp;lt;&amp;lt; "Sensor initialized\n"; }
    ~Sensor() { std::cout &amp;lt;&amp;lt; "Sensor destroyed\n"; }
};

void testSensor() {
    std::unique_ptr&amp;lt;Sensor&amp;gt; sensor = std::make_unique&amp;lt;Sensor&amp;gt;();
    // Auto-deletes when out of scope (RAII)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures automatic memory cleanup, preventing leaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Portability Across Embedded Architectures
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;br&gt;
C++ must run on various microcontrollers or real-time operating systems (RTOS) with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited RAM/CPU&lt;/li&gt;
&lt;li&gt;No standard library support&lt;/li&gt;
&lt;li&gt;Different instruction sets (ARM, RISC-V)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution: Use Embedded C++ Subsets + Cross-Compilers&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid exceptions, RTTI, dynamic memory (where unsupported)&lt;/li&gt;
&lt;li&gt;Use cross-platform frameworks (e.g., RTEMS, FreeRTOS with C++)&lt;/li&gt;
&lt;li&gt;Cross-compile using GCC/Clang with appropriate flags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example (Embedded-safe loop):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// No STL used
void monitorBattery(float* readings, int count) {
    float total = 0;
    for (int i = 0; i &amp;lt; count; ++i)
        total += readings[i];

    float avg = total / count;
    if (avg &amp;lt; 21.0f)
        std::cout &amp;lt;&amp;lt; "Battery level low\n";
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, use hardware abstraction layers (HALs) to isolate hardware-specific code.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Harsh Radiation Causing Bit Flips
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Radiation in space can flip bits in:&lt;/li&gt;
&lt;li&gt;Program memory (code)&lt;/li&gt;
&lt;li&gt;RAM (data)&lt;/li&gt;
&lt;li&gt;Registers (instruction execution)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can crash or corrupt a system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution: Use ECC Memory + Software Fault Tolerance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Error-Correcting Code (ECC) RAM (corrects 1-bit errors)&lt;/li&gt;
&lt;li&gt;Add software redundancy: checksums, watchdog timers, and self-diagnostics&lt;/li&gt;
&lt;li&gt;Implement triple modular redundancy (TMR) in critical modules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example (Simple checksum validation):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool validatePacket(const std::string&amp;amp; data, uint32_t checksum) {
    uint32_t sum = 0;
    for (char c : data) sum += c;
    return (sum == checksum);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This kind of redundancy catches silent data corruption.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mars Mission Software (Integrated Code Sample)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;memory&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;cmath&amp;gt;

class Navigation {
    double x, y, velocity;
public:
    void update(double nx, double ny, double vel) {
        x = nx; y = ny; velocity = vel;
        std::cout &amp;lt;&amp;lt; "Location: " &amp;lt;&amp;lt; x &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; y &amp;lt;&amp;lt; " | Vel: " &amp;lt;&amp;lt; velocity &amp;lt;&amp;lt; "\n";
    }

    double timeToTarget(double targetX, double targetY) {
        double dist = sqrt(pow(targetX - x, 2) + pow(targetY - y, 2));
        return dist / velocity;
    }
};

class Comm {
public:
    void send(const std::string&amp;amp; msg) {
        std::cout &amp;lt;&amp;lt; "[Comm] Sending: " &amp;lt;&amp;lt; msg &amp;lt;&amp;lt; "\n";
    }
    bool receive() {
        return rand() % 10 != 1; // Simulate signal loss
    }
};

class LifeSupport {
    double o2;
public:
    LifeSupport(double level) : o2(level) {}
    void check() {
        if (o2 &amp;lt; 20) std::cerr &amp;lt;&amp;lt; "WARNING: Oxygen low!\n";
        else std::cout &amp;lt;&amp;lt; "O2 OK\n";
    }
};

int main() {
    Navigation nav;
    nav.update(0, 0, 100);
    std::cout &amp;lt;&amp;lt; "Time to Mars base: " &amp;lt;&amp;lt; nav.timeToTarget(500, 500) &amp;lt;&amp;lt; "s\n";

    Comm comm;
    comm.send("Telemetry nominal");
    if (!comm.receive()) std::cerr &amp;lt;&amp;lt; "Signal lost!\n";

    LifeSupport ls(19.8);
    ls.check();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Despite its challenges, C++ remains one of the most powerful languages to take us to Mars and back—because it gives us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance for real-time reactions&lt;/li&gt;
&lt;li&gt;Control over hardware behavior&lt;/li&gt;
&lt;li&gt;Determinism and precision&lt;/li&gt;
&lt;li&gt;Strong community and legacy tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following modern practices, using safety features, and architecting carefully, we can overcome every challenge—turning C++ into the backbone of our journey across the solar system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thought:
&lt;/h2&gt;

&lt;p&gt;“We used C to land on the Moon. We’ll use C++ to walk on Mars.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Also read:&lt;/strong&gt; &lt;a href="https://dev.to/kindssoul/how-i-used-python-to-almost-crash-chatgpt-n91"&gt;How I Used Python to Almost Crash ChatGPT&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>programming</category>
      <category>cplus</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How I Used Python to Almost Crash ChatGPT</title>
      <dc:creator>Abhishak Bhatnagar</dc:creator>
      <pubDate>Mon, 05 May 2025 07:33:49 +0000</pubDate>
      <link>https://forem.com/kindssoul/how-i-used-python-to-almost-crash-chatgpt-n91</link>
      <guid>https://forem.com/kindssoul/how-i-used-python-to-almost-crash-chatgpt-n91</guid>
      <description>&lt;p&gt;As AI continues to evolve, developers and researchers are exploring its boundaries. One such experiment I undertook involved using Python to test the limits of ChatGPT's response generation capabilities. This blog post documents how I structured the experiment, what I observed, and the key takeaways from the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objective
&lt;/h2&gt;

&lt;p&gt;The goal was to explore:&lt;/p&gt;

&lt;p&gt;How ChatGPT handles dynamically generated prompts at scale.&lt;/p&gt;

&lt;p&gt;How it deals with recursion, large inputs, and nested logic.&lt;/p&gt;

&lt;p&gt;What practical limitations (length, processing, memory) exist in the interaction model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;I used Python to generate structured prompts that grew in complexity, size, or logical depth. The experiments were run using both the ChatGPT web interface and API, where applicable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Environment&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Python version:&lt;/strong&gt; 3.11&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ChatGPT version:&lt;/strong&gt; GPT-4 (via web)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Libraries:&lt;/strong&gt; None required beyond standard Python&lt;/p&gt;
&lt;h2&gt;
  
  
  Experiment 1: Recursive Prompt Generation
&lt;/h2&gt;

&lt;p&gt;I wrote a Python script to create recursive text prompts, where each prompt builds on the previous one with increasing complexity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def generate_recursive_prompts(count):
    prompts = []
    base = "Explain recursion."
    for i in range(1, count + 1):
        base = f"Explain recursion based on: [{base}]"
        prompts.append(base)
    return prompts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test Details
&lt;/h2&gt;

&lt;p&gt;Generated prompts ranging from 1 to 500 levels of nesting.&lt;/p&gt;

&lt;p&gt;Copied the most complex prompt (character count &amp;gt; 8000) into the ChatGPT interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Observations
&lt;/h2&gt;

&lt;p&gt;ChatGPT truncated or summarized after a certain complexity level.&lt;/p&gt;

&lt;p&gt;At around 10–15 levels deep, it began to generalize rather than expand on each level.&lt;/p&gt;

&lt;p&gt;Beyond a certain character limit (~4,096 tokens for web interface), it failed to process the full prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Experiment 2: Bulk Prompt Submission
&lt;/h2&gt;

&lt;p&gt;I used Python to simulate sending multiple prompts programmatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompts = [f"Explain the concept of item {i}" for i in range(1000)]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While I didn’t use the API to send them automatically (due to OpenAI usage limits), I manually tested the effect of batch processing multiple related prompts back-to-back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observations&lt;/strong&gt;&lt;br&gt;
The model maintained context well up to ~10–15 prompts in a thread.&lt;/p&gt;

&lt;p&gt;After ~20 prompts, earlier context began to degrade unless explicitly restated.&lt;/p&gt;

&lt;p&gt;Repeated similar prompts sometimes triggered output repetition or optimization attempts by the model.&lt;/p&gt;
&lt;h2&gt;
  
  
  Experiment 3: Token Overflow Test
&lt;/h2&gt;

&lt;p&gt;I used Python to construct a prompt exceeding the token limits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text = "This is a test sentence. " * 2000
print(len(text))  # Character count
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;At ~8,000 characters (approx. 3,000–4,000 tokens), ChatGPT returned a "message too long" error.&lt;/li&gt;
&lt;li&gt;The model did not crash, but it refused to process the input.&lt;/li&gt;
&lt;li&gt;Token limits are strictly enforced; longer prompts are automatically rejected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Learnings
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. ChatGPT Has Hard Limits&lt;/strong&gt;&lt;br&gt;
The web interface caps token limits around 4,096 tokens (input + output combined).&lt;/p&gt;

&lt;p&gt;API limits are higher (up to 8,192 or 32,768 tokens depending on the model), but still finite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Recursive or Nested Prompts Are Abstracted&lt;/strong&gt;&lt;br&gt;
ChatGPT recognizes recursion but will not endlessly expand recursive logic unless specifically instructed—and even then, only within safe limits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Context Management Is Strong but Not Infinite&lt;/strong&gt;&lt;br&gt;
ChatGPT can handle sequential prompts but begins to lose accuracy and detail as the thread length increases.&lt;/p&gt;

&lt;p&gt;Resetting context or summarizing helps manage longer sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While I did not "crash" ChatGPT in a literal sense, these experiments clearly revealed its processing limitations. Using Python to automate prompt generation is an effective way to test the robustness and practical boundaries of large language models.&lt;/p&gt;

&lt;p&gt;For developers, researchers, or curious users, this type of testing provides useful insights into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Designing better prompts&lt;/li&gt;
&lt;li&gt;Understanding AI constraints&lt;/li&gt;
&lt;li&gt;Identifying when to switch from chat-based interactions to API-based solutions for scalability&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>chatgpt</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
