<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jean-Luc Martel</title>
    <description>The latest articles on DEV Community by Jean-Luc Martel (@jlmartel).</description>
    <link>https://dev.to/jlmartel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4061410%2Fc407a2f0-c9db-4796-bcf2-43f744536ee6.jpg</url>
      <title>DEV Community: Jean-Luc Martel</title>
      <link>https://dev.to/jlmartel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jlmartel"/>
    <language>en</language>
    <item>
      <title>On Error Resume Next, PLEASE</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Wed, 18 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/on-error-resume-next-please-4j7a</link>
      <guid>https://dev.to/jlmartel/on-error-resume-next-please-4j7a</guid>
      <description>&lt;p&gt;Over the past several articles, we've explored the stranger corners of PHP, JavaScript, Python, C#, Java, and, of course, Perl.&lt;/p&gt;

&lt;p&gt;Especially Perl.&lt;/p&gt;

&lt;p&gt;We've encountered variables that lie, loops that corrupt data, compilers that enthusiastically approve terrible decisions, and programming languages that seem to regard predictability as an optional feature.&lt;/p&gt;

&lt;p&gt;But there's a problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We've barely scratched the surface of programming-language insanity.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The history of software development is littered with languages that introduced ideas so peculiar they deserve to be preserved in a museum.&lt;/p&gt;

&lt;p&gt;Some were brilliant.&lt;/p&gt;

&lt;p&gt;Some were genuinely useful.&lt;/p&gt;

&lt;p&gt;Some were products of their era.&lt;/p&gt;

&lt;p&gt;And a few appear to have been designed by people who were actively trying to make programmers suffer.&lt;/p&gt;

&lt;p&gt;So, before we retire this series, let's visit eight languages that didn't get their own articles.&lt;/p&gt;

&lt;p&gt;The also-rans.&lt;/p&gt;

&lt;p&gt;The honorable mentions.&lt;/p&gt;

&lt;p&gt;The programming-language equivalent of the drawer where you keep mysterious cables (and more-magic switches) because you're afraid to throw them away.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. VBScript: What if We Just Ignored All the Errors?
&lt;/h2&gt;

&lt;p&gt;Let's start with one of Microsoft's more memorable contributions to defensive programming.&lt;/p&gt;

&lt;p&gt;VBScript.&lt;/p&gt;

&lt;p&gt;For a generation of Windows administrators and web developers, VBScript was a familiar tool for automation, Active Server Pages, and various tasks that nobody particularly wanted to perform manually.&lt;/p&gt;

&lt;p&gt;It was lightweight, accessible, and closely related to Visual Basic.&lt;/p&gt;

&lt;p&gt;And it had a magnificent approach to error handling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;On Error Resume Next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On error. Resume next.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not "handle the error."&lt;/p&gt;

&lt;p&gt;Not "log the error."&lt;/p&gt;

&lt;p&gt;Not "recover gracefully."&lt;/p&gt;

&lt;p&gt;Just continue.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;On Error Resume Next

x = 1 / 0

WScript.Echo "Everything is fine!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Everything is fine!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We divided by zero.&lt;/p&gt;

&lt;p&gt;And the program carried on.&lt;/p&gt;

&lt;p&gt;No exception bubbling up to interrupt execution.&lt;/p&gt;

&lt;p&gt;No dramatic crash.&lt;/p&gt;

&lt;p&gt;Just an application confidently proceeding as though nothing had happened.&lt;/p&gt;

&lt;p&gt;To be fair, VBScript wasn't entirely reckless.&lt;/p&gt;

&lt;p&gt;It provided an &lt;code&gt;Err&lt;/code&gt; object that programmers could inspect after an operation to determine whether something went wrong.&lt;/p&gt;

&lt;p&gt;You were supposed to check &lt;code&gt;Err.Number&lt;/code&gt;, handle the failure, clear the error when appropriate, and continue.&lt;/p&gt;

&lt;p&gt;And you could disable the behavior with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;On Error GoTo 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the language also made it perfectly possible to put &lt;code&gt;On Error Resume Next&lt;/code&gt; near the beginning of a procedure and effectively turn error handling into a philosophical question.&lt;/p&gt;

&lt;p&gt;Did the operation succeed?&lt;/p&gt;

&lt;p&gt;Who knows?&lt;/p&gt;

&lt;p&gt;Did the program continue?&lt;/p&gt;

&lt;p&gt;Absolutely.&lt;/p&gt;

&lt;p&gt;This was especially entertaining in Windows automation, where scripts might interact with files, COM objects, network resources, and other components capable of failing in ways that were anything but obvious.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Sometimes the most dangerous error-handling strategy is one that makes the errors disappear.&lt;/p&gt;

&lt;p&gt;VBScript's motto might as well have been:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"If we don't acknowledge the problem, is it really a problem?"&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Go: Please Format This Date Using January 2, 2006
&lt;/h2&gt;

&lt;p&gt;Go has a reputation for simplicity.&lt;/p&gt;

&lt;p&gt;Minimal syntax.&lt;/p&gt;

&lt;p&gt;Straightforward tooling.&lt;/p&gt;

&lt;p&gt;A deliberate resistance to unnecessary language complexity.&lt;/p&gt;

&lt;p&gt;And a rather distinctive approach to date formatting.&lt;/p&gt;

&lt;p&gt;In most programming languages, date formats use tokens.&lt;/p&gt;

&lt;p&gt;Something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;YYYY-MM-DD HH:mm:ss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or perhaps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yyyy-MM-dd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact syntax varies, which is annoying, but the general idea is familiar.&lt;/p&gt;

&lt;p&gt;You describe which components of a date you want.&lt;/p&gt;

&lt;p&gt;Go looked at that and decided to do something different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Go, you format a date by writing an example of what a particular date would look like.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that particular date is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mon Jan 2 15:04:05 MST 2006
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not today's date.&lt;/p&gt;

&lt;p&gt;Not the Unix epoch.&lt;/p&gt;

&lt;p&gt;Not the beginning of the Gregorian calendar.&lt;/p&gt;

&lt;p&gt;January 2, 2006, at 3:04:05 PM, in a timezone seven hours behind UTC.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because the components form a memorable numerical sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Month   = 1
Day     = 2
Hour    = 3 (12-hour clock)
Minute  = 4
Second  = 5
Year    = 6 (2006)
Timezone = 7 hours west of UTC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if you want to format a date as year-month-day, you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2006-01-02"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want hours, minutes, and seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"15:04:05"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you want a complete timestamp:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2006-01-02 15:04:05"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is actually rather clever.&lt;/p&gt;

&lt;p&gt;Instead of memorizing whether uppercase &lt;code&gt;M&lt;/code&gt; means month or minute, you memorize one reference date.&lt;/p&gt;

&lt;p&gt;But it creates some wonderfully counterintuitive code.&lt;/p&gt;

&lt;p&gt;Because in Go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="s"&gt;"2006-01-02"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is a formatting specification.&lt;/p&gt;

&lt;p&gt;While:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="s"&gt;"YYYY-MM-DD"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is essentially just a literal string.&lt;/p&gt;

&lt;p&gt;Imagine discovering that after spending an hour wondering why every timestamp says &lt;code&gt;YYYY-MM-DD&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The truly delightful part is that Go's own source documentation describes the American month-before-day convention used by the reference date as a regrettable historical error.&lt;/p&gt;

&lt;p&gt;So even the people responsible for this design are willing to acknowledge that part of it is unfortunate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Go simplified date formatting by inventing an entirely different way to think about date formatting.&lt;/p&gt;

&lt;p&gt;Which, depending on your perspective, is either brilliant or a small act of aggression.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. COBOL: What if GOTO Could Change Its Mind?
&lt;/h2&gt;

&lt;p&gt;COBOL has an unfair reputation.&lt;/p&gt;

&lt;p&gt;People make fun of its verbosity, its age, and its tendency to resemble an accounting department's attempt to invent English.&lt;/p&gt;

&lt;p&gt;But COBOL was built for serious business computing.&lt;/p&gt;

&lt;p&gt;Banks.&lt;/p&gt;

&lt;p&gt;Insurance companies.&lt;/p&gt;

&lt;p&gt;Payroll systems.&lt;/p&gt;

&lt;p&gt;Financial transactions.&lt;/p&gt;

&lt;p&gt;Applications where getting the answer right was rather important.&lt;/p&gt;

&lt;p&gt;Which makes one of its historical features particularly entertaining.&lt;/p&gt;

&lt;p&gt;Meet &lt;code&gt;ALTER&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cobol"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ROUTER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;PROCEED&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SECOND-OPTION&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does this do?&lt;/p&gt;

&lt;p&gt;Well, imagine you have a paragraph containing a &lt;code&gt;GO TO&lt;/code&gt; statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cobol"&gt;&lt;code&gt;&lt;span class="n"&gt;ROUTER&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="k"&gt;GO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FIRST-OPTION&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ordinarily, executing &lt;code&gt;ROUTER&lt;/code&gt; transfers control to &lt;code&gt;FIRST-OPTION&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But after executing that &lt;code&gt;ALTER&lt;/code&gt; statement, subsequent executions of &lt;code&gt;ROUTER&lt;/code&gt; transfer control to &lt;code&gt;SECOND-OPTION&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You've changed the destination of a GOTO at runtime.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The original source code still says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cobol"&gt;&lt;code&gt;&lt;span class="k"&gt;GO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FIRST-OPTION&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the program no longer goes there.&lt;/p&gt;

&lt;p&gt;Because some other part of the program changed its mind.&lt;/p&gt;

&lt;p&gt;This is not simply changing a variable used by a conditional branch.&lt;/p&gt;

&lt;p&gt;Historically, the semantics were described in terms of altering the executable branch itself.&lt;/p&gt;

&lt;p&gt;Now imagine debugging a large business application.&lt;/p&gt;

&lt;p&gt;You find a paragraph that clearly says &lt;code&gt;GO TO FIRST-OPTION&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But the program goes somewhere else.&lt;/p&gt;

&lt;p&gt;You check the source.&lt;/p&gt;

&lt;p&gt;You check the debugger.&lt;/p&gt;

&lt;p&gt;You question your career choices.&lt;/p&gt;

&lt;p&gt;Eventually, you discover that 800 lines earlier, another paragraph executed an &lt;code&gt;ALTER&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And now the program's control flow depends on which historical path led to the current execution.&lt;/p&gt;

&lt;p&gt;This was a real COBOL feature, not a parody.&lt;/p&gt;

&lt;p&gt;It was classified as obsolete in the COBOL 1985 standard and excluded from later standards, although some implementations retain support for compatibility.&lt;/p&gt;

&lt;p&gt;The GnuCOBOL documentation even strongly discourages its use because of its disastrous effects on readability and debugging.&lt;/p&gt;

&lt;p&gt;Which is a rather polite way of saying:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Whoever thought this was a good idea should be required to maintain it."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; &lt;code&gt;GOTO&lt;/code&gt; was already controversial. COBOL found a way to make its destination negotiable.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Common Lisp: Would You Like That Number in Roman Numerals?
&lt;/h2&gt;

&lt;p&gt;Common Lisp is one of the most powerful and expressive programming languages ever designed.&lt;/p&gt;

&lt;p&gt;It has macros, dynamic typing, multiple dispatch through CLOS, sophisticated condition handling, and an extraordinary ability to extend itself.&lt;/p&gt;

&lt;p&gt;But today, we're going to ignore all that.&lt;/p&gt;

&lt;p&gt;Because Common Lisp can turn numbers into English words and Roman numerals using its ordinary string-formatting function.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="s"&gt;"~R"&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"forty-two"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's right.&lt;/p&gt;

&lt;p&gt;The formatting function just spelled out the number.&lt;/p&gt;

&lt;p&gt;Now add a colon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="s"&gt;"~:R"&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"forty-second"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An ordinal number.&lt;/p&gt;

&lt;p&gt;Now add an at-sign:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="s"&gt;"~@R"&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"XLII"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Roman numerals.&lt;/p&gt;

&lt;p&gt;And now both:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="s"&gt;"~:@R"&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"IIII"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Old-style Roman numeral notation.&lt;/p&gt;

&lt;p&gt;Let's review.&lt;/p&gt;

&lt;p&gt;Common Lisp's standard formatting system knows how to produce cardinal English numbers, ordinal English numbers, modern Roman numerals, and additive Roman numeral notation.&lt;/p&gt;

&lt;p&gt;And you select among them using combinations of punctuation characters.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because apparently formatting numbers in decimal, hexadecimal, and binary wasn't ambitious enough.&lt;/p&gt;

&lt;p&gt;To be fair, Common Lisp's &lt;code&gt;format&lt;/code&gt; facility is astonishingly sophisticated.&lt;/p&gt;

&lt;p&gt;It can perform conditional formatting, iteration, justification, and many other operations that would require substantial code in simpler formatting systems.&lt;/p&gt;

&lt;p&gt;But I particularly enjoy the fact that some language designers apparently sat down and decided that support for Roman numerals belonged in the standard output formatting facility.&lt;/p&gt;

&lt;p&gt;Not a third-party library.&lt;/p&gt;

&lt;p&gt;Not a cute example in a tutorial.&lt;/p&gt;

&lt;p&gt;The actual language standard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Common Lisp is so powerful that even its string formatter has features most languages would implement as entire libraries.&lt;/p&gt;

&lt;p&gt;And the next time someone complains that Common Lisp has too many parentheses, remind them that it can produce &lt;code&gt;XLII&lt;/code&gt; without importing anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. ObjectPAL: What if SQL Were an ASCII-Art Project?
&lt;/h2&gt;

&lt;p&gt;Let's revisit a largely forgotten corner of desktop database development.&lt;/p&gt;

&lt;p&gt;Borland Paradox.&lt;/p&gt;

&lt;p&gt;And its programming language, ObjectPAL.&lt;/p&gt;

&lt;p&gt;Paradox was a serious competitor in the desktop database world, particularly during the DOS and early Windows eras.&lt;/p&gt;

&lt;p&gt;It provided tables, forms, reports, and a powerful query system.&lt;/p&gt;

&lt;p&gt;And one of its most distinctive features was Query by Example, or QBE.&lt;/p&gt;

&lt;p&gt;Instead of writing SQL statements, users could build queries by filling out table-shaped grids.&lt;/p&gt;

&lt;p&gt;That was the visual interface.&lt;/p&gt;

&lt;p&gt;Fair enough.&lt;/p&gt;

&lt;p&gt;But here's the wonderful part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Those queries could also be represented as text files containing ASCII-style table grids.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And ObjectPAL could execute them.&lt;/p&gt;

&lt;p&gt;A simplified illustration of the format looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query

CUSTOMER.DB  | Name  | Balance |
             | Check | &amp;gt;100    |

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

&lt;/div&gt;



&lt;p&gt;This is a schematic example of the grid format, rather than a ready-to-run saved query.&lt;/p&gt;

&lt;p&gt;But the important part is real.&lt;/p&gt;

&lt;p&gt;Paradox QBE files used rows, columns, field names, selection criteria, and markers such as &lt;code&gt;Check&lt;/code&gt; to describe what should be returned.&lt;/p&gt;

&lt;p&gt;You could save a query to a &lt;code&gt;.QBE&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;And ObjectPAL could load and execute it.&lt;/p&gt;

&lt;p&gt;Which means a database query could literally resemble a tiny spreadsheet drawn with vertical bars.&lt;/p&gt;

&lt;p&gt;Now imagine trying to construct one dynamically.&lt;/p&gt;

&lt;p&gt;In ObjectPAL, you could build the query text programmatically.&lt;/p&gt;

&lt;p&gt;Including the column separators.&lt;/p&gt;

&lt;p&gt;And the line breaks.&lt;/p&gt;

&lt;p&gt;And the field names.&lt;/p&gt;

&lt;p&gt;And the selection criteria.&lt;/p&gt;

&lt;p&gt;All while maintaining the structural layout the query parser expected.&lt;/p&gt;

&lt;p&gt;So instead of writing a conventional query expression, you could find yourself concatenating strings to construct something resembling an ASCII-art table.&lt;/p&gt;

&lt;p&gt;And if the grid was malformed, Paradox could complain about inconsistent columns.&lt;/p&gt;

&lt;p&gt;I particularly love this because it captures an era when visual database tools were trying to make querying accessible to ordinary business users.&lt;/p&gt;

&lt;p&gt;And sometimes succeeded brilliantly.&lt;/p&gt;

&lt;p&gt;But when programmers needed to automate those same systems, they inherited the visual metaphor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; ObjectPAL could make a database query look less like programming and more like formatting a table in a terminal.&lt;/p&gt;

&lt;p&gt;To be fair, Query by Example was a genuinely important idea originating at IBM Research in the 1970s, and Paradox didn't invent it.&lt;/p&gt;

&lt;p&gt;But Paradox's text-based QBE representation deserves a special place in programming history.&lt;/p&gt;

&lt;p&gt;SQL asks what data you want.&lt;/p&gt;

&lt;p&gt;Paradox occasionally asked whether you could draw it.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. dBASE: Your Variable Can Become Part of the Program
&lt;/h2&gt;

&lt;p&gt;While we're visiting desktop databases, let's talk about dBASE.&lt;/p&gt;

&lt;p&gt;dBASE and its descendants, including FoxPro and Clipper, helped define an entire generation of business application development.&lt;/p&gt;

&lt;p&gt;They were database systems and programming environments rolled into one.&lt;/p&gt;

&lt;p&gt;And they provided some extraordinarily flexible mechanisms for working with data.&lt;/p&gt;

&lt;p&gt;One of my favorites is macro substitution.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STORE "CUSTOMER" TO mFile

USE &amp;amp;mFile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;amp;&lt;/code&gt; operator substitutes the contents of the variable into the command.&lt;/p&gt;

&lt;p&gt;So the second line effectively becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USE CUSTOMER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's convenient.&lt;/p&gt;

&lt;p&gt;You can select which database file to open dynamically.&lt;/p&gt;

&lt;p&gt;But it doesn't stop there.&lt;/p&gt;

&lt;p&gt;In traditional dBASE dialects, macro substitution could be used to construct field references, expressions, and even commands dynamically.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STORE '? "Hello from a variable"' TO mCommand

&amp;amp;mCommand
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The substituted command is executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your variable just became executable program text.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And in some dBASE implementations, the expanded statement could be recompiled at runtime.&lt;/p&gt;

&lt;p&gt;This is an extraordinarily powerful mechanism.&lt;/p&gt;

&lt;p&gt;It's also the kind of feature that can make static code analysis rather challenging.&lt;/p&gt;

&lt;p&gt;Because the actual command being executed might not appear anywhere in the source code in its final form.&lt;/p&gt;

&lt;p&gt;Instead, it gets assembled from strings at runtime.&lt;/p&gt;

&lt;p&gt;Sound familiar?&lt;/p&gt;

&lt;p&gt;Yes, modern languages have &lt;code&gt;eval&lt;/code&gt;, dynamic SQL, reflection, and other forms of runtime indirection.&lt;/p&gt;

&lt;p&gt;But dBASE made macro substitution a natural part of ordinary application development.&lt;/p&gt;

&lt;p&gt;The ampersand was effectively a little doorway between data and program text.&lt;/p&gt;

&lt;p&gt;And as every security engineer will tell you, blurring that boundary creates interesting opportunities.&lt;/p&gt;

&lt;p&gt;Some good.&lt;/p&gt;

&lt;p&gt;Some considerably less good.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; dBASE didn't merely allow variables to contain values. It allowed variables to participate in writing the instructions the computer would execute.&lt;/p&gt;

&lt;p&gt;Which is fine until your data decides it would rather be code.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. MUMPS: Put a Caret in Front of a Variable and It Becomes a Database
&lt;/h2&gt;

&lt;p&gt;Now we arrive at one of the terrifying languages in computing history. (Not THE most terrifying, we'll get to that next).&lt;/p&gt;

&lt;p&gt;MUMPS.&lt;/p&gt;

&lt;p&gt;Also known as M.&lt;/p&gt;

&lt;p&gt;Developed in the 1960s, MUMPS became particularly influential in healthcare information systems.&lt;/p&gt;

&lt;p&gt;And unlike some of the deliberately obscure languages we'll encounter, MUMPS has powered serious, mission-critical applications.&lt;/p&gt;

&lt;p&gt;Including systems handling patient data, hospital operations, and enormous amounts of clinical information.&lt;/p&gt;

&lt;p&gt;Which makes its approach to data storage particularly fascinating.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SET PATIENT(42,"NAME")="Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets a local variable with subscripts.&lt;/p&gt;

&lt;p&gt;Fine.&lt;/p&gt;

&lt;p&gt;Now add one character.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SET ^PATIENT(42,"NAME")="Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That caret changes everything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The variable is now a global stored in the system's persistent database.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not merely a process-local variable.&lt;/p&gt;

&lt;p&gt;A database-backed structure that can survive program termination and be accessed by other processes with access to the same database environment.&lt;/p&gt;

&lt;p&gt;Read it back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WRITE ^PATIENT(42,"NAME")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MUMPS globals are hierarchical, persistent, multidimensional structures.&lt;/p&gt;

&lt;p&gt;You can use subscripts to organize data into tree-like arrangements.&lt;/p&gt;

&lt;p&gt;And the database is deeply integrated into the language.&lt;/p&gt;

&lt;p&gt;No separate ORM.&lt;/p&gt;

&lt;p&gt;No SQL statement required.&lt;/p&gt;

&lt;p&gt;No explicit database connection for every basic operation.&lt;/p&gt;

&lt;p&gt;Just a caret.&lt;/p&gt;

&lt;p&gt;This is a different programming model from the one most modern developers know.&lt;/p&gt;

&lt;p&gt;In a typical contemporary application, the distinction between application memory and persistent storage is fundamental.&lt;/p&gt;

&lt;p&gt;You have variables.&lt;/p&gt;

&lt;p&gt;You have a database.&lt;/p&gt;

&lt;p&gt;And you write code to move information between them.&lt;/p&gt;

&lt;p&gt;MUMPS decided those concepts could live much closer together.&lt;/p&gt;

&lt;p&gt;Which is genuinely elegant.&lt;/p&gt;

&lt;p&gt;But also somewhat alarming to programmers accustomed to variables disappearing when a process exits.&lt;/p&gt;

&lt;p&gt;Consider the sentence:&lt;/p&gt;

&lt;p&gt;"I changed one variable, and now every application using that database can potentially see the change."&lt;/p&gt;

&lt;p&gt;In MUMPS, that's not necessarily a bug.&lt;/p&gt;

&lt;p&gt;That's how the architecture is intended to work.&lt;/p&gt;

&lt;p&gt;Of course, real systems provide database environments, access controls, transactions, and other mechanisms that determine what can be accessed and modified.&lt;/p&gt;

&lt;p&gt;But the core idea remains extraordinary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In MUMPS, the difference between an ordinary variable and persistent shared storage can be a single punctuation character.&lt;/p&gt;

&lt;p&gt;And you thought Perl had an unhealthy relationship with punctuation.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. INTERCAL: Your Compiler Would Appreciate Some Manners
&lt;/h2&gt;

&lt;p&gt;We've saved the best for last. Well, "best".&lt;/p&gt;

&lt;p&gt;Because until now, every language we've discussed was trying, in its own peculiar way, to solve real programming problems.&lt;/p&gt;

&lt;p&gt;INTERCAL had a different objective.&lt;/p&gt;

&lt;p&gt;Created in 1972 by Don Woods and James Lyon, INTERCAL was designed as a parody of programming languages.&lt;/p&gt;

&lt;p&gt;Its name was short for:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compiler Language With No Pronounceable Acronym.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Which is already a promising start.&lt;/p&gt;

&lt;p&gt;The language deliberately rejected conventional design choices.&lt;/p&gt;

&lt;p&gt;Its syntax was intentionally strange.&lt;/p&gt;

&lt;p&gt;Its control flow was deliberately hostile to intuition.&lt;/p&gt;

&lt;p&gt;And it included instructions such as &lt;code&gt;IGNORE&lt;/code&gt;, &lt;code&gt;FORGET&lt;/code&gt;, and &lt;code&gt;ABSTAIN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But my favorite feature is its requirement for politeness.&lt;/p&gt;

&lt;p&gt;In INTERCAL, statements can be introduced using keywords such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PLEASE DO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the fun part.&lt;/p&gt;

&lt;p&gt;In traditional INTERCAL implementations, your program needs to contain enough &lt;code&gt;PLEASE&lt;/code&gt; statements to satisfy the compiler.&lt;/p&gt;

&lt;p&gt;If fewer than roughly one-fifth of your statements use the polite form, compilation fails.&lt;/p&gt;

&lt;p&gt;With an error like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PROGRAMMER IS INSUFFICIENTLY POLITE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is wonderful.&lt;/p&gt;

&lt;p&gt;But it gets better.&lt;/p&gt;

&lt;p&gt;If you use &lt;code&gt;PLEASE&lt;/code&gt; too often, the compiler also complains.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PROGRAMMER IS OVERLY POLITE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can fail compilation by being too rude or too polite.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The accepted ratio is approximately one polite statement for every three or four statements.&lt;/p&gt;

&lt;p&gt;Not enough manners?&lt;/p&gt;

&lt;p&gt;Rejected.&lt;/p&gt;

&lt;p&gt;Too many manners?&lt;/p&gt;

&lt;p&gt;Also rejected.&lt;/p&gt;

&lt;p&gt;The compiler apparently believes you're being insincere.&lt;/p&gt;

&lt;p&gt;This is not a metaphor.&lt;/p&gt;

&lt;p&gt;This is documented INTERCAL behavior.&lt;/p&gt;

&lt;p&gt;The C-INTERCAL implementation even preserves the traditional error codes for insufficient and excessive politeness.&lt;/p&gt;

&lt;p&gt;And in keeping with the language's philosophy, its manual describes various behaviors with a level of deliberate absurdity that makes ordinary technical documentation seem positively joyless.&lt;/p&gt;

&lt;p&gt;One particularly entertaining detail is that an Emacs mode for INTERCAL was designed to help programmers maintain the proper politeness ratio by occasionally inserting &lt;code&gt;PLEASE&lt;/code&gt; automatically.&lt;/p&gt;

&lt;p&gt;Because of course it was.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; INTERCAL is the only language in this article where the absurdity is explicitly the point.&lt;/p&gt;

&lt;p&gt;The hilarious part is that, after everything we've seen in the preceding seven examples, INTERCAL doesn't seem quite as ridiculous as it probably did in 1972.&lt;/p&gt;

&lt;p&gt;Which may be the most damning observation of all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Museum of Questionable Decisions
&lt;/h2&gt;

&lt;p&gt;It's tempting to laugh at all of these.&lt;/p&gt;

&lt;p&gt;But there's something interesting hiding underneath the absurdity.&lt;/p&gt;

&lt;p&gt;Each language reflects the world in which it was created.&lt;/p&gt;

&lt;p&gt;VBScript prioritized easy automation.&lt;/p&gt;

&lt;p&gt;Go prioritized simplicity and consistency, even when that required unconventional conventions.&lt;/p&gt;

&lt;p&gt;COBOL evolved alongside early business computing and control-flow techniques that later generations largely abandoned.&lt;/p&gt;

&lt;p&gt;Common Lisp embraced expressive power and an unusually rich standard library.&lt;/p&gt;

&lt;p&gt;Paradox and dBASE made databases accessible to generations of business programmers.&lt;/p&gt;

&lt;p&gt;MUMPS integrated computation and persistent data storage in a way that still feels distinctive decades later.&lt;/p&gt;

&lt;p&gt;And INTERCAL existed to remind everyone that programming languages are human inventions, and therefore perfectly legitimate targets for satire.&lt;/p&gt;

&lt;p&gt;The history of programming languages isn't a neat sequence of progressively better ideas.&lt;/p&gt;

&lt;p&gt;It's a sprawling collection of experiments.&lt;/p&gt;

&lt;p&gt;Some succeeded.&lt;/p&gt;

&lt;p&gt;Some failed.&lt;/p&gt;

&lt;p&gt;Some were wildly influential.&lt;/p&gt;

&lt;p&gt;And some became cautionary tales.&lt;/p&gt;

&lt;p&gt;But almost all of them teach us something about the problems programmers were trying to solve, and the assumptions they made along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  One Final Observation
&lt;/h2&gt;

&lt;p&gt;After exploring all these languages, I think the most interesting distinction isn't between modern and obsolete languages.&lt;/p&gt;

&lt;p&gt;Or compiled and interpreted languages.&lt;/p&gt;

&lt;p&gt;Or strongly typed and dynamically typed languages.&lt;/p&gt;

&lt;p&gt;It's between languages whose designers believed programmers needed protection from complexity and languages whose designers believed programmers should have the freedom to create as much complexity as they wanted.&lt;/p&gt;

&lt;p&gt;And then there's INTERCAL.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Bonus point if you're familiar with the Whitespace language.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>discuss</category>
      <category>devhistory</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Perl: An Exercise in Write-Only Programming</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/perl-an-exercise-in-write-only-programming-24o3</link>
      <guid>https://dev.to/jlmartel/perl-an-exercise-in-write-only-programming-24o3</guid>
      <description>&lt;p&gt;In Part 1, we explored Perl's remarkable ability to make ordinary programming concepts behave in extraordinary ways.&lt;/p&gt;

&lt;p&gt;We encountered expressions that change meaning depending on context, variables consisting entirely of punctuation, operators with their own memories, and data structures that create themselves when you look at them.&lt;/p&gt;

&lt;p&gt;We also learned that Larry Wall endorsed an unofficial expansion of Perl's name:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pathologically Eclectic Rubbish Lister.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But we barely scratched the surface.&lt;/p&gt;

&lt;p&gt;Because Perl's greatest weirdness isn't necessarily in its syntax.&lt;/p&gt;

&lt;p&gt;It's in the extraordinary freedom it gives programmers to redefine what their programs are doing.&lt;/p&gt;

&lt;p&gt;And occasionally, what everyone else's programs are doing.&lt;/p&gt;

&lt;p&gt;So let's venture into the deeper waters.&lt;/p&gt;

&lt;p&gt;Bring a flashlight.&lt;/p&gt;

&lt;p&gt;And maybe a rocking chair.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Regular Expressions: Perl's Other Programming Language
&lt;/h2&gt;

&lt;p&gt;Let's begin with the feature that helped make Perl famous.&lt;/p&gt;

&lt;p&gt;Regular expressions.&lt;/p&gt;

&lt;p&gt;Perl didn't invent regexes, but it helped popularize a particularly powerful flavor of them.&lt;/p&gt;

&lt;p&gt;And when I say powerful, I mean it.&lt;/p&gt;

&lt;p&gt;Let's start innocently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, world!&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;s/world/Perl/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, Perl!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok.&lt;/p&gt;

&lt;p&gt;A little cryptic, perhaps, but efficient.&lt;/p&gt;

&lt;p&gt;Now add some capture groups, backreferences, lookarounds, and modifiers.&lt;/p&gt;

&lt;p&gt;Before long, you have something resembling a cryptographic key accidentally pasted into your source code.&lt;/p&gt;

&lt;p&gt;And then Perl asks:&lt;/p&gt;

&lt;p&gt;"Would you like to execute arbitrary Perl code inside that regex?"&lt;/p&gt;

&lt;h3&gt;
  
  
  Wait. Regexes Can Execute Code?
&lt;/h3&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;/c(?{ $count++ })at/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;(?{ ... })&lt;/code&gt; construct executes Perl code as part of the regex engine's matching process.&lt;/p&gt;

&lt;p&gt;Deep breaths.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your regular expression is executing program statements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's no longer merely describing a pattern.&lt;/p&gt;

&lt;p&gt;It's doing things.&lt;/p&gt;

&lt;p&gt;And Perl also provides &lt;code&gt;(??{ ... })&lt;/code&gt;, which can execute Perl code that produces another pattern to be matched dynamically.&lt;/p&gt;

&lt;p&gt;So your regular expression can generate more regular expression while it's running.&lt;/p&gt;

&lt;p&gt;At some point, you have to wonder whether we're still matching strings or conducting a programming experiment.&lt;/p&gt;

&lt;p&gt;To be fair, these features have legitimate uses, and Perl restricts potentially dangerous execution from interpolated patterns unless explicitly enabled.&lt;/p&gt;

&lt;p&gt;But they're a spectacular illustration of just how far Perl is willing to take an abstraction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Regex Replacement Is Also a Programming Environment
&lt;/h3&gt;

&lt;p&gt;Perl's substitution operator has another trick.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/e&lt;/code&gt; modifier evaluates the replacement as code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cats and dogs&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;s/(\w+)/uc($1)/g&lt;/span&gt;&lt;span class="nv"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CATS AND DOGS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;g&lt;/code&gt; means global substitution.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;e&lt;/code&gt; means evaluate the replacement as a Perl expression.&lt;/p&gt;

&lt;p&gt;So Perl finds each word, executes &lt;code&gt;uc($1)&lt;/code&gt;, and substitutes the result.&lt;/p&gt;

&lt;p&gt;Elegant.&lt;/p&gt;

&lt;p&gt;Powerful.&lt;/p&gt;

&lt;p&gt;And the kind of feature that makes security auditors develop a nervous twitch when they discover someone has been constructing replacement expressions from untrusted input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your Regex Remembers Where It Left Off
&lt;/h3&gt;

&lt;p&gt;Remember the flip-flop operator from Part 1?&lt;/p&gt;

&lt;p&gt;Perl's regex engine also has memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alpha beta gamma&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;/(\w+)/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;pos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="nv"&gt;$text&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;/(\w+)/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;pos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;/g&lt;/code&gt; modifier, when used in scalar context, maintains a match position associated with the target string.&lt;/p&gt;

&lt;p&gt;Subsequent matches can continue from that position.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;pos()&lt;/code&gt; lets you inspect or change it.&lt;/p&gt;

&lt;p&gt;So your pattern matching can have state beyond the current expression.&lt;/p&gt;

&lt;p&gt;This is genuinely useful for building parsers and scanners.&lt;/p&gt;

&lt;p&gt;It's also another reminder that Perl occasionally treats seemingly ordinary operators as tiny stateful machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  And Then There's Catastrophic Backtracking
&lt;/h3&gt;

&lt;p&gt;Consider this pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="sr"&gt;/^(a+)+$/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks harmless.&lt;/p&gt;

&lt;p&gt;It matches one or more groups of one or more &lt;code&gt;a&lt;/code&gt; characters.&lt;/p&gt;

&lt;p&gt;Now feed it a long string of &lt;code&gt;a&lt;/code&gt; characters followed by a &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The pattern can't match.&lt;/p&gt;

&lt;p&gt;But the regex engine may spend a lot of of time exploring different ways to divide the &lt;code&gt;a&lt;/code&gt; characters into groups before giving up.&lt;/p&gt;

&lt;p&gt;For vulnerable patterns and inputs, the work can grow exponentially.&lt;/p&gt;

&lt;p&gt;This is called &lt;em&gt;catastrophic backtracking&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It's not unique to Perl, but Perl's powerful backtracking engine makes it particularly relevant.&lt;/p&gt;

&lt;p&gt;And yes, similar mistakes can become denial-of-service vulnerabilities when a web application evaluates expensive patterns against attacker-controlled inputs.&lt;/p&gt;

&lt;p&gt;Perl provides tools such as atomic groups and possessive quantifiers to control backtracking.&lt;/p&gt;

&lt;p&gt;Those tools are useful.&lt;/p&gt;

&lt;p&gt;But let's appreciate the situation.&lt;/p&gt;

&lt;p&gt;We started with a language for processing text.&lt;/p&gt;

&lt;p&gt;We now have a regex engine with embedded code execution, dynamic pattern generation, persistent match state, recursive matching capabilities, and performance characteristics that can become explosive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl's regular expressions aren't merely a feature. They're a programming language that escaped into another programming language.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And somehow, this is still one of Perl's greatest strengths.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. DWIM: Perl Does What It Thinks You Meant
&lt;/h2&gt;

&lt;p&gt;One of Perl's underlying philosophies is DWIM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do What I Mean.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not necessarily what I wrote.&lt;/p&gt;

&lt;p&gt;What Perl thinks I meant.&lt;/p&gt;

&lt;p&gt;This sounds wonderful in theory.&lt;/p&gt;

&lt;p&gt;It's also a rather ambitious responsibility to assign to a programming language.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;12cats&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without numeric warnings enabled, the result is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;13
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perl interprets the leading numeric portion of &lt;code&gt;"12cats"&lt;/code&gt; as 12.&lt;/p&gt;

&lt;p&gt;Then adds 1.&lt;/p&gt;

&lt;p&gt;With warnings enabled, Perl will complain that &lt;code&gt;"12cats"&lt;/code&gt; isn't numeric, but the calculation can still produce 13.&lt;/p&gt;

&lt;p&gt;And it gets better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;different&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without warnings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;equal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because &lt;code&gt;==&lt;/code&gt; is numeric comparison.&lt;/p&gt;

&lt;p&gt;And both nonnumeric strings can be coerced to zero.&lt;/p&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 == 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;True.&lt;/p&gt;

&lt;p&gt;Now compare them using &lt;code&gt;eq&lt;/code&gt;, Perl's string equality operator, and you get the expected result.&lt;/p&gt;

&lt;p&gt;Perl actually has separate operators for numeric and string comparison.&lt;/p&gt;

&lt;p&gt;Which is sensible once you understand the system.&lt;/p&gt;

&lt;p&gt;But there's a broader philosophy here.&lt;/p&gt;

&lt;p&gt;Perl tries very hard to make operations work in whatever context you've created.&lt;/p&gt;

&lt;p&gt;Sometimes that means interpreting a string as a number.&lt;/p&gt;

&lt;p&gt;Sometimes that means automatically using &lt;code&gt;$_&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes that means treating a bareword before &lt;code&gt;=&amp;gt;&lt;/code&gt; as a string.&lt;/p&gt;

&lt;p&gt;Sometimes that means providing special behavior for operations such as splitting on whitespace.&lt;/p&gt;

&lt;p&gt;The language makes educated guesses.&lt;/p&gt;

&lt;p&gt;And sometimes those guesses are brilliant.&lt;/p&gt;

&lt;p&gt;Other times, they're the programming equivalent of autocomplete sending a resignation letter to your boss.&lt;/p&gt;

&lt;p&gt;To Perl's credit, &lt;code&gt;use strict&lt;/code&gt; and &lt;code&gt;use warnings&lt;/code&gt; catch many potentially dangerous mistakes.&lt;/p&gt;

&lt;p&gt;Modern Perl developers should generally enable both.&lt;/p&gt;

&lt;p&gt;But the underlying philosophy remains fascinating.&lt;/p&gt;

&lt;p&gt;Most programming languages want you to tell the compiler exactly what you mean.&lt;/p&gt;

&lt;p&gt;Perl often tries to meet you halfway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem is that halfway between what you wrote and what you meant isn't always somewhere you'd like to end up.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Tied Variables: Your Variable Might Secretly Be an Object
&lt;/h2&gt;

&lt;p&gt;In most programming languages, variables are reasonably honest.&lt;/p&gt;

&lt;p&gt;You read one.&lt;/p&gt;

&lt;p&gt;You get its value.&lt;/p&gt;

&lt;p&gt;You write one.&lt;/p&gt;

&lt;p&gt;Its value changes.&lt;/p&gt;

&lt;p&gt;Perl considers this unnecessarily predictable.&lt;/p&gt;

&lt;p&gt;Enter &lt;code&gt;tie&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Perl allows you to connect a scalar, array, hash, or filehandle to an object that intercepts operations performed on it.&lt;/p&gt;

&lt;p&gt;Let's create a particularly obnoxious variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nv"&gt;Loud&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;TIESCALAR&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;bless&lt;/span&gt; &lt;span class="o"&gt;\&lt;/span&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;FETCH&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SOMEONE READ ME!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;STORE&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SOMEONE CHANGED ME!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;tie&lt;/span&gt; &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Loud&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;

&lt;span class="nv"&gt;$secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SOMEONE CHANGED ME!
SOMEONE READ ME!
42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's right.&lt;/p&gt;

&lt;p&gt;An ordinary assignment invoked an object method.&lt;/p&gt;

&lt;p&gt;An ordinary variable read invoked another.&lt;/p&gt;

&lt;p&gt;The code using &lt;code&gt;$secret&lt;/code&gt; doesn't need to know anything about the machinery underneath.&lt;/p&gt;

&lt;p&gt;And the possibilities go far beyond printing messages.&lt;/p&gt;

&lt;p&gt;A tied hash can transparently store data in a database.&lt;/p&gt;

&lt;p&gt;A tied scalar can retrieve information from an external system.&lt;/p&gt;

&lt;p&gt;A tied filehandle can implement custom input and output behavior.&lt;/p&gt;

&lt;p&gt;This is extraordinarily powerful.&lt;/p&gt;

&lt;p&gt;It also means a variable access that looks completely harmless might involve disk operations, network requests, or whatever else the implementing class decides to do.&lt;/p&gt;

&lt;p&gt;Imagine asking a programmer whether reading a scalar could trigger a database query.&lt;/p&gt;

&lt;p&gt;In Perl, the correct answer is:&lt;/p&gt;

&lt;p&gt;"Depends. Who tied it up?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Perl doesn't merely let you overload operators. It can let you redefine what accessing a variable actually means.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. AUTOLOAD: The Method Doesn't Exist, but We'll Run It Anyway
&lt;/h2&gt;

&lt;p&gt;Most object-oriented languages have a fairly simple rule.&lt;/p&gt;

&lt;p&gt;If you call a method that doesn't exist, something goes wrong.&lt;/p&gt;

&lt;p&gt;Perl has an alternative proposal.&lt;/p&gt;

&lt;p&gt;What if the method doesn't exist, but we pretend it might?&lt;/p&gt;

&lt;p&gt;Enter &lt;code&gt;AUTOLOAD&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nv"&gt;Ghost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;our&lt;/span&gt; &lt;span class="nv"&gt;$AUTOLOAD&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;AUTOLOAD&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$self&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You called &lt;/span&gt;&lt;span class="si"&gt;$AUTOLOAD&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;DESTROY&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;bless&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ghost&lt;/span&gt;&lt;span class="p"&gt;';&lt;/span&gt;

&lt;span class="nv"&gt;$object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;this_method_does_not_exist&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You called Ghost::this_method_does_not_exist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No missing-method exception.&lt;/p&gt;

&lt;p&gt;No compilation failure.&lt;/p&gt;

&lt;p&gt;The method doesn't exist, but Perl found &lt;code&gt;AUTOLOAD&lt;/code&gt; and invoked it instead.&lt;/p&gt;

&lt;p&gt;The name of the missing method appears in the package's &lt;code&gt;$AUTOLOAD&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;So your class can inspect the name and decide what to do.&lt;/p&gt;

&lt;p&gt;Maybe generate a method dynamically.&lt;/p&gt;

&lt;p&gt;Maybe forward the call somewhere else.&lt;/p&gt;

&lt;p&gt;Maybe implement a flexible interface where method names correspond to data fields.&lt;/p&gt;

&lt;p&gt;Or maybe just pretend everything is fine.&lt;/p&gt;

&lt;p&gt;There are legitimate uses for dynamic dispatch like this.&lt;/p&gt;

&lt;p&gt;But imagine maintaining a codebase where searching for a method's definition returns absolutely nothing.&lt;/p&gt;

&lt;p&gt;Because the method genuinely doesn't exist.&lt;/p&gt;

&lt;p&gt;Yet the application has been calling it successfully for years.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl has turned "method not found" from an error into an optional design decision.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Typeglobs: Let's Manipulate the Symbol Table Directly
&lt;/h2&gt;

&lt;p&gt;And just when you thought &lt;code&gt;AUTOLOAD&lt;/code&gt; was sufficiently strange, Perl offers typeglobs.&lt;/p&gt;

&lt;p&gt;In Perl, the familiar prefixes &lt;code&gt;$&lt;/code&gt;, &lt;code&gt;@&lt;/code&gt;, and &lt;code&gt;%&lt;/code&gt; distinguish scalars, arrays, and hashes.&lt;/p&gt;

&lt;p&gt;But a typeglob, written with &lt;code&gt;*&lt;/code&gt;, represents a symbol-table entry containing slots for different kinds of things.&lt;/p&gt;

&lt;p&gt;For example, a name can be associated with a scalar, array, hash, subroutine, and other entities.&lt;/p&gt;

&lt;p&gt;Now consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;our&lt;/span&gt; &lt;span class="nv"&gt;$original&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;*alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;*original&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$original&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We haven't copied the value.&lt;/p&gt;

&lt;p&gt;We've aliased the symbol-table entry.&lt;/p&gt;

&lt;p&gt;And a full typeglob alias can affect more than just the scalar slot.&lt;/p&gt;

&lt;p&gt;Arrays, hashes, subroutines, and other things associated with that symbol name can be aliased too.&lt;/p&gt;

&lt;p&gt;This is part of the machinery behind Perl's traditional module import and export system.&lt;/p&gt;

&lt;p&gt;Which is clever.&lt;/p&gt;

&lt;p&gt;But it's also the kind of language feature that makes you wonder why everyone else bothered inventing encapsulation.&lt;/p&gt;

&lt;p&gt;Perl lets you inspect and manipulate some of the structures that other languages generally keep hidden behind the compiler or runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If ordinary metaprogramming is rearranging furniture, Perl's typeglobs let you move the load-bearing walls.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. CGI-BIN: When the Internet Was a Directory Full of Executables
&lt;/h2&gt;

&lt;p&gt;To understand Perl's historical influence, we need to return to the early web.&lt;/p&gt;

&lt;p&gt;Before modern application servers, REST APIs, container orchestration, and eighteen layers of middleware, a web application might simply be an executable script in a directory called &lt;code&gt;cgi-bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The Common Gateway Interface, or CGI, provided a way for web servers to execute external programs and communicate with them through environment variables, standard input, and standard output.&lt;/p&gt;

&lt;p&gt;A typical Perl CGI script might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/perl&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type: text/html&lt;/span&gt;&lt;span class="se"&gt;\r\n\r\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;h1&amp;gt;Hello, Internet!&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was a web application.&lt;/p&gt;

&lt;p&gt;Well, at least a web response.&lt;/p&gt;

&lt;p&gt;A web server could launch the script, pass information about the HTTP request through the CGI environment, and send the script's output back to the browser.&lt;/p&gt;

&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Flexible.&lt;/p&gt;

&lt;p&gt;And wonderfully direct.&lt;/p&gt;

&lt;p&gt;Perl was particularly well suited to this model because it excelled at processing strings, handling files, and generating text.&lt;/p&gt;

&lt;p&gt;Of course, there were complications.&lt;/p&gt;

&lt;p&gt;Traditional CGI generally involved starting a new process for every request.&lt;/p&gt;

&lt;p&gt;That meant interpreter startup and application initialization overhead.&lt;/p&gt;

&lt;p&gt;It could also create operational and security headaches.&lt;/p&gt;

&lt;p&gt;And parsing form data, managing cookies, handling sessions, validating input, and producing correct HTTP headers all required care.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;CGI.pm&lt;/code&gt; module helped a lot with many of these tasks.&lt;/p&gt;

&lt;p&gt;It was so important to Perl's early web-development culture that it became practically synonymous with Perl CGI programming.&lt;/p&gt;

&lt;p&gt;Interestingly, CGI.pm was removed from Perl's core distribution in Perl 5.22, although it remains available on CPAN.&lt;/p&gt;

&lt;p&gt;But here's the thing.&lt;/p&gt;

&lt;p&gt;Despite all the jokes, CGI was remarkably successful.&lt;/p&gt;

&lt;p&gt;It helped ordinary programmers build dynamic web applications without requiring a massive application framework.&lt;/p&gt;

&lt;p&gt;And Perl was one of the languages that made that revolution possible.&lt;/p&gt;

&lt;p&gt;Then developers noticed that launching a new Perl interpreter for every request wasn't particularly efficient.&lt;/p&gt;

&lt;p&gt;Naturally, someone had an idea.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What if we kept Perl running inside the web server?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Which brings us to one of my favorite chapters in web-development history.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. mod_perl: Congratulations, Your Web Server Remembers the Previous User
&lt;/h2&gt;

&lt;p&gt;Enter &lt;code&gt;mod_perl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of launching a fresh Perl interpreter for every request, mod_perl embedded Perl into Apache and allowed Perl code and interpreter state to persist across requests.&lt;/p&gt;

&lt;p&gt;The performance benefits could be substantial.&lt;/p&gt;

&lt;p&gt;No need to repeatedly start an interpreter.&lt;/p&gt;

&lt;p&gt;Previously loaded modules could remain in memory.&lt;/p&gt;

&lt;p&gt;Code could be reused.&lt;/p&gt;

&lt;p&gt;Database connections and other expensive resources could potentially be retained.&lt;/p&gt;

&lt;p&gt;For the time, this was a very attractive proposition.&lt;/p&gt;

&lt;p&gt;But it introduced a spectacularly dangerous distinction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A traditional CGI request generally started with a fresh Perl process. A mod_perl request might inherit application state left behind by an earlier request.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And so the fun begins.&lt;/p&gt;

&lt;p&gt;Imagine a badly written authentication routine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;our&lt;/span&gt; &lt;span class="nv"&gt;$authenticated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;authenticate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;@_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;valid_credentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$authenticated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice anything missing?&lt;/p&gt;

&lt;p&gt;The variable is set to true when authentication succeeds.&lt;/p&gt;

&lt;p&gt;But it isn't reset when authentication fails.&lt;/p&gt;

&lt;p&gt;Under a fresh-process CGI model, the process ends after the request, so this particular stale-state problem normally disappears with it.&lt;/p&gt;

&lt;p&gt;Under a persistent interpreter, the variable may remain true.&lt;/p&gt;

&lt;p&gt;User Alice logs in successfully.&lt;/p&gt;

&lt;p&gt;The worker retains &lt;code&gt;$authenticated = 1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Later, Bob makes a request handled by that same worker.&lt;/p&gt;

&lt;p&gt;Bob supplies an incorrect password.&lt;/p&gt;

&lt;p&gt;The function doesn't set &lt;code&gt;$authenticated&lt;/code&gt; back to false.&lt;/p&gt;

&lt;p&gt;And if the application relies on that variable afterward, Bob may be treated as authenticated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations. Your authentication state has become a community resource.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And this isn't merely a hypothetical horror story.&lt;/p&gt;

&lt;p&gt;The historical &lt;em&gt;mod_perl Guide&lt;/em&gt; explicitly documents this class of mistake, including scenarios where one user could gain access to another user's account because a global variable remained set in a reused server process.&lt;/p&gt;

&lt;p&gt;Now, an important technical distinction.&lt;/p&gt;

&lt;p&gt;This doesn't mean mod_perl automatically shares session variables between random threads.&lt;/p&gt;

&lt;p&gt;In threaded mod_perl configurations, Perl interpreters have their own state, and sharing between threads requires additional mechanisms.&lt;/p&gt;

&lt;p&gt;The problem is that requests handled by the same persistent interpreter can encounter state left behind by previous requests.&lt;/p&gt;

&lt;p&gt;With multiple server workers or interpreters, the behavior can appear random because different requests land on different workers.&lt;/p&gt;

&lt;p&gt;And Perl package namespaces don't automatically isolate state by HTTP user or session.&lt;/p&gt;

&lt;p&gt;A package global belongs to its Perl interpreter, not to whichever visitor happens to be using the website.&lt;/p&gt;

&lt;p&gt;That's what made these bugs so nasty.&lt;/p&gt;

&lt;p&gt;They might disappear when you restarted Apache.&lt;/p&gt;

&lt;p&gt;They might work perfectly on a development server.&lt;/p&gt;

&lt;p&gt;They might occur only when a particular worker had previously served an administrator.&lt;/p&gt;

&lt;p&gt;And testing the same page repeatedly could produce inconsistent results.&lt;/p&gt;

&lt;p&gt;There's another especially charming mod_perl trap involving regular expressions.&lt;/p&gt;

&lt;p&gt;Remember Perl's &lt;code&gt;/o&lt;/code&gt; modifier, which tells the interpreter to compile an interpolated pattern only once at that regex location?&lt;/p&gt;

&lt;p&gt;Under persistent execution, the first request's pattern could remain compiled and be used for later requests, even when those requests supplied different search terms.&lt;/p&gt;

&lt;p&gt;So you could write code that accepted a search keyword from the user, then accidentally keep searching for the first keyword supplied to that worker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not only did your server remember the previous user. Your regex remembered what they were searching for.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The fixes were straightforward in principle:&lt;/p&gt;

&lt;p&gt;Keep request-specific state in request-local variables or objects.&lt;/p&gt;

&lt;p&gt;Initialize authentication decisions independently for every request.&lt;/p&gt;

&lt;p&gt;Avoid using package globals as if they were session storage.&lt;/p&gt;

&lt;p&gt;And don't assume a persistent process behaves like a fresh CGI invocation.&lt;/p&gt;

&lt;p&gt;But the underlying lesson is broader.&lt;/p&gt;

&lt;p&gt;Moving from a process-per-request model to a persistent execution environment changes the meaning of application state.&lt;/p&gt;

&lt;p&gt;Perl developers learned that lesson spectacularly.&lt;/p&gt;

&lt;p&gt;And modern developers building applications with persistent workers, reused containers, asynchronous services, or shared caches should recognize the problem immediately.&lt;/p&gt;

&lt;p&gt;Different decade.&lt;/p&gt;

&lt;p&gt;Same class of bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Source Filters: Why Stop at Changing the Meaning of Variables?
&lt;/h2&gt;

&lt;p&gt;By now we've seen Perl intercept variable access, invent missing methods, manipulate symbol tables, and execute code inside regexes.&lt;/p&gt;

&lt;p&gt;Surely there's a limit.&lt;/p&gt;

&lt;p&gt;Well.&lt;/p&gt;

&lt;p&gt;Perl also has source filters.&lt;/p&gt;

&lt;p&gt;A source filter can transform the source text as Perl reads it.&lt;/p&gt;

&lt;p&gt;Which means the code the interpreter ultimately compiles might not be the same text you originally wrote.&lt;/p&gt;

&lt;p&gt;The legitimate uses include specialized preprocessing and transformations.&lt;/p&gt;

&lt;p&gt;But the feature also opens the door to some breathtakingly strange experiments.&lt;/p&gt;

&lt;p&gt;You can alter source text before compilation.&lt;/p&gt;

&lt;p&gt;You can introduce syntax-like behavior using preprocessing.&lt;/p&gt;

&lt;p&gt;You can construct programs whose actual instructions are difficult to recognize from their source.&lt;/p&gt;

&lt;p&gt;And naturally, there's a catch.&lt;/p&gt;

&lt;p&gt;Traditional source filters operate on text, not on a fully parsed representation of the Perl program.&lt;/p&gt;

&lt;p&gt;This makes them notoriously fragile around quoting, comments, regular expressions, and other syntax.&lt;/p&gt;

&lt;p&gt;Even Perl's own documentation warns about these limitations.&lt;/p&gt;

&lt;p&gt;Which is particularly entertaining given that Perl itself already has an unusually complicated relationship with parsing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We have a language famous for difficult-to-parse syntax, and someone decided the solution was to let modules rewrite the source before parsing it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's commitment.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Smartmatch: The Feature That Was Condemned, Then Pardoned
&lt;/h2&gt;

&lt;p&gt;Let's talk about &lt;code&gt;~~&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The smartmatch operator.&lt;/p&gt;

&lt;p&gt;Introduced in Perl 5.10, smartmatch tried to provide a convenient way to compare values according to their types and structures.&lt;/p&gt;

&lt;p&gt;Depending on the operands, it could perform different kinds of matching.&lt;/p&gt;

&lt;p&gt;Sometimes string comparisons.&lt;/p&gt;

&lt;p&gt;Sometimes numeric comparisons.&lt;/p&gt;

&lt;p&gt;Sometimes array membership checks.&lt;/p&gt;

&lt;p&gt;Sometimes other matching behavior.&lt;/p&gt;

&lt;p&gt;Sounds useful.&lt;/p&gt;

&lt;p&gt;Except the rules became sufficiently complicated and surprising that smartmatch acquired a reputation for being difficult to reason about.&lt;/p&gt;

&lt;p&gt;Its semantics changed during its early releases.&lt;/p&gt;

&lt;p&gt;It was subsequently classified as experimental.&lt;/p&gt;

&lt;p&gt;Then deprecated in Perl 5.38.&lt;/p&gt;

&lt;p&gt;And scheduled for removal in Perl 5.42.&lt;/p&gt;

&lt;p&gt;Which would have been a perfectly ordinary ending for an unsuccessful language feature.&lt;/p&gt;

&lt;p&gt;Except Perl 5.42 changed course.&lt;/p&gt;

&lt;p&gt;After further discussion, removal was postponed indefinitely.&lt;/p&gt;

&lt;p&gt;Smartmatch was retained, with explicit feature controls for modern feature bundles.&lt;/p&gt;

&lt;p&gt;So the operator went through an extraordinary lifecycle:&lt;/p&gt;

&lt;p&gt;Introduced.&lt;/p&gt;

&lt;p&gt;Changed.&lt;/p&gt;

&lt;p&gt;Declared experimental.&lt;/p&gt;

&lt;p&gt;Deprecated.&lt;/p&gt;

&lt;p&gt;Scheduled for execution.&lt;/p&gt;

&lt;p&gt;Reprieved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl managed to give a comparison operator its own redemption arc.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's something wonderfully appropriate about that.&lt;/p&gt;

&lt;p&gt;A language built around doing things in multiple ways developed an operator that tried to choose the right comparison automatically.&lt;/p&gt;

&lt;p&gt;Then the language's developers spent years debating what the right comparison actually was.&lt;/p&gt;

&lt;p&gt;And eventually decided the operator should stay, albeit with restrictions.&lt;/p&gt;

&lt;p&gt;That's not just programming-language history.&lt;/p&gt;

&lt;p&gt;That's philosophy.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. CPAN: The Internet's Original "There's a Module for That"
&lt;/h2&gt;

&lt;p&gt;We can't finish an article about Perl without discussing CPAN.&lt;/p&gt;

&lt;p&gt;The Comprehensive Perl Archive Network.&lt;/p&gt;

&lt;p&gt;Established in 1995, CPAN became one of the earliest and most influential large-scale package ecosystems for a programming language.&lt;/p&gt;

&lt;p&gt;Long before npm became the default answer to every JavaScript left-padding problem, Perl developers had a vast archive of modules that could be downloaded, installed, tested, and reused.&lt;/p&gt;

&lt;p&gt;And CPAN was genuinely transformative.&lt;/p&gt;

&lt;p&gt;Database connectivity?&lt;/p&gt;

&lt;p&gt;DBI.&lt;/p&gt;

&lt;p&gt;HTTP clients?&lt;/p&gt;

&lt;p&gt;LWP.&lt;/p&gt;

&lt;p&gt;Date and time handling?&lt;/p&gt;

&lt;p&gt;DateTime.&lt;/p&gt;

&lt;p&gt;Object systems?&lt;/p&gt;

&lt;p&gt;Moose.&lt;/p&gt;

&lt;p&gt;Web frameworks?&lt;/p&gt;

&lt;p&gt;Catalyst, Mojolicious, Dancer, and others.&lt;/p&gt;

&lt;p&gt;There were modules for practically every serious programming task.&lt;/p&gt;

&lt;p&gt;And, naturally, for a remarkable number of unserious ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Acme Namespace: Where Perl Developers Go to Express Themselves
&lt;/h3&gt;

&lt;p&gt;CPAN has a long tradition of humorous and experimental modules, many living under the &lt;code&gt;Acme::&lt;/code&gt; namespace.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Acme::Bleach&lt;/strong&gt; provides a way to make Perl source code appear almost entirely as whitespace.&lt;/p&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;A module for making your source code less visible.&lt;/p&gt;

&lt;p&gt;Because apparently Perl wasn't already challenging enough to read.&lt;/p&gt;

&lt;p&gt;Then there's &lt;strong&gt;Acme::EyeDrops&lt;/strong&gt;, which can transform Perl programs into visual ASCII-art arrangements.&lt;/p&gt;

&lt;p&gt;Executable code shaped like pictures.&lt;/p&gt;

&lt;p&gt;A programming technique that makes code review feel like interpreting ancient cave paintings.&lt;/p&gt;

&lt;p&gt;These aren't representative of ordinary production Perl development.&lt;/p&gt;

&lt;p&gt;But they capture something wonderful about CPAN culture.&lt;/p&gt;

&lt;p&gt;It's not merely a software repository.&lt;/p&gt;

&lt;p&gt;It's also a laboratory for ideas, experiments, jokes, and things somebody implemented because they wondered whether it was possible.&lt;/p&gt;

&lt;p&gt;And sometimes those experiments become genuinely useful technologies.&lt;/p&gt;

&lt;h3&gt;
  
  
  CPAN Was Also Serious Engineering
&lt;/h3&gt;

&lt;p&gt;Behind the jokes was an impressive technical ecosystem.&lt;/p&gt;

&lt;p&gt;Module distributions had standardized packaging conventions.&lt;/p&gt;

&lt;p&gt;Dependency information could be declared.&lt;/p&gt;

&lt;p&gt;Automated test suites became an important part of the culture.&lt;/p&gt;

&lt;p&gt;CPAN Testers gathered reports from many platforms and environments.&lt;/p&gt;

&lt;p&gt;Tools such as &lt;code&gt;cpan&lt;/code&gt;, &lt;code&gt;cpanm&lt;/code&gt;, and &lt;code&gt;local::lib&lt;/code&gt; made installing and managing modules more practical.&lt;/p&gt;

&lt;p&gt;MetaCPAN made the archive searchable and its documentation accessible.&lt;/p&gt;

&lt;p&gt;These ideas helped establish expectations that modern package ecosystems now take for granted.&lt;/p&gt;

&lt;p&gt;Of course, installing dependencies wasn't always painless.&lt;/p&gt;

&lt;p&gt;Some modules depended on native libraries.&lt;/p&gt;

&lt;p&gt;Some needed compilers.&lt;/p&gt;

&lt;p&gt;Some behaved differently across operating systems.&lt;/p&gt;

&lt;p&gt;And sometimes you discovered that installing one module meant compiling half the known universe.&lt;/p&gt;

&lt;p&gt;But unlike the regex sorcery and magical symbol tables, CPAN's legacy is overwhelmingly positive.&lt;/p&gt;

&lt;p&gt;It helped make Perl extraordinarily productive.&lt;/p&gt;

&lt;p&gt;And its model influenced how later language communities organized and distributed reusable software.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl didn't merely help invent dependency hell. It helped invent the infrastructure that made dependency management worth having.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Perl Was Weird Because It Was Trying to Be Useful
&lt;/h2&gt;

&lt;p&gt;After two articles, we've covered quite a collection.&lt;/p&gt;

&lt;p&gt;A language where expressions change behavior depending on context.&lt;/p&gt;

&lt;p&gt;Where zero can be true.&lt;/p&gt;

&lt;p&gt;Where a lookup can create data.&lt;/p&gt;

&lt;p&gt;Where regular expressions execute code.&lt;/p&gt;

&lt;p&gt;Where ordinary variables can secretly delegate to objects.&lt;/p&gt;

&lt;p&gt;Where nonexistent methods can run anyway.&lt;/p&gt;

&lt;p&gt;Where symbol tables are yours to manipulate.&lt;/p&gt;

&lt;p&gt;Where source code can be transformed before compilation.&lt;/p&gt;

&lt;p&gt;And where persistent web-server state once caused some truly memorable production disasters.&lt;/p&gt;

&lt;p&gt;It's tempting to dismiss all of this as terrible language design.&lt;/p&gt;

&lt;p&gt;But that would miss something important.&lt;/p&gt;

&lt;p&gt;Perl wasn't designed in a vacuum.&lt;/p&gt;

&lt;p&gt;It emerged from a world of Unix tools, shell scripts, text files, system administration, reporting, and ad hoc data manipulation.&lt;/p&gt;

&lt;p&gt;The goal wasn't to produce the purest type system or the smallest language specification.&lt;/p&gt;

&lt;p&gt;It was to help programmers get useful work done.&lt;/p&gt;

&lt;p&gt;Quickly.&lt;/p&gt;

&lt;p&gt;Flexibly.&lt;/p&gt;

&lt;p&gt;Often with very little code.&lt;/p&gt;

&lt;p&gt;And when the early web arrived, Perl was extraordinarily well positioned to take advantage of it.&lt;/p&gt;

&lt;p&gt;It could process text.&lt;/p&gt;

&lt;p&gt;Manipulate files.&lt;/p&gt;

&lt;p&gt;Talk to databases.&lt;/p&gt;

&lt;p&gt;Generate HTML.&lt;/p&gt;

&lt;p&gt;Automate systems.&lt;/p&gt;

&lt;p&gt;And do it all in an environment where developers often had limited resources and needed results immediately.&lt;/p&gt;

&lt;p&gt;Perl's philosophy of DWIM and TMTOWTDI came from that pragmatic background.&lt;/p&gt;

&lt;p&gt;Sometimes the result was beautiful.&lt;/p&gt;

&lt;p&gt;Sometimes it was incomprehensible.&lt;/p&gt;

&lt;p&gt;Sometimes it was both.&lt;/p&gt;

&lt;p&gt;And to be fair, Perl has continued to evolve. Modern Perl development isn't limited to CGI scripts and punctuation-heavy one-liners. Its contemporary ecosystem includes modern object systems, web frameworks, testing tools, and actively maintained language features.&lt;/p&gt;

&lt;p&gt;But Perl never entirely abandoned the personality that made it famous.&lt;/p&gt;

&lt;h3&gt;
  
  
  The GOAT of Programming Weirdness?
&lt;/h3&gt;

&lt;p&gt;We've now explored the stranger corners of PHP, JavaScript, Python, C#, Java, and Perl.&lt;/p&gt;

&lt;p&gt;Every language has surprises.&lt;/p&gt;

&lt;p&gt;Every language has historical baggage.&lt;/p&gt;

&lt;p&gt;Every language has design decisions that make perfect sense until you encounter them in production.&lt;/p&gt;

&lt;p&gt;But Perl occupies a special place.&lt;/p&gt;

&lt;p&gt;Other languages occasionally surprise you with something unexpected.&lt;/p&gt;

&lt;p&gt;Perl seems to have anticipated that you might want the unexpected behavior, documented it, and provided three alternative syntaxes for invoking it.&lt;/p&gt;

&lt;p&gt;And that, I think, is what makes it the GOAT.&lt;/p&gt;

&lt;p&gt;Not because it's the best language for every task.&lt;/p&gt;

&lt;p&gt;Not because all its design decisions were good.&lt;/p&gt;

&lt;p&gt;But because very few languages have ever been so unapologetically themselves.&lt;/p&gt;

&lt;p&gt;Larry Wall gave us a language that tried to understand what programmers meant.&lt;/p&gt;

&lt;p&gt;Sometimes it succeeded brilliantly.&lt;/p&gt;

&lt;p&gt;Sometimes it understood something entirely different.&lt;/p&gt;

&lt;p&gt;And sometimes it let the previous user's session hang around long enough to make things really interesting.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Final Thought: Everyone Has a Perl Phase
&lt;/h2&gt;

&lt;p&gt;I've come to believe that every programmer exists in one of two states:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You are either before your Perl phase or after it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before Perl, you believe programming languages should be logical, predictable, and preferably readable by other human beings.&lt;/p&gt;

&lt;p&gt;After Perl, you understand that a programming language can be a tool, a philosophy, a practical joke, and a cry for help, sometimes in the same line of code.&lt;/p&gt;

&lt;p&gt;You emerge with a deeper appreciation for regular expressions, a healthy suspicion of punctuation, and the unsettling realization that most programming languages are far more restrictive than they strictly need to be.&lt;/p&gt;

&lt;p&gt;You may never write another line of Perl.&lt;/p&gt;

&lt;p&gt;You may spend the rest of your career pretending that you don't know what a typeglob is.&lt;/p&gt;

&lt;p&gt;But something has changed.&lt;/p&gt;

&lt;p&gt;You've seen what happens when a programming language stops asking &lt;em&gt;"Should we allow this?"&lt;/em&gt; and starts asking &lt;em&gt;"Why the hell not?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And there's no going back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You don't really finish learning Perl. You survive it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And afterward, every other programming language feels just a little bit... supervised.&lt;/p&gt;

</description>
      <category>perl</category>
      <category>regex</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Let's Talk About the Pathologically Eclectic Rubbish Lister</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Wed, 11 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/lets-talk-about-the-pathologically-eclectic-rubbish-lister-1lfn</link>
      <guid>https://dev.to/jlmartel/lets-talk-about-the-pathologically-eclectic-rubbish-lister-1lfn</guid>
      <description>&lt;p&gt;We've explored PHP's questionable life choices, JavaScript's relationship with alternate realities, Python's talent for silently corrupting your data, C# quirks and the .Net identity crisis, and Java's industrial-scale production of factories.&lt;/p&gt;

&lt;p&gt;But now we've arrived at the main event. &lt;/p&gt;

&lt;p&gt;The granddaddy of weird programming languages.&lt;/p&gt;

&lt;p&gt;The Swiss Army chainsaw.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Created by Larry Wall in 1987, Perl became one of the defining languages of Unix scripting, system administration, text processing, and the early web.&lt;/p&gt;

&lt;p&gt;And it came with a philosophy that was almost aggressively different from the languages that followed.&lt;/p&gt;

&lt;p&gt;Python would eventually tell us there should preferably be one obvious way to do something.&lt;/p&gt;

&lt;p&gt;Perl had already declared:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"There's More Than One Way To Do It."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Known affectionately as TMTOWTDI, pronounced "Tim Toady."&lt;/p&gt;

&lt;p&gt;But here's my favorite bit of Perl history.&lt;/p&gt;

&lt;p&gt;The name is commonly expanded as &lt;em&gt;Practical Extraction and Report Language&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But Larry Wall also endorsed another expansion:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pathologically Eclectic Rubbish Lister.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's not something invented by Perl's critics.&lt;/p&gt;

&lt;p&gt;That's the language's own creator getting in on the joke.&lt;/p&gt;

&lt;p&gt;And the more Perl you learn, the more you appreciate just how accurate that description can be.&lt;/p&gt;

&lt;p&gt;There is so much wonderful weirdness in Perl that we're going to need two articles.&lt;/p&gt;

&lt;p&gt;Let's begin with six of its greatest hits.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Your Code Doesn't Decide What It Returns. The Caller Does.
&lt;/h2&gt;

&lt;p&gt;Most programming languages have a fairly straightforward understanding of expressions.&lt;/p&gt;

&lt;p&gt;You evaluate something.&lt;/p&gt;

&lt;p&gt;It produces a result.&lt;/p&gt;

&lt;p&gt;The surrounding code does something with that result.&lt;/p&gt;

&lt;p&gt;Perl considers this approach unnecessarily restrictive.&lt;/p&gt;

&lt;p&gt;Instead, Perl has the concept of &lt;em&gt;context&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Expressions can behave differently depending on whether they're evaluated in scalar context, list context, or void context.&lt;/p&gt;

&lt;p&gt;And we're not merely talking about automatic type conversion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The same expression can perform a fundamentally different operation depending on what the caller expects.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@animals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;

&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@animals&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;@result&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dog cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yawn.&lt;/p&gt;

&lt;p&gt;Now change the assignment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@animals&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$result&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;godtac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interesting.&lt;/p&gt;

&lt;p&gt;We didn't change the function.&lt;/p&gt;

&lt;p&gt;We didn't change the arguments.&lt;/p&gt;

&lt;p&gt;We changed the type of variable &lt;em&gt;receiving&lt;/em&gt; the result.&lt;/p&gt;

&lt;p&gt;And Perl completely changed what &lt;code&gt;reverse()&lt;/code&gt; does.&lt;/p&gt;

&lt;p&gt;In list context, &lt;code&gt;reverse()&lt;/code&gt; reverses the order of the elements.&lt;/p&gt;

&lt;p&gt;In scalar context, it concatenates the elements and reverses the resulting string.&lt;/p&gt;

&lt;p&gt;The first example reverses the list.&lt;/p&gt;

&lt;p&gt;The second reverses the characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The caller effectively gets to decide which version of reality it wants.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's another example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;

&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;@colors&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$count&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When an array is evaluated in scalar context, you get the number of elements.&lt;/p&gt;

&lt;p&gt;In list context, you get the elements themselves.&lt;/p&gt;

&lt;p&gt;This is all deliberate.&lt;/p&gt;

&lt;p&gt;In fact, Perl even provides &lt;code&gt;wantarray&lt;/code&gt;, allowing subroutines to detect whether they're being called in list, scalar, or void context.&lt;/p&gt;

&lt;p&gt;Meaning a function can explicitly choose what to do based on how its return value will be used.&lt;/p&gt;

&lt;p&gt;To be fair, this can be genuinely powerful.&lt;/p&gt;

&lt;p&gt;It's also an excellent way to make a function behave differently after someone innocently refactors the calling code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Perl, context isn't merely where an expression appears. It's part of what the expression means.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Zero Is False. Except When Zero Is True.
&lt;/h2&gt;

&lt;p&gt;We've encountered strange truthiness rules before.&lt;/p&gt;

&lt;p&gt;PHP, for example, considers the string &lt;code&gt;"0"&lt;/code&gt; to be false.&lt;/p&gt;

&lt;p&gt;Perl does too. (And no, PHP didn't start as a Perl script, but that's for a different post).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TRUE&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, nothing we haven't seen before.&lt;/p&gt;

&lt;p&gt;But Perl has a particularly entertaining trick.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0E0&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TRUE&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay.&lt;/p&gt;

&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0E0&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's review.&lt;/p&gt;

&lt;p&gt;The value is numerically zero.&lt;/p&gt;

&lt;p&gt;But it's logically true.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perl has successfully invented zero that isn't false.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The explanation is that &lt;code&gt;"0E0"&lt;/code&gt; is a nonempty string that isn't exactly &lt;code&gt;"0"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So it's truthy.&lt;/p&gt;

&lt;p&gt;But interpreted numerically, it's scientific notation for zero multiplied by ten to the power of zero.&lt;/p&gt;

&lt;p&gt;Which is zero.&lt;/p&gt;

&lt;p&gt;This isn't just an amusing edge case.&lt;/p&gt;

&lt;p&gt;The idiom is used deliberately in Perl's database ecosystem.&lt;/p&gt;

&lt;p&gt;For example, DBI can return the string &lt;code&gt;"0E0"&lt;/code&gt; from certain successful operations that affect zero rows.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because sometimes you need to distinguish between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An operation that failed.&lt;/li&gt;
&lt;li&gt;An operation that succeeded but affected zero records.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You want the result to be numerically zero while remaining true in a boolean test.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;"0E0"&lt;/code&gt; does exactly that.&lt;/p&gt;

&lt;p&gt;Perl has turned an apparent inconsistency into a feature.&lt;/p&gt;

&lt;p&gt;That's a very Perl thing to do.&lt;/p&gt;

&lt;p&gt;There's even a traditional expression for this kind of value:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Zero but true."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Which sounds less like a programming concept and more like a philosophical position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Perl's scalar values can behave differently in numeric, string, and boolean contexts, sometimes quite deliberately.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Checking Whether Something Exists Can Create It
&lt;/h2&gt;

&lt;p&gt;Let's talk about nested data structures.&lt;/p&gt;

&lt;p&gt;Suppose you have a hash containing configuration information.&lt;/p&gt;

&lt;p&gt;You want to find out whether a deeply nested key exists.&lt;/p&gt;

&lt;p&gt;Reasonable enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nv"&gt;strict&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nv"&gt;warnings&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;exists&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}{&lt;/span&gt;&lt;span class="nv"&gt;preferences&lt;/span&gt;&lt;span class="p"&gt;}{&lt;/span&gt;&lt;span class="nv"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Theme exists&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing prints.&lt;/p&gt;

&lt;p&gt;Of course not.&lt;/p&gt;

&lt;p&gt;The hash is empty.&lt;/p&gt;

&lt;p&gt;The key doesn't exist.&lt;/p&gt;

&lt;p&gt;End of story.&lt;/p&gt;

&lt;p&gt;Except...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Data::&lt;/span&gt;&lt;span class="nv"&gt;Dumper&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;Dumper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;&lt;span class="nv"&gt;%config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$VAR1 = {
          'user' =&amp;gt; {
                      'preferences' =&amp;gt; {}
                    }
        };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excuse me?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We checked whether something existed, and Perl created a bunch of things that didn't exist.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final &lt;code&gt;theme&lt;/code&gt; key still doesn't exist.&lt;/p&gt;

&lt;p&gt;But the intermediate structures do.&lt;/p&gt;

&lt;p&gt;This behavior is called &lt;em&gt;autovivification&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And it's one of Perl's most adorable features.&lt;/p&gt;

&lt;p&gt;When you access nested elements through references, Perl can automatically create intermediate structures when the operation requires them.&lt;/p&gt;

&lt;p&gt;This makes constructing complex data structures extraordinarily convenient.&lt;/p&gt;

&lt;p&gt;You can write deeply nested assignments without manually initializing every level.&lt;/p&gt;

&lt;p&gt;But it creates an interesting consequence.&lt;/p&gt;

&lt;p&gt;A lookup that appears harmless can have side effects.&lt;/p&gt;

&lt;p&gt;In this example, the existence check caused Perl to create the intermediate hashes required to reach the final key.&lt;/p&gt;

&lt;p&gt;So the act of asking whether something exists can change the structure you're examining.&lt;/p&gt;

&lt;p&gt;To be precise, not every kind of lookup autovivifies, and the exact context matters.&lt;/p&gt;

&lt;p&gt;But the behavior above is real, intentional, and documented in the official Perl FAQ.&lt;/p&gt;

&lt;p&gt;Which makes the following statement entirely accurate:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"I checked whether the data existed, and now some of it does."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you need to test a deeply nested structure without modifying it, check each level carefully or use an appropriate helper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Perl sometimes treats data structures as things that should helpfully assemble themselves while you're looking at them.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;code&gt;foreach&lt;/code&gt; Doesn't Give You a Variable. It Gives You an Alias.
&lt;/h2&gt;

&lt;p&gt;Here's a familiar-looking loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;@numbers&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you expect?&lt;/p&gt;

&lt;p&gt;If you're coming from many other programming languages, you might assume that &lt;code&gt;$number&lt;/code&gt; is a local variable containing the current element's value.&lt;/p&gt;

&lt;p&gt;So modifying it shouldn't necessarily affect the original array.&lt;/p&gt;

&lt;p&gt;Right?&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 20 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You just modified every element in the original array.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Perl, the &lt;code&gt;foreach&lt;/code&gt; loop variable is an alias to the corresponding element when iterating over an ordinary array.&lt;/p&gt;

&lt;p&gt;It isn't simply receiving a copy.&lt;/p&gt;

&lt;p&gt;So when you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're changing the actual array element.&lt;/p&gt;

&lt;p&gt;This is useful when you deliberately want to transform a collection in place.&lt;/p&gt;

&lt;p&gt;But it's a potential disaster when you don't realize the aliasing is happening.&lt;/p&gt;

&lt;p&gt;And remember our PHP article?&lt;/p&gt;

&lt;p&gt;PHP has its own famous by-reference &lt;code&gt;foreach&lt;/code&gt; surprise.&lt;/p&gt;

&lt;p&gt;Except Perl doesn't need an ampersand to make its loop variable an alias.&lt;/p&gt;

&lt;p&gt;It just does it.&lt;/p&gt;

&lt;p&gt;Naturally.&lt;/p&gt;

&lt;p&gt;The safer approach, when you only want to inspect or compute something, is to avoid mutating the loop variable or explicitly copy it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$copy&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$copy&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you're operating on a separate value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Perl's &lt;code&gt;foreach&lt;/code&gt; is powerful precisely because the iteration variable can be an alias. Just don't mistake that power for ordinary value-copying semantics.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Perl Has an Operator That Remembers Things
&lt;/h2&gt;

&lt;p&gt;Here's where we start getting into genuinely exotic territory.&lt;/p&gt;

&lt;p&gt;Consider the range operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty straightforward.&lt;/p&gt;

&lt;p&gt;You get the integers from 1 through 5.&lt;/p&gt;

&lt;p&gt;Nothing especially strange about that.&lt;/p&gt;

&lt;p&gt;But remember our first example?&lt;/p&gt;

&lt;p&gt;Perl has context.&lt;/p&gt;

&lt;p&gt;And context can change what an operator means.&lt;/p&gt;

&lt;p&gt;In list context, &lt;code&gt;..&lt;/code&gt; creates a range.&lt;/p&gt;

&lt;p&gt;In scalar context, it becomes something entirely different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A flip-flop operator.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;An operator that maintains internal state.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;before&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;START&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;beta&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;END&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
    &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;after&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$line&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt; &lt;span class="ow"&gt;eq&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;START&lt;/span&gt;&lt;span class="p"&gt;")&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt; &lt;span class="ow"&gt;eq&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;END&lt;/span&gt;&lt;span class="p"&gt;"))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$line&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;START
alpha
beta
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened?&lt;/p&gt;

&lt;p&gt;The scalar &lt;code&gt;..&lt;/code&gt; operator acts like a stateful switch.&lt;/p&gt;

&lt;p&gt;Initially, it evaluates to false.&lt;/p&gt;

&lt;p&gt;When the left condition becomes true, it switches on.&lt;/p&gt;

&lt;p&gt;It then remains true across subsequent evaluations until the right condition becomes true.&lt;/p&gt;

&lt;p&gt;After that, it switches off for the next evaluation.&lt;/p&gt;

&lt;p&gt;It's particularly useful for extracting sections of text between markers.&lt;/p&gt;

&lt;p&gt;The strange part is that &lt;strong&gt;the operator itself maintains state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You don't have to declare a separate boolean variable.&lt;/p&gt;

&lt;p&gt;You don't have to track whether you've encountered the start marker.&lt;/p&gt;

&lt;p&gt;You don't have to manage the transition explicitly.&lt;/p&gt;

&lt;p&gt;Perl does it inside the operator.&lt;/p&gt;

&lt;p&gt;And each occurrence of the scalar flip-flop operator maintains its own state, even across calls to a subroutine containing it.&lt;/p&gt;

&lt;p&gt;Now consider that &lt;code&gt;...&lt;/code&gt; is also a flip-flop operator in scalar context, but differs in exactly when it tests the ending condition.&lt;/p&gt;

&lt;p&gt;Because apparently one stateful range operator wasn't sufficient.&lt;/p&gt;

&lt;p&gt;To be fair, this is beautifully suited to Perl's text-processing origins.&lt;/p&gt;

&lt;p&gt;It's concise, expressive, and genuinely useful.&lt;/p&gt;

&lt;p&gt;It's also an operator with a memory.&lt;/p&gt;

&lt;p&gt;And that isn't something you encounter every day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Perl, an operator can be more than a calculation. It can be a miniature state machine hiding behind two dots.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Perl's Variable Names Look Like Someone Fell Asleep on the Keyboard
&lt;/h2&gt;

&lt;p&gt;We've saved the most visually Perl-like example for last.&lt;/p&gt;

&lt;p&gt;Most languages encourage descriptive variable names.&lt;/p&gt;

&lt;p&gt;Things like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;current_user
error_message
record_count
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perl supports those too.&lt;/p&gt;

&lt;p&gt;But Perl also has an extensive collection of special variables.&lt;/p&gt;

&lt;p&gt;And some of their names are... unconventional.&lt;/p&gt;

&lt;p&gt;Meet the family:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;
&lt;span class="vg"&gt;$!&lt;/span&gt;
&lt;span class="vg"&gt;$?&lt;/span&gt;
&lt;span class="vg"&gt;$@&lt;/span&gt;
&lt;span class="vg"&gt;$/&lt;/span&gt;
&lt;span class="vg"&gt;$$&lt;/span&gt;
&lt;span class="vg"&gt;$^O&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This isn't obfuscated code.&lt;/p&gt;

&lt;p&gt;These are legitimate built-in Perl variables.&lt;/p&gt;

&lt;p&gt;And they all mean different things.&lt;/p&gt;

&lt;p&gt;A few highlights:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$_&lt;/code&gt;&lt;/strong&gt; is the default input and pattern-matching variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$!&lt;/code&gt;&lt;/strong&gt; contains information about the most recent system error, with useful string and numeric interpretations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$?&lt;/code&gt;&lt;/strong&gt; contains status information from the last child process or certain related operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$@&lt;/code&gt;&lt;/strong&gt; contains the exception message from the last &lt;code&gt;eval&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$/&lt;/code&gt;&lt;/strong&gt; controls the input record separator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$$&lt;/code&gt;&lt;/strong&gt; is the current process ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$^O&lt;/code&gt;&lt;/strong&gt; identifies the operating system Perl was built for.&lt;/p&gt;

&lt;p&gt;That's quite a collection.&lt;/p&gt;

&lt;p&gt;And some of them are genuinely powerful.&lt;/p&gt;

&lt;p&gt;For example, consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;  hello  &lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;

&lt;span class="sr"&gt;s/^\s+|\s+$//g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something?&lt;/p&gt;

&lt;p&gt;We didn't explicitly pass a string to the substitution operator.&lt;/p&gt;

&lt;p&gt;Perl simply used &lt;code&gt;$_&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Many Perl operations default to working on that variable when you don't specify another target.&lt;/p&gt;

&lt;p&gt;It's convenient.&lt;/p&gt;

&lt;p&gt;It's concise.&lt;/p&gt;

&lt;p&gt;And it means an extraordinary amount of behavior can be hiding in code that barely seems to contain any variables.&lt;/p&gt;

&lt;p&gt;But let's go further.&lt;/p&gt;

&lt;p&gt;Remember &lt;code&gt;$/&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;By default, it tells Perl to read input one line at a time.&lt;/p&gt;

&lt;p&gt;Change it, and you can change how input records are read.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local&lt;/span&gt; &lt;span class="vg"&gt;$/&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;undef&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$contents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;$fh&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming &lt;code&gt;$fh&lt;/code&gt; is an open filehandle, this reads the remaining contents of the file at once rather than one line at a time.&lt;/p&gt;

&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;Set a punctuation-named variable to &lt;code&gt;undef&lt;/code&gt;, and you've changed the input-reading behavior.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;local&lt;/code&gt; keeps that change confined to the block's dynamic scope.&lt;/p&gt;

&lt;p&gt;It's an elegant little idiom once you understand it.&lt;/p&gt;

&lt;p&gt;Before that, it looks like someone has accidentally assigned &lt;code&gt;undef&lt;/code&gt; to a typo.&lt;/p&gt;

&lt;p&gt;And if you dislike all these punctuation variables, Perl provides the &lt;code&gt;English&lt;/code&gt; module, which offers more descriptive aliases for many of them.&lt;/p&gt;

&lt;p&gt;For example, you can use &lt;code&gt;$OS_ERROR&lt;/code&gt; instead of &lt;code&gt;$!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Which means Perl provides readable variable names.&lt;/p&gt;

&lt;p&gt;It just also provides the option not to use them.&lt;/p&gt;

&lt;p&gt;Because TMTOWTDI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Perl's punctuation variables aren't arbitrary decoration. They're compact interfaces to important runtime state and built-in behavior.&lt;/p&gt;

&lt;p&gt;Whether that makes them brilliant or terrifying is largely a matter of personal temperament.&lt;/p&gt;

&lt;h2&gt;
  
  
  And This Is Only Part One
&lt;/h2&gt;

&lt;p&gt;Let's take stock.&lt;/p&gt;

&lt;p&gt;We've encountered a language where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The context of an expression can completely change what it does.&lt;/li&gt;
&lt;li&gt;A string can represent numeric zero while evaluating as true.&lt;/li&gt;
&lt;li&gt;Checking whether something exists can create part of it.&lt;/li&gt;
&lt;li&gt;A loop variable can silently alias the original data.&lt;/li&gt;
&lt;li&gt;An operator can maintain its own internal state.&lt;/li&gt;
&lt;li&gt;Punctuation marks can act as variables controlling the interpreter's behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And everything we've covered is documented, intentional behavior.&lt;/p&gt;

&lt;p&gt;Not bugs.&lt;/p&gt;

&lt;p&gt;Not accidents.&lt;/p&gt;

&lt;p&gt;Features.&lt;/p&gt;

&lt;p&gt;But here's something important.&lt;/p&gt;

&lt;p&gt;For all the jokes about Perl being unreadable, much of this weirdness reflects a coherent philosophy.&lt;/p&gt;

&lt;p&gt;Larry Wall approached programming-language design with a strong interest in human language.&lt;/p&gt;

&lt;p&gt;Natural languages are full of context, ambiguity, shortcuts, implied subjects, and multiple ways of saying the same thing.&lt;/p&gt;

&lt;p&gt;Perl deliberately embraces many of those characteristics.&lt;/p&gt;

&lt;p&gt;Rather than forcing every programmer to express every operation in a single standardized style, it provides tools for writing concise, expressive code suited to the task at hand.&lt;/p&gt;

&lt;p&gt;Sometimes that produces wonderfully elegant solutions.&lt;/p&gt;

&lt;p&gt;Sometimes it produces code that looks like a cat walked across the keyboard while holding down Shift.&lt;/p&gt;

&lt;p&gt;And sometimes those are the same thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coming in Part Two: The Deep Magic
&lt;/h2&gt;

&lt;p&gt;If you think we've exhausted Perl's peculiarities, we haven't even started on the truly alarming stuff.&lt;/p&gt;

&lt;p&gt;And perhaps we'll even discuss how Perl 6 eventually became Raku, a separate language with its own fascinating history.&lt;/p&gt;

&lt;p&gt;Because, naturally, one Perl wasn't enough.&lt;/p&gt;

&lt;p&gt;But that's for Part Two.&lt;/p&gt;

&lt;p&gt;For now, I'll leave you with this.&lt;/p&gt;

&lt;p&gt;Perl has been called the Swiss Army chainsaw of programming languages.&lt;/p&gt;

&lt;p&gt;It can accomplish an extraordinary amount with very little code.&lt;/p&gt;

&lt;p&gt;It can also make that code almost incomprehensible to the next person who encounters it.&lt;/p&gt;

&lt;p&gt;Which might be you, six months later.&lt;/p&gt;

</description>
      <category>perl</category>
      <category>regex</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>.NET: The Framework Formerly Known as Framework</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Mon, 09 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/net-the-framework-formerly-known-as-framework-40pe</link>
      <guid>https://dev.to/jlmartel/net-the-framework-formerly-known-as-framework-40pe</guid>
      <description>&lt;p&gt;In our last installment, we explored some of C#'s more surprising behaviors.&lt;/p&gt;

&lt;p&gt;But C# is only part of a much bigger story.&lt;/p&gt;

&lt;p&gt;A story involving multiple programming languages, competing user interface frameworks, a rather complicated relationship with open source, and enough product renaming to keep an entire marketing department employed for decades.&lt;/p&gt;

&lt;p&gt;Welcome to .NET.&lt;/p&gt;

&lt;p&gt;Or .NET Framework.&lt;/p&gt;

&lt;p&gt;Or .NET Core.&lt;/p&gt;

&lt;p&gt;Or just .NET again.&lt;/p&gt;

&lt;p&gt;We'll get to that.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. In the Beginning, There Was Windows
&lt;/h2&gt;

&lt;p&gt;When Microsoft launched .NET Framework in 2002, it represented an ambitious new direction for Windows development.&lt;/p&gt;

&lt;p&gt;At its heart was the Common Language Runtime (CLR), an execution environment providing garbage collection, memory management, exception handling, and other services that developers previously had to manage themselves.&lt;/p&gt;

&lt;p&gt;Instead of compiling directly to native machine code, supported languages generally compiled into Common Intermediate Language (CIL), which the runtime could then execute using just-in-time compilation.&lt;/p&gt;

&lt;p&gt;That was a pretty powerful idea.&lt;/p&gt;

&lt;p&gt;Multiple programming languages could share a runtime, a type system, and an extensive library ecosystem.&lt;/p&gt;

&lt;p&gt;A developer could write a library in one language and consume it from another.&lt;/p&gt;

&lt;p&gt;Naturally, Microsoft decided that one programming language wasn't enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. C#, VB.NET, and F#: Three Languages Walk Into a Runtime
&lt;/h2&gt;

&lt;p&gt;C# was the obvious flagship.&lt;/p&gt;

&lt;p&gt;Modern syntax, strong typing, object-oriented programming, and enough familiarity with Java and C++ to make developers feel at home.&lt;/p&gt;

&lt;p&gt;But Microsoft had another a constituency to consider.&lt;/p&gt;

&lt;p&gt;Visual Basic developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  VB.NET: It's Visual Basic, Jim, but Not as We Know It
&lt;/h3&gt;

&lt;p&gt;Visual Basic had been wildly popular for Windows application development.&lt;/p&gt;

&lt;p&gt;Its selling point was accessibility. You could drag controls onto a form, write some event handlers, and have a functioning application without spending six months studying Windows internals.&lt;/p&gt;

&lt;p&gt;For a generation of developers, Visual Basic was how you built business applications, full stop.&lt;/p&gt;

&lt;p&gt;So Microsoft brought Visual Basic into .NET.&lt;/p&gt;

&lt;p&gt;Except VB.NET wasn't simply the old Visual Basic with a new runtime.&lt;/p&gt;

&lt;p&gt;It was substantially redesigned.&lt;/p&gt;

&lt;p&gt;The old VB6 world included COM-based components, default form instances, and a programming model that was quite different from the CLR's object-oriented architecture.&lt;/p&gt;

&lt;p&gt;VB.NET introduced a new type system, inheritance, structured exception handling, and the other capabilities required to participate in .NET.&lt;/p&gt;

&lt;p&gt;That was great for architectural consistency.&lt;/p&gt;

&lt;p&gt;Less great for developers discovering that their existing VB6 applications weren't going to migrate quite as effortlessly as they'd hoped.&lt;/p&gt;

&lt;p&gt;Today, Visual Basic still exists in modern .NET.&lt;/p&gt;

&lt;p&gt;But Microsoft has made its direction clear: VB will remain supported and stable, without aggressively expanding into new workloads or pursuing every new language feature introduced in C#.&lt;/p&gt;

&lt;p&gt;Which is a polite way of saying:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"You are tolerated, former incumbent."&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  F#: Wait, We Also Have a Functional Language?
&lt;/h3&gt;

&lt;p&gt;Then there's F#.&lt;/p&gt;

&lt;p&gt;While C# and VB.NET largely embraced object-oriented programming, F# arrived with a functional-first philosophy.&lt;/p&gt;

&lt;p&gt;Immutability by default.&lt;/p&gt;

&lt;p&gt;Pattern matching.&lt;/p&gt;

&lt;p&gt;Type inference.&lt;/p&gt;

&lt;p&gt;Functions as first-class citizens.&lt;/p&gt;

&lt;p&gt;And a syntax that looks refreshingly different from the sea of curly braces elsewhere in the ecosystem.&lt;/p&gt;

&lt;p&gt;What makes F# particularly interesting is that it isn't a separate runtime universe.&lt;/p&gt;

&lt;p&gt;It uses .NET too.&lt;/p&gt;

&lt;p&gt;An F# library can be consumed by C# code. Both can use much of the same underlying framework.&lt;/p&gt;

&lt;p&gt;That's convenient.&lt;/p&gt;

&lt;p&gt;You can write enterprise business logic in C#, functional transformations in F#, and maintain an application in VB.NET, all within the same general ecosystem.&lt;/p&gt;

&lt;p&gt;Although anyone who has actually maintained a multilingual solution will tell you that &lt;em&gt;technically interoperable&lt;/em&gt; and &lt;em&gt;pleasant to maintain&lt;/em&gt; are not necessarily synonyms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fascinating part:&lt;/strong&gt; .NET was designed to make programming languages less important than the runtime and libraries they shared.&lt;/p&gt;

&lt;p&gt;Twenty-four years later, C# overwhelmingly dominates the ecosystem, VB remains supported, and F# continues to serve developers who appreciate its different approach.&lt;/p&gt;

&lt;p&gt;One platform. Three officially supported languages. Three rather different philosophies.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Windows Forms: Just Drag the Button On Form1
&lt;/h2&gt;

&lt;p&gt;Let's talk about building user interfaces.&lt;/p&gt;

&lt;p&gt;For many developers in the early .NET era, Windows Forms was one of the platform's most appealing features.&lt;/p&gt;

&lt;p&gt;Open Visual Studio.&lt;/p&gt;

&lt;p&gt;Create a form.&lt;/p&gt;

&lt;p&gt;Drag a button onto it.&lt;/p&gt;

&lt;p&gt;Double-click the button.&lt;/p&gt;

&lt;p&gt;Write some code.&lt;/p&gt;

&lt;p&gt;Keep the default icon.&lt;/p&gt;

&lt;p&gt;Congratulations. You have a Windows application.&lt;/p&gt;

&lt;p&gt;WinForms was wonderfully pragmatic.&lt;/p&gt;

&lt;p&gt;Its programming model was event-driven and closely tied to traditional Windows desktop controls.&lt;/p&gt;

&lt;p&gt;For business applications, internal tools, and database frontends, it was often exactly what developers needed.&lt;/p&gt;

&lt;p&gt;Of course, Microsoft eventually decided that Windows application development needed something more sophisticated.&lt;/p&gt;

&lt;p&gt;Enter WPF.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. WPF and XAML: What if Buttons Were XML?
&lt;/h2&gt;

&lt;p&gt;In 2006, Microsoft introduced Windows Presentation Foundation as part of .NET Framework 3.0.&lt;/p&gt;

&lt;p&gt;WPF brought an entirely different approach to desktop UI development.&lt;/p&gt;

&lt;p&gt;Instead of primarily positioning controls in a visual designer and attaching event handlers, developers could describe interfaces declaratively using XAML.&lt;/p&gt;

&lt;p&gt;Extensible Application Markup Language.&lt;/p&gt;

&lt;p&gt;Because apparently XML hadn't yet appeared in enough places.&lt;/p&gt;

&lt;p&gt;To be fair, XAML enabled some powerful ideas.&lt;/p&gt;

&lt;p&gt;Data binding.&lt;/p&gt;

&lt;p&gt;Reusable styles and templates.&lt;/p&gt;

&lt;p&gt;Resolution-independent layouts.&lt;/p&gt;

&lt;p&gt;Rich graphics and animation.&lt;/p&gt;

&lt;p&gt;And better separation between the visual interface and application logic.&lt;/p&gt;

&lt;p&gt;WPF could produce interfaces that were dramatically more sophisticated than traditional WinForms applications.&lt;/p&gt;

&lt;p&gt;It also introduced concepts such as dependency properties, routed events, and elaborate binding mechanisms.&lt;/p&gt;

&lt;p&gt;Things that were pretty cool, right up until a binding silently failed and you spent the afternoon trying to understand why a button was disabled.&lt;/p&gt;

&lt;p&gt;Then came the familiar Microsoft ecosystem question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which UI technology should you actually use?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WinForms was still around.&lt;/p&gt;

&lt;p&gt;WPF was supposed to be the modern alternative.&lt;/p&gt;

&lt;p&gt;Someone at Microsoft said: "we're gonna need a bigger boat".&lt;/p&gt;

&lt;p&gt;SO they came up with Silverlight, UWP, WinUI, and eventually .NET MAUI.&lt;/p&gt;

&lt;p&gt;And here's an important distinction: XAML isn't itself a competing UI framework. It's a declarative markup language used by multiple frameworks, including WPF, WinUI, and .NET MAUI, with differences between their implementations.&lt;/p&gt;

&lt;p&gt;(And what about Xamarin? "THERE WAS NEVER A XAMARIN").&lt;/p&gt;

&lt;p&gt;Today, WinForms and WPF remain supported on modern .NET.&lt;/p&gt;

&lt;p&gt;WinUI is Microsoft's primary recommendation for new general-purpose Windows desktop applications.&lt;/p&gt;

&lt;p&gt;And .NET MAUI targets multiple platforms, including Windows, macOS, Android, and iOS.&lt;/p&gt;

&lt;p&gt;Yes, a platform famous for introducing alternatives has managed to retain several of them simultaneously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Microsoft rarely eliminates an old development technology simply because a newer one exists. Sometimes the future arrives, and the past just moves into the spare bedroom. Except for Xamarin.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Plot Twist: .NET Escapes Windows
&lt;/h2&gt;

&lt;p&gt;For much of its early history, Microsoft's official .NET Framework was closely associated with Windows.&lt;/p&gt;

&lt;p&gt;But an important part of this story happened outside Microsoft.&lt;/p&gt;

&lt;p&gt;The Mono project began developing an open-source, cross-platform implementation of .NET in the early 2000s.&lt;/p&gt;

&lt;p&gt;It demonstrated that .NET technology could live beyond Windows, including on Linux.&lt;/p&gt;

&lt;p&gt;This was a mic drop moment.&lt;/p&gt;

&lt;p&gt;Because the underlying .NET concepts were not inherently Windows-specific, even though many framework APIs and application technologies were.&lt;/p&gt;

&lt;p&gt;Years later, Microsoft began moving toward a much more open development strategy.&lt;/p&gt;

&lt;p&gt;It open-sourced major pieces of its developer tooling and runtime ecosystem.&lt;/p&gt;

&lt;p&gt;Then, in 2016, .NET Core 1.0 arrived.&lt;/p&gt;

&lt;p&gt;Open source.&lt;/p&gt;

&lt;p&gt;Cross-platform.&lt;/p&gt;

&lt;p&gt;Designed with modern server workloads, cloud deployment, and modularity in mind.&lt;/p&gt;

&lt;p&gt;A Microsoft development platform running naturally on Linux would once have seemed like a fairly elaborate practical joke.&lt;/p&gt;

&lt;p&gt;Now it was part of the official strategy.&lt;/p&gt;

&lt;p&gt;But there was a catch.&lt;/p&gt;

&lt;p&gt;.NET Core wasn't simply a cross-platform copy of everything in .NET Framework.&lt;/p&gt;

&lt;p&gt;It was a different implementation with different APIs and initially a smaller surface area.&lt;/p&gt;

&lt;p&gt;Some applications could migrate relatively easily.&lt;/p&gt;

&lt;p&gt;Others depended on Windows-specific technologies, legacy framework components, or third-party libraries that weren't available.&lt;/p&gt;

&lt;p&gt;And some simply couldn't be moved without significant rewrites.&lt;/p&gt;

&lt;p&gt;But the direction was clear.&lt;/p&gt;

&lt;p&gt;.NET was no longer synonymous with Windows.&lt;/p&gt;

&lt;p&gt;Or proprietary software.&lt;/p&gt;

&lt;p&gt;Which brings us to the naming department.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The Naming Department Has Entered the Chat
&lt;/h2&gt;

&lt;p&gt;Let's recap.&lt;/p&gt;

&lt;p&gt;We started with .NET Framework.&lt;/p&gt;

&lt;p&gt;Then Microsoft introduced .NET Core.&lt;/p&gt;

&lt;p&gt;Meanwhile, we had .NET Standard, which wasn't another runtime at all, but an API specification designed to help libraries work across different .NET implementations.&lt;/p&gt;

&lt;p&gt;Then, after .NET Core 3.1, Microsoft released...&lt;/p&gt;

&lt;p&gt;.NET 5.&lt;/p&gt;

&lt;p&gt;Not .NET Core 4.&lt;/p&gt;

&lt;p&gt;Not .NET Framework 5.&lt;/p&gt;

&lt;p&gt;Just .NET 5.&lt;/p&gt;

&lt;p&gt;Why skip four?&lt;/p&gt;

&lt;p&gt;Partly to avoid confusion with the existing .NET Framework 4.x product line.&lt;/p&gt;

&lt;p&gt;So Microsoft solved one naming conflict by skipping a number and dropping a word.&lt;/p&gt;

&lt;p&gt;There was probably a PowerPoint presentation involved.&lt;/p&gt;

&lt;p&gt;Since then, modern .NET has continued with annual version releases, reaching .NET 10 in November 2025.&lt;/p&gt;

&lt;p&gt;Meanwhile, the original .NET Framework continues to exist, with version 4.8.1 supported on Windows.&lt;/p&gt;

&lt;p&gt;And just to complete the picture, ASP.NET Core retains the word "Core" even though the main runtime dropped it.&lt;/p&gt;

&lt;p&gt;So today:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;.NET Framework&lt;/strong&gt; means the original Windows-only implementation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.NET&lt;/strong&gt; means the modern open-source, cross-platform implementation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.NET Standard&lt;/strong&gt; describes a compatibility-oriented API specification, not a runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ASP.NET Core&lt;/strong&gt; is the modern web framework, despite the runtime's naming change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.NET Core&lt;/strong&gt; is the former name of what evolved into modern .NET.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's brace ourselves for .NET Copilot which is almost certainly cooking somewhere in Redmond.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. And Then There's PowerShell
&lt;/h2&gt;

&lt;p&gt;Here's a part of the .NET ecosystem that doesn't always get enough attention.&lt;/p&gt;

&lt;p&gt;PowerShell.&lt;/p&gt;

&lt;p&gt;Most people think of it as a command-line shell and scripting language, particularly associated with Windows administration.&lt;/p&gt;

&lt;p&gt;Not wrong.&lt;/p&gt;

&lt;p&gt;But PowerShell is also deeply connected to .NET.&lt;/p&gt;

&lt;p&gt;Unlike traditional Unix shells, which primarily pass text between commands, PowerShell pipelines can pass structured objects.&lt;/p&gt;

&lt;p&gt;Actual objects, with properties and methods.&lt;/p&gt;

&lt;p&gt;Those objects are frequently .NET objects.&lt;/p&gt;

&lt;p&gt;Which means a PowerShell script can access parts of the .NET ecosystem directly.&lt;/p&gt;

&lt;p&gt;Want to work with filesystem APIs?&lt;/p&gt;

&lt;p&gt;Use .NET objects.&lt;/p&gt;

&lt;p&gt;Need regular expressions?&lt;/p&gt;

&lt;p&gt;They're available.&lt;/p&gt;

&lt;p&gt;Want to instantiate framework classes or call static methods?&lt;/p&gt;

&lt;p&gt;You can do that too.&lt;/p&gt;

&lt;p&gt;PowerShell is, in many ways, a .NET automation environment disguised as a shell.&lt;/p&gt;

&lt;p&gt;And naturally, it has its own version of the great .NET identity crisis.&lt;/p&gt;

&lt;p&gt;Windows PowerShell 5.1 runs on the original .NET Framework.&lt;/p&gt;

&lt;p&gt;Modern PowerShell 7 runs on modern .NET and supports Windows, Linux, and macOS.&lt;/p&gt;

&lt;p&gt;Both can exist on the same Windows machine.&lt;/p&gt;

&lt;p&gt;And they can behave differently when scripts depend on incompatible modules or framework APIs.&lt;/p&gt;

&lt;p&gt;So now we have two PowerShell families corresponding to two .NET families.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At this point, the family tree needs a database.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But underneath the confusing history lies something genuinely powerful: an administrator can write a script that manipulates rich runtime objects, while developers can expose functionality that PowerShell can consume without inventing an entirely separate scripting interface.&lt;/p&gt;

&lt;p&gt;It's one of .NET's more underappreciated achievements.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. So What Exactly Is .NET?
&lt;/h2&gt;

&lt;p&gt;After all that, it's worth asking the obvious question.&lt;/p&gt;

&lt;p&gt;Is .NET a programming language?&lt;/p&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;An operating system?&lt;/p&gt;

&lt;p&gt;Also no.&lt;/p&gt;

&lt;p&gt;A framework?&lt;/p&gt;

&lt;p&gt;Yes, but that answer is incomplete.&lt;/p&gt;

&lt;p&gt;A runtime?&lt;/p&gt;

&lt;p&gt;Yes, but still incomplete.&lt;/p&gt;

&lt;p&gt;.NET is better understood as an entire development platform.&lt;/p&gt;

&lt;p&gt;It includes runtimes, compilers, standard libraries, SDKs, development tools, and application frameworks.&lt;/p&gt;

&lt;p&gt;It supports different languages and workloads.&lt;/p&gt;

&lt;p&gt;You can build web APIs, desktop applications, cloud services, mobile applications, games, and command-line tools.&lt;/p&gt;

&lt;p&gt;The current platform is powerful.&lt;/p&gt;

&lt;p&gt;And the shift from the original Windows-centric .NET Framework to today's open-source implementation is one of Microsoft's most significant technological transformations.&lt;/p&gt;

&lt;p&gt;There is also a wonderfully ironic outcome.&lt;/p&gt;

&lt;p&gt;Microsoft spent years building an ecosystem closely associated with Windows development.&lt;/p&gt;

&lt;p&gt;Then it invested heavily in making that ecosystem work without Windows.&lt;/p&gt;

&lt;p&gt;Developers can now build a C# application on Linux, deploy it in a Linux container, run it in the cloud, and never touch a Windows desktop.&lt;/p&gt;

&lt;p&gt;Which would have sounded strange in 2002.&lt;/p&gt;

&lt;p&gt;Somehow, all those identities coexist.&lt;/p&gt;

&lt;p&gt;Not always elegantly.&lt;/p&gt;

&lt;p&gt;Not always compatibly.&lt;/p&gt;

&lt;p&gt;And certainly not under a naming scheme that anyone would describe as intuitive.&lt;/p&gt;

&lt;p&gt;But the result is impressive.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Java: Write Once, Run Anywhere, But Consult Legal First</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Mon, 09 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/java-write-once-run-anywhere-but-consult-legal-first-4i2f</link>
      <guid>https://dev.to/jlmartel/java-write-once-run-anywhere-but-consult-legal-first-4i2f</guid>
      <description>&lt;p&gt;In our previous installment, we explored Java's peculiar relationship with integer equality, collections that refuse to behave like collections, and the remarkable amount of engineering involved in concatenating two strings.&lt;/p&gt;

&lt;p&gt;But those were merely quirks of the language.&lt;/p&gt;

&lt;p&gt;The Java ecosystem is something else entirely.&lt;/p&gt;

&lt;p&gt;Because somewhere along the way, Java stopped being just a programming language and became an entire civilization.&lt;/p&gt;

&lt;p&gt;Complete with competing governments, religious disagreements, competing implementations, licensing disputes, and an astonishing number of products named after coffee.&lt;/p&gt;

&lt;p&gt;If you think choosing a programming language should be the difficult part, Java has some news for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. First, Let's Figure Out What Java Actually Is
&lt;/h2&gt;

&lt;p&gt;This should be straightforward.&lt;/p&gt;

&lt;p&gt;Java is a programming language.&lt;/p&gt;

&lt;p&gt;Except Java is also commonly used to describe a runtime platform, a collection of libraries, a development kit, and an entire ecosystem of technologies that don't necessarily involve writing Java at all.&lt;/p&gt;

&lt;p&gt;Let's meet the family.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt; The programming language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JVM:&lt;/strong&gt; The Java Virtual Machine, which executes Java bytecode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JRE:&lt;/strong&gt; The Java Runtime Environment, traditionally the package needed to run Java applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JDK:&lt;/strong&gt; The Java Development Kit, containing the compiler, runtime, and development tools.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OpenJDK:&lt;/strong&gt; The open-source project providing a reference implementation of the Java platform and the foundation for many JDK distributions.&lt;/p&gt;

&lt;p&gt;Simple enough.&lt;/p&gt;

&lt;p&gt;Except the JVM isn't necessarily written by the same organization that distributes your JDK.&lt;/p&gt;

&lt;p&gt;And a JDK doesn't have to use the same JVM implementation as another JDK.&lt;/p&gt;

&lt;p&gt;And the JVM can execute programs written in languages other than Java.&lt;/p&gt;

&lt;p&gt;And modern Java deployments often ship custom runtime images rather than requiring a separately installed JRE.&lt;/p&gt;

&lt;p&gt;Already, we've managed to turn "install Java" into an architectural discussion.&lt;/p&gt;

&lt;p&gt;But don't worry.&lt;/p&gt;

&lt;p&gt;It gets better.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. One JVM to Rule Them All. Except There Isn't One.
&lt;/h2&gt;

&lt;p&gt;Java's original promise was revolutionary.&lt;/p&gt;

&lt;p&gt;Write your program once. Compile it into bytecode. Run that bytecode anywhere a compatible JVM exists.&lt;/p&gt;

&lt;p&gt;Which naturally raises an interesting question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whose JVM?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  HotSpot: The Default Suspect
&lt;/h3&gt;

&lt;p&gt;HotSpot is the familiar JVM implementation used by most mainstream OpenJDK distributions.&lt;/p&gt;

&lt;p&gt;It's mature, highly optimized, and has spent decades becoming terrific at figuring out which parts of your code deserve special attention.&lt;/p&gt;

&lt;p&gt;Its just-in-time compiler can optimize frequently executed code based on what actually happens at runtime.&lt;/p&gt;

&lt;p&gt;This is one reason Java applications can perform impressively well despite running inside a virtual machine.&lt;/p&gt;

&lt;p&gt;But HotSpot isn't the only game in town.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenJ9: Because One Virtual Machine Wasn't Enough
&lt;/h3&gt;

&lt;p&gt;Eclipse OpenJ9 is an alternative JVM implementation with its own approaches to garbage collection, memory management, and compilation.&lt;/p&gt;

&lt;p&gt;It's used in IBM Semeru Runtimes.&lt;/p&gt;

&lt;p&gt;The interesting part is that OpenJ9 can run ordinary compatible Java applications.&lt;/p&gt;

&lt;p&gt;Same language.&lt;/p&gt;

&lt;p&gt;Same bytecode.&lt;/p&gt;

&lt;p&gt;Different virtual machine implementation.&lt;/p&gt;

&lt;p&gt;Depending on the workload, switching JVMs can change memory consumption, startup characteristics, garbage collection behavior, and performance.&lt;/p&gt;

&lt;p&gt;Which means Java developers can spend hours tuning code, only to discover that changing the underlying JVM produces a bigger improvement.&lt;/p&gt;

&lt;p&gt;Or makes everything worse.&lt;/p&gt;

&lt;p&gt;Benchmark first. Celebrate later.&lt;/p&gt;

&lt;h3&gt;
  
  
  GraalVM: What if We Compiled the Whole Thing?
&lt;/h3&gt;

&lt;p&gt;Then there's GraalVM.&lt;/p&gt;

&lt;p&gt;GraalVM builds on HotSpot and provides the Graal compiler, an advanced just-in-time compiler written in Java.&lt;/p&gt;

&lt;p&gt;Yes, Java has a compiler written in Java that helps Java run faster.&lt;/p&gt;

&lt;p&gt;But GraalVM's especially interesting trick is Native Image.&lt;/p&gt;

&lt;p&gt;Instead of running your application on a JVM at deployment time, you can compile it ahead of time into a native executable.&lt;/p&gt;

&lt;p&gt;Potential advantages include faster startup and lower resource consumption.&lt;/p&gt;

&lt;p&gt;Particularly attractive for certain cloud and serverless workloads.&lt;/p&gt;

&lt;p&gt;Of course, ahead-of-time compilation brings different tradeoffs, including build complexity and restrictions around some forms of dynamic behavior.&lt;/p&gt;

&lt;p&gt;So now Java can run on a JVM.&lt;/p&gt;

&lt;p&gt;Or on a different JVM.&lt;/p&gt;

&lt;p&gt;Or on a HotSpot-based runtime with a different optimizing compiler.&lt;/p&gt;

&lt;p&gt;Or as a native executable that doesn't require a JVM at runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write once. Run anywhere. Spend three weeks deciding how.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Oracle Java Licensing: The Plot Twist Nobody Requested
&lt;/h2&gt;

&lt;p&gt;For decades, Java was associated with Sun Microsystems.&lt;/p&gt;

&lt;p&gt;Then Oracle acquired Sun in 2010.&lt;/p&gt;

&lt;p&gt;And eventually, Java licensing became really interesting.&lt;/p&gt;

&lt;p&gt;Not necessarily interesting in the fun programming-language sense.&lt;/p&gt;

&lt;p&gt;More in the "why is procurement suddenly attending our architecture meetings?" sense.&lt;/p&gt;

&lt;p&gt;Let's walk through the major developments.&lt;/p&gt;

&lt;h3&gt;
  
  
  2019: Wait, Java Isn't Free Anymore?
&lt;/h3&gt;

&lt;p&gt;In April 2019, Oracle changed the licensing terms for certain Oracle Java SE releases and updates.&lt;/p&gt;

&lt;p&gt;Some commercial production uses of newer Oracle JDK updates now required paid licensing where earlier terms had allowed broader use without a separate fee.&lt;/p&gt;

&lt;p&gt;That created considerable confusion.&lt;/p&gt;

&lt;p&gt;Because developers had spent years treating Java as something they could download, install, and run without thinking much about licensing.&lt;/p&gt;

&lt;p&gt;Suddenly, organizations had to examine exactly which Java distribution they were using and under what terms.&lt;/p&gt;

&lt;p&gt;But here's the important distinction:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java the language did not suddenly become a paid product.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OpenJDK remained open source.&lt;/p&gt;

&lt;p&gt;Alternative distributions remained available.&lt;/p&gt;

&lt;p&gt;The licensing changes concerned specific Oracle-provided binaries and their terms.&lt;/p&gt;

&lt;p&gt;Java itself hadn't disappeared behind a paywall.&lt;/p&gt;

&lt;p&gt;Nevertheless, the confusion was understandable.&lt;/p&gt;

&lt;h3&gt;
  
  
  2021: Good News! It's Free Again. Sort Of.
&lt;/h3&gt;

&lt;p&gt;Oracle introduced its No-Fee Terms and Conditions license, commonly abbreviated NFTC, with JDK 17.&lt;/p&gt;

&lt;p&gt;This permitted free use, including commercial production use, for eligible Oracle JDK releases under those terms.&lt;/p&gt;

&lt;p&gt;Excellent.&lt;/p&gt;

&lt;p&gt;Problem solved?&lt;/p&gt;

&lt;p&gt;Not exactly.&lt;/p&gt;

&lt;p&gt;The free-use period for updates to an Oracle JDK long-term-support release doesn't necessarily last for that release's entire support lifetime.&lt;/p&gt;

&lt;p&gt;Later updates can move to different licensing terms.&lt;/p&gt;

&lt;p&gt;For example, Oracle JDK 21 updates through September 2026 were available under NFTC.&lt;/p&gt;

&lt;p&gt;Beginning with the October 2026 update cycle, subsequent Oracle JDK 21 updates moved to the Oracle Technology Network licensing model, which doesn't grant the same unrestricted free commercial production rights.&lt;/p&gt;

&lt;p&gt;Meanwhile, Oracle JDK 25 remains available under NFTC, with its own future transition schedule.&lt;/p&gt;

&lt;p&gt;So if you're using Oracle JDK, you need to consider not only the Java version but also the specific update release and its license.&lt;/p&gt;

&lt;p&gt;Because apparently version numbers weren't already complicated enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  2023: How Many Employees Do You Have?
&lt;/h3&gt;

&lt;p&gt;Then came Oracle's Java SE Universal Subscription.&lt;/p&gt;

&lt;p&gt;Introduced in January 2023, this subscription moved to employee-based licensing.&lt;/p&gt;

&lt;p&gt;Rather than simply counting installations or processors, the subscription model generally considers the size of the organization, according to its contractual employee definition.&lt;/p&gt;

&lt;p&gt;That raised an obvious question.&lt;/p&gt;

&lt;p&gt;What does the number of people working in accounting have to do with how many Java applications you're running?&lt;/p&gt;

&lt;p&gt;Well, that's a question for the licensing department.&lt;/p&gt;

&lt;p&gt;Oracle has since updated its pricing, including new small-business tiers introduced in October 2026. Its commercial offerings also include support, updates, and management capabilities.&lt;/p&gt;

&lt;p&gt;And to be clear, organizations don't universally need an Oracle subscription to run Java commercially.&lt;/p&gt;

&lt;p&gt;You can use appropriately licensed OpenJDK distributions.&lt;/p&gt;

&lt;p&gt;But now the phrase "Which Java are we using?" can have financial consequences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A programming language has successfully turned runtime selection into a procurement strategy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Impressive, really.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Everyone Has Their Own Java
&lt;/h2&gt;

&lt;p&gt;Thankfully, Java's open-source ecosystem provides plenty of alternatives.&lt;/p&gt;

&lt;p&gt;You can choose from several OpenJDK-based distributions, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eclipse Temurin, from the Adoptium project.&lt;/li&gt;
&lt;li&gt;Amazon Corretto.&lt;/li&gt;
&lt;li&gt;Azul Zulu.&lt;/li&gt;
&lt;li&gt;Microsoft Build of OpenJDK.&lt;/li&gt;
&lt;li&gt;BellSoft Liberica.&lt;/li&gt;
&lt;li&gt;Red Hat builds of OpenJDK.&lt;/li&gt;
&lt;li&gt;Oracle's own OpenJDK builds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most of these use HotSpot.&lt;/p&gt;

&lt;p&gt;Some vendors offer additional runtime technologies or support arrangements.&lt;/p&gt;

&lt;p&gt;And many are compatible implementations of essentially the same Java platform.&lt;/p&gt;

&lt;p&gt;So why so many?&lt;/p&gt;

&lt;p&gt;Different organizations provide different combinations of update schedules, supported platforms, packaging, long-term maintenance, commercial support, and optimization.&lt;/p&gt;

&lt;p&gt;These differences can matter enormously for enterprises running thousands of applications.&lt;/p&gt;

&lt;p&gt;But for developers trying to install Java on a new laptop, the experience can feel a little absurd.&lt;/p&gt;

&lt;p&gt;You wanted a compiler.&lt;/p&gt;

&lt;p&gt;Instead, you've been asked to evaluate a supply chain.&lt;/p&gt;

&lt;p&gt;And then someone suggests SDKMAN! to manage all your JDK installations.&lt;/p&gt;

&lt;p&gt;Which is genuinely useful.&lt;/p&gt;

&lt;p&gt;But also rather funny.&lt;/p&gt;

&lt;p&gt;We've created a tool to help manage the consequences of having so many tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The JVM Doesn't Actually Care Whether You Write Java
&lt;/h2&gt;

&lt;p&gt;Here's where the ecosystem becomes much more interesting.&lt;/p&gt;

&lt;p&gt;The JVM executes bytecode.&lt;/p&gt;

&lt;p&gt;It doesn't particularly care which programming language produced that bytecode.&lt;/p&gt;

&lt;p&gt;And developers have taken full advantage of that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kotlin: Java, but With Less Java
&lt;/h3&gt;

&lt;p&gt;Kotlin was developed by JetBrains and has become particularly prominent in Android development.&lt;/p&gt;

&lt;p&gt;It offers concise syntax, null-safety features, extension functions, and strong interoperability with Java.&lt;/p&gt;

&lt;p&gt;You can call Java libraries from Kotlin.&lt;/p&gt;

&lt;p&gt;You can call Kotlin code from Java.&lt;/p&gt;

&lt;p&gt;You can even mix the two within the same project.&lt;/p&gt;

&lt;p&gt;Kotlin also targets JavaScript, native platforms, and WebAssembly, so it isn't exclusively a JVM language.&lt;/p&gt;

&lt;p&gt;But its JVM compatibility is a major reason for its success.&lt;/p&gt;

&lt;p&gt;It offers developers a different language without requiring them to abandon the enormous Java library ecosystem.&lt;/p&gt;

&lt;p&gt;Which is a polite way of saying:&lt;/p&gt;

&lt;p&gt;"I like everything Java has built. I'd just rather not write so much Java."&lt;/p&gt;

&lt;h3&gt;
  
  
  Scala: What if Java Had a PhD?
&lt;/h3&gt;

&lt;p&gt;Scala combines object-oriented and functional programming with a sophisticated type system.&lt;/p&gt;

&lt;p&gt;It supports advanced abstraction, immutability, pattern matching, and a programming style very different from traditional Java.&lt;/p&gt;

&lt;p&gt;It's also deeply connected to Apache Spark, which we'll get to shortly.&lt;/p&gt;

&lt;p&gt;Scala can be extremely expressive.&lt;/p&gt;

&lt;p&gt;It can also produce code that feels like a graduate thesis escaped into production.&lt;/p&gt;

&lt;p&gt;The language is powerful enough to let you create abstractions that are beautiful, mathematically elegant, and almost completely incomprehensible to whoever maintains them next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Groovy: Java After a Few Drinks
&lt;/h3&gt;

&lt;p&gt;Groovy brings dynamic language features and scripting conveniences to the JVM.&lt;/p&gt;

&lt;p&gt;It's closely associated with parts of the Java tooling world, particularly Gradle's traditional build-script DSL.&lt;/p&gt;

&lt;p&gt;Groovy can use Java libraries and integrate with existing Java code.&lt;/p&gt;

&lt;p&gt;Which means you can add a more flexible scripting language without leaving the ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clojure: For the Parentheses Enthusiast
&lt;/h3&gt;

&lt;p&gt;Clojure brings a Lisp dialect and a functional programming philosophy to the JVM.&lt;/p&gt;

&lt;p&gt;Immutable data structures.&lt;/p&gt;

&lt;p&gt;Persistent collections.&lt;/p&gt;

&lt;p&gt;Functions and sequences.&lt;/p&gt;

&lt;p&gt;And parentheses.&lt;/p&gt;

&lt;p&gt;Lots of parentheses.&lt;/p&gt;

&lt;p&gt;Clojure demonstrates the JVM's flexibility particularly well.&lt;/p&gt;

&lt;p&gt;You can write something that looks almost nothing like Java and still take advantage of Java's runtime and libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The JVM has become a place where programming languages with wildly different philosophies agree to share the same infrastructure.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If only their developers could agree on indentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Apache: Where Java Became Infrastructure
&lt;/h2&gt;

&lt;p&gt;Now let's leave ordinary applications behind.&lt;/p&gt;

&lt;p&gt;Because Java's influence extends far beyond enterprise web development.&lt;/p&gt;

&lt;p&gt;A remarkable amount of modern data infrastructure grew out of the Java and JVM ecosystem.&lt;/p&gt;

&lt;p&gt;And much of it lives under the Apache Software Foundation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hadoop: The Elephant in the Data Center
&lt;/h3&gt;

&lt;p&gt;Apache Hadoop helped popularize large-scale distributed data processing.&lt;/p&gt;

&lt;p&gt;Its ecosystem included HDFS for distributed storage, MapReduce for processing, and YARN for resource management.&lt;/p&gt;

&lt;p&gt;The appeal was simple.&lt;/p&gt;

&lt;p&gt;Take large datasets.&lt;/p&gt;

&lt;p&gt;Spread them across multiple machines.&lt;/p&gt;

&lt;p&gt;Process them in parallel.&lt;/p&gt;

&lt;p&gt;Make the system resilient when individual machines fail.&lt;/p&gt;

&lt;p&gt;Simple in concept.&lt;/p&gt;

&lt;p&gt;Considerably less simple when you're actually operating a cluster.&lt;/p&gt;

&lt;p&gt;Suddenly your data pipeline has dozens of configuration files, services that need to discover each other, and an impressive collection of logs.&lt;/p&gt;

&lt;p&gt;But Hadoop was enormously influential.&lt;/p&gt;

&lt;p&gt;And it helped lay the foundations for much of the modern big-data world.&lt;/p&gt;

&lt;h3&gt;
  
  
  Spark: Python Developers, Meet Your JVM
&lt;/h3&gt;

&lt;p&gt;Apache Spark emerged as a more flexible distributed processing engine.&lt;/p&gt;

&lt;p&gt;Its core is closely tied to Scala and the JVM.&lt;/p&gt;

&lt;p&gt;But Spark supports Java, Scala, Python, SQL, and, with some qualifications depending on version, R.&lt;/p&gt;

&lt;p&gt;This creates a particularly entertaining situation.&lt;/p&gt;

&lt;p&gt;A data scientist writes PySpark code in Python.&lt;/p&gt;

&lt;p&gt;Spark coordinates distributed execution using its JVM-based engine, with Python worker processes involved where necessary.&lt;/p&gt;

&lt;p&gt;So a Python application can be orchestrating work through a Java-based distributed computing platform without the developer writing a single line of Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java has successfully infiltrated the Python ecosystem while allowing Python to take the credit.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To be fair, that's a pretty good arrangement for everyone involved.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kafka: Everything Is an Event Now
&lt;/h3&gt;

&lt;p&gt;Apache Kafka provides distributed event streaming.&lt;/p&gt;

&lt;p&gt;Applications publish events.&lt;/p&gt;

&lt;p&gt;Other applications consume them.&lt;/p&gt;

&lt;p&gt;Events can be retained, replayed, and processed by multiple consumers.&lt;/p&gt;

&lt;p&gt;Kafka became central to many event-driven architectures, data pipelines, and streaming systems.&lt;/p&gt;

&lt;p&gt;It's powerful infrastructure.&lt;/p&gt;

&lt;p&gt;It also has its own terminology, operational model, and configuration universe.&lt;/p&gt;

&lt;p&gt;But there's one historical detail that deserves special attention.&lt;/p&gt;

&lt;p&gt;Kafka spent more than a decade relying on another Apache project.&lt;/p&gt;

&lt;p&gt;ZooKeeper.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. ZooKeeper: Challenge Accepted
&lt;/h2&gt;

&lt;p&gt;Distributed systems have a fundamental problem.&lt;/p&gt;

&lt;p&gt;Several machines need to cooperate.&lt;/p&gt;

&lt;p&gt;Machines fail.&lt;/p&gt;

&lt;p&gt;Networks become unreliable.&lt;/p&gt;

&lt;p&gt;Nodes disagree about who's responsible for what.&lt;/p&gt;

&lt;p&gt;Someone needs to coordinate the chaos.&lt;/p&gt;

&lt;p&gt;Enter Apache ZooKeeper.&lt;/p&gt;

&lt;p&gt;ZooKeeper provides distributed coordination primitives for tasks such as naming, configuration management, synchronization, and leader election.&lt;/p&gt;

&lt;p&gt;For years, Kafka used ZooKeeper to help manage cluster metadata and coordination.&lt;/p&gt;

&lt;p&gt;Which meant that to run your distributed event streaming platform, you also needed a separate distributed coordination service.&lt;/p&gt;

&lt;p&gt;You now had a cluster to manage your cluster.&lt;/p&gt;

&lt;p&gt;And that cluster needed its own monitoring, configuration, and operational care.&lt;/p&gt;

&lt;p&gt;At some point, the infrastructure diagram began to resemble a family tree drawn by someone with a grudge.&lt;/p&gt;

&lt;p&gt;But here's the plot twist.&lt;/p&gt;

&lt;p&gt;In March 2025, Apache Kafka 4.0 eliminated its ZooKeeper dependency entirely.&lt;/p&gt;

&lt;p&gt;Kafka moved fully to KRaft, its own Raft-based metadata management architecture.&lt;/p&gt;

&lt;p&gt;So after years of operating an additional distributed system to coordinate Kafka, the Kafka project finally said:&lt;/p&gt;

&lt;p&gt;"Perhaps we could do this ourselves."&lt;/p&gt;

&lt;p&gt;ZooKeeper itself remains a useful project for other distributed systems.&lt;/p&gt;

&lt;p&gt;But Kafka's departure is a nice illustration of how the Java ecosystem evolves.&lt;/p&gt;

&lt;p&gt;First, build a powerful framework.&lt;/p&gt;

&lt;p&gt;Then build supporting infrastructure.&lt;/p&gt;

&lt;p&gt;Then build infrastructure to manage that infrastructure.&lt;/p&gt;

&lt;p&gt;Then spend several years simplifying the whole thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And we haven't even discussed Apache Flink, HBase, Hive, or the wider collection of projects that helped turn Java into the plumbing of big data.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. The Great Java IDE Wars
&lt;/h2&gt;

&lt;p&gt;Surely, with all this complexity, at least the development environment is straightforward?&lt;/p&gt;

&lt;p&gt;Of course not.&lt;/p&gt;

&lt;p&gt;Java has an impressive history of competing IDEs.&lt;/p&gt;

&lt;p&gt;And for a long time, choosing one was practically a declaration of personal identity.&lt;/p&gt;

&lt;h3&gt;
  
  
  NetBeans: The Old Guard
&lt;/h3&gt;

&lt;p&gt;NetBeans has a long history, including years under Sun Microsystems and later Oracle.&lt;/p&gt;

&lt;p&gt;It's now an Apache project.&lt;/p&gt;

&lt;p&gt;It offers an integrated Java development experience with editors, debugging, refactoring, project tools, and GUI development capabilities.&lt;/p&gt;

&lt;p&gt;For many developers, NetBeans was their introduction to serious Java programming.&lt;/p&gt;

&lt;p&gt;A comfortable place to write code.&lt;/p&gt;

&lt;p&gt;A reminder of a time when an IDE could feel like one reasonably coherent application rather than a marketplace for extensions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Eclipse: Your IDE Is Also a Platform
&lt;/h3&gt;

&lt;p&gt;Eclipse took a different approach.&lt;/p&gt;

&lt;p&gt;Its plugin architecture allowed developers to extend the environment extensively.&lt;/p&gt;

&lt;p&gt;Java Development Tools.&lt;/p&gt;

&lt;p&gt;Refactoring.&lt;/p&gt;

&lt;p&gt;Debugging.&lt;/p&gt;

&lt;p&gt;Build integration.&lt;/p&gt;

&lt;p&gt;Language support.&lt;/p&gt;

&lt;p&gt;Application development frameworks.&lt;/p&gt;

&lt;p&gt;And approximately seventeen different perspectives, views, and preferences screens.&lt;/p&gt;

&lt;p&gt;Eclipse was enormously important to enterprise Java development.&lt;/p&gt;

&lt;p&gt;It also introduced many developers to the experience of installing one plugin, discovering that it required three others, and then spending an afternoon resolving version compatibility.&lt;/p&gt;

&lt;p&gt;Your IDE needed dependency management.&lt;/p&gt;

&lt;p&gt;Which, in fairness, was excellent preparation for Java development.&lt;/p&gt;

&lt;h3&gt;
  
  
  IntelliJ IDEA: What if the IDE Actually Understood Your Code?
&lt;/h3&gt;

&lt;p&gt;Then there's IntelliJ IDEA from JetBrains.&lt;/p&gt;

&lt;p&gt;IntelliJ built a strong reputation around code analysis, refactoring, navigation, and developer productivity.&lt;/p&gt;

&lt;p&gt;It also offers first-class support for Kotlin, which makes sense given that JetBrains created the language.&lt;/p&gt;

&lt;p&gt;For many developers, IntelliJ became the preferred environment for modern Java development.&lt;/p&gt;

&lt;p&gt;Although the perpetual debate over which IDE is best remains alive and well.&lt;/p&gt;

&lt;p&gt;As with most religious disputes, empirical evidence is rarely invited to the discussion.&lt;/p&gt;

&lt;h3&gt;
  
  
  VS Code: Fine, Let's Make Everything an Extension
&lt;/h3&gt;

&lt;p&gt;And naturally, Java development is also supported in Visual Studio Code.&lt;/p&gt;

&lt;p&gt;Install the appropriate extensions, configure the JDK, set up your build system, and off you go.&lt;/p&gt;

&lt;p&gt;Which means the Java IDE wars now include a lightweight editor that can be transformed into something resembling an IDE through plugins.&lt;/p&gt;

&lt;p&gt;We've come full circle.&lt;/p&gt;

&lt;p&gt;The IDE became a platform.&lt;/p&gt;

&lt;p&gt;Then the editor became a platform.&lt;/p&gt;

&lt;p&gt;And everyone continued arguing about keyboard shortcuts.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Maven, Gradle, and the Art of Building a Build System
&lt;/h2&gt;

&lt;p&gt;Before we finish, we need to talk about building Java applications.&lt;/p&gt;

&lt;p&gt;Because writing code is only half the battle.&lt;/p&gt;

&lt;p&gt;The other half is convincing your dependencies to cooperate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Maven: XML Will Save Us
&lt;/h3&gt;

&lt;p&gt;Apache Maven brought standardized project structures, dependency management, and build lifecycles to Java.&lt;/p&gt;

&lt;p&gt;It was a major improvement over manually downloading JAR files and assembling mysterious classpaths.&lt;/p&gt;

&lt;p&gt;But Maven also embraced XML configuration.&lt;/p&gt;

&lt;p&gt;A lot of XML configuration.&lt;/p&gt;

&lt;p&gt;You could have a beautifully organized project whose build file was longer than some of its source files.&lt;/p&gt;

&lt;p&gt;Still, Maven provided consistency.&lt;/p&gt;

&lt;p&gt;And that's valuable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gradle: What if Our Build Files Were Programs?
&lt;/h3&gt;

&lt;p&gt;Gradle offered a more programmable build system, supporting Groovy and Kotlin DSLs.&lt;/p&gt;

&lt;p&gt;More flexibility.&lt;/p&gt;

&lt;p&gt;More control.&lt;/p&gt;

&lt;p&gt;Potentially less XML.&lt;/p&gt;

&lt;p&gt;Naturally, this also meant build scripts could become arbitrarily sophisticated programs with their own bugs.&lt;/p&gt;

&lt;p&gt;Because sometimes a build configuration isn't complicated enough until you can debug it.&lt;/p&gt;

&lt;p&gt;Scala developers may also encounter sbt, adding another build tool to the mix.&lt;/p&gt;

&lt;p&gt;And underneath much of this sits Maven Central and the wider ecosystem of artifact repositories, transitive dependencies, version conflicts, and the occasional library whose presence in your application nobody can explain.&lt;/p&gt;

&lt;p&gt;Java didn't invent dependency hell.&lt;/p&gt;

&lt;p&gt;But it certainly helped industrialize it.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. And Then There's Enterprise Java
&lt;/h2&gt;

&lt;p&gt;We could stop here.&lt;/p&gt;

&lt;p&gt;But that would mean ignoring a particularly entertaining corner of the ecosystem.&lt;/p&gt;

&lt;p&gt;Enterprise Java.&lt;/p&gt;

&lt;p&gt;Java EE.&lt;/p&gt;

&lt;p&gt;Jakarta EE.&lt;/p&gt;

&lt;p&gt;Spring.&lt;/p&gt;

&lt;p&gt;Spring Boot.&lt;/p&gt;

&lt;p&gt;Hibernate.&lt;/p&gt;

&lt;p&gt;Quarkus.&lt;/p&gt;

&lt;p&gt;Micronaut.&lt;/p&gt;

&lt;p&gt;And decades of arguments about dependency injection, annotations, XML configuration, and whether a sufficiently abstract factory should require another factory.&lt;/p&gt;

&lt;p&gt;Java EE eventually moved from Oracle-led stewardship to the Eclipse Foundation, becoming Jakarta EE.&lt;/p&gt;

&lt;p&gt;And because software history enjoys a good practical joke, the transition also involved moving many APIs from the &lt;code&gt;javax.*&lt;/code&gt; namespace to &lt;code&gt;jakarta.*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Which sounds simple until you're migrating an application with years of dependencies.&lt;/p&gt;

&lt;p&gt;Meanwhile, Spring built an enormous ecosystem around enterprise application development, and newer frameworks such as Quarkus and Micronaut pursued approaches tailored to modern cloud deployment.&lt;/p&gt;

&lt;p&gt;All useful technologies.&lt;/p&gt;

&lt;p&gt;All with their own philosophies.&lt;/p&gt;

&lt;p&gt;All capable of inspiring passionate architectural disagreements.&lt;/p&gt;

&lt;p&gt;At this point, the Java ecosystem contains enough competing approaches to solving enterprise application development that you could spend an entire career evaluating frameworks without ever deploying an application.&lt;/p&gt;

&lt;p&gt;Although that might itself qualify as enterprise architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java's Greatest Strength Is Also Its Greatest Joke
&lt;/h2&gt;

&lt;p&gt;After all this, it's tempting to conclude that the Java ecosystem is a confusing mess.&lt;/p&gt;

&lt;p&gt;And in some ways, it is.&lt;/p&gt;

&lt;p&gt;Multiple JVM implementations.&lt;/p&gt;

&lt;p&gt;Numerous JDK distributions.&lt;/p&gt;

&lt;p&gt;Oracle licensing policies that require careful attention.&lt;/p&gt;

&lt;p&gt;Languages ranging from Kotlin to Clojure.&lt;/p&gt;

&lt;p&gt;An enormous collection of Apache infrastructure projects.&lt;/p&gt;

&lt;p&gt;Competing IDEs.&lt;/p&gt;

&lt;p&gt;Competing build tools.&lt;/p&gt;

&lt;p&gt;Competing application frameworks.&lt;/p&gt;

&lt;p&gt;Competing opinions about nearly everything.&lt;/p&gt;

&lt;p&gt;But here's the remarkable part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Much of it actually works together.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Kotlin application can consume Java libraries.&lt;/p&gt;

&lt;p&gt;A Scala-based Spark engine can process workloads submitted through Python APIs.&lt;/p&gt;

&lt;p&gt;A compatible Java application can move between different OpenJDK distributions.&lt;/p&gt;

&lt;p&gt;A large Java codebase can survive decades of changes to operating systems, hardware, runtimes, tools, and deployment environments.&lt;/p&gt;

&lt;p&gt;That's not a trivial achievement.&lt;/p&gt;

&lt;p&gt;The JVM became one of the most successful common execution platforms in software history precisely because it allowed an extraordinary amount of innovation to happen around a relatively stable foundation.&lt;/p&gt;

&lt;p&gt;And that flexibility created competition.&lt;/p&gt;

&lt;p&gt;Competition created alternatives.&lt;/p&gt;

&lt;p&gt;Alternatives created choices.&lt;/p&gt;

&lt;p&gt;And choices created endless arguments.&lt;/p&gt;

&lt;p&gt;Which brings us back to Java's famous promise.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Write once, run anywhere.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thirty years later, we've added a few practical qualifications.&lt;/p&gt;

&lt;p&gt;Write once.&lt;/p&gt;

&lt;p&gt;Choose a JDK distribution.&lt;/p&gt;

&lt;p&gt;Check the license.&lt;/p&gt;

&lt;p&gt;Select a JVM.&lt;/p&gt;

&lt;p&gt;Pick an IDE.&lt;/p&gt;

&lt;p&gt;Choose a build tool.&lt;/p&gt;

&lt;p&gt;Resolve your dependencies.&lt;/p&gt;

&lt;p&gt;Decide which framework you believe in.&lt;/p&gt;

&lt;p&gt;Configure your deployment environment.&lt;/p&gt;

&lt;p&gt;And then...&lt;/p&gt;

&lt;p&gt;Run anywhere.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jvm</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Java: When Life Gives You Problems, Build a ProblemFactory</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Fri, 06 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/java-when-life-gives-you-problems-build-a-problemfactory-534a</link>
      <guid>https://dev.to/jlmartel/java-when-life-gives-you-problems-build-a-problemfactory-534a</guid>
      <description>&lt;p&gt;We've already explored PHP's questionable decisions, JavaScript's complicated relationship with logic, Python's ability to produce confidently incorrect results, and C#'s enterprise-grade surprises.&lt;/p&gt;

&lt;p&gt;Now it's Java's turn.&lt;/p&gt;

&lt;p&gt;Java is different.&lt;/p&gt;

&lt;p&gt;Java is serious.&lt;/p&gt;

&lt;p&gt;Java is strongly typed, object-oriented, carefully specified, and famously obsessed with backward compatibility.&lt;/p&gt;

&lt;p&gt;This is a language that makes you declare what things are before you're allowed to do anything with them.&lt;/p&gt;

&lt;p&gt;Surely, then, Java should be relatively free of surprises?&lt;/p&gt;

&lt;p&gt;Well.&lt;/p&gt;

&lt;p&gt;Let's talk about that.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. String Concatenation: Apparently, &lt;code&gt;+&lt;/code&gt; Needed a Performance Review
&lt;/h2&gt;

&lt;p&gt;Let's start with something that every Java developer has written thousands of times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfectly reasonable.&lt;/p&gt;

&lt;p&gt;Now consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Total: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total: 12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" total"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 total
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same numbers. Same operator. Different arithmetic.&lt;/p&gt;

&lt;p&gt;Because Java evaluates these expressions from left to right, and once a string enters the expression, &lt;code&gt;+&lt;/code&gt; becomes string concatenation.&lt;/p&gt;

&lt;p&gt;Fine. We can live with that.&lt;/p&gt;

&lt;p&gt;But Java has another surprise waiting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Meet StringBuilder
&lt;/h3&gt;

&lt;p&gt;Java strings are immutable.&lt;/p&gt;

&lt;p&gt;Once created, a &lt;code&gt;String&lt;/code&gt; cannot be modified.&lt;/p&gt;

&lt;p&gt;So what happens when you repeatedly append characters?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conceptually, each iteration creates a new string containing the accumulated result plus the new value.&lt;/p&gt;

&lt;p&gt;As the string grows, increasingly large amounts of data may need to be deal with by the jvm.&lt;/p&gt;

&lt;p&gt;That's potentially a lot of unnecessary work.&lt;/p&gt;

&lt;p&gt;Java developers have traditionally solved this problem with &lt;code&gt;StringBuilder&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;StringBuilder&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringBuilder&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;append&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;finalResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One mutable buffer, rather than repeatedly rebuilding an immutable string.&lt;/p&gt;

&lt;p&gt;Much better for this kind of workload.&lt;/p&gt;

&lt;p&gt;For years, the conventional advice was simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;+&lt;/code&gt; for simple concatenation. Use &lt;code&gt;StringBuilder&lt;/code&gt; when you're building strings in loops.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But Java being Java, it couldn't leave things quite that straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plot Twist: The Compiler Was Already Helping
&lt;/h3&gt;

&lt;p&gt;Before Java 9, the Java compiler typically translated ordinary string concatenation expressions into &lt;code&gt;StringBuilder&lt;/code&gt; operations behind the scenes.&lt;/p&gt;

&lt;p&gt;So this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wasn't necessarily doing the naive string-building work you might imagine.&lt;/p&gt;

&lt;p&gt;Then Java 9 introduced a new concatenation mechanism using &lt;code&gt;invokedynamic&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This allowed the runtime to select and optimize string-concatenation strategies more flexibly, without requiring the compiler to generate an explicit &lt;code&gt;StringBuilder&lt;/code&gt; sequence.&lt;/p&gt;

&lt;p&gt;So now we've got:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strings that can't be changed.&lt;/li&gt;
&lt;li&gt;A mutable class specifically for building strings.&lt;/li&gt;
&lt;li&gt;A compiler that historically generated that class automatically.&lt;/li&gt;
&lt;li&gt;A newer mechanism that can optimize concatenation differently.&lt;/li&gt;
&lt;li&gt;Performance characteristics that depend on the expression, loop structure, compiler, and runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Congratulations. We've turned joining two strings into a discussion about bytecode generation.&lt;/p&gt;

&lt;p&gt;To be fair, modern Java handles ordinary &lt;code&gt;+&lt;/code&gt; concatenation quite well.&lt;/p&gt;

&lt;p&gt;The real performance concern remains repeated accumulation into a growing string, particularly in loops. An explicit &lt;code&gt;StringBuilder&lt;/code&gt; is still a sensible choice there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Java's simple syntax can hide considerable compiler and runtime sophistication. And performance advice from 2005 doesn't always survive contact with modern JVMs.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Two Integers Are Equal. Until They Aren't.
&lt;/h2&gt;

&lt;p&gt;Here's one of Java's most entertaining party tricks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay.&lt;/p&gt;

&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a typical JVM configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait. What?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two integers containing the same number can compare equal or unequal depending on the number.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The trick is that &lt;code&gt;Integer&lt;/code&gt; isn't the same thing as &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int&lt;/code&gt; is a primitive value.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Integer&lt;/code&gt; is an object wrapper around an integer value.&lt;/p&gt;

&lt;p&gt;And for objects, &lt;code&gt;==&lt;/code&gt; checks reference identity, not numerical equality.&lt;/p&gt;

&lt;p&gt;But Java caches certain &lt;code&gt;Integer&lt;/code&gt; objects.&lt;/p&gt;

&lt;p&gt;Specifically, &lt;code&gt;Integer.valueOf()&lt;/code&gt; is guaranteed to cache values from -128 through 127.&lt;/p&gt;

&lt;p&gt;Autoboxing uses this mechanism.&lt;/p&gt;

&lt;p&gt;So when you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both variables normally refer to the same cached object.&lt;/p&gt;

&lt;p&gt;But outside the guaranteed range, Java is allowed to create separate objects.&lt;/p&gt;

&lt;p&gt;Hence the surprising result for 128.&lt;/p&gt;

&lt;p&gt;There's one more complication: implementations are permitted to cache additional values, so 128 isn't guaranteed to produce &lt;code&gt;false&lt;/code&gt; everywhere.&lt;/p&gt;

&lt;p&gt;Which makes relying on this behavior an even worse idea.&lt;/p&gt;

&lt;p&gt;The correct comparison:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or compare the underlying primitive values when appropriate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Java, &lt;code&gt;==&lt;/code&gt; can mean numerical equality or object identity depending on the types involved. And integer caching makes that distinction particularly easy to overlook.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;Arrays.asList()&lt;/code&gt; Gives You a List. Terms and Conditions Apply.
&lt;/h2&gt;

&lt;p&gt;Here's a perfectly ordinary bit of Java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;

&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You now have a list.&lt;/p&gt;

&lt;p&gt;And lists are mutable collections, right?&lt;/p&gt;

&lt;p&gt;Let's add someone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dave"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.lang.UnsupportedOperationException
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excuse me?&lt;/p&gt;

&lt;p&gt;We created a list.&lt;/p&gt;

&lt;p&gt;We tried to add an item.&lt;/p&gt;

&lt;p&gt;And Java objected.&lt;/p&gt;

&lt;p&gt;Here's the explanation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Arrays.asList()&lt;/code&gt; returns a &lt;strong&gt;fixed-size list backed by the original array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It isn't a regular, independently resizable &lt;code&gt;ArrayList&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can replace existing elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Zoe"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That works.&lt;/p&gt;

&lt;p&gt;But you can't change the list's size.&lt;/p&gt;

&lt;p&gt;No adding.&lt;/p&gt;

&lt;p&gt;No removing.&lt;/p&gt;

&lt;p&gt;And here's the really interesting part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Zoe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing the list changed the original array!&lt;/p&gt;

&lt;p&gt;Because they're backed by the same storage.&lt;/p&gt;

&lt;p&gt;The reverse is true too. Change an element in the array, and the list reflects that change.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;Arrays.asList()&lt;/code&gt; gives you something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Looks like a normal list.&lt;/li&gt;
&lt;li&gt;Lets you replace elements.&lt;/li&gt;
&lt;li&gt;Refuses to grow or shrink.&lt;/li&gt;
&lt;li&gt;Shares its underlying data with the original array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Java also offers &lt;code&gt;List.of()&lt;/code&gt;, which creates an unmodifiable list.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;new ArrayList&amp;lt;&amp;gt;(...)&lt;/code&gt;, which creates a separate, resizable list.&lt;/p&gt;

&lt;p&gt;Three ways to obtain something called a list, with three different sets of rules.&lt;/p&gt;

&lt;p&gt;The fix when you want an independent, resizable list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;asList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Java, knowing that something implements &lt;code&gt;List&lt;/code&gt; doesn't tell you everything about what operations it supports.&lt;/p&gt;

&lt;p&gt;Sometimes the interface makes a promise that the implementation politely declines to fulfill.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Removing an Integer Can Remove the Wrong Integer
&lt;/h2&gt;

&lt;p&gt;This one is genuinely nasty.&lt;/p&gt;

&lt;p&gt;Suppose you have a list of numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you want to remove the number 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens?&lt;/p&gt;

&lt;p&gt;The list becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 55]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can kind of guess this one.&lt;/p&gt;

&lt;p&gt;Our friend &lt;code&gt;List&lt;/code&gt; has two overloaded &lt;code&gt;remove()&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;One removes an element by index.&lt;/p&gt;

&lt;p&gt;The other removes an element by value.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when you pass the literal integer &lt;code&gt;1&lt;/code&gt;, Java selects the overload accepting a primitive &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Means:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Remove the element at index 1."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Remove the integer whose value is 1."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you actually want to remove the value 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;valueOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Java selects the object-based overload.&lt;/p&gt;

&lt;p&gt;Same method name.&lt;/p&gt;

&lt;p&gt;Same apparent kind of argument.&lt;/p&gt;

&lt;p&gt;Completely different operation.&lt;/p&gt;

&lt;p&gt;And because both operations are perfectly valid, the compiler has absolutely nothing to complain about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Method overloading, autoboxing, and collection APIs can combine into a surprisingly effective footgun.&lt;/p&gt;

&lt;p&gt;Sometimes Java's type system is so helpful it confidently does the wrong thing you explicitly asked it to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Two Decimal Numbers Can Be Equal but Not Equal
&lt;/h2&gt;

&lt;p&gt;For our final example, let's involve money.&lt;/p&gt;

&lt;p&gt;Java provides &lt;code&gt;BigDecimal&lt;/code&gt; for decimal arithmetic where precision matters.&lt;/p&gt;

&lt;p&gt;Unlike ordinary binary floating-point numbers, &lt;code&gt;BigDecimal&lt;/code&gt; can represent decimal values exactly.&lt;/p&gt;

&lt;p&gt;Very useful for financial applications.&lt;/p&gt;

&lt;p&gt;Now consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.0"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.00"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seriously?&lt;/p&gt;

&lt;p&gt;Two dollars is not equal to two dollars?&lt;/p&gt;

&lt;p&gt;Now try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compareTo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the numbers compare as equal.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;equals()&lt;/code&gt; says they're different.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;BigDecimal&lt;/code&gt; stores both an unscaled numerical value and a scale.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2.0&lt;/code&gt; and &lt;code&gt;2.00&lt;/code&gt; represent the same numerical value, but they have different scales.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;BigDecimal.equals()&lt;/code&gt; considers scale part of equality.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;compareTo()&lt;/code&gt; compares their numerical values instead.&lt;/p&gt;

&lt;p&gt;That's actually defensible. Scale can matter for certain decimal calculations.&lt;/p&gt;

&lt;p&gt;But it creates a wonderfully awkward consequence.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;hashSet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

&lt;span class="n"&gt;hashSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.0"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="n"&gt;hashSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.00"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hashSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;treeSet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TreeSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

&lt;span class="n"&gt;treeSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.0"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="n"&gt;treeSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2.00"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;treeSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Two sets. Same values. Different answers about how many distinct elements exist.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HashSet&lt;/code&gt; uses &lt;code&gt;equals()&lt;/code&gt; and &lt;code&gt;hashCode()&lt;/code&gt; to determine uniqueness.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TreeSet&lt;/code&gt; uses ordering comparisons, which for &lt;code&gt;BigDecimal&lt;/code&gt; normally means &lt;code&gt;compareTo()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;BigDecimal&lt;/code&gt; explicitly defines those operations differently.&lt;/p&gt;

&lt;p&gt;So Java gives you two completely legitimate definitions of uniqueness for the same numerical values.&lt;/p&gt;

&lt;p&gt;Imagine discovering that while reconciling financial records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Equality, numerical comparison, and collection uniqueness aren't necessarily interchangeable. With &lt;code&gt;BigDecimal&lt;/code&gt;, choosing the wrong one can produce very real business problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Is Predictable. You Just Need to Predict the Right Things.
&lt;/h2&gt;

&lt;p&gt;Here's what makes Java interesting.&lt;/p&gt;

&lt;p&gt;Unlike JavaScript, Java generally doesn't let values wander casually between unrelated types.&lt;/p&gt;

&lt;p&gt;Unlike PHP, it doesn't enthusiastically reinterpret everything based on context.&lt;/p&gt;

&lt;p&gt;And unlike Python, it tends to insist that you explain exactly what you're trying to do.&lt;/p&gt;

&lt;p&gt;Java is explicit.&lt;/p&gt;

&lt;p&gt;Java is disciplined.&lt;/p&gt;

&lt;p&gt;Java is designed to make large programs easier to reason about.&lt;/p&gt;

&lt;p&gt;And yet...&lt;/p&gt;

&lt;p&gt;An integer can be identical to another integer until you increase it by one.&lt;/p&gt;

&lt;p&gt;A list can refuse to let you add anything.&lt;/p&gt;

&lt;p&gt;Removing a number can remove a completely different number.&lt;/p&gt;

&lt;p&gt;Two decimal values can be equal according to one method and unequal according to another.&lt;/p&gt;

&lt;p&gt;And joining strings can involve compiler transformations, runtime call sites, and an optimization discussion that lasts longer than the code itself.&lt;/p&gt;

&lt;p&gt;None of this is random.&lt;/p&gt;

&lt;p&gt;There are carefully documented reasons for every behavior.&lt;/p&gt;

&lt;p&gt;But that doesn't make the surprises any less entertaining.&lt;/p&gt;

&lt;p&gt;In fact, it makes them more interesting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java is a language where even the weirdness comes with a specification.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  But Wait. Which Java Are We Talking About?
&lt;/h2&gt;

&lt;p&gt;There's one more twist.&lt;/p&gt;

&lt;p&gt;We've spent this article discussing Java, the programming language.&lt;/p&gt;

&lt;p&gt;But Java is also commonly used to describe an entire development platform.&lt;/p&gt;

&lt;p&gt;And that platform has a rather complicated family tree.&lt;/p&gt;

&lt;p&gt;For starters, there's the JVM: the Java Virtual Machine.&lt;/p&gt;

&lt;p&gt;The thing that executes Java bytecode.&lt;/p&gt;

&lt;p&gt;Except there isn't just one implementation of the JVM.&lt;/p&gt;

&lt;p&gt;There's HotSpot, the familiar JVM used by most OpenJDK distributions.&lt;/p&gt;

&lt;p&gt;There's Eclipse OpenJ9, a separate JVM implementation with different approaches to memory management, startup performance, and garbage collection.&lt;/p&gt;

&lt;p&gt;Then there's GraalVM, which builds on HotSpot while offering advanced compilation technology and Native Image, a way to compile Java applications into native executables that don't require a JVM at runtime.&lt;/p&gt;

&lt;p&gt;And that's before we get into the different JDK distributions.&lt;/p&gt;

&lt;p&gt;Oracle JDK.&lt;/p&gt;

&lt;p&gt;Eclipse Temurin.&lt;/p&gt;

&lt;p&gt;Amazon Corretto.&lt;/p&gt;

&lt;p&gt;Azul Zulu.&lt;/p&gt;

&lt;p&gt;Microsoft's Build of OpenJDK.&lt;/p&gt;

&lt;p&gt;Those are distributions rather than entirely separate JVM implementations, but their packaging, support, licensing, and release policies can differ.&lt;/p&gt;

&lt;p&gt;And then there's the small matter of the languages.&lt;/p&gt;

&lt;p&gt;Because the Java Virtual Machine doesn't actually require you to write Java.&lt;/p&gt;

&lt;p&gt;You can use Kotlin.&lt;/p&gt;

&lt;p&gt;Scala.&lt;/p&gt;

&lt;p&gt;Clojure.&lt;/p&gt;

&lt;p&gt;And plenty of others.&lt;/p&gt;

&lt;p&gt;So now we have one language, multiple JVM implementations, multiple JDK distributions, multiple languages targeting the JVM, and an alternative compilation model that can eliminate the need for a running JVM altogether.&lt;/p&gt;

&lt;p&gt;Remember Java's original promise?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write once, run anywhere.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Turns out the more interesting question is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run where, on which JVM, from which vendor, using which language?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that's a rabbit hole worthy of its own article.&lt;/p&gt;

&lt;p&gt;Coming next: the Java ecosystem, where the language is only the beginning of the confusion.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jvm</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>C#: Your Code Compiled. That's Where the Good News Ends.</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Thu, 05 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/c-your-code-compiled-thats-where-the-good-news-ends-21bf</link>
      <guid>https://dev.to/jlmartel/c-your-code-compiled-thats-where-the-good-news-ends-21bf</guid>
      <description>&lt;p&gt;We've already explored PHP's questionable decisions, JavaScript's complicated relationship with reality, and Python's talent for producing beautifully formatted mistakes.&lt;/p&gt;

&lt;p&gt;Now it's C#'s turn.&lt;/p&gt;

&lt;p&gt;And C# is a different kind of beast.&lt;/p&gt;

&lt;p&gt;Unlike some of its more chaotic cousins, C# has always presented itself as a serious, carefully engineered programming language.&lt;/p&gt;

&lt;p&gt;Strong typing. Managed memory. A sophisticated compiler. A comprehensive runtime. The kind of language that wears a suit to work.&lt;/p&gt;

&lt;p&gt;It also has some really weird behavior hiding beneath that professional exterior.&lt;/p&gt;

&lt;p&gt;But before we get into that, a little history.&lt;/p&gt;

&lt;p&gt;C# arrived in 2002 as part of Microsoft's original .NET Framework, an ecosystem closely associated with Windows and Microsoft's proprietary development tools.&lt;/p&gt;

&lt;p&gt;For years, C# was the language many developers associated with enterprise Windows applications, corporate IT departments, and Visual Studio.&lt;/p&gt;

&lt;p&gt;Then something unexpected happened.&lt;/p&gt;

&lt;p&gt;Microsoft embraced open source.&lt;/p&gt;

&lt;p&gt;.NET Core arrived in 2016 as an open-source, cross-platform implementation. In 2020, .NET 5 dropped the "Core" name, establishing the modern .NET platform.&lt;/p&gt;

&lt;p&gt;Today, C# runs on Linux, macOS, Windows, and plenty of places its original developers probably never imagined. Steve Ballmer would turn in his grave if he was already dead.&lt;/p&gt;

&lt;p&gt;The full story of how Microsoft's development ecosystem went from Windows-centric and largely proprietary to open-source and cross-platform deserves its own article.&lt;/p&gt;

&lt;p&gt;We'll get to that.&lt;/p&gt;

&lt;p&gt;For now, let's explore five ways C# can make perfectly valid code do something completely unexpected.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A Loop That Remembers the Wrong Number
&lt;/h2&gt;

&lt;p&gt;Let's start with something innocent.&lt;/p&gt;

&lt;p&gt;You want to create three actions, each printing a different number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;actions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What would you expect?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reasonable.&lt;/p&gt;

&lt;p&gt;Here's what you actually get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
3
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every action prints 3, even though the loop only ran for values 0, 1, and 2.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The culprit is closure capture.&lt;/p&gt;

&lt;p&gt;When you create a lambda expression referencing a local variable, C# captures the &lt;em&gt;variable&lt;/em&gt;, not a snapshot of its value.&lt;/p&gt;

&lt;p&gt;All three lambdas reference the same &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And by the time you invoke them, the loop has finished, leaving &lt;code&gt;i&lt;/code&gt; equal to 3.&lt;/p&gt;

&lt;p&gt;The fix is to create a new variable inside the loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;captured&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;captured&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now each lambda captures a different variable.&lt;/p&gt;

&lt;p&gt;But here's the particularly interesting part.&lt;/p&gt;

&lt;p&gt;Modern C# handles &lt;code&gt;foreach&lt;/code&gt; differently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;actions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since C# 5, each iteration of a &lt;code&gt;foreach&lt;/code&gt; loop gets its own iteration variable for closure capture.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;for&lt;/code&gt; loops retain their original behavior.&lt;/p&gt;

&lt;p&gt;Same language. Similar loops. Different closure semantics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Closures capture variables, not values, and apparently the exact type of loop matters more than you'd expect.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;async&lt;/code&gt; Doesn't Mean What You Think It Means
&lt;/h2&gt;

&lt;p&gt;C# has excellent support for asynchronous programming.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords make it possible to write asynchronous operations that look almost like ordinary sequential code.&lt;/p&gt;

&lt;p&gt;But there's a common misunderstanding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marking a method &lt;code&gt;async&lt;/code&gt; doesn't automatically make it run on another thread.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In fact, an async method begins executing synchronously.&lt;/p&gt;

&lt;p&gt;Let's demonstrate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;gate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;TaskCompletionSource&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;DoWork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Started"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;gate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Resumed"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;DoWork&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Caller continues"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;gate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Started
Caller continues
Resumed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that &lt;code&gt;"Started"&lt;/code&gt; appears before &lt;code&gt;"Caller continues"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Even though &lt;code&gt;DoWork()&lt;/code&gt; is async.&lt;/p&gt;

&lt;p&gt;That's because an async method executes normally until it encounters an &lt;code&gt;await&lt;/code&gt; whose operation hasn't completed.&lt;/p&gt;

&lt;p&gt;Only then does it suspend and return control to the caller.&lt;/p&gt;

&lt;p&gt;If the awaited operation is already complete, the method may continue executing synchronously.&lt;/p&gt;

&lt;p&gt;And if there's no &lt;code&gt;await&lt;/code&gt; at all, the method can execute entirely synchronously.&lt;/p&gt;

&lt;p&gt;Which makes &lt;code&gt;async&lt;/code&gt; a rather misleading name if you're expecting automatic background execution.&lt;/p&gt;

&lt;p&gt;It enables asynchronous control flow. It doesn't magically create a new thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; &lt;code&gt;async&lt;/code&gt; is about how execution can be suspended and resumed, not necessarily where that execution happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. C# Lets You Store an Integer in a String Array. Until You Try.
&lt;/h2&gt;

&lt;p&gt;C# is strongly typed.&lt;/p&gt;

&lt;p&gt;The compiler is supposed to protect us from putting the wrong kinds of things into the wrong places.&lt;/p&gt;

&lt;p&gt;And generally, it does a pretty good job.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This compiles.&lt;/p&gt;

&lt;p&gt;No warnings. No complaints.&lt;/p&gt;

&lt;p&gt;A string array can be assigned to a variable of type &lt;code&gt;object[]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's because C# arrays are &lt;em&gt;covariant&lt;/em&gt; for reference types.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;string&lt;/code&gt; derives from &lt;code&gt;object&lt;/code&gt;, a &lt;code&gt;string[]&lt;/code&gt; can be treated as an &lt;code&gt;object[]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So far, so good.&lt;/p&gt;

&lt;p&gt;Now let's try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compiler accepts it.&lt;/p&gt;

&lt;p&gt;After all, an integer can be boxed as an object.&lt;/p&gt;

&lt;p&gt;But at runtime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.ArrayTypeMismatchException
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You've written type-correct code that violates the actual type of the array.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The array is still fundamentally a &lt;code&gt;string[]&lt;/code&gt;, regardless of the reference used to access it.&lt;/p&gt;

&lt;p&gt;The runtime checks assignments to protect the array from incompatible elements.&lt;/p&gt;

&lt;p&gt;And it throws when you attempt to store an integer.&lt;/p&gt;

&lt;p&gt;The behavior is deliberate and comes from the type system's historical design.&lt;/p&gt;

&lt;p&gt;Modern generic collections generally avoid this problem by using different variance rules.&lt;/p&gt;

&lt;p&gt;But arrays still have to preserve their existing behavior for compatibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Static type safety doesn't mean every type-related problem can be detected at compile time. Sometimes the runtime has to finish the compiler's job.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. You Can Call a Method That Changes Nothing
&lt;/h2&gt;

&lt;p&gt;Here's one of my favorites.&lt;/p&gt;

&lt;p&gt;C# has value types called structs.&lt;/p&gt;

&lt;p&gt;Unlike classes, which are reference types, structs have value semantics.&lt;/p&gt;

&lt;p&gt;That means copies can appear in places you might not expect.&lt;/p&gt;

&lt;p&gt;Consider this simple counter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;++;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing unusual.&lt;/p&gt;

&lt;p&gt;Now let's put it inside a class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And try to increment it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actual:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You called a method that modifies the counter, but the counter didn't change.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And no exception was thrown.&lt;/p&gt;

&lt;p&gt;Here's the trick.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Counter&lt;/code&gt; field is marked &lt;code&gt;readonly&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;Counter&lt;/code&gt; is a mutable struct, the compiler creates a &lt;em&gt;defensive copy&lt;/em&gt; before calling its mutating method through that readonly field.&lt;/p&gt;

&lt;p&gt;The method increments the copy.&lt;/p&gt;

&lt;p&gt;Then the copy disappears.&lt;/p&gt;

&lt;p&gt;The original counter remains unchanged.&lt;/p&gt;

&lt;p&gt;Your code compiled successfully, executed successfully, and accomplished absolutely nothing.&lt;/p&gt;

&lt;p&gt;To avoid this, mutable structs need to be handled carefully. Where appropriate, use an immutable or &lt;code&gt;readonly struct&lt;/code&gt;, or use a class when reference semantics are what you actually need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Value types can introduce invisible copies, and mutating an invisible copy is an excellent way to accomplish nothing with confidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. One Exception Can Permanently Poison an Entire Type
&lt;/h2&gt;

&lt;p&gt;Let's finish with something particularly unpleasant.&lt;/p&gt;

&lt;p&gt;C# supports static constructors.&lt;/p&gt;

&lt;p&gt;They're executed automatically when a type needs to be initialized, typically before its first relevant use.&lt;/p&gt;

&lt;p&gt;You can use them to initialize shared state.&lt;/p&gt;

&lt;p&gt;But what happens if a static constructor throws an exception?&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Configuration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Configuration failed!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"Ready"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The runtime throws a &lt;code&gt;TypeInitializationException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's reasonable. Initialization failed.&lt;/p&gt;

&lt;p&gt;But suppose you catch the exception, fix whatever caused the problem, and try again.&lt;/p&gt;

&lt;p&gt;Too late.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The runtime won't retry the static constructor.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A static constructor runs at most once per type initialization context.&lt;/p&gt;

&lt;p&gt;If it throws, the type remains uninitialized and unusable for the lifetime of that context, ordinarily the application's current runtime lifetime.&lt;/p&gt;

&lt;p&gt;Subsequent attempts to access the type fail again.&lt;/p&gt;

&lt;p&gt;This is particularly nasty if static initialization depends on something transient, like a configuration file, an external service, or a database connection.&lt;/p&gt;

&lt;p&gt;A temporary problem can become a permanent failure for that running application.&lt;/p&gt;

&lt;p&gt;The exception may be recoverable in theory.&lt;/p&gt;

&lt;p&gt;But the type isn't.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Static constructors should be boring, predictable, and extremely unlikely to fail. One bad initialization can leave an entire type unusable.&lt;/p&gt;

&lt;h2&gt;
  
  
  C# Is Weird. But .NET Might Be Even More Interesting.
&lt;/h2&gt;

&lt;p&gt;Here's what makes C# different from some of the languages we've covered.&lt;/p&gt;

&lt;p&gt;Most of these behaviors aren't the result of loose typing or a particularly cavalier attitude toward language design.&lt;/p&gt;

&lt;p&gt;They're the consequences of deliberate engineering decisions.&lt;/p&gt;

&lt;p&gt;Closures capture variables because that enables useful programming patterns.&lt;/p&gt;

&lt;p&gt;Async methods execute synchronously until suspension because asynchronous programming doesn't inherently require additional threads.&lt;/p&gt;

&lt;p&gt;Array covariance exists partly for historical compatibility.&lt;/p&gt;

&lt;p&gt;Structs use value semantics because value types provide important performance and design benefits.&lt;/p&gt;

&lt;p&gt;And static constructors run once because type initialization needs predictable lifecycle guarantees.&lt;/p&gt;

&lt;p&gt;Every feature has a rationale.&lt;/p&gt;

&lt;p&gt;The weirdness appears when those rationales collide with a developer's perfectly reasonable expectations.&lt;/p&gt;

&lt;p&gt;But there's another fascinating story hiding behind C#.&lt;/p&gt;

&lt;p&gt;When the original .NET Framework appeared in 2002, Microsoft's development ecosystem was fundamentally different from what it is today.&lt;/p&gt;

&lt;p&gt;Windows was central.&lt;/p&gt;

&lt;p&gt;Visual Studio was the dominant development experience.&lt;/p&gt;

&lt;p&gt;The framework itself was proprietary.&lt;/p&gt;

&lt;p&gt;Today, modern .NET is open source, cross-platform, and developed in public.&lt;/p&gt;

&lt;p&gt;Even the compiler is open source.&lt;/p&gt;

&lt;p&gt;And somewhere along the way, Microsoft managed to create one of the more confusing naming histories in software development.&lt;/p&gt;

&lt;p&gt;.NET Framework.&lt;/p&gt;

&lt;p&gt;.NET Core.&lt;/p&gt;

&lt;p&gt;.NET Standard.&lt;/p&gt;

&lt;p&gt;.NET 5.&lt;/p&gt;

&lt;p&gt;And yes, they skipped .NET Core 4 partly to avoid confusion with .NET Framework 4.x.&lt;/p&gt;

&lt;p&gt;Because apparently the solution to confusing names was more confusing names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That's a story worth exploring next.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How did Microsoft's proprietary Windows development platform become an open-source, cross-platform ecosystem?&lt;/p&gt;

&lt;p&gt;What actually changed?&lt;/p&gt;

&lt;p&gt;What's the difference between .NET Framework and modern .NET?&lt;/p&gt;

&lt;p&gt;And why did Microsoft decide to open-source something that had been so central to its development strategy?&lt;/p&gt;

&lt;p&gt;We'll tackle that in the next installment.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Python: while...else and Other Crimes Against Intuition</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Mon, 02 Nov 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/python-whileelse-and-other-crimes-against-intuition-33pd</link>
      <guid>https://dev.to/jlmartel/python-whileelse-and-other-crimes-against-intuition-33pd</guid>
      <description>&lt;p&gt;We've already explored some of PHP's more questionable life choices and JavaScript's remarkable ability to make perfectly valid code look like a practical joke.&lt;/p&gt;

&lt;p&gt;Now it's Python's turn.&lt;/p&gt;

&lt;p&gt;Python is particularly interesting because it has become the language of choice for data science, machine learning, and AI worlds.&lt;/p&gt;

&lt;p&gt;And understandably so.&lt;/p&gt;

&lt;p&gt;It's readable. It's expressive. Its ecosystem is extraordinary. You can go from a CSV file to a predictive model in 5 lines of code.&lt;/p&gt;

&lt;p&gt;But Python has a few surprises of its own.&lt;/p&gt;

&lt;p&gt;And when you're working with data, some of those surprises can produce results that are &lt;strong&gt;plausible, reproducible, and completely wrong&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Which is arguably worse than code that simply crashes.&lt;/p&gt;

&lt;p&gt;Here are five of my favorites.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One Change to a Matrix Changes Every Row
&lt;/h2&gt;

&lt;p&gt;Let's start with something familiar to anyone who works with tabular data.&lt;/p&gt;

&lt;p&gt;You need a 3×3 matrix initialized to zero.&lt;/p&gt;

&lt;p&gt;Easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[0, 0, 0],
 [0, 0, 0],
 [0, 0, 0]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect.&lt;/p&gt;

&lt;p&gt;Now let's change one value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'd expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[99, 0, 0],
 [ 0, 0, 0],
 [ 0, 0, 0]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[99, 0, 0],
 [99, 0, 0],
 [99, 0, 0]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait. What?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You modified one cell, and an entire column changed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The explanation is simple, but rather unpleasant.&lt;/p&gt;

&lt;p&gt;When Python evaluates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't create three independent inner lists.&lt;/p&gt;

&lt;p&gt;It creates one list and repeats the &lt;em&gt;reference&lt;/em&gt; to that list three times.&lt;/p&gt;

&lt;p&gt;All three rows are actually the same object.&lt;/p&gt;

&lt;p&gt;You can prove it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now each row is independent.&lt;/p&gt;

&lt;p&gt;To be clear, this is a native Python list problem, not how NumPy array construction works. But it's exactly the kind of mistake that can creep into preprocessing code, custom numerical algorithms, or quick exploratory scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Repeating a list doesn't necessarily create independent copies. Sometimes it just gives the same object several different places to hide.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Your Function Remembers Things You Never Asked It to Remember
&lt;/h2&gt;

&lt;p&gt;Suppose you're collecting results from an experiment.&lt;/p&gt;

&lt;p&gt;You write a little helper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt;
    &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks perfectly reasonable.&lt;/p&gt;

&lt;p&gt;Now you run two experiments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;record_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Experiment A&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;record_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Experiment B&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['Experiment A']
['Experiment A', 'Experiment B']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe that's what you wanted.&lt;/p&gt;

&lt;p&gt;But what if the second experiment was supposed to have its own history?&lt;/p&gt;

&lt;p&gt;Too bad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python has been maintaining a shared list behind your back.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The culprit is the default argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python, default argument values are evaluated when the function is &lt;em&gt;defined&lt;/em&gt;, not every time the function is called.&lt;/p&gt;

&lt;p&gt;That list is created once and reused across calls that omit the argument.&lt;/p&gt;

&lt;p&gt;Which means your convenient little helper has accidentally acquired state.&lt;/p&gt;

&lt;p&gt;In a data science workflow, that could mean results from one experiment leaking into another.&lt;/p&gt;

&lt;p&gt;The solution is the familiar &lt;code&gt;None&lt;/code&gt; pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now every call without an explicit history gets a fresh list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Python's default arguments aren't necessarily defaults in the sense you expect. Mutable defaults can become accidental storage devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;True&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, and &lt;code&gt;1.0&lt;/code&gt; Are the Same Dictionary Key
&lt;/h2&gt;

&lt;p&gt;Here's an especially entertaining one for anyone working with categorical data.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;boolean&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;integer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;float&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three keys, three types.&lt;/p&gt;

&lt;p&gt;You might reasonably expect three entries.&lt;/p&gt;

&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{True: 'float'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One entry.&lt;/p&gt;

&lt;p&gt;The last value wins.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because Python considers all three keys equal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="bp"&gt;True&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;      &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;       &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;    &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And their hashes are equal, too.&lt;/p&gt;

&lt;p&gt;Even more interesting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, &lt;code&gt;bool&lt;/code&gt; is actually a subclass of &lt;code&gt;int&lt;/code&gt; in Python.&lt;/p&gt;

&lt;p&gt;So dictionaries treat these values as equivalent keys.&lt;/p&gt;

&lt;p&gt;The first key object remains, but its value gets overwritten twice.&lt;/p&gt;

&lt;p&gt;This can matter when you're mixing boolean indicators with numeric category identifiers.&lt;/p&gt;

&lt;p&gt;If your categories need to distinguish between a boolean &lt;code&gt;True&lt;/code&gt; and the integer &lt;code&gt;1&lt;/code&gt;, a plain dictionary won't do it automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Python, equality and identity are different concepts, and dictionaries care about equality and hashing, not whether two keys have different types.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Python Has a &lt;code&gt;while...else&lt;/code&gt;. Because Apparently &lt;code&gt;if&lt;/code&gt; Wasn't Enough.
&lt;/h2&gt;

&lt;p&gt;Most programmers are familiar with &lt;code&gt;if...else&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some languages have &lt;code&gt;try...else&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Python went full "hold my beer" and decided that loops should have an &lt;code&gt;else&lt;/code&gt; too.&lt;/p&gt;

&lt;p&gt;Yes, really.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This will never run&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;But this will!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;But this will!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, that's a little unusual, but not completely insane.&lt;/p&gt;

&lt;p&gt;Now try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Loop finished!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
Loop finished!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait. What?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;while&lt;/code&gt; condition was "true", the loop executed, and somehow the &lt;code&gt;else&lt;/code&gt; block still ran.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Welcome to Python.&lt;/p&gt;

&lt;p&gt;Here's the secret: a loop's &lt;code&gt;else&lt;/code&gt; clause doesn't mean what you'd normally expect from the word "else."&lt;/p&gt;

&lt;p&gt;It actually means something closer to &lt;strong&gt;"the loop completed without encountering a &lt;code&gt;break&lt;/code&gt;."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Finished!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, the &lt;code&gt;else&lt;/code&gt; block doesn't execute.&lt;/p&gt;

&lt;p&gt;Because the loop ended with &lt;code&gt;break&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Which means the &lt;code&gt;else&lt;/code&gt; runs when the loop terminates normally, including when it never runs at all, but not when a &lt;code&gt;break&lt;/code&gt; interrupts it.&lt;/p&gt;

&lt;p&gt;To be fair, there's a legitimate use case here. When searching for something in a loop, you can use &lt;code&gt;break&lt;/code&gt; when you find it and &lt;code&gt;else&lt;/code&gt; when the search finishes without finding anything.&lt;/p&gt;

&lt;p&gt;But you have to admit that &lt;code&gt;else&lt;/code&gt; is a rather creative choice of keyword.&lt;/p&gt;

&lt;p&gt;Python's own documentation describes the behavior by comparing loop &lt;code&gt;else&lt;/code&gt; clauses to the &lt;code&gt;else&lt;/code&gt; in a &lt;code&gt;try&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Python, &lt;code&gt;else&lt;/code&gt; doesn't always mean "otherwise." Sometimes it means "congratulations, nobody broke out of the loop."&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Python Objects Can Share a Secret You Never Intended Them to Share
&lt;/h2&gt;

&lt;p&gt;Let's get into object-oriented programming.&lt;/p&gt;

&lt;p&gt;Suppose you're tracking machine learning experiments. Each experiment has a name and a collection of metrics.&lt;/p&gt;

&lt;p&gt;You write a simple class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Experiment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_metric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks reasonable enough.&lt;/p&gt;

&lt;p&gt;Now let's create two independent experiments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;experiment_a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Experiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Model A&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;experiment_b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Experiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Model B&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;experiment_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_metric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.95&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;experiment_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;experiment_b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0.95]
[0.95]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excuse me?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You added a metric to Model A, and Model B somehow knows about it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The two experiments are completely separate instances.&lt;/p&gt;

&lt;p&gt;Different names. Different objects.&lt;/p&gt;

&lt;p&gt;But apparently, they have a shared memory.&lt;/p&gt;

&lt;p&gt;Here's what's happening.&lt;/p&gt;

&lt;p&gt;In Python, attributes declared directly inside a class body are &lt;em&gt;class attributes&lt;/em&gt;, not instance attributes.&lt;/p&gt;

&lt;p&gt;So this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Experiment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates one list shared by every instance of &lt;code&gt;Experiment&lt;/code&gt;, unless an instance overrides the attribute.&lt;/p&gt;

&lt;p&gt;When Python evaluates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks for &lt;code&gt;metrics&lt;/code&gt; on the instance.&lt;/p&gt;

&lt;p&gt;Doesn't find it.&lt;/p&gt;

&lt;p&gt;Looks on the class.&lt;/p&gt;

&lt;p&gt;Finds the shared list.&lt;/p&gt;

&lt;p&gt;And modifies it.&lt;/p&gt;

&lt;p&gt;Now here's where things get even more interesting.&lt;/p&gt;

&lt;p&gt;Suppose you do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;experiment_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.99&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;experiment_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# [0.99]
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;experiment_b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# [0.95]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suddenly, the experiments are independent!&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because assigning to &lt;code&gt;experiment_a.metrics&lt;/code&gt; creates an instance attribute that shadows the class attribute.&lt;/p&gt;

&lt;p&gt;But calling &lt;code&gt;.append()&lt;/code&gt; on the original list modifies the shared class attribute.&lt;/p&gt;

&lt;p&gt;So two operations that look like they're manipulating the same property can behave very differently.&lt;/p&gt;

&lt;p&gt;The correct implementation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Experiment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_metric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now every experiment gets its own metrics list.&lt;/p&gt;

&lt;p&gt;And this isn't limited to experimental metrics. The same problem can appear in cached results, configuration objects, event handlers, and any class that accidentally shares mutable state between instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In Python, where you declare an attribute matters. Put mutable per-instance state in &lt;code&gt;__init__&lt;/code&gt;, unless you genuinely want every object to share it.&lt;/p&gt;

&lt;p&gt;Because nothing inspires confidence in your machine learning results quite like discovering that two supposedly independent experiments have been sharing their data all along.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Python Throws an Exception. Your Data Changes Anyway.
&lt;/h2&gt;

&lt;p&gt;I saved my favorite for last.&lt;/p&gt;

&lt;p&gt;Because this one challenges a fairly reasonable assumption:&lt;/p&gt;

&lt;p&gt;If an operation fails, surely it didn't complete?&lt;/p&gt;

&lt;p&gt;Meet Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],)&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Operation failed!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Operation failed!
([1, 2, 3],)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's review what just happened.&lt;/p&gt;

&lt;p&gt;Python threw an exception.&lt;/p&gt;

&lt;p&gt;We caught it.&lt;/p&gt;

&lt;p&gt;And the data changed anyway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The operation failed successfully.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's why.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;data&lt;/code&gt; is a tuple containing a list.&lt;/p&gt;

&lt;p&gt;Tuples are immutable, meaning you can't replace their elements.&lt;/p&gt;

&lt;p&gt;But the objects &lt;em&gt;inside&lt;/em&gt; a tuple can still be mutable.&lt;/p&gt;

&lt;p&gt;When Python executes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things happen.&lt;/p&gt;

&lt;p&gt;First, the list is modified in place. The value &lt;code&gt;3&lt;/code&gt; is appended.&lt;/p&gt;

&lt;p&gt;Then Python attempts to assign the result back into the tuple.&lt;/p&gt;

&lt;p&gt;That second step fails because tuples don't support item assignment.&lt;/p&gt;

&lt;p&gt;But the first step already happened.&lt;/p&gt;

&lt;p&gt;And Python doesn't automatically roll it back.&lt;/p&gt;

&lt;p&gt;So you get an exception AND modified data.&lt;/p&gt;

&lt;p&gt;To avoid this particular problem, you can mutate the contained list explicitly when that's what you intend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or use immutable contents if you need the entire structure to remain unchanged.&lt;/p&gt;

&lt;p&gt;The truly wonderful detail is that this behavior is documented in the official Python FAQ.&lt;/p&gt;

&lt;p&gt;It's not a bug.&lt;/p&gt;

&lt;p&gt;It's a consequence of Python's object model and augmented assignment semantics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Exceptions do not imply atomicity. A failed operation can leave behind side effects, and those side effects can matter enormously in data-processing pipelines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beautiful Is Better Than Ugly. Usually.
&lt;/h2&gt;

&lt;p&gt;Python's famous Zen includes principles like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Beautiful is better than ugly.&lt;/li&gt;
&lt;li&gt;Explicit is better than implicit.&lt;/li&gt;
&lt;li&gt;Simple is better than complex.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And Python generally does an admirable job of living up to them.&lt;/p&gt;

&lt;p&gt;But as we've seen, simple syntax doesn't always imply simple behavior.&lt;/p&gt;

&lt;p&gt;The most dangerous programming errors aren't necessarily the ones that crash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;They're the ones that quietly give you the wrong answer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And in data science, that wrong answer might come with a beautiful chart and a very convincing confidence interval.&lt;/p&gt;




&lt;p&gt;This is part of an ongoing series exploring the stranger corners of familiar programming languages. We've already visited PHP and JavaScript. C# and Perl are still waiting.&lt;/p&gt;

&lt;p&gt;Perl, naturally, is preparing something involving regex.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>machinelearning</category>
      <category>discuss</category>
    </item>
    <item>
      <title>JavaScript: The Language That Gaslights Its Developers</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Fri, 30 Oct 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/javascript-the-language-that-gaslights-its-developers-1m08</link>
      <guid>https://dev.to/jlmartel/javascript-the-language-that-gaslights-its-developers-1m08</guid>
      <description>&lt;p&gt;After writing about PHP's greatest hits in the Weird Language Hall of Fame, it felt only fair to turn to JavaScript.&lt;/p&gt;

&lt;p&gt;Because if PHP is the language of historical baggage, JavaScript is the language of &lt;strong&gt;"this seems impossible, and yet it is fully specified behavior."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript has a special talent for producing results that look like bugs, feel like bugs, and absolutely are not bugs.&lt;/p&gt;

&lt;p&gt;Most of the time, the culprit is type coercion, implicit conversion, or one of the language's many "technically reasonable, emotionally devastating" rules.&lt;/p&gt;

&lt;p&gt;So here are a few of my favorite examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. An Empty Array Is Truthy... But Also Equal to &lt;code&gt;false&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Let's begin with a classic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nc"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;       &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;       &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;      &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the kind of thing that makes developers stare at the screen and wonder why they picked computing science instead of accounting like their mom advised.&lt;/p&gt;

&lt;p&gt;An empty array is truthy.&lt;/p&gt;

&lt;p&gt;So far, so normal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yep, truthy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That runs.&lt;/p&gt;

&lt;p&gt;But then this also happens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;   &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because JavaScript doesn't use the same rules for boolean contexts and loose equality.&lt;/p&gt;

&lt;p&gt;In a boolean context, arrays are simply objects, and objects are truthy.&lt;/p&gt;

&lt;p&gt;But with &lt;code&gt;==&lt;/code&gt;, JavaScript starts converting values. The empty array becomes an empty string, which then becomes the number &lt;code&gt;0&lt;/code&gt;. Meanwhile, &lt;code&gt;false&lt;/code&gt; also becomes &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So JavaScript ends up comparing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is, unfortunately, true.&lt;/p&gt;

&lt;p&gt;And if you really want to ruin your afternoon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;   &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because &lt;code&gt;![]&lt;/code&gt; becomes &lt;code&gt;false&lt;/code&gt;, and now you're back in the previous example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; truthiness and loose equality are not the same thing. If you're comparing values in JavaScript, &lt;code&gt;===&lt;/code&gt; should be your default.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;typeof null&lt;/code&gt; Is &lt;code&gt;"object"&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This one has survived for decades.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;         &lt;span class="c1"&gt;// "object"&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;    &lt;span class="c1"&gt;// "undefined"&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;           &lt;span class="c1"&gt;// "object"&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;          &lt;span class="c1"&gt;// "number"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's focus on the weirdest part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;   &lt;span class="c1"&gt;// "object"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Except &lt;code&gt;null&lt;/code&gt; is not an object.&lt;/p&gt;

&lt;p&gt;This is a long-standing historical bug in JavaScript that became untouchable because too much code depended on it.&lt;/p&gt;

&lt;p&gt;So now it just lives there, like haunted wallpaper.&lt;/p&gt;

&lt;p&gt;And since JavaScript enjoys layering confusion on top of confusion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; is not an object, but &lt;code&gt;typeof null&lt;/code&gt; says it is.&lt;/li&gt;
&lt;li&gt;Arrays are objects, so &lt;code&gt;typeof []&lt;/code&gt; is also &lt;code&gt;"object"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NaN&lt;/code&gt; means "Not a Number," but &lt;code&gt;typeof NaN&lt;/code&gt; is &lt;code&gt;"number"&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can almost hear the language whispering, &lt;em&gt;"If you can't handle me on my worst days, you don't deserve me."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; &lt;code&gt;typeof&lt;/code&gt; is useful, but not always precise. If you need to distinguish arrays, nulls, and objects, use more specific checks like &lt;code&gt;Array.isArray()&lt;/code&gt; and explicit &lt;code&gt;value === null&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;map(parseInt)&lt;/code&gt; Produces Nonsense
&lt;/h2&gt;

&lt;p&gt;This is one of the best examples in the entire language because every piece of it looks reasonable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What would you expect?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you actually get?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Naturally.&lt;/p&gt;

&lt;p&gt;Here's what's happening.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; doesn't just pass each array element to the callback. It passes three arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the current value
&lt;/li&gt;
&lt;li&gt;the current index
&lt;/li&gt;
&lt;li&gt;the whole array&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;effectively becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// 10&lt;/span&gt;
&lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// NaN&lt;/span&gt;
&lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And why is that a problem?&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;parseInt()&lt;/code&gt; takes a second argument: the radix.&lt;/p&gt;

&lt;p&gt;So JavaScript interprets the array index as the number base.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"10"&lt;/code&gt; in base 0 becomes 10&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"10"&lt;/code&gt; in base 1 is invalid, so &lt;code&gt;NaN&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"10"&lt;/code&gt; in base 2 becomes 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is one of those perfect JavaScript moments where two completely legitimate APIs collide and create chaos.&lt;/p&gt;

&lt;p&gt;The fix is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Don't hand a function to &lt;code&gt;map()&lt;/code&gt; unless you know exactly what arguments it expects.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;code&gt;sort()&lt;/code&gt; Sorts Numbers Like Strings
&lt;/h2&gt;

&lt;p&gt;This one has caused real bugs in real applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What you probably expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What JavaScript gives you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because by default, &lt;code&gt;sort()&lt;/code&gt; compares elements as strings.&lt;/p&gt;

&lt;p&gt;So JavaScript is effectively sorting these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;"1"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"2"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"10"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"20"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"3"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And in string comparison, &lt;code&gt;"10"&lt;/code&gt; comes before &lt;code&gt;"2"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This makes perfect sense if you're sorting words.&lt;/p&gt;

&lt;p&gt;It makes much less sense if you're sorting numbers in a programming language and expected numeric order to be the default.&lt;/p&gt;

&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you get what you wanted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; JavaScript's default behaviors are often optimized for generality, not for your expectations.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, Is JavaScript Bad?
&lt;/h2&gt;

&lt;p&gt;Not really.&lt;/p&gt;

&lt;p&gt;Like PHP, JavaScript is often mocked for behavior that is actually consistent with its own rules.&lt;/p&gt;

&lt;p&gt;The problem is that many of those rules are invisible until you trip over them.&lt;/p&gt;

&lt;p&gt;An empty array can be truthy while also loosely equal to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;typeof null&lt;/code&gt; can lie to your face.&lt;/p&gt;

&lt;p&gt;A perfectly innocent-looking &lt;code&gt;map(parseInt)&lt;/code&gt; can produce results that seem like a prank.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;sort()&lt;/code&gt; can rearrange numbers alphabetically, because apparently that was a reasonable default choice at some point in human history.&lt;/p&gt;

&lt;p&gt;But that's also what makes JavaScript fascinating.&lt;/p&gt;

&lt;p&gt;Its weirdness isn't random. It's the product of a language that was created to validate forms in web pages and became something people use to build microservices and large-scale data streaming pipelines, and evolved while the entire internet was standing on top of it.&lt;/p&gt;

&lt;p&gt;Which is kind of impressive.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is part of a series on programming languages that occasionally make developers question the nature of reality.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PHP already had its turn. Python, C#, and Perl are waiting patiently in the wings.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And Perl, as always, remains less a programming language than a dare.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>PHP: 30 Years of Making Developers Say "Wait, What?" (Part 2: It Gets Worse)</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Wed, 28 Oct 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/jlmartel/php-30-years-of-making-developers-say-wait-what-part-2-it-gets-worse-1jk8</link>
      <guid>https://dev.to/jlmartel/php-30-years-of-making-developers-say-wait-what-part-2-it-gets-worse-1jk8</guid>
      <description>&lt;p&gt;Apparently, three examples of PHP weirdness weren't enough.&lt;/p&gt;

&lt;p&gt;In the original post, we explored how PHP considers &lt;code&gt;"0"&lt;/code&gt; to be false, how array keys can silently overwrite one another, and how an innocent-looking &lt;code&gt;foreach&lt;/code&gt; loop can unexpectedly modify your data.&lt;/p&gt;

&lt;p&gt;Those were fun.&lt;/p&gt;

&lt;p&gt;But PHP has been around for three decades, and you don't accumulate that much history without developing a few interesting personality traits.&lt;/p&gt;

&lt;p&gt;So here are four more examples of PHP doing exactly what it was designed to do, even when that seems deeply unreasonable.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Filtering an Array Can Turn It Into a JSON Object
&lt;/h2&gt;

&lt;p&gt;Let's say you're building an API.&lt;/p&gt;

&lt;p&gt;You have an array of fruit. You want to remove one item and return the rest as JSON.&lt;/p&gt;

&lt;p&gt;Simple enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'apple'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'banana'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'cherry'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nv"&gt;$filtered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;$items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$item&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'banana'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$filtered&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you expect?&lt;/p&gt;

&lt;p&gt;Probably this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"cherry"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What you actually get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"cherry"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait. What?&lt;/p&gt;

&lt;p&gt;You started with an array. You filtered an array. You encoded an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And somehow, you got a JSON object.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's why.&lt;/p&gt;

&lt;p&gt;PHP's &lt;code&gt;array_filter()&lt;/code&gt; preserves the original keys.&lt;/p&gt;

&lt;p&gt;After filtering, the array looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'apple'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'cherry'&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;json_encode()&lt;/code&gt; encounters a PHP array whose keys aren't consecutive integers starting at zero, it serializes it as a JSON object rather than a JSON array.&lt;/p&gt;

&lt;p&gt;Your perfectly reasonable filtering operation has silently changed the shape of your API response.&lt;/p&gt;

&lt;p&gt;Imagine the delight of the frontend developer expecting an array.&lt;/p&gt;

&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;array_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$filtered&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which gives you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"cherry"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; If you're filtering arrays for JSON responses, remember that &lt;code&gt;array_filter()&lt;/code&gt; preserves keys. Use &lt;code&gt;array_values()&lt;/code&gt; when you need a proper JSON array.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A Variable Can Exist and Still Not Be Set
&lt;/h2&gt;

&lt;p&gt;Let's talk about &lt;code&gt;isset()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The name seems reasonably self-explanatory.&lt;/p&gt;

&lt;p&gt;Surely it tells you whether something exists?&lt;/p&gt;

&lt;p&gt;Well, not exactly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'timeout'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the key is right there!&lt;/p&gt;

&lt;p&gt;You can see it. I can see it. PHP can presumably see it.&lt;/p&gt;

&lt;p&gt;And yet &lt;code&gt;isset()&lt;/code&gt; returns false.&lt;/p&gt;

&lt;p&gt;That's because &lt;code&gt;isset()&lt;/code&gt; doesn't actually mean "does this variable or key exist?"&lt;/p&gt;

&lt;p&gt;It means something closer to &lt;strong&gt;"does this exist AND contain a value other than null?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So we have two functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;                &lt;span class="c1"&gt;// false&lt;/span&gt;

&lt;span class="nb"&gt;array_key_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same array. Same key. Different answers.&lt;/p&gt;

&lt;p&gt;And there's a practical consequence.&lt;/p&gt;

&lt;p&gt;Suppose &lt;code&gt;null&lt;/code&gt; means "disable the timeout," while a missing key means "use the default timeout."&lt;/p&gt;

&lt;p&gt;You might write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the null coalescing operator also falls back when the value is &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;$timeout&lt;/code&gt; becomes &lt;code&gt;30&lt;/code&gt;, even though the configuration explicitly contained &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If those two states matter, you need to distinguish them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_key_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'timeout'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now an explicitly configured &lt;code&gt;null&lt;/code&gt; stays &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; In PHP, "missing" and "present but null" are different states, but &lt;code&gt;isset()&lt;/code&gt; treats them the same. Sometimes that's convenient. Sometimes it's a bug waiting for the right configuration file.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Two Different Strings Can Be Equal Because They're Both Zero
&lt;/h2&gt;

&lt;p&gt;Here's a fun one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0e123"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"0e999"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What would you expect?&lt;/p&gt;

&lt;p&gt;They're clearly different strings.&lt;/p&gt;

&lt;p&gt;Surely the answer is false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool(true)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course it is.&lt;/p&gt;

&lt;p&gt;The explanation involves PHP's numeric-string handling.&lt;/p&gt;

&lt;p&gt;Both strings are valid representations of numbers in scientific notation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0e123&lt;/code&gt; means zero multiplied by ten to the power of 123.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0e999&lt;/code&gt; means zero multiplied by ten to the power of 999.&lt;/p&gt;

&lt;p&gt;Both evaluate numerically to zero.&lt;/p&gt;

&lt;p&gt;And because PHP's loose comparison operator (&lt;code&gt;==&lt;/code&gt;) recognizes both strings as numeric, it compares their numeric values.&lt;/p&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s2"&gt;"0e123"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"0e999"&lt;/span&gt;    &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="s2"&gt;"0e123"&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"0e999"&lt;/span&gt;   &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This particular behavior has a wonderful nickname: &lt;strong&gt;magic hashes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Certain hash outputs happen to consist entirely of a zero, followed by &lt;code&gt;e&lt;/code&gt;, followed by digits.&lt;/p&gt;

&lt;p&gt;When two such hashes are compared using loose equality, PHP can interpret them as equal numeric values even though their string contents differ.&lt;/p&gt;

&lt;p&gt;Historically, this has contributed to security vulnerabilities in applications that compared hash strings incorrectly.&lt;/p&gt;

&lt;p&gt;And no, switching from PHP 7 to PHP 8 doesn't eliminate this particular issue. Both operands here are valid numeric strings, so the loose comparison still considers them equal.&lt;/p&gt;

&lt;p&gt;The fix is straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s2"&gt;"0e123"&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"0e999"&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For security-sensitive hash comparisons, use the appropriate cryptographic comparison functions, such as &lt;code&gt;hash_equals()&lt;/code&gt; when comparing authentication-related strings, or &lt;code&gt;password_verify()&lt;/code&gt; for password hashes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Loose equality isn't merely a convenience feature. When values originate from external input, it can become a security problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;code&gt;switch&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; Disagree About Reality
&lt;/h2&gt;

&lt;p&gt;PHP 8 introduced &lt;code&gt;match&lt;/code&gt;, a more modern alternative to &lt;code&gt;switch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And naturally, they don't quite agree on what constitutes a match.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Integer ten"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"String ten"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Integer ten
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value is a string.&lt;/p&gt;

&lt;p&gt;The first case is an integer.&lt;/p&gt;

&lt;p&gt;But PHP's &lt;code&gt;switch&lt;/code&gt; uses loose comparisons, so &lt;code&gt;"10"&lt;/code&gt; matches &lt;code&gt;10&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first matching case wins.&lt;/p&gt;

&lt;p&gt;Now let's rewrite that using &lt;code&gt;match&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="mi"&gt;10&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Integer ten"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"10"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"String ten"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String ten
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same input. Same alternatives. Different result.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;match&lt;/code&gt; uses strict comparisons (&lt;code&gt;===&lt;/code&gt;), while &lt;code&gt;switch&lt;/code&gt; uses loose comparisons (&lt;code&gt;==&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;match&lt;/code&gt; has some other differences, including no fall-through and a requirement to handle unmatched values or provide a default.&lt;/p&gt;

&lt;p&gt;To be fair, &lt;code&gt;match&lt;/code&gt; is arguably the better-designed construct.&lt;/p&gt;

&lt;p&gt;But imagine converting an old &lt;code&gt;switch&lt;/code&gt; statement to &lt;code&gt;match&lt;/code&gt; during a refactoring session, assuming that you're just modernizing the syntax.&lt;/p&gt;

&lt;p&gt;You could change application behavior without changing any of the values being compared.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; When replacing &lt;code&gt;switch&lt;/code&gt; with &lt;code&gt;match&lt;/code&gt;, you're not merely changing syntax. You're changing comparison semantics.&lt;/p&gt;

&lt;h2&gt;
  
  
  PHP Is Consistent. That's Not Always Comforting.
&lt;/h2&gt;

&lt;p&gt;Here's the interesting thing about all seven examples we've now explored across these two articles.&lt;/p&gt;

&lt;p&gt;None of them are random.&lt;/p&gt;

&lt;p&gt;PHP has rules governing truthiness, type coercion, array keys, references, JSON serialization, and comparisons.&lt;/p&gt;

&lt;p&gt;The interpreter follows those rules consistently.&lt;/p&gt;

&lt;p&gt;The problem is that those rules don't always line up with what developers intuitively expect.&lt;/p&gt;

&lt;p&gt;And sometimes two individually reasonable rules interact to produce something spectacularly unreasonable.&lt;/p&gt;

&lt;p&gt;That's what makes PHP such a fascinating language to revisit.&lt;/p&gt;

&lt;p&gt;It has evolved a lot since the 1990s. Modern PHP is faster, more expressive, and substantially better engineered than the language many developers remember.&lt;/p&gt;

&lt;p&gt;But it still has a few surprises hiding behind perfectly ordinary syntax.&lt;/p&gt;

&lt;p&gt;And after thirty years, I suspect it's earned the right to be a little eccentric.&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>PHP: 30 Years of Making Developers Say "Wait, What?"</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Sun, 25 Oct 2026 01:57:59 +0000</pubDate>
      <link>https://dev.to/jlmartel/php-30-years-of-making-developers-say-wait-what-3flc</link>
      <guid>https://dev.to/jlmartel/php-30-years-of-making-developers-say-wait-what-3flc</guid>
      <description>&lt;p&gt;With PHP suddenly back in the spotlight, I figured this was a good time to revisit one of the web's most successful, most criticized, and occasionally most bewildering programming languages.&lt;/p&gt;

&lt;p&gt;PHP has been powering websites for decades. It has evolved a lot, particularly through PHP 7 and 8, but it still carries some fascinating quirks.&lt;/p&gt;

&lt;p&gt;And I'm not talking about obscure syntax or features nobody uses. I'm talking about perfectly ordinary code that does something completely unexpected.&lt;/p&gt;

&lt;p&gt;Here are three of my favorites.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The String "0" Is False. The String "00" Is True.
&lt;/h2&gt;

&lt;p&gt;Let's start with something simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"00"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"false"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;       &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isn't that beautiful?&lt;/p&gt;

&lt;p&gt;The string &lt;code&gt;"0"&lt;/code&gt; evaluates to false, but &lt;code&gt;"00"&lt;/code&gt; evaluates to true.&lt;/p&gt;

&lt;p&gt;Even the literal string &lt;code&gt;"false"&lt;/code&gt; evaluates to true.&lt;/p&gt;

&lt;p&gt;PHP considers an empty string and the specific string &lt;code&gt;"0"&lt;/code&gt; to be falsy. Other nonempty strings, including &lt;code&gt;"00"&lt;/code&gt;, are truthy.&lt;/p&gt;

&lt;p&gt;Now consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No password provided!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Except a password &lt;strong&gt;was&lt;/strong&gt; provided. PHP just decided it didn't count.&lt;/p&gt;

&lt;p&gt;And if you're thinking that &lt;code&gt;empty()&lt;/code&gt; might save you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"00"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; Don't use truthiness to determine whether a string contains meaningful input. Be explicit about what you're checking.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. PHP Arrays Can Silently Overwrite Your Data
&lt;/h2&gt;

&lt;p&gt;PHP arrays aren't really conventional arrays. They're ordered maps that support both integer and string keys.&lt;/p&gt;

&lt;p&gt;Which sounds perfectly reasonable until you do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"8"&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"eight"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;8&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"EIGHT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"08"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"zero eight"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might expect three entries.&lt;/p&gt;

&lt;p&gt;You get two.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array
(
    [8] =&amp;gt; EIGHT
    [08] =&amp;gt; zero eight
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PHP automatically converts the string key &lt;code&gt;"8"&lt;/code&gt; to the integer &lt;code&gt;8&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So the second entry overwrites the first.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;"08"&lt;/code&gt; stays a string because it isn't a valid decimal integer representation for this conversion.&lt;/p&gt;

&lt;p&gt;And it gets better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"integer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"1"&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"boolean"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array
(
    [1] =&amp;gt; boolean
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three apparently different keys. One surviving value.&lt;/p&gt;

&lt;p&gt;The first two collide because &lt;code&gt;"1"&lt;/code&gt; becomes integer &lt;code&gt;1&lt;/code&gt;. The third collides because &lt;code&gt;true&lt;/code&gt; also becomes integer &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; PHP array keys undergo implicit type conversion. If your application depends on distinguishing keys by type, you're in for an unpleasant surprise.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A &lt;code&gt;foreach&lt;/code&gt; Loop Can Quietly Corrupt Your Array
&lt;/h2&gt;

&lt;p&gt;This is my favorite, because it's the kind of bug that can survive a code review.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some processing&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some more processing&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing particularly exotic here.&lt;/p&gt;

&lt;p&gt;The first loop iterates by reference. The second iterates normally.&lt;/p&gt;

&lt;p&gt;What does the final array contain?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array
(
    [0] =&amp;gt; 1
    [1] =&amp;gt; 2
    [2] =&amp;gt; 2
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait. What happened to the 3?&lt;/p&gt;

&lt;p&gt;The culprit is that innocent-looking ampersand in the first loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When that loop finishes, &lt;code&gt;$number&lt;/code&gt; remains a reference to the &lt;strong&gt;last element of the array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The reference doesn't magically disappear when the loop ends.&lt;/p&gt;

&lt;p&gt;Then the second loop reuses &lt;code&gt;$number&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Each iteration assigns another array value to a variable that's &lt;em&gt;still referencing the last element&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;By the time the second loop finishes, the last element has been overwritten with the second-to-last value.&lt;/p&gt;

&lt;p&gt;The truly delightful part?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This behavior is explicitly documented in the PHP manual.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The fix is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$numbers&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some processing&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Break the reference&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the fact that you need to remember to do this is what makes the behavior so interesting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The lesson:&lt;/strong&gt; References in PHP can outlive the control structures that introduced them. Reusing a variable after a by-reference loop can have side effects that are surprisingly difficult to spot.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, Is PHP Broken?
&lt;/h2&gt;

&lt;p&gt;Not really.&lt;/p&gt;

&lt;p&gt;All three behaviors follow documented rules. They're not random, and they're not bugs in the PHP interpreter.&lt;/p&gt;

&lt;p&gt;But they illustrate something interesting about programming languages.&lt;/p&gt;

&lt;p&gt;A language can be internally consistent while still producing results that surprise the people using it.&lt;/p&gt;

&lt;p&gt;PHP has spent decades balancing developer convenience, backward compatibility, and language evolution. Sometimes those priorities have produced genuinely useful features. Sometimes they've produced behavior that makes you stare at your screen for a few minutes.&lt;/p&gt;

&lt;p&gt;And that's part of what makes exploring programming languages so entertaining.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This was fun so I think I'll make it a series looking at the stranger corners of familiar languages.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Migrating AKS workloads from AAD Pod Identity to Entra Workload ID</title>
      <dc:creator>Jean-Luc Martel</dc:creator>
      <pubDate>Thu, 22 Oct 2026 02:49:22 +0000</pubDate>
      <link>https://dev.to/jlmartel/migrating-aks-workloads-from-aad-pod-identity-to-entra-workload-id-3bk8</link>
      <guid>https://dev.to/jlmartel/migrating-aks-workloads-from-aad-pod-identity-to-entra-workload-id-3bk8</guid>
      <description>&lt;p&gt;You're looking at an AKS cluster for a client. &lt;/p&gt;

&lt;p&gt;Somewhere in it, a pod is authenticating to Azure using AAD Pod Identity. It relies on AzureIdentity and AzureIdentityBinding custom resources. It depends on the Node Managed Identity (NMI) pods intercepting metadata requests on port 2579. &lt;/p&gt;

&lt;p&gt;It is deprecated. Microsoft pulled the plug a year ago. The NMI intercept is a tax on the cluster's CPU and a liability in the threat model. &lt;/p&gt;

&lt;p&gt;You need to move it to Entra Workload ID. It uses OIDC federation. It is cleaner. But cleaner does not mean easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inventory the plumbing
&lt;/h2&gt;

&lt;p&gt;Do not just generate new manifests and hope for the best. &lt;/p&gt;

&lt;p&gt;Inventory what you actually have. Every &lt;code&gt;AzureIdentityBinding&lt;/code&gt; is a dependency. Every &lt;code&gt;AzureIdentity&lt;/code&gt; is a managed identity mapped to a specific set of pod labels. &lt;/p&gt;

&lt;p&gt;Map each workload to its intended federated Kubernetes Service Account. If you do not know exactly what the old identity does, you will not know what permissions the new one needs. &lt;/p&gt;

&lt;p&gt;Treat the old bindings as a map of your actual access patterns, not just a list of resources to delete.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate the exact strings
&lt;/h2&gt;

&lt;p&gt;Entra Workload ID does not guess. It matches strings. &lt;/p&gt;

&lt;p&gt;When you create the federated identity credential in Entra ID, the issuer is your AKS OIDC endpoint. The subject must be exactly &lt;code&gt;system:serviceaccount:&amp;lt;namespace&amp;gt;:&amp;lt;name&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Miss a colon. Add a trailing space. Use the wrong namespace. &lt;strong&gt;It will not give you a helpful error&lt;/strong&gt;. It will just give you a 401 Unauthorized.&lt;/p&gt;

&lt;p&gt;The pod also requires the label &lt;code&gt;azure.workload.identity/use: "true"&lt;/code&gt;. Without it, the Entra workload identity mutating webhook ignores the pod. No environment variables get injected. No service account token gets projected. The pod starts, but it cannot authenticate.&lt;/p&gt;

&lt;p&gt;Test the token exchange before you move production traffic. &lt;/p&gt;

&lt;p&gt;Exec into a debug pod. Request the token from the projected volume. Decode it. Check the aud (audience) and sub (subject) claims. Verify the exact string matches what you configured in Entra ID. &lt;/p&gt;

&lt;h2&gt;
  
  
  Stage the migration
&lt;/h2&gt;

&lt;p&gt;Do not do a cutover. Do a &lt;strong&gt;migration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Deploy the new service account and the federated identity credential. Update the workload definition to use the new service account and apply the required pod label. &lt;/p&gt;

&lt;p&gt;Watch the logs. Verify the token exchange succeeds. &lt;/p&gt;

&lt;p&gt;Once the new identity is serving traffic and passing health checks, kill the old &lt;code&gt;AzureIdentityBinding&lt;/code&gt; and &lt;code&gt;AzureIdentity&lt;/code&gt; resources. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not&lt;/strong&gt; leave the old plumbing in the cluster "just in case." Deprecated resources left behind become permanent attack surface. If you do not need it, delete it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prove it works
&lt;/h2&gt;

&lt;p&gt;You are not done when the pod starts. You are done when you prove it can do its job.&lt;/p&gt;

&lt;p&gt;Check the Azure Activity Log. Look for the API calls. &lt;/p&gt;

&lt;p&gt;See the new managed identity making the requests. See the old one go silent. &lt;/p&gt;

&lt;p&gt;That is the only evidence that matters. The new identity reaches the required services with the intended permissions, and the old plumbing is gone.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
