<?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[Software Grognard - Medium]]></title>
        <description><![CDATA[Thoughts on software development, coding, startups, and stuff in general. grognard m. (plural grognards)
 
 1. an old veteran soldier; specifically of the grenadiers of the Imperial Guard (Grenadiers à Pied de la Garde Impériale); an old complaining soldier. - Medium]]></description>
        <link>https://medium.com/software-grognard?source=rss----8f1b6108381---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Software Grognard - Medium</title>
            <link>https://medium.com/software-grognard?source=rss----8f1b6108381---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:16:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/software-grognard" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hide Your Phone Number]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/software-grognard/hide-your-phone-number-e55be9344622?source=rss----8f1b6108381---4"><img src="https://cdn-images-1.medium.com/max/600/1*MkKUV77eil_vn6h4IFwXdA.jpeg" width="600"></a></p><p class="medium-feed-snippet">A lot of companies list their phone number &#x201C;raw&#x201D; on their websites. That makes it very easy to scrape, which is why your number is&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/software-grognard/hide-your-phone-number-e55be9344622?source=rss----8f1b6108381---4">Continue reading on Software Grognard »</a></p></div>]]></description>
            <link>https://medium.com/software-grognard/hide-your-phone-number-e55be9344622?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/e55be9344622</guid>
            <category><![CDATA[website]]></category>
            <category><![CDATA[small-business-marketing]]></category>
            <category><![CDATA[small-business]]></category>
            <category><![CDATA[website-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Fri, 21 Mar 2025 15:32:59 GMT</pubDate>
            <atom:updated>2025-03-21T15:32:59.086Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Laravel Developers: Stop Writing SQL or Eloquent]]></title>
            <link>https://medium.com/software-grognard/laravel-developers-stop-writing-sql-or-eloquent-859779701a35?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/859779701a35</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[laravel-development]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[eloquent]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 02:00:14 GMT</pubDate>
            <atom:updated>2025-03-11T17:08:55.995Z</atom:updated>
            <content:encoded><![CDATA[<p>LLMs can do some absolutely amazing things. Unfortunately, writing big complicated SQL or Eloquent is fairly expensive and time consuming. But there is a solution. Just keep reading until the end.</p><p>Sure, LLMs can handle small databases. Just dump your schema to a text file, attach it to your prompt, and ask it to write SQL. I gave ChatGPT 4o the metadata for a schema with users, posts, and comments tables and asked it:</p><pre>write sql that shows all comments with the name of the user</pre><p>No Problem. It came back with:</p><pre>SELECT comments.id, comments.content, comments.post_id, posts.title AS post_title, users.name AS user_name<br>FROM comments<br>JOIN posts ON comments.post_id = posts.id<br>JOIN users ON posts.user_id = users.id;</pre><p>It did this in one shot. If only all our projects only had three tables. But then again, it would be hard to make a living in such a simple domain.</p><p>Let’s build a test database with a lot of tables. Here’s a migration to gin up a test schema:</p><pre>&lt;?php<br><br>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;<br><br>return new class extends Migration<br>{<br>    /**<br>     * Run the migrations.<br>     */<br>    public function up(): void<br>    {<br>        // Create the organizations table<br>        Schema::create(&#39;organizations&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;string(&#39;domain&#39;)-&gt;nullable();<br>            $table-&gt;text(&#39;description&#39;)-&gt;nullable();<br>            $table-&gt;timestamps();<br>            $table-&gt;softDeletes();<br>        });<br><br>        // Define base tables and their schemas<br>        $baseSchemas = [<br>            &#39;posts&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;organization_id&#39;)-&gt;constrained();<br>                $table-&gt;string(&#39;title&#39;);<br>                $table-&gt;text(&#39;content&#39;);<br>                $table-&gt;boolean(&#39;is_published&#39;)-&gt;default(false);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;comments&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;post&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;posts&#39; . $version);<br>                $table-&gt;text(&#39;content&#39;);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;categories&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;string(&#39;name&#39;);<br>                $table-&gt;string(&#39;slug&#39;)-&gt;unique();<br>                $table-&gt;text(&#39;description&#39;)-&gt;nullable();<br>                $table-&gt;timestamps();<br>            },<br>            &#39;post_category&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;post&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;posts&#39; . $version);<br>                $table-&gt;foreignId(&#39;category&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;categories&#39; . $version);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;tags&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;string(&#39;name&#39;);<br>                $table-&gt;string(&#39;slug&#39;)-&gt;unique();<br>                $table-&gt;timestamps();<br>            },<br>            &#39;taggables&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;tag&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;tags&#39; . $version);<br>                $table-&gt;morphs(&#39;taggable&#39;);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;media&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;nullableMorphs(&#39;mediable&#39;);<br>                $table-&gt;string(&#39;file_path&#39;);<br>                $table-&gt;string(&#39;file_name&#39;);<br>                $table-&gt;string(&#39;mime_type&#39;);<br>                $table-&gt;integer(&#39;file_size&#39;);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;likes&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;morphs(&#39;likeable&#39;);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;products&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;organization_id&#39;)-&gt;constrained();<br>                $table-&gt;foreignId(&#39;category&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;categories&#39; . $version);<br>                $table-&gt;string(&#39;name&#39;);<br>                $table-&gt;text(&#39;description&#39;);<br>                $table-&gt;decimal(&#39;price&#39;, 10, 2);<br>                $table-&gt;integer(&#39;stock&#39;)-&gt;default(0);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;orders&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;string(&#39;order_number&#39;)-&gt;unique();<br>                $table-&gt;decimal(&#39;total&#39;, 10, 2);<br>                $table-&gt;enum(&#39;status&#39;, [&#39;pending&#39;, &#39;processing&#39;, &#39;completed&#39;, &#39;cancelled&#39;]);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;order_items&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;order&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;orders&#39; . $version);<br>                $table-&gt;foreignId(&#39;product&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;products&#39; . $version);<br>                $table-&gt;integer(&#39;quantity&#39;);<br>                $table-&gt;decimal(&#39;price&#39;, 10, 2);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;notifications&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;string(&#39;type&#39;);<br>                $table-&gt;morphs(&#39;notifiable&#39;);<br>                $table-&gt;text(&#39;data&#39;);<br>                $table-&gt;timestamp(&#39;read_at&#39;)-&gt;nullable();<br>                $table-&gt;timestamps();<br>            },<br>            &#39;events&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;organization_id&#39;)-&gt;constrained();<br>                $table-&gt;string(&#39;title&#39;);<br>                $table-&gt;text(&#39;description&#39;);<br>                $table-&gt;timestamp(&#39;start_time&#39;);<br>                $table-&gt;timestamp(&#39;end_time&#39;);<br>                $table-&gt;string(&#39;location&#39;)-&gt;nullable();<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;attendees&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;event&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;events&#39; . $version);<br>                $table-&gt;enum(&#39;status&#39;, [&#39;invited&#39;, &#39;attending&#39;, &#39;maybe&#39;, &#39;declined&#39;]);<br>                $table-&gt;timestamps();<br>            },<br>            &#39;projects&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;organization_id&#39;)-&gt;constrained();<br>                $table-&gt;string(&#39;name&#39;);<br>                $table-&gt;text(&#39;description&#39;)-&gt;nullable();<br>                $table-&gt;date(&#39;start_date&#39;);<br>                $table-&gt;date(&#39;end_date&#39;)-&gt;nullable();<br>                $table-&gt;enum(&#39;status&#39;, [&#39;planning&#39;, &#39;active&#39;, &#39;on_hold&#39;, &#39;completed&#39;]);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;tasks&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;project&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;projects&#39; . $version);<br>                $table-&gt;string(&#39;title&#39;);<br>                $table-&gt;text(&#39;description&#39;)-&gt;nullable();<br>                $table-&gt;date(&#39;due_date&#39;)-&gt;nullable();<br>                $table-&gt;enum(&#39;priority&#39;, [&#39;low&#39;, &#39;medium&#39;, &#39;high&#39;, &#39;urgent&#39;]);<br>                $table-&gt;enum(&#39;status&#39;, [&#39;todo&#39;, &#39;in_progress&#39;, &#39;review&#39;, &#39;done&#39;]);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;messages&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;text(&#39;content&#39;);<br>                $table-&gt;timestamps();<br>                $table-&gt;softDeletes();<br>            },<br>            &#39;message_recipients&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;message&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;messages&#39; . $version);<br>                $table-&gt;timestamp(&#39;read_at&#39;)-&gt;nullable();<br>                $table-&gt;timestamps();<br>            },<br>            &#39;groups&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;organization_id&#39;)-&gt;constrained();<br>                $table-&gt;string(&#39;name&#39;);<br>                $table-&gt;text(&#39;description&#39;)-&gt;nullable();<br>                $table-&gt;timestamps();<br>            },<br>            &#39;group_members&#39; =&gt; function (Blueprint $table, $version) {<br>                $table-&gt;id();<br>                $table-&gt;foreignId(&#39;group&#39; . $version . &#39;_id&#39;)-&gt;constrained(&#39;groups&#39; . $version);<br>                $table-&gt;boolean(&#39;is_admin&#39;)-&gt;default(false);<br>                $table-&gt;timestamps();<br>            }<br>        ];<br><br>        // Create multiple versions of each base table<br>        for ($version = 1; $version &lt;= 10; $version++) {<br>            foreach ($baseSchemas as $tableName =&gt; $schemaCallback) {<br>                $versionedTableName = $tableName . $version;<br><br>                Schema::create($versionedTableName, function (Blueprint $table) use ($schemaCallback, $version) {<br>                    $schemaCallback($table, $version);<br>                });<br>            }<br>        }<br>    }<br><br>    /**<br>     * Reverse the migrations.<br>     */<br>    public function down(): void<br>    {<br>        // Drop tables in reverse order to avoid foreign key constraints issues<br>        for ($version = 10; $version &gt;= 1; $version--) {<br>            $baseTables = [<br>                &#39;group_members&#39;,<br>                &#39;groups&#39;,<br>                &#39;message_recipients&#39;,<br>                &#39;messages&#39;,<br>                &#39;tasks&#39;,<br>                &#39;projects&#39;,<br>                &#39;attendees&#39;,<br>                &#39;events&#39;,<br>                &#39;notifications&#39;,<br>                &#39;order_items&#39;,<br>                &#39;orders&#39;,<br>                &#39;products&#39;,<br>                &#39;likes&#39;,<br>                &#39;media&#39;,<br>                &#39;taggables&#39;,<br>                &#39;tags&#39;,<br>                &#39;post_category&#39;,<br>                &#39;categories&#39;,<br>                &#39;comments&#39;,<br>                &#39;posts&#39;<br>            ];<br><br>            foreach ($baseTables as $baseTable) {<br>                Schema::dropIfExists($baseTable . $version);<br>            }<br>        }<br><br>        // Drop organizations table last<br>        Schema::dropIfExists(&#39;organizations&#39;);<br>    }<br>};</pre><p>Here’s what a simplified version of the entity relationship diagram looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hpt_iEg2pzDBHekKZ-4JRw.jpeg" /><figcaption>ER Diagram</figcaption></figure><p>Cute, huh? It only took me a couple of prompts. Run that migration and then the following SQL:</p><pre>SELECT COUNT(*) AS table_count <br>FROM information_schema.tables <br>WHERE table_schema = &#39;laravel&#39;</pre><p>and I get 210 tables. Not really that big, I’ve worked with databases with 1,000s of tables. But it’s big enough to confuse even the advanced models today.</p><p>I attached a mysqldump of that schema:</p><pre>mysqldump -h mysql -u sail -ppassword --no-data --skip-lock-tables --no-tablespaces laravel</pre><p>And gave it the following prompt:</p><pre>show all group_members1 that are in organizations that have comments1</pre><p>Should be pretty simple. Looking at the ER diagram, we can see that we should be able to join groups, organizations, and posts to get to comments.</p><p>A month ago, ChatGPT 4o failed at this. It tried to read the sql dump, decided it was too large, and gave up. But today it went through a ton of steps and eventually got the right answer, even though it didn’t think so. You can scroll past this, but it’s pretty interesting.</p><pre>I&#39;ll process the SQL file and extract all group_members1 that belong to organizations with comments1. Let me analyze the structure and execute the necessary query.<br><br>Always show details<br><br>import sqlite3<br>import pandas as pd<br><br># Load the SQL file<br>sql_file_path = &quot;/mnt/data/database.sql&quot;<br><br># Read the contents of the SQL file<br>with open(sql_file_path, &quot;r&quot;, encoding=&quot;utf-8&quot;) as file:<br>    sql_script = file.read()<br><br># Create an in-memory SQLite database and execute the SQL script<br>conn = sqlite3.connect(&quot;:memory:&quot;)<br>cursor = conn.cursor()<br><br>try:<br>    cursor.executescript(sql_script)<br>    conn.commit()<br>except Exception as e:<br>    conn.rollback()<br>    error_message = str(e)<br><br># Check available tables<br>tables_query = &quot;SELECT name FROM sqlite_master WHERE type=&#39;table&#39;;&quot;<br>tables = pd.read_sql(tables_query, conn)<br><br>tables<br><br>Result<br><br>Empty DataFrame<br>Columns: [name]<br>Index: []<br><br>It looks like the SQL script didn&#39;t create any tables in the in-memory database, possibly due to missing CREATE TABLE statements or unsupported commands. I can inspect the SQL file further to determine the structure of the data. Let me extract and analyze its contents. ​<br><br>​<br><br>Always show details<br><br># Display the first few lines of the SQL file to analyze its structure<br>sql_script_preview = &quot;\n&quot;.join(sql_script.splitlines()[:50])  # Show first 50 lines<br>sql_script_preview<br><br>Result<br><br>&quot;-- MySQL dump 10.13  Distrib 8.0.41, for Linux (x86_64)\n--\n-- Host: mysql    Database: laravel\n-- ------------------------------------------------------\n-- Server version\t8.0.32\n\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n/*!50503 SET NAMES utf8mb4 */;\n/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n/*!40103 SET TIME_ZONE=&#39;+00:00&#39; */;\n/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=&#39;NO_AUTO_VALUE_ON_ZERO&#39; */;\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n--\n-- Table structure for table `attendees1`\n--\n\nDROP TABLE IF EXISTS `attendees1`;\n/*!40101 SET @saved_cs_client     = @@character_set_client */;\n/*!50503 SET character_set_client = utf8mb4 */;\nCREATE TABLE `attendees1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `event1_id` bigint unsigned NOT NULL,\n  `status` enum(&#39;invited&#39;,&#39;attending&#39;,&#39;maybe&#39;,&#39;declined&#39;) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `attendees1_event1_id_foreign` (`event1_id`),\n  CONSTRAINT `attendees1_event1_id_foreign` FOREIGN KEY (`event1_id`) REFERENCES `events1` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n/*!40101 SET character_set_client = @saved_cs_client */;\n\n--\n-- Table structure for table `attendees10`\n--\n\nDROP TABLE IF EXISTS `attendees10`;\n/*!40101 SET @saved_cs_client     = @@character_set_client */;\n/*!50503 SET character_set_client = utf8mb4 */;\nCREATE TABLE `attendees10` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `event10_id` bigint unsigned NOT NULL,\n  `status` enum(&#39;invited&#39;,&#39;attending&#39;,&#39;maybe&#39;,&#39;declined&#39;) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),&quot;<br><br>The SQL file appears to be a MySQL dump, including table definitions and foreign key constraints. To properly restore and query it, I need to parse the dump, extract relevant table structures, and load them into an SQLite-compatible format.<br><br>I&#39;ll now:<br><br>    Identify and extract group_members1, organizations, and any table containing comments1.<br>    Reconstruct them in SQLite.<br>    Execute the query to find all group_members1 in organizations that have comments1. ​<br><br>    ​<br><br>Always show details<br><br>import re<br><br># Extract CREATE TABLE statements for relevant tables<br>tables_of_interest = [&quot;group_members1&quot;, &quot;organizations&quot;, &quot;comments1&quot;]<br>create_statements = {}<br><br># Regex pattern to capture CREATE TABLE statements<br>pattern = re.compile(r&quot;CREATE TABLE `(\w+)` \((.*?)\) ENGINE=InnoDB&quot;, re.S)<br><br>for match in pattern.finditer(sql_script):<br>    table_name, table_def = match.groups()<br>    if table_name in tables_of_interest:<br>        create_statements[table_name] = f&quot;CREATE TABLE `{table_name}` ({table_def});&quot;<br><br># Display extracted CREATE TABLE statements<br>create_statements<br><br>Result<br><br>{&#39;comments1&#39;: &#39;CREATE TABLE `comments1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `post1_id` bigint unsigned NOT NULL,\n  `content` text COLLATE utf8mb4_unicode_ci NOT NULL,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  `deleted_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `comments1_post1_id_foreign` (`post1_id`),\n  CONSTRAINT `comments1_post1_id_foreign` FOREIGN KEY (`post1_id`) REFERENCES `posts1` (`id`)\n);&#39;,<br> &#39;group_members1&#39;: &quot;CREATE TABLE `group_members1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `group1_id` bigint unsigned NOT NULL,\n  `is_admin` tinyint(1) NOT NULL DEFAULT &#39;0&#39;,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `group_members1_group1_id_foreign` (`group1_id`),\n  CONSTRAINT `group_members1_group1_id_foreign` FOREIGN KEY (`group1_id`) REFERENCES `groups1` (`id`)\n);&quot;,<br> &#39;organizations&#39;: &#39;CREATE TABLE `organizations` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `domain` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n  `description` text COLLATE utf8mb4_unicode_ci,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  `deleted_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`)\n);&#39;}<br><br>The SQL dump contains the necessary tables:<br><br>    group_members1: Contains members linked to group1_id.<br>    organizations: Stores organization details.<br>    comments1: Stores comments linked to post1_id.<br><br>To find group_members1 in organizations with comments1, I need to determine:<br><br>    The connection between organizations and comments1 (likely through posts1).<br>    The connection between group_members1 and organizations (possibly via groups1).<br><br>I&#39;ll now extract and analyze groups1 and posts1 structures to establish these links. ​<br><br>​<br><br>Always show details<br><br># Extract CREATE TABLE statements for groups1 and posts1<br>additional_tables = [&quot;groups1&quot;, &quot;posts1&quot;]<br>for match in pattern.finditer(sql_script):<br>    table_name, table_def = match.groups()<br>    if table_name in additional_tables:<br>        create_statements[table_name] = f&quot;CREATE TABLE `{table_name}` ({table_def});&quot;<br><br># Display extracted CREATE TABLE statements for additional tables<br>create_statements<br><br>Result<br><br>{&#39;comments1&#39;: &#39;CREATE TABLE `comments1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `post1_id` bigint unsigned NOT NULL,\n  `content` text COLLATE utf8mb4_unicode_ci NOT NULL,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  `deleted_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `comments1_post1_id_foreign` (`post1_id`),\n  CONSTRAINT `comments1_post1_id_foreign` FOREIGN KEY (`post1_id`) REFERENCES `posts1` (`id`)\n);&#39;,<br> &#39;group_members1&#39;: &quot;CREATE TABLE `group_members1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `group1_id` bigint unsigned NOT NULL,\n  `is_admin` tinyint(1) NOT NULL DEFAULT &#39;0&#39;,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `group_members1_group1_id_foreign` (`group1_id`),\n  CONSTRAINT `group_members1_group1_id_foreign` FOREIGN KEY (`group1_id`) REFERENCES `groups1` (`id`)\n);&quot;,<br> &#39;organizations&#39;: &#39;CREATE TABLE `organizations` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `domain` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n  `description` text COLLATE utf8mb4_unicode_ci,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  `deleted_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`)\n);&#39;,<br> &#39;groups1&#39;: &#39;CREATE TABLE `groups1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `organization_id` bigint unsigned NOT NULL,\n  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `description` text COLLATE utf8mb4_unicode_ci,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `groups1_organization_id_foreign` (`organization_id`),\n  CONSTRAINT `groups1_organization_id_foreign` FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`)\n);&#39;,<br> &#39;posts1&#39;: &quot;CREATE TABLE `posts1` (\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\n  `organization_id` bigint unsigned NOT NULL,\n  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\n  `content` text COLLATE utf8mb4_unicode_ci NOT NULL,\n  `is_published` tinyint(1) NOT NULL DEFAULT &#39;0&#39;,\n  `created_at` timestamp NULL DEFAULT NULL,\n  `updated_at` timestamp NULL DEFAULT NULL,\n  `deleted_at` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `posts1_organization_id_foreign` (`organization_id`),\n  CONSTRAINT `posts1_organization_id_foreign` FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`)\n);&quot;}<br><br>The relationships between tables are now clear:<br><br>    group_members1 → groups1 (group1_id links to groups1.id).<br>    groups1 → organizations (organization_id links to organizations.id).<br>    posts1 → organizations (organization_id links to organizations.id).<br>    comments1 → posts1 (post1_id links to posts1.id).<br><br>To find all group_members1 in organizations with comments1:<br><br>    Identify organization_ids from posts1 that have comments in comments1.<br>    Find group_members1 linked to those organizations through groups1.<br><br>I&#39;ll now extract and load relevant data into SQLite to run this query. ​<br><br>​<br><br>Always show details<br><br># Extract INSERT statements for relevant tables<br>insert_statements = {table: [] for table in create_statements}<br><br># Regex pattern to capture INSERT INTO statements<br>insert_pattern = re.compile(r&quot;INSERT INTO `(\w+)` VALUES (.+);&quot;, re.S)<br><br>for match in insert_pattern.finditer(sql_script):<br>    table_name, values = match.groups()<br>    if table_name in insert_statements:<br>        insert_statements[table_name].append(f&quot;INSERT INTO `{table_name}` VALUES {values};&quot;)<br><br># Create tables in SQLite<br>for table, create_stmt in create_statements.items():<br>    try:<br>        cursor.execute(create_stmt)<br>    except Exception as e:<br>        print(f&quot;Error creating table {table}: {e}&quot;)<br><br># Insert data into tables<br>for table, inserts in insert_statements.items():<br>    for insert_stmt in inserts:<br>        try:<br>            cursor.execute(insert_stmt)<br>        except Exception as e:<br>            print(f&quot;Error inserting data into {table}: {e}&quot;)<br><br>conn.commit()<br><br># Execute query to find group_members1 in organizations with comments1<br>query = &quot;&quot;&quot;<br>SELECT gm.*<br>FROM group_members1 gm<br>JOIN groups1 g ON gm.group1_id = g.id<br>JOIN organizations o ON g.organization_id = o.id<br>JOIN posts1 p ON o.id = p.organization_id<br>JOIN comments1 c ON p.id = c.post1_id;<br>&quot;&quot;&quot;<br><br># Fetch and display results<br>result_df = pd.read_sql(query, conn)<br>import ace_tools as tools<br>tools.display_dataframe_to_user(name=&quot;Group Members in Commented Organizations&quot;, dataframe=result_df)<br><br>STDOUT/STDERR<br><br>Error creating table comments1: near &quot;AUTO_INCREMENT&quot;: syntax error<br>Error creating table group_members1: near &quot;AUTO_INCREMENT&quot;: syntax error<br>Error creating table organizations: near &quot;AUTO_INCREMENT&quot;: syntax error<br>Error creating table groups1: near &quot;AUTO_INCREMENT&quot;: syntax error<br>Error creating table posts1: near &quot;AUTO_INCREMENT&quot;: syntax error<br><br>---------------------------------------------------------------------------<br>OperationalError                          Traceback (most recent call last)<br>File ~/.local/lib/python3.11/site-packages/pandas/io/sql.py:2018, in SQLiteDatabase.execute(self, *args, **kwargs)<br>   2017 try:<br>-&gt; 2018     cur.execute(*args, **kwargs)<br>   2019     return cur<br><br>OperationalError: no such table: group_members1<br><br>The above exception was the direct cause of the following exception:<br><br>DatabaseError                             Traceback (most recent call last)<br>Cell In[5], line 40<br>     30 query = &quot;&quot;&quot;<br>     31 SELECT gm.*<br>     32 FROM group_members1 gm<br>   (...)<br>     36 JOIN comments1 c ON p.id = c.post1_id;<br>     37 &quot;&quot;&quot;<br>     39 # Fetch and display results<br>---&gt; 40 result_df = pd.read_sql(query, conn)<br>     41 import ace_tools as tools<br>     42 tools.display_dataframe_to_user(name=&quot;Group Members in Commented Organizations&quot;, dataframe=result_df)<br><br>File ~/.local/lib/python3.11/site-packages/pandas/io/sql.py:564, in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize)<br>    561 pandas_sql = pandasSQL_builder(con)<br>    563 if isinstance(pandas_sql, SQLiteDatabase):<br>--&gt; 564     return pandas_sql.read_query(<br>    565         sql,<br>    566         index_col=index_col,<br>    567         params=params,<br>    568         coerce_float=coerce_float,<br>    569         parse_dates=parse_dates,<br>    570         chunksize=chunksize,<br>    571     )<br>    573 try:<br>    574     _is_table_name = pandas_sql.has_table(sql)<br><br>File ~/.local/lib/python3.11/site-packages/pandas/io/sql.py:2078, in SQLiteDatabase.read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize, dtype)<br>   2066 def read_query(<br>   2067     self,<br>   2068     sql,<br>   (...)<br>   2074     dtype: DtypeArg | None = None,<br>   2075 ) -&gt; DataFrame | Iterator[DataFrame]:<br>   2077     args = _convert_params(sql, params)<br>-&gt; 2078     cursor = self.execute(*args)<br>   2079     columns = [col_desc[0] for col_desc in cursor.description]<br>   2081     if chunksize is not None:<br><br>File ~/.local/lib/python3.11/site-packages/pandas/io/sql.py:2030, in SQLiteDatabase.execute(self, *args, **kwargs)<br>   2027     raise ex from inner_exc<br>   2029 ex = DatabaseError(f&quot;Execution failed on sql &#39;{args[0]}&#39;: {exc}&quot;)<br>-&gt; 2030 raise ex from exc<br><br>DatabaseError: Execution failed on sql &#39;<br>SELECT gm.*<br>FROM group_members1 gm<br>JOIN groups1 g ON gm.group1_id = g.id<br>JOIN organizations o ON g.organization_id = o.id<br>JOIN posts1 p ON o.id = p.organization_id<br>JOIN comments1 c ON p.id = c.post1_id;<br>&#39;: no such table: group_members1<br><br>It looks like SQLite doesn&#39;t support AUTO_INCREMENT in the same way as MySQL, causing the table creation to fail. I&#39;ll modify the table definitions to be SQLite-compatible and reload the data before running the query again. ​<br><br>​<br><br>Always show details<br><br># Modify CREATE TABLE statements to be SQLite-compatible<br>sqlite_create_statements = {<br>    &quot;comments1&quot;: &quot;&quot;&quot;<br>    CREATE TABLE comments1 (<br>        id INTEGER PRIMARY KEY,<br>        post1_id INTEGER NOT NULL,<br>        content TEXT NOT NULL,<br>        created_at TIMESTAMP,<br>        updated_at TIMESTAMP,<br>        deleted_at TIMESTAMP,<br>        FOREIGN KEY (post1_id) REFERENCES posts1(id)<br>    );<br>    &quot;&quot;&quot;,<br>    &quot;group_members1&quot;: &quot;&quot;&quot;<br>    CREATE TABLE group_members1 (<br>        id INTEGER PRIMARY KEY,<br>        group1_id INTEGER NOT NULL,<br>        is_admin INTEGER NOT NULL DEFAULT 0,<br>        created_at TIMESTAMP,<br>        updated_at TIMESTAMP,<br>        FOREIGN KEY (group1_id) REFERENCES groups1(id)<br>    );<br>    &quot;&quot;&quot;,<br>    &quot;organizations&quot;: &quot;&quot;&quot;<br>    CREATE TABLE organizations (<br>        id INTEGER PRIMARY KEY,<br>        name TEXT NOT NULL,<br>        domain TEXT,<br>        description TEXT,<br>        created_at TIMESTAMP,<br>        updated_at TIMESTAMP,<br>        deleted_at TIMESTAMP<br>    );<br>    &quot;&quot;&quot;,<br>    &quot;groups1&quot;: &quot;&quot;&quot;<br>    CREATE TABLE groups1 (<br>        id INTEGER PRIMARY KEY,<br>        organization_id INTEGER NOT NULL,<br>        name TEXT NOT NULL,<br>        description TEXT,<br>        created_at TIMESTAMP,<br>        updated_at TIMESTAMP,<br>        FOREIGN KEY (organization_id) REFERENCES organizations(id)<br>    );<br>    &quot;&quot;&quot;,<br>    &quot;posts1&quot;: &quot;&quot;&quot;<br>    CREATE TABLE posts1 (<br>        id INTEGER PRIMARY KEY,<br>        organization_id INTEGER NOT NULL,<br>        title TEXT NOT NULL,<br>        content TEXT NOT NULL,<br>        is_published INTEGER NOT NULL DEFAULT 0,<br>        created_at TIMESTAMP,<br>        updated_at TIMESTAMP,<br>        deleted_at TIMESTAMP,<br>        FOREIGN KEY (organization_id) REFERENCES organizations(id)<br>    );<br>    &quot;&quot;&quot;<br>}<br><br># Recreate tables in SQLite<br>cursor.execute(&quot;PRAGMA foreign_keys = ON;&quot;)  # Enable foreign key support<br>for table, create_stmt in sqlite_create_statements.items():<br>    try:<br>        cursor.execute(create_stmt)<br>    except Exception as e:<br>        print(f&quot;Error creating table {table}: {e}&quot;)<br><br># Re-attempt inserting data into tables<br>for table, inserts in insert_statements.items():<br>    for insert_stmt in inserts:<br>        try:<br>            cursor.execute(insert_stmt.replace(&quot;AUTO_INCREMENT&quot;, &quot;&quot;))  # Adjust MySQL syntax<br>        except Exception as e:<br>            print(f&quot;Error inserting data into {table}: {e}&quot;)<br><br>conn.commit()<br><br># Re-run the query to find group_members1 in organizations with comments1<br>query = &quot;&quot;&quot;<br>SELECT gm.*<br>FROM group_members1 gm<br>JOIN groups1 g ON gm.group1_id = g.id<br>JOIN organizations o ON g.organization_id = o.id<br>JOIN posts1 p ON o.id = p.organization_id<br>JOIN comments1 c ON p.id = c.post1_id;<br>&quot;&quot;&quot;<br><br># Fetch and display results<br>result_df = pd.read_sql(query, conn)<br>import ace_tools as tools<br>tools.display_dataframe_to_user(name=&quot;Group Members in Commented Organizations&quot;, dataframe=result_df)<br><br>Result<br><br>Empty DataFrame<br>Columns: [id, group1_id, is_admin, created_at, updated_at]<br>Index: []<br><br>Group Members in Commented Organizations<br>Unable to display visualization<br><br>The query executed successfully, but it returned no results, meaning there are no group_members1 associated with organizations that have comments1 in the provided dataset. If you want me to further investigate or adjust the approach, let me know! ​</pre><p>At least it didn’t lie or hallucinate. But it took several minutes to come up with this answer. I don’t know how many tokens it used, but it was probably expensive. I also suspect that it had familiarity with these tables because they’re a common demonstration domain. This was the smoking gun:</p><pre>To find group_members1 in organizations with comments1, I need to determine:<br><br>    The connection between organizations and comments1 (likely through posts1).<br>    The connection between group_members1 and organizations (possibly via groups1).</pre><p>If it’s a set of tables that it has seen before, it can generate the SQL quite easily. But when it’s handed something large, it has to do an in-depth analysis. We need to make this easier so that it can do what it does well.</p><p>That’s why I wrote this package: <a href="https://github.com/gleman17/Laravel-Tools">gleman17/Laravel-Tools</a>. This package will talk to any LLM that is supported by <a href="https://github.com/prism-php/prism">Prism-PHP</a>.</p><p>In order to give the LLM a chance to write SQL (and even Eloquent) quickly, we need to give it:</p><ul><li>A list of tables that is limited only to the tables the LLM will need to answer our prompt.</li><li>The relationships between those tables.</li></ul><p>That’s what ChatGPT 4o eventually figured out, but we can short circuit this process and make the query much more efficient.</p><p>The first thing to do is create a graph of the relationships in the database. I’m not going to show the entire class, you can look through the code in the package yourself if you’re interested. Here are the relevant parts:</p><pre>public function analyze(): void<br>    {<br>        $tables = (new DatabaseTableService())-&gt;getDatabaseTables();<br>        foreach ($tables as $table) {<br>            $this-&gt;adjacencyList[$table] = [];<br>            $this-&gt;columnList[$table] = [];<br>        }<br>        foreach ($tables as $table) {<br>            $this-&gt;addTableToGraph($table);<br>        }<br>    }<br><br> public function addTableToGraph(string $table): void<br>    {<br>        $columns = Schema::getColumnListing($table);<br><br>        foreach ($columns as $column) {<br>            if (str_ends_with($column, &#39;_id&#39;)) {<br>                $relatedTable = substr($column, 0, -3);<br><br>                if ($this-&gt;checkIfTheTableExistsDirectly($relatedTable, $table, $column)){<br>                    continue;<br>                }<br><br>                if ($this-&gt;checkForPluralVersion($relatedTable, $table, $column)){<br>                    continue;<br>                }<br><br>                $this-&gt;checkForNumberedTables($relatedTable, $table, $column);<br>            }<br>        }<br>    }</pre><p>This is relying upon the Laravel convention that primary and foreign keys are end with “_id” and have the singular of the table name in front of them. It also needs to check for the case of tables that end in a number. Having it analyze the foreign keys as well would be easy enough.</p><p>Now that we have the graph, we analyze the initial natural language query to get the entities in that query. We can do that with this prompt:</p><pre>Given this natural language query, determine the tables that are involved in the query.<br> Match terms in the query to the most relevant table names in the database,<br> including synonyms.  Your response must only include table names.  If there is<br> a synonym, use the table name and not the synonym.  If there are multiple matches between<br> synonyms and tables, chose the most specific match.  Do not include any additional matches, just pick the best one.<br> Before returning the results, check that the table name<br> exists in the list of tables in the database.  Table names that are in the form of aaa_bbb where bbb<br> is plural indicate a pivot table between aaa and bbb, so include both aaa, bbb, and the pivot table name<br> in your response.<br> Your output should be in the following json format:<br> {&quot;tables&quot;: array_of_table_names, &quot;reasoning&quot;: &quot;Your reasoning here&quot;}<br> Do not include any additional text or formatting.<br> This is the query inside quotes: &quot;$query&quot;<br> This is the list of tables in the database: $dbTablesJson</pre><p>In the case of our test query, it can tell that the entities will be group_members1, organizations, and comments1. But that won’t get us all the way there. We still need to figure out to give it the data for groups1 and posts1 so that it can do all the linkages.</p><p>For this, we just need to know the route(s) between group_members1 and comments1. We compute the minimal set of connecting tables that link our entities together and then provide the metadata for the prompt:</p><pre>You are a database, SQL, and Laravel expert. Your responses must consist only of raw,<br>valid SQL SELECT queries, with no additional formatting, tags, explanations, or code block<br>delimiters such as triple backticks. Generate these SQL queries based solely on the provided<br>database structure and relationships.<br><br>Do not provide any sql that will result in modification of the data, such as update, delete, or insert.<br><br>Table names that are in the form of aaa_bbb where bbb is plural indicate a pivot table between aaa and bbb,<br>so if you are joining with a pivot table, ensure that the output includes both aaa, bbb, and the pivot table name.<br><br>When creating a join clause, the left side of the &quot;on&quot; clause should be the key of the table being joined.  A correct<br>example: JOIN posts ON posts.user_id = users.id.  This would be wrong: JOIN posts ON users.id = posts.user_id.<br><br>Determine which entities have been explicitly asked for when generating the columns to include in a select. If joins are<br>required to perform the query, determine if they asked for the joined entities in the columns to be returned.<br>For instance, &quot;show users with posts&quot; should generate a query that only retrieves the columns in the users table since<br>posts were not asked for but were only part of the limiting conditions.<br><br>If an entity has been asked for, include all of the columns mentioned for that entity, even if they are in a condition.<br><br>This is the json structure of the database tables: $jsonStructure<br><br>This is the relationship graph of the database in json: $graphJson<br><br>Use the database structure and relationship graph to generate queries efficiently<br>and accurately. Assume the relationships in the graph are reliable and complete. Verify that any<br>columns you use in your SQL queries are actually present in the database.</pre><p>Here’s what it returns in just one step for that query:</p><pre>SELECT group_members1.* FROM group_members1 <br>  JOIN groups1 ON group_members1.group1_id = groups1.id <br>  JOIN organizations ON groups1.organization_id = organizations.id <br>  JOIN posts1 ON organizations.id = posts1.organization_id <br>  JOIN comments1 ON posts1.id = comments1.post1_id;  </pre><p>The code for doing this is pretty easy as well:</p><pre>use Gleman17\LaravelTools\Services\AIQueryService;<br><br>$aiQueryService = new AIQueryService();<br>$prompt = &#39;show all group_members1 that are in organizations that have comments1&#39;;<br>$sql = $aiQueryService-&gt;getQuery($prompt);</pre><p>Sometimes a query might not use exactly the table names that are in our database. For example, a natural language query could refer to “staff” or “employees” instead of “users.” While the LLMs will do a pretty good job of translating your query into table names, you can also add some synonyms:</p><pre>use Gleman17\LaravelTools\Services\AIQueryService;<br><br>$aiQueryService = new AIQueryService();<br>$prompt = &#39;show all members that are in organizations that have notes&#39;;<br>$synonyms = [<br>  &#39;members&#39; =&gt; &#39;group_members1&#39;,<br>  &#39;notes&#39; =&gt; &#39;comments&#39;,<br>];<br>$sql = $aiQueryService-&gt;getQuery($prompt, $synonyms);</pre><p>If you want to add to the prompt, there’s a third parameter for additional rules. Just pass a null to synonyms if you want to skip it.</p><p>There’s really no reason to spend time writing complicated SQL in your Laravel development. But be very careful in exposing this functionality in your application. If your admin role really can see anything, then I suppose it would be acceptable. On the other hand, a user could create natural language queries that would expose all kinds of data.</p><p>This article is not being monetized. If you found this repo useful, it could use some stars. I’m also available for consulting. Check me out at <a href="https://gregleman.com/">https://gregleman.com</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=859779701a35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/laravel-developers-stop-writing-sql-or-eloquent-859779701a35">Laravel Developers: Stop Writing SQL or Eloquent</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Kidding Yourself About Data Privacy]]></title>
            <link>https://medium.com/software-grognard/stop-kidding-yourself-about-data-privacy-f69adfc317aa?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/f69adfc317aa</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Tue, 10 May 2022 17:36:44 GMT</pubDate>
            <atom:updated>2022-05-10T14:13:16.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Most of this will be old hat for people that work in these areas, but for everybody else there probably isn’t the realization of exactly how much Big Tech knows about every little detail of your life. I was recently involved in a conversation where someone said “But that data is anonymized! It’s not useful for tracking actual people!” Tsk Tsk.</p><p>Back in the 1990s, I was the CEO/founder of a startup that had a real-time mapping system for public safety. That doesn’t seem like much now that we’re all carrying smartphones with a variety of GPS mapping solutions, but it was cutting edge back then. Police/Fire/EMS were installing GPS receivers on their vehicles and the E911 systems were providing caller id/location to dispatch centers. Our system was able to show the locations of all units in relationship to the calls they were answering. It was a big deal. I was in the dispatch center of a major metro area the night we first turned on the system. About an hour in a dispatcher noticed that an ambulance responding to a drive by shooting was headed the wrong direction — they heard South over the radio when they should have gone to North. It sped up the response by 20 minutes. The dispatcher turned to me and said “You just saved someone’s life.”</p><p>The big problem back then was that people were starting to carry cell phones and a lot of calls came into E911 dispatch centers without the location data they got from landlines. There was interest in using pings from cell towers to triangulate the locations of callers, but they couldn’t narrow it down to a specific area. One story that happened was a caller had a heart attack while in his car and couldn’t speak. The dispatcher had every unit in the area alternate turning on their sirens. They used the sound coming over the radio to narrow down where the caller was.</p><p>I remember thinking back then that the tower pings wouldn’t turn out to be useful for dispatch in real time because they weren’t precise enough, but if the police started collecting this data, they could match it to crime and get an idea of who was in the area at a time. One of the techniques we used whenever a new crime spree happened was to overlay a map of the crimes with the locations of newly released parolees. Believe it or not, when a lot of people get out on parole, they do not immediately become model citizens. We caught a lot of bad guys. Being able to combine that data with tower pings of the subjects would solve even more.</p><p>Remember the Scott Peterson case in 2004? I think a lot of people missed the significance of the fact that the cops found Laci’s body by comparing the cell phone tower pings of Scott’s phone with his story of where he had gone fishing. This was the first time I was aware that police were comparing historical location data from tower pings to their theory of a case. Scott is still serving a life sentence.</p><p>In the later 1990s cities started to install red light cameras and license plate readers. Police started getting real time access to this data. They could enter in a plate and get an alert when the plate was picked up and dispatch the closest unit to find that vehicle. Police also started installing automated readers in their cars. Many departments would cruise the parking lots of motels and have the system automatically check for wants and warrants. It was a simple matter of going to the front desk to find out which room to go pick up their “customer.”</p><p>And then smart phones happened.</p><p><strong>Privacy Has Left The Building</strong></p><p>Somewhere around 2006 I attended a talk at a conference by a data scientist from IBM. He laid out the following:</p><ul><li>There is a massive trove of location information that can be purchased from the telecommunications industry. It’s anonymized, but it shows the paths of where everyone travels on a day-to-day basis.</li><li>Public data such as voter registrations and property taxes can be used to build a profile of every person and where they live.</li><li>There is a massive database of cash register transactions that show the group of things people buy, with the exact time and date. This is also anonymized.</li><li>There are multiple sources of data that can be purchased that tell us where people are employed.</li></ul><p>His point was that it would soon be possible to combine all of this data and completely de-anonymize it. If we know where you work and where you live, we can figure out which anonymized id is really your phone. We can also look at the transactions that match with when you’re at the grocery store and over a long enough time period we can determine which receipts are yours. We’ll know what you buy on certain days of the week, and when you arrive at the store we could send you a coupon. Amazingly prescient.</p><p>I remember thinking “They’ll never be able to handle that much data.”</p><p>Indeed, the only thing holding us back was processing power and data storage. In 2006, 1GB of disk could be purchased for $0.32. 1GB now costs about $0.02, and that’s because prices have spiked due to the current supply issues. In 2006 the cloud was just getting started. Today I can buy <a href="https://www.vultr.com/?ref=8202711">a virtual server for $2.50/month</a> with a couple of keystrokes.</p><p>That data scientist was thinking too small. None of us would have believed back then the amount of data people would voluntarily give up just to load an app onto their smartphone.</p><p>When people tell me they’re concerned about online privacy, I usually point out that they’re carrying a tracking device in their pocket with them at all times.</p><p><strong>The Data Ecosystem</strong></p><p>Location Intelligence is now a mature market. It’s a $14B market sector. There are dozens of companies that act as brokers for all of the location data being scooped up by the various apps on smartphones and tablets all over the world. They anonymize the data and provide it with an id that allows them to track the movements of a device but not to the person. But as the IBM guy postulated back in 2006, it turned out to be pretty easy to de-anonymize the data.</p><p>Every time you click “I Agree” to the terms of service on an app for your phone, you’re agreeing to hand over your location data to yet another vendor. You didn’t think those apps were really free, did you? <a href="https://www.investopedia.com/terms/t/tanstaafl.asp">TANSTAAFL</a>. Walk into a national chain store and you’ll often start seeing ads for things you’re interested in purchasing at that store. They know who you are and where you are.</p><p>This data is now extremely accurate. Instead of the cell tower pings, this is actual GPS location data coming from the apps. Periodically I misplace my iPhone and use the “Find My iPhone” app to find it. It can show me which corner of the house I left it. GPS enabled smartphones are <a href="https://www.gps.gov/systems/gps/performance/accuracy/#:~:text=GPS%20satellites%20broadcast%20their%20signals,4.9%20m%20(16%20ft.)">typically accurate to within a 4.9m </a>(16 ft) radius.</p><p>There’s a lot of money to be made with this data. Big companies are willing to pay handsomely for it, because the analytics they get from it really does turn into sales.</p><p>It’s available for anyone who can afford the purchase price. Don’t kid yourself that the government doesn’t have all of it.</p><p><strong>But Wait, There’s More!</strong></p><p>Location Intelligence is just one sector. It’s just one facet of knowing everything about you. Sure, they know how often you visit Wendy’s on your way home from work. But they also have data on everyone you interact with. They can compute the social graph of everyone you’ve spent a certain amount of time with in the same area. If you’re using a service such as Gmail there is an AI reading every email. Every text you send/receive is analyzed and added to your social graph. They’re reading everything you post on social media.</p><p>They’re doing this because it works. Companies wouldn’t be spending money to be able to target their ads if they weren’t getting a return on their investment.</p><p>I’ve often wondered how long it will be before my health insurance provider starts sending me texts that I’m 30 minutes late and should go to the gym to work off that side of fries I ordered last night instead of the salad. Totally doable.</p><p><strong>Little Green Army Men</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*tQ0-fSBTronT_YR2hmJ7cg.jpeg" /></figure><p>I know someone who was convinced that smartphones are listening to our conversations and targeting ads based upon what they hear. Everything I’ve read on this subject debunks this claim. My own impression is that the amount of processing power it would take just to listen and turn it into actionable information fairly would be mind blowing.</p><p>I suggested an experiment. We would have a few conversations about a product that neither of us had ever expressed any interest in in any way ever. No emails, no blog posts, no texts, never visited a store that sells it, nothing. For the next few days we discussed my desire to purchase some “Little Green Army Men.” Remember the children’s toy that kids choked on in the 1970s? Yes, I was planning on making a fairly substantial purchase of little green army men.</p><p>Two days later I started seeing ads in my feed for little green army men. I cannot explain that.</p><p>There’s no such thing as privacy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f69adfc317aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/stop-kidding-yourself-about-data-privacy-f69adfc317aa">Stop Kidding Yourself About Data Privacy</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meeting Creep]]></title>
            <link>https://medium.com/software-grognard/meeting-creep-f65218eaae98?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/f65218eaae98</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[meetings]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Tue, 10 May 2022 02:12:54 GMT</pubDate>
            <atom:updated>2022-05-09T14:17:12.884Z</atom:updated>
            <content:encoded><![CDATA[<p>Constance Xu has a great article <a href="https://levelup.gitconnected.com/we-need-to-talk-about-the-software-engineer-grind-culture-801f3c3613aa">“We Need to Talk about the Software Engineer Grind Culture”</a> where she discusses the craziness of back-to-back meetings and crazy schedules:</p><blockquote>“When I started working fulltime, I realized I got into a habit of skipping lunch as well. I work pacific coast hours from Texas, and sometimes a meeting will go straight through my lunchtime and then I have back-to-back meetings, and suddenly, it is 6PM , and time for dinner.”</blockquote><p>Throw in working across several time zones globally and it gets even worse. A day that starts at 6:00AM and ends with a 9:00PM meeting is not uncommon. 6:00AM my time is 6:30PM in Bangalore. Meetings can go until they’re headed to bed around 11:00pm, you can throw in some calls with EMEA until early afternoon, then the west coast people fill your afternoon, and finally the folks in India are starting their day around 9:00PM. You can fit in some time for dinner and errands on a light day, but working remotely can quickly devolve into working around the clock if you’re not careful.</p><p>We’ve tried to have the rule that “No one should have to work past 9:00PM”, but that’s just not possible. I know people that regularly have to do calls with US/EMEA/India/Singapore. Someone is going to have to stay up late.</p><h3>How To Cope</h3><p>I’ve participated in a few practices that seem to work pretty well in dealing with this:</p><ul><li>All meetings start promptly. The meeting organizer uses a mobile phone for exact time, and the meeting stops when the minute flips over to 1 past. We play “the pizza game” where we voluntarily throw money into a virtual hat if we’re late to a meeting. Seems only fair that if you leave other people sitting you should pay for some of their next pizza party. A lot of the extra length of meetings is because the first 5 minutes can be wasted with waiting for everyone to join.</li><li>All meetings start at :15 and :45 past the hour. Meetings are scheduled for either 15 or 45 minutes. This eliminates the problem of being late to the next meeting because your previous meeting ran over. Whatever you could do in an hour can also be done in 45 minutes if you realize you’re on a shorter deadline. It also means you don’t go multiple hours without a bio break, being able to respond to an email, or just catch your breath.</li><li>Personal time is blocked in the calendar. Lunch and dinner go in as an event so that someone can’t schedule over you. I block out time in the late afternoon to hit the gym.</li><li>Meetings that are before 8:00AM locally for anyone must be scheduled or cancelled before 10:00PM their time the previous night. There’s nothing worse than setting your alarm for an early morning meeting and waking up to find out you could have slept another 2 hours. Likewise, waking up and finding out you missed a meeting that someone scheduled during the middle of their day isn’t fun either.</li></ul><h3>Don’t Have So Many Meetings</h3><p>I wish I could say the answer was “Don’t have so many meetings” but we really do our best to not have useless meetings. Most meetings could be an email, or a direct conversation between two people that results in an email to a wider group to keep everyone on the same page. When we see that happening, we evaluate whether we really need the meeting.</p><p>A lot of people complain about the daily standup. Here’s a hint: the daily standup should only be about blockers. If no one has a blocker, cancel it. Having people stand around and talk about which Jira ticket they’re working on is useless. I can read the dashboard in Jira just fine myself, thank you.</p><p>I’ve tried having a “No Meeting Wednesday” but that quickly broke down with outside groups scheduling meetings when my calendar freed up. And then I started having meetings with just my direct managers, and it all broke down.</p><p>Having a lot of meetings is just part of the collaboration and coordination that takes place with software development. A one-person team sitting in a cube slinging code by themselves is not going to accomplish very much.</p><h3>Keep Your Pace Sustainable</h3><p>Let’s not forget about the Agile principle of sustainability:</p><blockquote>Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.</blockquote><p>I wrote about sustainability in <a href="https://www.linkedin.com/pulse/keep-your-pace-sustainable-greg-leman/">“Keep Your Pace Sustainable”</a>. The key is “the grind” or what I call “coding on caffeine and adrenalin” is just not sustainable. Eventually those people burn out, and then all of the hard learned domain knowledge walks out the door. You are much worse off in the long run.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f65218eaae98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/meeting-creep-f65218eaae98">Meeting Creep</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TDD is very fast once you get into that flow. Consider the three rules:]]></title>
            <link>https://medium.com/software-grognard/tdd-is-very-fast-once-you-get-into-that-flow-consider-the-three-rules-2f2e9adbaafd?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/2f2e9adbaafd</guid>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Mon, 09 May 2022 20:33:34 GMT</pubDate>
            <atom:updated>2022-05-09T20:32:36.018Z</atom:updated>
            <content:encoded><![CDATA[<p>TDD is very fast once you get into that flow. Consider the three rules:</p><ol><li>You are not allowed to write any production code unless it is to make a failing unit test pass.</li><li>You are not allowed to write any more production code than is sufficient to pass the one failing unit test.</li><li>You are not allowed to write any more production code than is sufficient to pass the one failing unit test.</li></ol><p>If you’re spending a lot of time planning each step ahead of time you might be doing Test First Development, but not TDD. The planning that takes place in TDD is more on the design level, but the actual coding can actually be faster because you’re making more real progress.</p><p>I’d be interested to know how you determined that you had the same number of bugs when you didn’t write unit tests? Generally, when I see bugs in code with good test coverage it’s the case that the tests were not testing behaviors but rather were tightly coupled to the code. The same assumption that went into the code went into the tests, so they end up not providing any value. Or the bugs were at the integration level and the tests were again tightly coupled.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f2e9adbaafd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/tdd-is-very-fast-once-you-get-into-that-flow-consider-the-three-rules-2f2e9adbaafd">TDD is very fast once you get into that flow. Consider the three rules:</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Am Desperate For A Job]]></title>
            <link>https://medium.com/software-grognard/i-am-desperate-for-a-job-198f3a873b55?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/198f3a873b55</guid>
            <category><![CDATA[linkedin]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[job-search]]></category>
            <category><![CDATA[job-hunting]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Thu, 05 May 2022 16:55:30 GMT</pubDate>
            <atom:updated>2022-04-30T15:07:44.262Z</atom:updated>
            <content:encoded><![CDATA[<p>Most days I have a post in my LinkedIn feed along the lines of:</p><blockquote><em>I have been unemployed now for 18 months. My savings are almost exhausted, my family is suffering, and I am becoming quite depressed. I am experienced in Java and C++, please give me a job or forward this to someone who can.</em></blockquote><p>My first reaction is extreme sympathy. That must be an absolutely horrible situation. You cannot help but feel for someone in that position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*F6FhtYX1JBB-0h8nwZwmlw.jpeg" /></figure><p>My second reaction is that sadly that’s not going to work.</p><p>People hire to fit their needs, not yours.</p><p>A lot of employers reject people that have large gaps. The worst position to be in during a job search is to be unemployed. Frankly, I don’t see being unemployed as a negative — those are the people that will be most thankful for a job and highly motivated to keep it. But it’s not what you lead with.</p><p>One of the rules of interviewing is that you never speak badly of a past employer, no matter how horrible they were. A more important rule is that you never speak poorly of <strong>yourself</strong>. That begging post just makes people wonder what is so wrong that you can’t find a job in this environment.</p><p>There is no reason for someone with programming skills to be unemployed for a lengthy period of time. Create your own job. There are dozens of freelance programming sites, go get a couple of projects. It probably pays better than unemployment and you’ll be making contacts. Do good work. Perhaps you’ll find a new career as a freelancer. Contribute to open source. It will keep your skills fresh and get you exposure. Your GitHub profile is a critical part of your job search.</p><p>At the very least, it will put your mind in a positive place instead of spiraling downwards. People can smell desperation.</p><p>Here’s a much better approach:</p><h4>I’ve been a freelance programmer for the last 18 months working in projects with Java and C++. I’ve recently learned the whizbang framework and am interested in joining a strong team that works with this technology to further my career. If you know of any opportunities for a hard working and highly motivated programmer in this area, please pass this along.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=198f3a873b55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/i-am-desperate-for-a-job-198f3a873b55">I Am Desperate For A Job</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Boss Won’t Let Me Write Unit Tests]]></title>
            <link>https://medium.com/software-grognard/my-boss-wont-let-me-write-unit-tests-d2647d30470b?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/d2647d30470b</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[management]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Thu, 05 May 2022 16:55:01 GMT</pubDate>
            <atom:updated>2022-04-28T20:56:03.944Z</atom:updated>
            <content:encoded><![CDATA[<p>I gave an in person talk at a conference pre-Covid on TDD/BDD. To my surprise, the room was overflowing with attendees. After the talk several people came up to speak with me. There was a lot of excitement about learning these techniques.</p><p>A couple of developers said “We really enjoyed your talk, but our management won’t let us write unit tests. They say it takes too much time.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*qlqQYJ2dDc3S2qBIQoTOmQ.jpeg" /></figure><p>This was disturbing, as I am usually the one cracking the whip about creating more tests so that we can be confident in our code. Are there really people who call themselves managers out there that don’t want to see any tests?</p><p>I asked them if their boss looked over their shoulder while they were coding. “Learn TDD on your own time on your own side projects. Then start using it at work and show management how much faster it is.” Their answer was that their management looks at all of their code check ins and would object if they started “wasting time” on unit tests. I was a bit flippant and said “Find a new job.”</p><p>I probably could have handled that better. But I think that advice was pretty good. As a developer, especially a younger one, you can’t waste time with a bad manager.</p><p>I’ve been very fortunate in my career. I’ve only had one boss that I thought was really bad at what he did, and I got out of there pretty quickly. Nothing can make you more miserable at your job than a bad manager. My early managers were very good and saw it as their job to develop their employees. I haven’t had a technical manager in decades, so the idea of someone looking over my shoulder while I code is pretty foreign.</p><p>I worked in a company that was building unit tests in the late 1980s, so none of this has seemed new or revolutionary to me, it’s just how it’s done. Perhaps it was because we were building systems upon which people’s lives depended.</p><p>When I was first exposed to the <a href="http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd">Three Rules of TDD</a> I had a giant “Aha!” moment. I had been doing Test First and Test After, but not TDD. I was sold on the benefits of having unit tests, but had not been exposed to the concept of letting the process actually drive the code.</p><p>Adopting TDD seemed like the most natural thing in the world.</p><p>Which is why I have a very difficult time understanding managers that are trying to prevent their developers from using TDD. And it’s even more gob smacking that in this day and age there are managers that are against the concept of unit tests.</p><p>Imagine if the way people learned to code was to follow TDD. Would anyone, having started that way, be able to be convinced that they should just dispense with tests and slam things into production because it’s faster that way?</p><p>We can make all the standard argument about how TDD is actually faster than “cowboy coding.” How your code is always never more than a few ctrl-Zs from being in a working state. How the code/debug cycle is responsible for more pain and misery than almost any other aspect of our jobs. I can go on for hours (and have) talking about the benefits of TDD.</p><p>But those arguments won’t work for someone that just doesn’t get it. How can writing twice as much code be faster? And if they aren’t willing to try it out and see for themselves, what is the answer?</p><p>Perhaps I was right. The real answer is “Find a new job.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2647d30470b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/my-boss-wont-let-me-write-unit-tests-d2647d30470b">My Boss Won’t Let Me Write Unit Tests</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developers Shouldn’t Play Golf]]></title>
            <link>https://medium.com/software-grognard/developers-shouldnt-play-golf-bf97ba850748?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/bf97ba850748</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Thu, 05 May 2022 16:51:53 GMT</pubDate>
            <atom:updated>2022-05-05T16:51:38.971Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the many horrible consequences of the whiteboard coding interview process has been Code Golf.</p><p>Developers aspiring to snag a coveted FAANG job spend endless hours on sites like Leetcode. Solutions are ranked on performance, and one of the ways to cheat a little on performance is to write code which is as lean as possible.</p><p>Wikipedia defines code golf as:</p><blockquote>…a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem.</blockquote><p>Code golf has been around for as long as I can remember, but as a curiosity and recreational activity. It has the benefit of allowing a developer to stretch the limits of their understanding of a programming language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*MG2I4uLJQnBkL8F7nkFFVw.jpeg" /></figure><p>Let’s take an example of solving FizzBuzz in Python.</p><p>A simple solution is:</p><pre>def fizzbuzz3(n):<br> output = []<br> for num in range(1, n+1):<br>    string = &quot;&quot;<br>    if num % 3 == 0:<br>      string = &quot;Fizz&quot;<br>    if num % 5 == 0:<br>      string = string + &quot;Buzz&quot;<br>    if num % 5 != 0 and num % 3 != 0:<br>      string = str(num)<br>    output.append(string)<br> return output</pre><p>The performance on this won’t be great, but it is extremely easy to read and understand what is going on. If I saw this in a code review I might suggest that a better implementation would be to stay with the conditional approach, but utilize the ternary operators to clean it up:</p><pre>def fizzbuzz2(n):<br> output = []<br> for i in range(1, n+1):<br>    fizz = &#39;Fizz&#39; if i % 3 == 0 else &#39;&#39;<br>    buzz = &#39;Buzz&#39; if i % 5 == 0 else &#39;&#39;<br>    output.append((fizz + buzz) or i)<br> return output</pre><p>This is nice and succinct, and the cognitive load isn’t very high. It also has fairly decent performance. If we are really at the top of our game we might solve this with a list comprehension:</p><pre>def fizzbuzz(n):<br> return [&#39;Fizz&#39; * (not i % 3) + &#39;Buzz&#39; * (not i % 5) or i for i in range(1, n+1)]</pre><p>This one has faster performance, but it pushes the readability envelope. If this was code that was going to be the subject of millions of iterations then I’d be fine with it because the performance really matters. But if it’s only going to be run once in a blue moon I’d ask to refactor it to something more readable.</p><p>Each of these are reasonable answers. But what would a code golfer do?</p><pre>Def fizzbuzz(i):<br>   while i:=i-1:o.append(&#39;FizzBuzz&#39;[i%-3&amp;4:12&amp;8-i%5]or i)<br>   return o;</pre><p>Yikes!</p><p>And this is the problem with code golfing and the whiteboard coding interview. We’re encouraging developers to sacrifice readability over performance and showing off their capabilities with a language. Hopefully during an interview a golfed response would be criticized, but all of that time spent practicing Leetcode trying to get to the highest performing answer encourages this sort of thing.</p><p>What are the least expensive resources in software development these days? Processors and disk. Virtual servers can be rented for $2.50/month, and that includes 10GB of disk. What is the most expensive resource? Developer time. It’s going to be extremely rare where we want to trade developer time for a little less disk or processor usage.</p><p>A lot of this falls into the trap of premature optimization. As Kent Beck said, “Make it work, make it right, make it fast.” The make it fast part must also answer the question “Do we need it to be fast?” If our code is going to be a bottleneck then we might opt for speed in the optimization process, but in most cases we’re going to try to optimize readability.</p><p>Don’t golf your code. Except for exceedingly rare occasions, it won’t be worth it. Six months from now you’re going to look at that code and wonder what the heck you were thinking.</p><p><em>If you found this story interesting, please consider a clap and a follow to keep me writing them. It’d be even better if you shared it on social media.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf97ba850748" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/developers-shouldnt-play-golf-bf97ba850748">Developers Shouldn’t Play Golf</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the Difference Between a Junior and Senior Developer?]]></title>
            <link>https://medium.com/software-grognard/what-is-the-difference-between-a-junior-and-senior-developer-41464ccb12e6?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/41464ccb12e6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[management]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Wed, 04 May 2022 19:56:53 GMT</pubDate>
            <atom:updated>2022-05-04T18:44:30.318Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most frequent questions from newly minted developers is “How do I become a senior developer?” Not surprisingly, people are interested in how to advance their career. In response, there is a lot written on this topic. Entering “difference between a ju” autocompletes on Google as “difference between a junior and senior developer” for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*vzXJGa7yDHlkJ2lM7Ok9Cw.jpeg" /><figcaption>Climbing the career ladder</figcaption></figure><p>There are many differences, but one stands out above them all. Let’s review the differences that a quick review of online literature provides:</p><p>A junior knows the basic syntax of a language and can reasonably code a set of instructions. A senior knows the ins and outs of a language and their code expresses things clearly and succinctly.</p><p>A junior can code a solution that is provided to them. A senior can come up with the solution.</p><p>A junior can code a class or module in response to a set of requirements. A senior thinks about structure, dependencies, fragility, and resilience. A senior has the SOLID principles down cold.</p><p>A junior can write code. A senior can use TDD/BDD/DDD for the proper circumstances.</p><p>A junior can write code. A senior can write code that someone else can easily understand. As <a href="https://quotepark.com/quotes/1876007-kent-beck-any-fool-can-write-code-that-a-computer-can-unders/">Kent Beck</a> said, “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”</p><p>A junior can create a solution to simple problems. A senior can break down complex problems into a series of easier to solve simple problems.</p><p>A junior can write a function. A senior can utilize functional programming and OOP.</p><p>A junior can write procedural code. A senior can write event driven code. A senior can deal with promises, concurrency, and multiple threads.</p><p>A junior will write code with if-then-else and switch. A senior thinks about whether polymorphism would work better.</p><p>A junior will write a getter with a side effect. A senior knows why that is a bad idea.</p><p>A junior knows all of the textbook algorithms. A senior can apply those algorithms and knows when to use a standard library vs creating their own.</p><p>A junior understands a module or a specific set of functionalities. A senior understands the entire ecosystem.</p><p>And of course, there is the area of domain knowledge that I wrote about in <a href="https://www.linkedin.com/pulse/one-skull-rule-greg-leman/">The One Skull Rule</a>.</p><p>I’m sure there are other differences that I’ve overlooked. If you can come up with any, let me know in the comments. But there is one difference that hardly anyone talks about.</p><h3>Software Development is a Team Game</h3><p>There will be very few times in your career where you will be a team of one. If you are a junior developer, this is a situation you should actively try to avoid. It’s senior developers on your team that can be the best learning resource.</p><p>Once you add a person to that one-person team you’ve gone from 0 to 1 in interactions. It’s no longer just a conversation in your head, you now have to deal with another human being. It is hugely more complex. The formula for the number of connections in an N node network is:</p><p>N*(N-1).</p><p>We use this formula because every connection on a team is bi-directional. Think about this for different team sizes:</p><p>3 -&gt; 6</p><p>4 -&gt; 12</p><p>5 -&gt; 20</p><p>6 -&gt; 30</p><p>The difference in communication complexity in going from a 3-person to a 6-person team is 5x! And that’s a fairly small team. The numbers escalate rapidly.</p><p>It’s even worse than this, because the dynamics of 2 conversations of 2 people each are different than if we put the same 3 people into one conversation. There are things that Bill may say to Sally in a 1:1 that would not come up in a joint conversation with Jill, Bill, and Sally. Yes, the complexity can get mind boggling if you think about it enough.</p><p>Now consider that a lot of juniors just get thrown onto a 15-person team (210 connections!), and the only exposure they had to group dynamics was a couple of group projects in school.</p><p>That’s why developing soft skills is so important. Working as part of an effective team is really the second most difficult part of the job (next to understanding what users are really asking for).</p><p>My advice for developers that want to move from junior to senior:</p><p>Do good work. Get really good at each of the items discussed above. But most importantly, be a fantastic team player.</p><p><em>If you found this story interesting, please consider a clap and a follow to keep me writing them. It’d be even better if you shared it on social media.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41464ccb12e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/what-is-the-difference-between-a-junior-and-senior-developer-41464ccb12e6">What is the Difference Between a Junior and Senior Developer?</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Software Developers are Amateurs]]></title>
            <link>https://medium.com/software-grognard/most-software-developers-are-amateurs-99ab25ff54a2?source=rss----8f1b6108381---4</link>
            <guid isPermaLink="false">https://medium.com/p/99ab25ff54a2</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gregory Leman]]></dc:creator>
            <pubDate>Mon, 02 May 2022 17:48:30 GMT</pubDate>
            <atom:updated>2022-05-02T17:48:05.091Z</atom:updated>
            <content:encoded><![CDATA[<p>Ben “The Hosk” Hosking has an excellent article titled “<a href="https://thehosk.medium.com/software-development-is-a-losers-game-fc68bb30d7eb">Software development is a loser’s game</a>”</p><p>In it, he makes the claim:</p><blockquote>“I estimate 80 percent of software developers are amateurs and 20 percent professionals.”</blockquote><p>He then goes on to define amateurs as being developers that don’t like widely accepted best practices.</p><p>But there’s another way to look at this. Uncle Bob posits <a href="https://blog.cleancoder.com/uncle-bob/2014/06/20/MyLawn.html">that the number of programmers has been doubling every five years</a>. Given the number of self-taught programmers being churned out due to access to online resources, this number might be even greater. This means that at any given time, roughly half of our current pool of programmers has less than five years of experience. 75% will have less than 10.</p><p>Another factor at play is what I call the Expectations Vs Experience relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*wqAw9ZODvnGu9KZCAGsi_A.jpeg" /></figure><p>When you are first starting out, everything seems possible. You don’t know what you don’t know. Your estimates of what it takes to do something are usually wildly off. You haven’t been burned by the perils of software projects yet. You haven’t had to work with a team. They didn’t teach you about the best practices The Hosk talks about at your code camp or even your top university. You know how to code and you’ve got youthful exuberance. Those bothersome practices such as code reviews, SOLID design, and standard just seem stupid and in the way of pouring out code on caffeine and adrenalin.</p><p>As you gain experience, your expectations of what can be done fall like a rock. You’ve been burned a few times. Perfectly good projects have resources yanked away halfway through. You’ve learned about the corner case. You’ve learned that users often have no idea what they really want. Coding under unreasonable deadline pressures can cause tiny mistakes that become incredibly painful. You start to gain respect for those best practices because you’ve seen what happens when they are ignored. At the bottom of the curve is when you think everything is impossible.</p><p><strong>This is where a lot of developers burn out.</strong></p><p>If you survive and get enough experience you start to follow those best practices. Now you’re gaining confidence in what can be done. It’s rare that you run into a problem that you at least haven’t seen some variant of before. Eventually you end up at the top of your game and your expectations of what can be done are very high, but tempered with the knowledge of what it takes.</p><p>I remember listening to a post-game interview with Dean Smith after they had lost a game. He was asked why with superstar freshmen he played his seniors in the final minutes of the game. His answer was “I like seniors. They know our system.” Then again, there’s the old joke “What coach either college or the NBA was able to hold Michael Jordan to under 20 points a game? Dean Smith.”</p><p>I like experienced developers who have gotten past the burn out stage and are on the other side of the experience curve. But if our industry is going to avoid devolving into a complete mess, those seniors need to step up and help the juniors. Those best practices are important.</p><p>By far, one of the most destructive influences in our industry right now is the idea that older programmers become outdated. They’re too expensive. They have too many demands for work-life balance. A self-taught 25-year-old willing to work 80-hour weeks is the best bang for the buck. This is the same idea that you can win a championship with a team of rookies. Sure, it’s possible, but the best teams have a mixture of rookies and veterans.</p><p>There’s also the rampant idea among less experienced developers that they know everything. I also was once young and stupid. It’s up to the seniors to help out the juniors and show them the way, but it’s also up to the juniors to take the advice. Unfortunately, most people have to get hit in the head with a proverbial frying pan a few times before it takes. At least that’s the way I was.</p><p>The Hosk is right about the 80/20 rule, but it’s not that most people are just amateurs and we should design our methodologies and practices around that.</p><p>The real answer is that we need to turn our amateurs into professionals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99ab25ff54a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-grognard/most-software-developers-are-amateurs-99ab25ff54a2">Most Software Developers are Amateurs</a> was originally published in <a href="https://medium.com/software-grognard">Software Grognard</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>