<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sourav Sarker on Medium]]></title>
        <description><![CDATA[Stories by Sourav Sarker on Medium]]></description>
        <link>https://medium.com/@ssarke?source=rss-2a01228c5124------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VliohdvbSqSCNi3836u7Ng.png</url>
            <title>Stories by Sourav Sarker on Medium</title>
            <link>https://medium.com/@ssarke?source=rss-2a01228c5124------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:45:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ssarke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Let’s take a cue!]]></title>
            <link>https://medium.com/@ssarke/lets-take-a-cue-beba22f74f63?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/beba22f74f63</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[configuration-as-code]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sat, 05 Sep 2026 19:46:05 GMT</pubDate>
            <atom:updated>2026-09-05T19:46:05.682Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Being explicit about intended systems and it’s parameterization has advantages, you see and get to review exactly what’s intended and if the same has been replicated on your target systems.</em></p><p><em>However, things can get verbose easily with service configs spanning definitions of multiple items.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_fUfjcbwRV9bDKFO" /></figure><p>Photo by <a href="https://unsplash.com/@liammward?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">liam ward</a> on <a href="https://unsplash.com/photos/a-pool-table-with-eight-balls-and-a-cue-Y72MQgLprz4?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></p><p><em>Originally posted on </em><a href="https://edplus.org.in/content/blogs"><em>https://edplus.org.in/content/blogs</em></a><em> May 1, 2025</em></p><p>Configuration as code has been around for a while. Meaning, you define the configuration of a system or infrastructure, and maintain/evolve its state.</p><p>There is some overlap with another related approach called IaC (Infrastructure as Code) which kind of focuses on creation/provisioning of foundational resources or infrastructure.</p><p>With infrastructure nowadays commonly on cloud, more and more services/applications are becoming kubernetes aligned, and it so happens that yaml becomes a de facto standard of defining their resources/objects.</p><p>However, things can get verbose easily with service configs spanning definitions of multiple items that constitute it.</p><p>To tackle this (how would you test/generate such large &amp; valid configuration files?) CUE was introduced.</p><p>Originally designed to configure <a href="https://kubernetes.io/blog/2015/04/borg-predecessor-to-kubernetes/">Borg</a>, the predecessor of Kubernetes, it introduces types, constraints to validate against and also helps with reducing boilerplate, which fits nicely with the modern needs of cloud configurations.</p><p>CUE generalizes how we write constraints as</p><pre>&lt;set of nodes&gt;: &lt;constraints&gt;<br>/*<br>a: string<br>b:c: int &amp; &lt;100 // element c, under b, has a condition guard &lt; 100<br>*/</pre><p>where nodes are the fields, values or types (they are considered same in CUE) are part of constraints.</p><p>The master type (if it can be called so :-)) is top or _. All types (like string, bool etc) inherit from the top type.</p><pre>// example.cue <br>// This is like a placeholder schema<br>a: _<br>b: _</pre><p>Passing any values for it would be possible with above schema</p><pre>// data.cue<br>a: 1<br>b: [1, &quot;one&quot;]</pre><pre>$ cue export example.cue data.cue<br>{<br>    &quot;a&quot;: 1,<br>    &quot;b&quot;: [<br>        1,<br>        &quot;one&quot;<br>    ]<br>}</pre><p>How about adding some restrictions and exact types now?</p><pre>// example.cue<br>a: string<br>b: [1,2, ...int]<br><br>$ cue vet example.cue data.cue // validating with vet action<br><br>a: conflicting values 1 and string (mismatched types int and string):<br>    ./data.cue:1:4<br>    ./example.cue:1:4<br>b.1: conflicting values &quot;one&quot; and 2 (mismatched types string and int):<br>    ./data.cue:2:8<br>    ./example.cue:2:7</pre><p>This schema now expects a to have a single string value, b to be a list with first 2 elements 1,2 and rest have to be int and thus fails in validation.</p><p>If we want to generate config from templates?</p><pre><br>// generate_bu.cue. Adding data and schema together<br><br>// data<br>BU: {<br>  finance: members: 4<br>  sales: mgr_name: &quot;Asish&quot;<br>  sales: travel_allowance: &quot;50k&quot;<br>  IT: _ // no customization here, so default values will be added<br>}<br><br>// schema<br>BU: [Team=_]: {<br>  name: Team<br>  members: int | *2 // add int for members, else default 2<br>  mgr_name: string | *&quot;Tim&quot; // add mgr_name (string, else default Tim<br>  travel_allowance: string | *&quot;10k&quot;<br>}<br><br><br>$ cue export generate_bu.cue<br>{<br>    &quot;BU&quot;: {<br>        &quot;finance&quot;: {<br>            &quot;members&quot;: 4,<br>            &quot;name&quot;: &quot;finance&quot;,<br>            &quot;mgr_name&quot;: &quot;Tim&quot;,<br>            &quot;travel_allowance&quot;: &quot;10k&quot;<br>        },<br>        &quot;sales&quot;: {<br>            &quot;mgr_name&quot;: &quot;Asish&quot;,<br>            &quot;travel_allowance&quot;: &quot;50k&quot;,<br>            &quot;name&quot;: &quot;sales&quot;,<br>            &quot;members&quot;: 2<br>        },<br>        &quot;IT&quot;: {<br>            &quot;name&quot;: &quot;IT&quot;,<br>            &quot;members&quot;: 2,<br>            &quot;mgr_name&quot;: &quot;Tim&quot;,<br>            &quot;travel_allowance&quot;: &quot;10k&quot;<br>        }<br>    }<br>}</pre><p>CUE files can unify all JSON, YAML and CUE data into JSON and/or YAML.</p><p>It’s possible to validate json, yaml data files via cue schema. CUE’s std library provides built in package to generate, parse or validate yaml/json data from within cue.</p><p>Example:</p><pre>// config.cue<br><br>//Definition<br>#Record: {<br>  name: string<br>  age: int<br>  if age &gt; 18 &amp;&amp; age &lt; 65 {<br> in_active_working_age?: true // optional field, gets true if condition met<br>  }<br>  country: #Country<br>}<br><br>#Country: &quot;India&quot; | &quot;Japan&quot; | &quot;Nepal&quot;<br><br>// nepal.yaml<br>name: &quot;Amit&quot;<br>age: 10<br>country: &quot;Nepal&quot;<br><br>// us.yaml<br>name: &quot;Sasha&quot;<br>age: 29<br>in_active_working_age: true<br>country: &quot;US&quot;<br><br>$ cue vet -c config.cue -d &#39;#Record&#39; nepal.yaml us.yaml<br>country: 3 errors in empty disjunction:<br>country: conflicting values &quot;India&quot; and &quot;US&quot;:<br>    ./config.cue:7:12<br>    ./config.cue:10:11<br>    ./us.yaml:4:10<br>country: conflicting values &quot;Japan&quot; and &quot;US&quot;:<br>    ./config.cue:7:12<br>    ./config.cue:10:21<br>    ./us.yaml:4:10<br>country: conflicting values &quot;Nepal&quot; and &quot;US&quot;:<br>    ./config.cue:7:12<br>    ./config.cue:10:31<br>    ./us.yaml:4:10</pre><p>CUE is a handy tool to have, and can be useful to migrate and rewrite configs efficiently at scale.</p><p>Got to take a cue and start using it more often :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beba22f74f63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Specs to rule them all?]]></title>
            <link>https://medium.com/@ssarke/specs-to-rule-them-all-e3629016a9a0?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3629016a9a0</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[spec-driven-development]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 09:55:25 GMT</pubDate>
            <atom:updated>2026-08-31T09:55:25.037Z</atom:updated>
            <content:encoded><![CDATA[<p><em>With LLMs being good enough to generate code, the implementation cost is dropping drastically. <br>And a trident is emerging which can be an attempt to harness how aligned agents are to real intent. Is Spec Driven Development here to stay?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Udjt71iaiShdxIqvayJM7A.png" /></figure><p>Photo by <a href="https://unsplash.com/@imshaamim">https://unsplash.com/@imshaamim</a></p><p>Originally posted at <a href="https://tochai.leaflet.pub/">https://tochai.leaflet.pub</a> 27 Mar, 2026</p><p><a href="https://tochai.leaflet.pub/3mhylkepuuc24">Specs to rule them all? - Tech Over Chai</a></p><h3>The legacy</h3><p>We have been through DevOps driven changes in the industry, where IaC (Infrastructure as Code), CaC (Configuration as Code), GitOps and so on tried to envision a world where configurations of a system define what it means to be able to replicate/produce it into existence.</p><p>It meant better templates, better scaffolding and schematic rigour to enforce a master version of desired truth.</p><p>We got Terraform, Pulumi, CloudFormation describing api driven ways to instantiate infrastructure.</p><p>Kubernetes, Cuelang, Dhall, Ansible gave us further ways to reason about configurations of the system.</p><p>What you maintain as an agreed specification, translates in the cloud or target layer as an equivalent implementation manifesting the resource and actively restricting any deviation in it’s state unless it’s from the actual source of truth.</p><h3>Re-imagining the process</h3><p>With LLMs being able to produce more accurate software code in a whole forest-variety of languages as the months roll on (when prompted and refined in isolation), agentic workflows now allow unhinged code implementations to solve whatever the agent comprehended from our prompt/context management tools.</p><p>But can we tether it to our actual intentions rather than depend on the non determinism LLMs inherently possess? (behavior can vary model to model or with different contexts).</p><p>MCP was a step towards that direction, enforcing programmatic management of features.</p><p>Then came skills, superpowers (I am probably missing a ton of other stuff, as this space adds on stuff so rapidly, but eventually some of them stick).</p><p>Markdown specs, defining how we want the workflow to reason about the tasks at hand and create code downstream as ephemeral/regenerative artifacts.</p><blockquote>In DevOps parlance, infrastructure was the throw-away piece, regenerative, immutable.</blockquote><blockquote>One can always spin up a new resource again instead of changing it.<br>The infra code, configuration specs became the assets that should evolve as per intent.</blockquote><blockquote>With the advent of coding agents, now we are at a juncture where it might be possible to think of development itself in similar terms.</blockquote><p>The programming implementations being the throwaway pieces, regenerative, ephemeral.<br>One can spin up the same or an updated implementation again instead of modifying it live.</p><p>The spec/design becomes the new assets that can evolve as needed.</p><h3>Spec Driven Development</h3><p>Chad Fowler calls it the Phoenix Architecture, you don’t refactor existing code, instead treat as immutable artifacts and regenerate when change is needed.</p><p>In Spec Driven Development, which is now gaining traction in AI landscape, we have a close coupling between 3 elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*21p4hFwJ54ZUNdisNzN3Fg.png" /></figure><ul><li>Spec defines what we want, how we want.</li><li>Spec is indicative enough for agents to create relevant tests/contracts.</li><li>Tests drive an almost TDD style development process, implement code to satisfy the tests.</li><li>Send feedback to check if code matches intent on test and/or spec, give checkpoints for the human in loop to make those decisions on tweaking the spec and iterate.</li></ul><h3>Will we reinvent the wheel?</h3><p>Is SDD going to be a sane stable way of reasoning about agentic applications? The new way of understanding how to develop in this paradigm?</p><p>Maybe, maybe not. <br>Who knows if this would stick around for the next couple of years?</p><p>Some are tinkering with this concept and feeling agent driven code implementations can be still buggy and have loopholes obviously, no matter how great our spec is.</p><p>Agent confidently notifying it aligns with tests perfectly when it may have skipped some.</p><p>Code solutions being bloated, unoptimized and weirdly constructed since it doesn’t do true evaluation of what’s better.</p><p>Agents taking weird shortcuts or decisions even on the best worded spec, and so on are still observed.</p><p>An updated approach might be brewing, which is to provide code implementations/ snippets, basically programmatic harnesses rather than just plaintext may yield better results!</p><p>Wait, what?</p><p>Actual code implementations for the agent to clearly get the intent, since it cannot make sound decisions all the time (yet)!!</p><p>At the end of the day, when the dust settles eventually, maybe we will come back again to revisit first principles and find better processes was the key.</p><p>SDD might just stuck around as one of the processes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3629016a9a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The impact of connotations in tech (an Indian pov)]]></title>
            <link>https://medium.com/@ssarke/the-impact-of-connotations-in-tech-an-indian-pov-916b51791265?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/916b51791265</guid>
            <category><![CDATA[language]]></category>
            <category><![CDATA[connotation]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 10:22:34 GMT</pubDate>
            <atom:updated>2026-08-30T10:22:34.663Z</atom:updated>
            <content:encoded><![CDATA[<p><em>An ecosystem evolves with the meaning and context of the words/conventions used by it’s participants.<br>We need shared understanding to have meaningful conversations around topics. The engineering &amp; scientific communities over the world have created common parlance where applicable, where does Indian context fit in?</em></p><p>Originally posted at <a href="https://tochai.leaflet.pub/">https://tochai.leaflet.pub</a> 01 March, 2026</p><p><a href="https://tochai.leaflet.pub/3mfyq6pxefc2z">The impact of connotations in tech (an Indian pov) - Tech Over Chai</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*Jnh_udA8TZSgmJ74YTjm8g.png" /></figure><p>Be honest.</p><p>How many semi-urban millennials like me from India, would be aware of where this line came from, at first glance?</p><p>This came from the movie <a href="https://en.wikipedia.org/wiki/Idiocracy">https://en.wikipedia.org/wiki/Idiocracy</a>.</p><p>The movie’s treatment of declining critical thinking is sometimes referenced to comment on the current AI trends nowadays.</p><p>Another one, searching for the mythical “Any” key. (from the Simpsons)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*nt4YBSBm77VQcOu4tH2myQ.png" /></figure><p>It was a running joke to comment on the confusion in early computer days, where people literally thought ‘Any’ could be the key the program expects!</p><p>This is context, that implicitly conveys meaning to those who share it.</p><p>When engineers/SMEs try to bring in some common cultural connotations in their conferences/discussions, it is to relate to the audience, to provide an idea where they are coming from on the topic/opinion at hand.</p><h3>Where am I coming from?</h3><p>The notion of conferences, tech meet-ups, communities, podcasts, learning in public etc is largely spearheaded by western experts and groups around US/Europe, since they engage proactively in these spaces, right from academia to industry and lead innovation in many domains.</p><p>There is an active culture of research, learning and sharing novelty, and they create or mature platforms for it.</p><p>Indian spaces are starkly different.</p><p>Consider a conference conducted by an Indian technical university. It can rank high in terms of capability &amp; knowledge like any other premier institution.</p><blockquote>However there will be referring to seniors as ‘Aravind Sir/ Shanti Ma’am’, felicitations with shawls or bouquets, and a general teacher student dynamic and likewise decorum, where a cultural emphasis on community recognition/reverence takes centre stage and not the core content or interactions to promote exchange of ideas.</blockquote><p>It’s rarely a matter of concern how much reach we are able to provide for such content, it’s not even broadcasted well enough.<br>We don’t see followups or initiatives to evaluate whether it creates lasting, tangible impact for learners and tinkerers in the long run.</p><h3>How words drive technicality</h3><p>The western counterparts create ecosystems with tools/processes on how to engage, learn and collaborate to build and enrich the community.</p><p>There are SIGs and forums where scientific and innovation driven culture make it easier to formalise/structure one’s ideas via collaboration and regular exploration.</p><p>A whole gamut of nuances, connotations and such, drive engineering communication. Think</p><ul><li>enshittification</li><li>cloud</li><li>side effects</li><li>client/server</li></ul><p>among others.</p><p>A plethora of common terms used in science are derived from certain nomenclature and terminologies/culture that is commonly aligned to western societies and vocabulary.</p><p>Think tactile, entanglement, theorize, axioms, C-Tactile Afferent, screening, public key infrastructure, distributed consensus, firewalls, repository, kernel and a zillion other terms commonly used in science/engineering, and think how they relate to Indian context or experiences in general life (if at all).</p><p>Now think what they translate to in system definitions or creating mental models.</p><pre>f.seek(0)<br><br># file handler calls a function &#39;seek&#39; to move pointer to the beginning 0th byte. <br># Seek has a meaning.</pre><pre>enum Option&lt;T&gt; {<br>  Some(T),<br>  None,<br>}<br><br>// Option monad signifies a computation that may return a value or nothing,<br>// hence the same in type signature</pre><p>SSL/TLS mutual authentication is connotative of a handshake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*TK-TCJN1UMqPU4sfFV3N0g.png" /></figure><pre>var list = std.ArrayList([]const u8).init(allocator);<br><br>// An array of variable length of string items, needs a memory allocator.<br>// which allocates memory explicitly.</pre><p>They are fused into the fabric of daily interactions where these terms are defined in a strictly engineering/science specific context and used to relay meaning to components of systems and interactions when they try to model it.</p><p>And it fits.</p><p>Thinking in systems, and using language that augments understanding and relates to the people.</p><h3>The Indian experience</h3><p>We in India are primarily trying to catch up to the concepts after they have been published, created and shared.</p><p>And that too in the English language (with scientific formalisations in certain cases) which is an abstraction on top of how we communicate in daily life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*62Qg3dBqZHM8CCqv_RVRQg.png" /></figure><p>Now I am not saying this is always the case.</p><p>Sure IISc, some IITs and other institutes would have indigenous research and capability building on top of some western systems/concepts.</p><p>However the way we learn, understand and produce artefacts rarely has an Indian transformation or enrichment. <br>And there are not enough broad ecosystems for the research / learning to seep into communities and affect daily life/experience (which can create common parlance).</p><p>If you know software engineers from Poland, Ukraine, Russia, China, Israel, Japan etc, you might get to see that their primary programming communication is built along their languages to a variable degree.</p><p>They have their own terms to symbolise engineering concepts, equivalents to the English counterparts.</p><ul><li>In Polish, Pamięć is memory, Zmienna is variable.</li><li>In Japanese, Hairetsu (配列) is array, Shin-gi-chi (真偽値) is boolean.</li><li>In Hebrew, Lula&#39;at &quot;avur&quot; (לולאת &quot;עבור&quot;) is for loop, Mimshak (ממשק) is for Interface.</li><li>In Chinese, Jǔzhèn(矩阵) is matrix, Suànfǎ (算法) is algorithm, and so on.</li></ul><p>You get the point..</p><p><em>(Take them with a pinch of salt [again a English saying], LLM produced translations after all)</em></p><p>In India, we have a Indlish reality. Use English words since we don&#39;t have an alternative vocabulary that&#39;s precise enough or common enough to reach consensus and relate to people.</p><p>(Hindi is not the be all, end all of Indian languages). You just don&#39;t call database anything other than a &#39;database&#39;, a network/function call is same and so on.</p><p>What are our core SOPs, approach to solving problems in general?</p><blockquote>Can we articulate for example, sovereign infrastructure in terms that are relatable to Indian general public, heck just even Indian students?</blockquote><blockquote>What do scientific/engineering action plans and collaboration look like beyond think tank groups?</blockquote><p>Example, this is from Digital India, covering a session at AI Summit</p><p><a href="https://www.youtube.com/live/8GjfZGe99O8?si=Z6buMBWQdT2DW2il">- YouTube</a></p><p>Can anyone tell me what does the implementation, processes exactly look like? (that is if anyone can figure out whatever was being said for majority of the video, since the quality makes it indecipherable)</p><p><strong>Can common citizens make sense of what is being talked about here, and how/why it matters? Are they incentivised to? Is there enough shared context?</strong></p><p>All this just creates isolated pockets of well meaning SMEs (perhaps) who had the privilege of advanced knowledge/education/discourse.</p><p>But we rarely form robust avenues/channels to distill it in a meaningful way to engage and bring on Indian minds/enthusiasts to collaborate and structure far reaching conversations for technological and public good.</p><p>I get it, in a country as diverse as India, it’s extremely difficult to have common indigenous codification for scientific (or any structured) communication/initiatives.</p><p>We simply have to adopt concept, languages developed in other parts of the world as they already provide foundation for others to build further.</p><p>But we can do a much better job of creating local communities that enable science and tech to be more approachable at grassroots levels and make them common aspects (like UPI did at a national level).</p><p>If we create enough shared constructive motivations for engagement, perhaps some day our language and experiences may also find a way to embed in the tech fabric, at least for our local contexts.</p><p>That itself, will be no small feat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=916b51791265" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will AI tools manifest more intent based API?]]></title>
            <link>https://medium.com/@ssarke/will-ai-tools-manifest-more-intent-based-api-ebe01d63d2d2?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebe01d63d2d2</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[mcp-protocol]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 08:49:13 GMT</pubDate>
            <atom:updated>2026-08-30T09:27:05.416Z</atom:updated>
            <content:encoded><![CDATA[<p><em>While LLMs provided a significant leap in capability, how ‘agentic’ we should be with them has been of significant interest over the last years.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*fJH-JeIozNnvxnes" /></figure><p><em>Photo by </em><a href="https://unsplash.com/@shanerounce"><em>https://unsplash.com/@shanerounce</em></a></p><p><em>Original article posted at </em><a href="https://leaflet.pub/6567e319-537f-465a-9fef-0525ea17736e"><em>https://tochai.leaflet.pub</em></a><em> 17 Feb, 2026</em></p><p><a href="https://tochai.leaflet.pub/3meys7zpehs2s">Will AI tools manifest more intent based API? - Tech Over Chai</a></p><h3>How we got here</h3><p>LLMs are not the be-all &amp; end-all of artificial intelligence, though that’s pretty much how it’s been hyped in recent memory (from around 2022/2023 when chatgpt became synonymous with everything AI in common parlance).</p><p>We got an interface to communicate in natural language, where the system creates contextual answers from a foundation model that has scoured the internet, trained on it’s data to provide probabalistic appropriate responses on a best effort basis.</p><p>This is almost the best way to achieve simplicity in terms of how to use a product, extracting out complexities, the knobs &amp; params, and just interact in plain language without any domain specific incantations.</p><p>And so began its evolution in business…</p><p>Initially it was about how performant and correct the incremental models became.</p><p>Most users were just wanting that novel feeling of driving a conversation on the (T/G)UI.</p><p>The AI behemoths started focusing on building AI infrastructure to provision for it’s heavy demand and expected widespread usage.</p><p>Meanwhile companies have been embedding LLM capabilities in their products and creating greenfield business propositions sometimes solely banking on AI play.</p><h3>Something missing</h3><p>Eventually, we began noticing limitations of a purely static &amp; central knowledge system.</p><p>Enterprises need to be selective what data could be shared with these models, if any at all.<br>How to integrate prompt calls in different applications, is the interfacing too custom, is it secure enough?</p><p>LLMs can suggest action items, but no scope of executing autonomously.<br>Most practical use cases need to break the loop to make external interactions and if anything requires follow up, must be fed back to the LLM again to continue on.</p><p>If the model hallucinates, what can be done to reaffirm and align with the user’s requirements/intention reliably.</p><p>Through prompts (text) how do we map it to correct programmatic actions, intended targets or APIs reliably.</p><h3>Protocoling the way to develop AI apps</h3><p>Somewhere down the line, it was a natural step:<br>A standard process for allowing models to iteratively take predefined actions, and thus become a native way to fit LLM utilization in AI applications.</p><p>MCP (Model Context Protocol) provided that: JSON-RPC comms for AI applications to utilise specific tools/functions provided from target systems.<br>This paves the way for further automation where AI is not dependent on just static information/training and can access stuff externally.</p><p>However, building complex workflows can become quite token heavy since there are set instructions at client that load valid, available tools from server into the LLM context, even if the workflow may not need it upfront or use all of them.<br>Then there are intermediate results/processing from one MCP tool to another that are again passed through the context.</p><h3>The way forward?</h3><p>To overcome this problem, Anthropic proposed an approach wherein the agent can decide what tool/code is needed to interface with server capabilities at any given point, via ‘skill’ based intents mentioned in a file.</p><p>It banks on the premise, that agent/LLMs are good enough to generate code, traverse files/folders to realise which tool/s are needed at any juncture and process the interaction on it’s own (albeit with some human oversight as the disclaimer always is).</p><p>This models what the request/response is going to be about, not how it must be done. This intent based abstraction gives the idea and guardrails for agents to proceed and take tool action when necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qBcDZWTxtzVjK1MH" /></figure><p><a href="https://platform.claude.com/docs/images/agent-skills-architecture.png">https://platform.claude.com/docs/images/agent-skills-architecture.png</a></p><p>This seems closer to the ideal concept of intent based API (in natural language too).</p><p>What is the desired state/action is more apparent and modelled as a contract of sorts, instead of procedural/rigid steps where client code is tightly coupled with the domain logic.</p><p>So this might be where we are heading to, more natural pragmatic contract designs for LLMs to base their actions on, chained as a series of capabilities left to the agent to decide when to use/create.</p><h3>Elephant/s in the room 🐘🐘</h3><p>There are elephant/s in the room though in general, for all agentic automation.</p><p>Since we expect instructions/intents to be in natural language mostly, what is instruction, and what is content (data) gets more blurred than it usually is when dealing with ex — say HTML / javascript where there are atleast some measures built over the years to distinguish executables.</p><p>This leaves fundamental security risks from potential hidden instructions masquerading as content in some website/github repo etc, allowed to be accessed via the flexible agents.</p><p>Here again, agent will try to honour the ‘intent’ (even from a malicious external prompt).</p><p>It will be interesting to see how this space evolves.</p><p>While the ‘skills’ model seems a great way of adding flexibility and cleaner intent instead of following predefined logic,<br>the same move reopens the data-instruction boundary problem,<br>and securing such systems become a huge challenge, especially with the industry pushing to make autonomous, privileged agents widely used in tech asap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebe01d63d2d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[comptime or !comptime?]]></title>
            <link>https://medium.com/@ssarke/comptime-or-comptime-4cbbd0f7e236?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cbbd0f7e236</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[zig]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Thu, 27 Aug 2026 10:21:06 GMT</pubDate>
            <atom:updated>2026-10-02T16:46:10.162Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Zig wants to be clear when it’s resolving types/structs and when it’s dealing with runtime data. Comptime bakes in your logic into the binary at compilation time, but when to actually use it?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bQWWXKF3r4OTiO-E" /></figure><p>Photo by <a href="https://unsplash.com/@bobdobelina?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Bob Coyne</a> on <a href="https://unsplash.com/photos/the-new-york-times-newspaper-2199hbtQQVw?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p><em>Originally posted on </em><a href="https://tochai.leaflet.pub/3mu2mr7glxs2o">https://tochai.leaflet.pub</a> Aug 27, 2026.</p><p>Maybe this is already obvious for some, but noting it for myself (and others if they happen to stumble upon this note or this question, or stumble upon this note and then get this question).</p><blockquote><strong><em>Types as values exist only at compile time.</em></strong></blockquote><p>Meaning? If you want your own custom struct describing an entity, that becomes a type definition and handling types cannot be left to runtime.</p><p>Let’s build an example.</p><pre>// enum of departments<br>const Dept = enum {<br>    petroleum,<br>    @&quot;roads &amp; highways&quot;,<br>    health,<br>    defence<br>};<br><br>const Minister = struct {<br>    name: []const u8, // always needs a &quot;Shri/ Honble&quot;<br>    authenticity: bool = false, // it&#39;s still changeable for an instance!<br>    departments: []const Dept, // infinite acumen<br>    generationalWealth: u128 // it will be quite large<br>};</pre><p>Here “honble” Minister is a type, but alas, we have kept the authenticity parameter open to instantiation during runtime.</p><pre>const ministerAlpha = Minister{<br>    .name = &quot;Shri Honble Fuel Maestro&quot;,<br>    .authenticity = true,<br>    .departments = &amp;.{ .petroleum, .@&quot;roads &amp; highways&quot; },<br>    .generationalWealth = 11000000000<br>}; </pre><p>If I can be assured authenticity is questionable even before declaring a minister, why not hardcode it? (not as in default values)</p><p>We can use comptime for this.</p><pre>//a &quot;real&quot; minister struct<br>const RealMinister = struct {<br>    pub const authenticity = false;<br><br>    name: []const u8,<br>    ...<br>};</pre><p>This will not get any space in the binary’s runtime memory for the field (why waste resource when we already know the value?).</p><p>If you check size</p><pre>std.debug.print(&quot;Size of Minister: {} bytes\n&quot;, .{@sizeOf(Minister)});<br>std.debug.print(&quot;Size of Real Minister: {} bytes\n&quot;, .{@sizeOf(RealMinister)});<br><br>size of Minister: 64 bytes<br>size of Real Minister: 48 bytes</pre><p>Now consider if we have departments being checked over and need conditional actions.</p><p>Let’s create a cabinet mapping, we give a dept name &amp; want to get the associated metrics.</p><pre>const PetroleumMetric = struct {<br>    tariff_price_enabled: bool = true,<br>    forced_e20_fuel: bool = true<br>};<br><br>const RoadsMetric = struct {<br>    space_tech: bool = true,<br>    longevity_in_days: f32 = 60.2<br>};<br><br>const FinanceMetric = struct { <br>    total_budget: u64 = 5000000,<br>    campaign_budget: u64 = 70000000<br>};<br>const HealthMetric = struct {<br>    active_hospitals: u32 = 20000,<br>    reqd_hospitals: u32 = 100000<br>};<br>const DefenceMetric = struct { <br>    security_clearance_level: u8 = 3,<br>    security_hardening_coverage: f32 = 20.04<br>};<br><br>const CabinetSystem = struct {<br>    petroleum: PetroleumMetric = .{},<br>    @&quot;roads &amp; highways&quot;: RoadsMetric = .{},<br>    finance: FinanceMetric = .{},<br>    health: HealthMetric = .{},<br>    defence: DefenceMetric = .{}<br>};<br><br>// let&#39;s get a runtime string (which will be comparable to our enum variants)<br>const input_dept: []const u8 = &quot;roads &amp; highways&quot;;<br><br>// convert to a enum to do 1-1 comparison<br>const runtime_val_as_enum = std.meta.stringToEnum(Dept, input_dept) orelse raise error.SomeError;<br><br>// cabinet instance, gets default values in it&#39;s fields<br>const cabinet = CabinetSystem{}</pre><p>Now let’s do a comptime switch case to match any of enum variants and show the associated metric, via inline else (for the switch) and inline for (for iterating the struct field)</p><pre>switch (runtime_val_as_enum) {<br>    inline else =&gt; |dep| {<br>        // make instance field accessible via it&#39;s comptime stored name<br>        // example, cabinet.finance, but this is comptime<br>        const dept_metric = @field(cabinet, @tagName(dep));<br><br>        // get the generic struct fields, from compiler<br>        const fields = std.meta.fields(@TypeOf(dept_metric));<br><br>        // loop for fields and print<br>        inline for (fields) |metric| {<br>            std.debug.print(&quot;field name is {s}, dept is [{s}], field value is {any}\n&quot;,<br>                .{metric.name, @tagName(dep), @field(dept_metric, metric.name)}<br>            );<br>        }<br>    }<br>}</pre><p>This switch statement actually signals compiler to resolve the logic branches upfront.</p><p>Get me all values possible for runtime_val_as_enum(which are the enum values).</p><p>Resolve automatically like</p><pre>switch (val) {<br>    .defence =&gt; {..}<br>    .health =&gt; {..}<br>    ...</pre><p>for each branch, get the struct field as an accessible type, and print out, the entire sequence being like a blueprint.</p><p>And we get</p><pre>field name is space_tech, dept is [roads &amp; highways], field value is true<br>field name is longevity_in_days, dept is [roads &amp; highways], field value is 60.2</pre><p>Note that each cabinet metric may contain different field types (f32, u64 etc), but here compiler handles it just fine.</p><p>Whenever runtime passes a string (that is supposed to match any of the enum) compiler has already laid out the branches, no runtime computation/wastage for this, it routes to matching branch immediately.</p><p>The entire unfolding of for/switch branches is taken care of, so we didn’t need to explictly define actions on each value. (less boilerplate).</p><blockquote><strong><em>How does it differ exactly than just accepting a runtime value and matching to print?</em></strong></blockquote><p>You can do the same without inline for/else too, just get the input string and do the match/resolution runtime.</p><p>But imagine each of these depts having different lookup data/computation logic within (rather than this simple print).</p><p>If we decide comptime resolution, none of that needs to be done at runtime, which can give significant savings on CPU cycles.</p><blockquote><strong><em>So should we prefer this?</em></strong></blockquote><p>IMO, it helps well with exhaustive handling of tagged unions, enums (take care to choose low cardinality cases which need exhaustive coverage nonetheless).</p><p>It can also be considered if you are generating code or types on the fly (similar to macros in other languages), or doing SerDe (go parse/handle fields in JSON etc).</p><p>Comptime however should be avoided when there are a lot of branches/loops to be unrolled, or needing heavy computation which will cause compiler to take more RAM and slow down while building the binary.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cbbd0f7e236" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tables for all!]]></title>
            <link>https://medium.com/@ssarke/tables-for-all-fe2c4ffc0b15?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe2c4ffc0b15</guid>
            <category><![CDATA[lua]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 16:47:42 GMT</pubDate>
            <atom:updated>2025-01-04T16:47:42.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*Gcnt8mPvBWDYHJcY.jpg" /></figure><p>What if a language manages most of it’s data handling requirements through just one of it’s data type?</p><p>Let’s take a look at a lua code snippet</p><pre>&gt; coll = {}<br>&gt; for i=1, 5 do coll[i] = i end<br><br>&gt; for i, item in ipairs(coll) do<br>    print(item)<br>  end<br>1<br>2<br>3<br>4<br>5</pre><p>You would obviously notice this is iterating over a collection and printing items.</p><p>This collection should be something like a list or array right…</p><p>Well this is a lua table type, and there is something different about it.</p><p>Lua tables are an associative array, where we can store any type (integer, string etc) index. They have no fixed size. So tables are like a master structure that can represent arrays, sets, queues etc.</p><pre>&gt; coll[&quot;x&quot;] = &quot;hey there, lua here&quot; <br>&gt; print(coll.x)<br>hey there, lua here<br><br>&gt; for _, item in ipairs(coll) do<br>    print(item)<br>  end<br>1<br>2<br>3<br>4<br>5</pre><p>Now we added a key value pair (accessed with dot notation, but can also be col[&#39;x&#39;]) But when iterating it’s not showing up is it?</p><p>That’s because ipairs iterates based on index position (usually for numeric tables, non numeric keys are ignored).</p><p>pairs gives all key value pairs.</p><pre>&gt; for _, item in pairs(coll) do<br>    print(item)<br>  end<br>1<br>2<br>3<br>4<br>5<br>hey there, lua here</pre><p>How about a nested table?</p><pre>&gt; master_table = {color=&#39;whatever&#39;, size=&#39;whatever again&#39;, 1,2,3, {color=&#39;blue&#39;, size=0.0}} <br><br>-- size of this table is interesting<br>&gt; #master_table<br>4</pre><p>4 items? but we added 6 elements right (considering the nested table as 1 item).</p><p>The trick here is size being fetched on integer indices. <br>1,2,3 and {color=&#39;blue&#39;, size=0.0} are considered 4 items. (this table as a whole is occupying the last index of master_table)</p><p>The first 2 items added are considered to be added via a constructor. Equivalent to</p><pre>temp = {}; temp.color = &#39;whatever&#39;; temp.size = &#39;whatever again&#39;</pre><p>and doesn’t have an integer index (color and size), hence not considered in the length count</p><p>Example:</p><pre>&gt; #{&quot;A&quot;, &quot;B&quot;, x=10, &quot;C&quot;}<br>3</pre><p>So it’s generally easier to iterate via pairs to get at the actual items.</p><p>The flexibility of tables allows us to package just about any variety of data, which is quite uncommon.</p><p>Example:</p><pre>&gt; Alan = {<br>	&quot;Alan&quot;,<br>	movie = &quot;Jurassic Park&quot;,<br>	2, -- # of kids to handle<br>	[3] = &quot;also in third movie&quot;,<br>	dino_insight = function() print(&quot;its vision is based on movement!&quot;) end,<br>}<br><br>&gt; Alan[1]<br>Alan<br>&gt; Alan[2]<br>2<br>&gt; Alan.dino_insight()<br>its vision is based on movement!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe2c4ffc0b15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s the deal with service account/location for BQ operator? (airflow 1 vs 2)]]></title>
            <link>https://medium.com/@ssarke/whats-the-deal-with-service-account-location-for-bq-operator-airflow-1-vs-2-59fb57962bd2?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/59fb57962bd2</guid>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[airflow-2]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 10:33:57 GMT</pubDate>
            <atom:updated>2023-02-05T10:33:57.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DBa6MybwSx7xgHEb" /><figcaption>Photo by <a href="https://unsplash.com/@jannis_magic?utm_source=medium&amp;utm_medium=referral">Jannis Klemm</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Where to use service account/location:</h3><p>If you are running BQ queries from airflow, you would mostly be using <em>BigQueryOperator</em> (in airflow 1) or <em>BigQueryExecuteQueryOperator</em> class (in airflow 2).</p><p>To pass a specific service account, region and project details, we can add them in airflow as connection info, which will be referred via hooks to provide service api/cursor that can execute our BQ queries.</p><pre>$ airflow connections -a --conn_id data_conn_id \<br>--conn_extra &#39;{&quot;extra__google_cloud_platform__project&quot;:&quot;project-aloha&quot;, \<br>&quot;extra__google_cloud_platform__key_path&quot;:&quot;/opt/svc_accounts/bq_svc.json&quot;, \<br>&quot;extra__google_cloud_platform__num_retries&quot;: 3, \<br>&quot;extra__google_cloud_platform__bq_location&quot;:&quot;us-west4&quot;}&#39; \<br>--conn_type &quot;Google Cloud Platform&quot; \<br>...<br><br>#rest of params can be blank or None</pre><p>Now considering that airflow jobs would likely be reading high volumes of data (ETLs after all), it makes sense to raise the quota threshold.</p><p>However, raising the quota can’t be limited to a specific user, it’s at the gcp project level and would be applicable for all.<br>For this reason, we could have a billing project id (which will have high enough or no cap on quota for bytes queried per user per day), and use this for only running ETLs.</p><p>Something like:</p><pre>$ airflow connections -a --conn_id data_billing_conn_id \<br>--conn_extra &#39;{&quot;extra__google_cloud_platform__project&quot;:&quot;project-aloha-billing&quot;, \<br>&quot;extra__google_cloud_platform__key_path&quot;:&quot;/opt/svc_accounts/bq_billing_svc.json&quot;, \<br>&quot;extra__google_cloud_platform__num_retries&quot;: 3, \<br>&quot;extra__google_cloud_platform__bq_location&quot;:&quot;us-west4&quot;}&#39; \<br>--conn_type &quot;Google Cloud Platform&quot; \<br>...<br><br>#rest of params can be blank or None</pre><p>Note the new project <em>project-aloha-billing </em>and the new service account keyfile (they have to be setup first), specifically for etl use.</p><h3>Implementation:</h3><p>In the <a href="https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/bigquery_operator.py"><strong>1.10</strong></a><strong> </strong>stable version instance parameters for <em>BigQueryOperator</em>, we get a <strong>bigquery_conn_id</strong> (defaults to ‘bigquery_default’).</p><p>Since we want the connection id to point to different project/service account while executing queries, we could pass our billing conn id to <em>bigquery_conn_id.<br></em>For location we can set from our connection extra config, <br>or add a Variable and reference it, or simply pass it at task config.</p><pre>&quot;&quot;&quot;<br>GoogleCloudBaseHook(self.data_billing_conn_id)._get_field(“bq_location”)<br>Or<br>Variable.get(&quot;bq_location&quot;) if set in variables<br>Or<br>Just pass it in the operator params<br>&quot;&quot;&quot;</pre><p>thereby creating the hook we want via:</p><pre>bq_hook = BigQueryHook(<br>    bigquery_conn_id=self.bigquery_conn_id,<br>    delegate_to=self.delegate_to,<br>    location=self.location<br>)</pre><p>How about in airflow 2?</p><p>Looking at <a href="https://github.com/apache/airflow/blob/v2-4-stable/airflow/providers/google/cloud/operators/bigquery.py"><strong>2.4</strong></a><strong> </strong>stable version, the <em>BigQueryExecuteQueryOperator </em>init expects a <strong>gcp_conn_id.</strong></p><p>In it’s execute:</p><pre>def execute(self, context: ‘Context’): <br>    if self.hook is None:<br>        self.log.info(‘Executing: %s’, self.sql)<br>        self.hook = BigQueryHook(<br>            gcp_conn_id=self.gcp_conn_id,<br>            use_legacy_sql=self.use_legacy_sql,<br>            delegate_to=self.delegate_to,<br>            location=self.location,<br>            impersonation_chain=self.impersonation_chain,<br>        )</pre><p>So if you are migrating to airflow 2.x, note that <strong>bigquery_conn_id</strong> is not used anymore, instead it’s <strong>gcp_conn_id.</strong></p><p>It’s also worth noting that if location is not passed, it would point to default EU/US regions (both in airflow 1 and 2)</p><pre>:param location: The geographic location of the job. Required except for US and EU. See details at https://cloud.google.com/bigquery/docs/locations#specifying_your_location</pre><p>But there is a difference in how airflow 1 treats None location.<br>In airflow 1 <em>BigQueryBaseCursor,</em> <em>run_query</em> calls <em>run_with_configuration </em>method.<br>Here, it creates a BQ job, without location specified:</p><pre>jobs = self.service.jobs()<br>job_data = {&#39;configuration&#39;: configuration}<br><br>query_reply = jobs.insert(project_id=self.project_id, body=job_data).execute()</pre><p>but checks, if there is any retrieved from jobReference.</p><pre>self.running_job_id = query_reply[‘jobReference’][‘job_id’]<br>if &#39;location&#39; in query_reply[&#39;jobReference&#39;]:<br>    location = query_reply[&#39;jobReference&#39;][&#39;location&#39;]<br>else:<br>location = self.location</pre><p>Next it polls for the job status using this location as a param.</p><pre>try:<br>    if location:<br>        job = jobs.get(<br>            projectId=self.project_id,<br>            jobId=self.running_job_id,<br>            location=location).execute(num_retries=self.num_retries)<br>    else:<br>        job = jobs.get(<br>            projectId=self.project_id,<br>            jobId=self.running_job_id).execute(num_retries=self.num_retries)</pre><p>While in Airflow 2 on the other hand, in <em>insert_job, </em>the location is specifically set in jobReference as part of the request body.</p><pre>location = location or self.location<br>job_id = job_id or self._custom_job_id(configuration)<br><br>client = self.get_client(project_id=project_id, location=location)<br>job_data = {<br>    &quot;configuration&quot;: configuration,<br>    &quot;jobReference&quot;: {&quot;jobId&quot;: job_id, &quot;project_id&quot;: project_id, &quot;location&quot;: location}<br>}<br>...<br>...<br># then initiates job and waits to finish<br>if no wait:<br>    job._begin()<br>else:<br>    job.result(timeout=timeout, retry=retry)<br>return job</pre><p>I was left scratching my head at first while switching BQ queries to airflow 2 :-) , as they started complaining about location being US (and thus dataset not found).<br>We didn’t pass location explicitly in airflow 1 either, so didn’t expect it to be a dealbreaker.</p><p>Nonetheless, it was an interesting exercise to search what changed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59fb57962bd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[python-attrs or dataclasses?]]></title>
            <link>https://medium.com/@ssarke/python-attrs-or-dataclasses-dc3d7c8a23c2?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc3d7c8a23c2</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 22:34:04 GMT</pubDate>
            <atom:updated>2022-06-29T22:36:19.998Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KgxThBRsKMcDNvXu" /><figcaption>Photo by <a href="https://unsplash.com/es/@mangofantasy?utm_source=medium&amp;utm_medium=referral">Tim Johnson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The modules <a href="https://docs.python.org/3/library/dataclasses.html"><em>dataclass</em></a>es and <a href="https://github.com/python-attrs/attrs"><em>attrs</em></a> both address the same problem space, which is getting a robust, clean and efficient way to create python classes.</p><p><em>Dataclasses </em>might feel a bit more intuitive with it’s struct like definition for classes/attributes right out of the box.<br>It has been in the standard library since python3.7 after all.</p><p>One could consider it as <em>“mutable namedtuples with defaults” <br></em>(as they put it in <a href="https://peps.python.org/pep-0557/">PEP-557</a>).</p><p>However, <em>dataclasses </em>was in fact created as a subset of <em>attrs</em>,<br>and there are other subtle features, options with <em>attrs </em>library.</p><p>So it’s not just a legacy predecessor :-)</p><p><strong>Using slots:</strong></p><p>Classes using slots are generally memory efficient and fast, since it doesn’t need to use default <em>object.__dict__</em> for instances.<br>Instead they use fixed length<em> object.__slots__</em> to get the instance attributes.</p><p>Using <em>attrs</em>, it would be like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dbe13b90350afbd5fda0ac426975573/href">https://medium.com/media/5dbe13b90350afbd5fda0ac426975573/href</a></iframe><p>A class created can’t be changed to incorporate slots, so <em>attrs </em>creates a new class under the hood with instance slots as a tuple.</p><pre>&gt;&gt;&gt; c = Point()<br>&gt;&gt;&gt; type(c.__slots__)<br>&lt;class ‘tuple’&gt;</pre><p>In <em>dataclasses</em>, this parameter is available only recently in python 3.10.</p><pre>@dataclass(slots=True)<br>class Point:<br>    x: int<br>    y: int</pre><p><strong>MRO:</strong></p><p>In case of inherited overriden attributes with other subclass fields, MRO for <em>attrs </em>keeps it in order expected. <br>It takes overriden attributes of the subclass to the end of attribute list with the relevant default value.</p><p>In <em>dataclass o</em>verwriting default argument in this manner will cause an error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fee1433ce2c1cb3924961c1a2f4e3efe/href">https://medium.com/media/fee1433ce2c1cb3924961c1a2f4e3efe/href</a></iframe><p>Interestingly in <em>attrs</em>, there is also a flag to indicate inherited attributes.</p><pre>from attrs import fields</pre><pre>&gt;&gt;&gt; fields(Employee)</pre><pre>(Attribute(name=&#39;name&#39;, default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, ha<br>sh=None, init=True, metadata=mappingproxy({}), type=&lt;class &#39;str&#39;&gt;, converter=None, kw_only=False, inherited=True, on_set<br>attr=None),<br> Attribute(name=&#39;age&#39;, default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, has<br>h=None, init=True, metadata=mappingproxy({}), type=&lt;class &#39;int&#39;&gt;, converter=None, kw_only=False, inherited=True, on_seta<br>ttr=None),<br> Attribute(name=&#39;emp_id&#39;, default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, <br>hash=None, init=True, metadata=mappingproxy({}), type=&lt;class &#39;int&#39;&gt;, converter=None, kw_only=False, inherited=False, on_<br>setattr=None),<br> Attribute(name=&#39;employee&#39;, default=True, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, h<br>ash=None, init=True, metadata=mappingproxy({}), type=&lt;class &#39;bool&#39;&gt;, converter=None, kw_only=False, inherited=False, on_<br>setattr=None))</pre><p><strong>Using asdict:</strong></p><p><em>Dataclass asdict </em>goes recursive dictification of list, tuples, dataclass objects.<br>But there is a caveat, it uses <em>deepcopy </em>(an expensive operation) for anything that is not any of the above (i.e. list/tuple/dataclass obj etc).</p><p><em>asdict </em>in such cases will create different object copies when it could point to the same.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96379d685aa997b6c32f3952e26b6a22/href">https://medium.com/media/96379d685aa997b6c32f3952e26b6a22/href</a></iframe><p>In <em>attrs</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b4c9f23eb1fb6283b595860e29bf7ca/href">https://medium.com/media/7b4c9f23eb1fb6283b595860e29bf7ca/href</a></iframe><p>There are other subtle differences,<br>like <em>attrs </em>has filter function to include/exclude attributes based on name/type.</p><pre>from attrs import define, fields, filters</pre><pre>@define<br>class A:<br>    x: int<br>    y: int<br>    z: str</pre><pre>&gt;&gt;&gt; asdict(A(1,2,&quot;string&quot;),filter=filters.exclude(fields(A).x),str)<br>&gt;&gt;&gt; {&#39;x&#39;: 1}</pre><p>With <em>dataclass</em>, we would have to pass a custom lambda to <em>dict_factory</em>, but filtering on types might be tricky and not as simple as above.</p><p><strong>Validators:</strong></p><p><em>attrs </em>has a host of validator functions, decorator support as well, in case we want to check some conditions while initializing.</p><p>One could pass native validator functions for an attribute.</p><pre>from attrs import define, validators, field</pre><pre>@define<br>class C:<br>    x: int = field(validator=validators.instance_of(int))</pre><pre>&gt;&gt;&gt; c = C(30)<br>&gt;&gt;&gt; c.x = &#39;30&#39;<br>TypeError: (&quot;&#39;x&#39; must be &lt;class &#39;int&#39;&gt; (got &#39;30&#39; that is a &lt;class &#39;str&#39;&gt;).&quot;, Attribute(name=&#39;x&#39;, default=NOTHING, valida<br>tor=&lt;instance_of validator for type &lt;class &#39;int&#39;&gt;&gt;, repr=True, eq=True, eq_key=None, order=True, order_key=None, hash=No<br>ne, init=True, metadata=mappingproxy({}), type=&lt;class &#39;int&#39;&gt;, converter=None, kw_only=False, inherited=False, on_setattr<br>=None), &lt;class &#39;int&#39;&gt;, &#39;30&#39;)</pre><p>Or a combination of custom and native checks (with a small dragonball z reference :-))</p><pre>def vegeta_calm(instance, attribute, value):<br>    if instance.goku_power &gt; 9000:<br>        raise ValueError(&quot;it&#39;s over 9000!!!&quot;)</pre><pre>@define<br>class Scouter:<br>    vegeta_max_expects: int = field(<br>        validator=[<br>            validators.instance_of(int),<br>            vegeta_calm<br>        ]<br>    )<br>    goku_power: int</pre><pre>&gt;&gt;&gt; Scouter(5000, 5000)<br> Scouter(vegeta_max_expects=5000, goku_power=5000)</pre><pre>&gt;&gt;&gt; Scouter(5000, 9001)<br>ValueError: it&#39;s over 9000!!!</pre><p>In <em>dataclass</em>, it would be custom, mostly using __post_init__(self) to assert.</p><p>In this area, <em>attrs </em>and another promising library <em>pydantic </em>have far more features, while omitting them in <em>dataclasses </em>had been a conscious choice.</p><p><strong>Converters:</strong></p><p>If we want to normalize input values, <em>attrs </em>converters would enable without forcing user to conform/adapt.</p><pre>@define<br>class A:<br>    x: list = field(converter=tuple)<br><br>&gt;&gt;&gt; a = A([&#39;a&#39;,&#39;b&#39;,&#39;c&#39;])<br><br>&gt;&gt;&gt; a.x<br>&gt;&gt;&gt; (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;)</pre><p><em>Dataclass </em>decided not to add this to their features, and rely on static type checking to cover with highlighting what to cast.</p><p><strong>In conclusion:</strong></p><p>There are concrete design decisions that paved the path for these two libraries to mature their own way.</p><p>If we need to depend solely on std library, or just need a quick intuitive way to setup classes, <em>dataclasses </em>is the first choice.</p><p>On the other hand <em>attrs </em>has a bit more fine grained control and features overall, it’s new APIs feel cleaner as well<em>.</em></p><p><em>Dataclasses </em>project was actively supported by some of the maintainers of <em>attrs, </em>among others, and arose to be a standard easy way to define classes.</p><p><em>attrs </em>meanwhile stayed outside the bounds of python release cycles, so that it doesn’t tie down to python versions.</p><p>As <em>attrs </em><a href="https://www.attrs.org/en/stable/why.html">doc </a>says, <br>if it stops overusing namedtuple, using either one is a huge win.</p><p>Personally, using either of them is much more soothing compared to managing hand-written classes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc3d7c8a23c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using python poetry with .pypirc]]></title>
            <link>https://medium.com/@ssarke/using-python-poetry-with-pypirc-333ae12c99eb?source=rss-2a01228c5124------2</link>
            <guid isPermaLink="false">https://medium.com/p/333ae12c99eb</guid>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Sourav Sarker]]></dc:creator>
            <pubDate>Sat, 21 May 2022 19:56:35 GMT</pubDate>
            <atom:updated>2022-07-15T13:06:09.990Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using python poetry with .pypirc</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mXGkLx7RpRpsE219" /><figcaption>Photo by <a href="https://unsplash.com/@kadh?utm_source=medium&amp;utm_medium=referral">Kira auf der Heide</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Poetry, the python dependency manager, ensures you have the right stack everywhere.</p><p>Your project dependencies can always be consistent, in an insulated environment whenever you want to use it, and you don’t need to manage a myriad of files/approaches like setup.py (though we are almost used to it, aren’t we :-) ), MANIFEST.in etc.</p><p>Being relatively new, there are some functionalities of the tool which have limitations with existing setup, for now atleast.</p><p>One such is usage with a pypirc file.</p><p>A .pypirc file is basically used to define the user creds and repositories, to upload a package to.</p><p>The format follows distutils package (which used to be a python packaging system and is deprecated)</p><p>Here is a sample:</p><pre>[distutils]<br>index-servers =<br>    my-repository<br><br>[my-repository]<br>repository = &lt;URL&gt;<br>username = &lt;username&gt;<br>password = &lt;password&gt;</pre><p>Poetry also allows one to configure remote repositories via its cli command:</p><pre>poetry config repositories.my-repository &lt;URL&gt;<br>poetry config http-basic.my-repository &lt;username&gt; &lt;password&gt;</pre><p>However, it uses system keyring if available (via <a href="https://pypi.org/project/keyring/">https://pypi.org/project/keyring/</a>), <br>or falls back to create the auth configs in a toml file, and poetry expects this toml to be available when running it’s publish commands.</p><p>Therefore, a simple workaround if we want a plaintext approach.</p><p>Read pypirc file and run poetry config commands to enable remote repositories.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b89b7dc032b6e0cad6251b895ce041e/href">https://medium.com/media/8b89b7dc032b6e0cad6251b895ce041e/href</a></iframe><p>References:</p><p><a href="https://python-poetry.org/docs/repositories/">https://python-poetry.org/docs/repositories</a></p><p>Looks like there is already a small module doing exactly this:</p><p><a href="https://pypi.org/project/poetry-pypirc/">https://pypi.org/project/poetry-pypirc/</a><br>It’s just a small file, can also basically reside as a standalone in your CI-CD pipeline.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=333ae12c99eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>