AI
5 Min Read

Introducing Ternary

Subhajeet Dey
January 14, 2025

When discussing conditional expressions in programming, the ternary operator is often a go-to topic. Known for its conciseness, the ternary operator condenses simple if-else statements into a single line. Its most recognizable form in languages like C, Java, and Python is:

result = value_if_true if condition else value_if_false

But beyond this common usage, certain programming languages have their own quirky, mind-bending, or downright bizarre implementations of the ternary operator, for example in PHP:

$result = $condition ? $value_if_true : $value_if_false;

This looks standard at a first glance but older versions of PHP had a surprising behavior with nested ternaries because they didn't require parentheses Consider this:

$result = true ? false : true ? "yes" : "no";

This expression doesn’t evaluate as you might intuitively expect. Instead of reading left-to-right, PHP evaluates it like this:

$result = (true ? false : (true ? "yes" : "no"));

Which is very confusing, due to this Php7.4 introduced a null coalescing operator and solved some of the issues.

I started my career in 2014 as a PHP developer, writing code for one of the biggest advertisement platforms, which had acquired Yellow Pages and was foraying into e-commerce and digital ads. Our team was tasked with integrating a price comparison engine we built into an e-commerce platform. At that time, comparing prices before buying products on websites like Amazon or Flipkart was a must due to frequent price changes, as the availability of stock often became a bottleneck. We developed an engine that crawled multiple marketplaces frequently, comparing prices and providing users with a fair view of any product before purchase.

In one of my integrations, I made a critical mistake while attempting to use ternary operators, forgetting the various quirks of PHP. This resulted in some product prices being erroneously displayed as zero, causing a massive headache for both the fulfilment and delivery teams. The issue was compounded because orders started coming in based on the incorrect prices, leading to chaos. Thankfully, the change had only been deployed to production for a very brief period before we caught the issue and quickly rolled back the changes, fiendishly apologising to all of our affected customers.

This incident left an indelible mark on my programming journey, teaching me a profound lesson about the importance of testing, understanding language-specific nuances, and the gravity of production-ready code. At the time, we were using PHP 5.3, a version with quirks and inconsistencies that would put modern programming languages like Rust and Zig to shame. This experience not only sharpened my skills but also instilled in me a deeper sense of responsibility and diligence as a developer—qualities that have stayed with me throughout my career. The idea behind this blog, Ternary, is to document the challenges and insights I encounter while navigating the evolving world of Technology, largely AI, Large Language Models (LLMs), and the emerging field of LLM Operations, or LLMOps—a term we’ve started using to describe the fusion of DevOps principles with the unique demands of LLMs.

As AI continues to transform industries, the focus has shifted to understanding the latest models, their capabilities, and the frameworks that power them. This includes everything from fine-tuning LLMs to optimizing deployments, ensuring scalability, and applying best practices from DevOps to build robust and efficient systems. In this modern, agentic era, where AI models are becoming increasingly autonomous and capable, managing their lifecycle and operations has become as critical as designing the models themselves.

Through Ternary, I aim to explore the cutting-edge advancements in AI, document my experiments with models and frameworks, share insights into deployment strategies, and highlight the practices shaping the LLMOps landscape. This journey reflects not just my technical growth but also my commitment to contributing to the broader understanding of how to responsibly and effectively build, deploy, and maintain AI systems.

To make this platform work smoothly, I needed a tech stack that would be easy to maintain but powerful enough to add new features quickly. For the backend, I decided to go with FastAPI. I’ve built up a lot of reusable components over the years, which makes it easy for me to set up APIs quickly. Although I thought about using Django, I found FastAPI simpler, especially since it would mostly act as a api layer over the CMS.

Choosing the right CMS was a bit tricky. I considered options like WordPress, Ghost, building my own, or even using Notion as the backend with its API. My main goal was to make content writing as easy as possible. After looking into it, I picked Ghost in headless mode for the CMS. Ghost is simple, offers a clean editor, and has useful features like tagging and seo friendly URLs. While Ghost provides its own content API, I chose to skip it and connect it directly to my FastAPI backend, storing posts in a MySQL database.

Infra Components

For the frontend, I went with NextJS, I wanted to take advantage of the latest features like Streaming SSR to make the site faster. With server components in React, I could ensure fast page load times and a better overall user experience.

Deployment is done through Github Actions where frontend and backend gets deployed separately, I am using monorepo setup for both the frontend and backend

This combination of FastAPI, Ghost, and NextJS gives me a powerful and easy-to-manage platform for Ternary. It lets me focus on sharing my thoughts on AI, LLMs, and modern tech while keeping things simple and efficient on the backend, with this we try to touch deep waters of AI and LLMs, you can simply signup with your google account to get latest updates in the form of newsletter.

Finally my email is at [email protected] if you want to get in touch and discuss LLMOps, AI Models, Devops or anything etc