#BabelOfCode 2024
Week 9
Language: Ada (Spark?)

Confidence level: High

PREV WEEK: https://mastodon.social/@mcc/114463342416949024
NEXT WEEK: https://mastodon.social/@mcc/114582208242623432

So I start reading the manual for Ada. I think: This is *great!* This has all these features, conveniences etc I was wishing for for years in C++, and didn't get until I jumped to Rust. I might have been using this for games in 2010 if I'd dug into it then!

Then I start writing an actual Ada program. It turns out to be basically a pain in the ass.

Now, it's possible that the reason I'm unhappy is I jumped directly into something Ada is not designed for. However, that thing I jumped into was "load a file at runtime into a string whose length is not known at compile time". I don't think this should be so hard in a recently-revised language. (I seem to be tragically consistent in this challenge at accidentally picking languages whose input systems prefer structured data-- like Ada and Fortran-- on puzzles where I'm parsing raw ASCII art.)
To pick at this. "Software" can mean a do of different things! There's environments where you spend lots of time poking at text strings— text files in a world where the UNIX "everything is a file" philosophy won, webdev. There's really important environments where they don't! If you're writing backend software interacting with databases and network services, maybe it turns out Ada is *perfect* for this environment and you don't care about the friction on files and variable-length strings. Dunno.
Anyway. I was able to open a file whose name is given on the command line, but not read lines from it (the line reader only wants to work with stdin). I was not able to take an arbitrary-length string from stdin (I hardcoded to 10,000 bytes, the length of my largest input). I wasted a bunch of time on it, decided this wasn't important, and moved on. I'm trying to write "professional" software in this challenge and Ada, at least for the UNIX-y cmdline-and-files environment, did not reward that.

Compromises on basic things continue. I want to create an array whose size is not known at compile time. I believe I can declare this with

Mem : Array (Natural range <>) of Integer range -1..Integer'Last;

But this errors there's no initialization. You can initialize an array to a fixed value with (Others => -1), but then it doesn't know the size. I wind up making a sub-procedure *just* because that is the only syntax I can find for initializing an array to a size. https://github.com/mcclure/aoc2024/blob/b46079ddcb5c45d52af5882e940a593050c7beb9/09-01-disk/src/puzzle.adb#L14

aoc2024/09-01-disk/src/puzzle.adb at b46079ddcb5c45d52af5882e940a593050c7beb9 · mcclure/aoc2024

Advent of Code 2024 challenge (laid-back/"babel" version) - mcclure/aoc2024

GitHub

Small observations:

- Inner procedures and functions of a larger procedure and function can access the outer procedure's local variables. That's nice. I suspect this is hiding some sort of horrible restriction on recursion, but it's nice.

- The error messages, at least in "gnat" the open source Ada compiler, are NOT good. I think this is downstream from the language having lots of minor similar-but-distinct concepts instead of single powerful concepts. There's a lot of jargon and lots of edges

Something I don't know how you'll feel about: You know how in every programming language except Lua you index arrays from 0, and in Lua you index arrays from 1? In Ada, if I'm understanding this correctly, you choose whether your code indexes arrays from 0 or 1. *On an array by array basis*. You could mix 0- and 1-indexed arrays in the same code. You could have an array which contains 10 elements at indexes 10 through 19 inclusive, if you wanted. An array is a map with integer keys in a range

Man writing Ada is *really* making me think I was too hard on Haskell
@mcc I have this mug that I got from when my dad was working as a SWE in the 70s. I've never written Ada or I imagine I might have to cross out the heart.
@vikxin @mcc tbh I have coworkers who would get a kick out of this mug lol
@ShinyQuagsire @vikxin I have a friend named Ada and I want to buy this mug for her wife
@mcc @ShinyQuagsire Unfortunately the other side is branded with a company that hasn't existed in a long time. I don't think they sell them anymore.