Live data from Hacker News

Today I learned that bash has hashmaps (2024)

xeiaso.net

131–137 of 137 posts

Re: Today I learned that bash has hashmaps (2024)

#131
post #94
post #38

Earlier quoted context omitted.

I think many devs don't know the difference and simply call any dictionary/associative array a hash map. It might be one of the concepts that "the internet" promotes: it sounds fancy, more technical, makes you seem more knowledgeable, so it gets repeated. Then newcomers think this is the way it's always been called, and that gives it enough visibility to become the preferred name.

Quite frankly I'd love a programmers dictionary over terms, I recently called a file with a csv like format a db because, well, its not a csv and I don't know what else to call it.

Character-separated-value file?

Re: Today I learned that bash has hashmaps (2024)

#132
post #95

Earlier quoted context omitted.

You can go a really really long way, with a script that will work everywhere, with just set -e and aborting at the first error. Better yet, 'bash unofficial strict mode': set -euo pipefail IFS=$'\n\t'

That has lots of issues. See https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail for some.

One can made arguments both for and against `set -e`.

Over may carrier I've seen many shell scripts:

The most common case is no `-e` and no explicit error/status checks for most commands. It's unreliable and such scripts is one of reasons why shell got it's bad reputation (and criticized by coders using languages where an unhanded exception would terminate a program).

In my own scripts I often use `-e` (but not always as it is a tradeoff). If you unfamiliar with shell `-e` also could cause problems. But `-e` is not magic which makes a script better, one have to know how it works.

The option author of this article advocates (no `-e` but explicitly check every command which could fail) is the least common IMHO. Unless the scripts calls just 1-2 commands it's tedious and the resulting script is harder to read. May be you can find such style in some opensource projects but I've never seen such scripts at work.

Re: Today I learned that bash has hashmaps (2024)

#133
post #32

Earlier quoted context omitted.

You should be getting bash from homebrew anyways.

Or using an OS which doesn’t ship ancient software. Linux exists. It’s pretty awesome.

My employer does not let me install Linux on my Mac.

Re: Today I learned that bash has hashmaps (2024)

#134
post #131
post #94

Earlier quoted context omitted.

Quite frankly I'd love a programmers dictionary over terms, I recently called a file with a csv like format a db because, well, its not a csv and I don't know what else to call it.

Character-separated-value file?

Well that's the problem, it isn't, its a pseudo csv. A simple csv can be done with {awk -F ,} you only have a certain amount of fields separated by ",". field N is ".+". This means you don't need a parser, but it also means the format is variable depending on the headers. but you also can create a simple BRE regex, thus having pretty good performance.

Re: Today I learned that bash has hashmaps (2024)

#135
post #27

To me, this is a development in the wrong direction. Shell is great precisely because it's so minimal. Everything is string rule is one that calms all of your type-induced fears. Having to implement hash-tables, while still keeping the appearances of everything being a string is the anti-pattern known as "string programming" (i.e. when application develops a convention about storing type / structure information insid…

> To me, this is a development in the wrong direction. That ship has sailed. These were introduced in Bash 4, released in 2009, and Bash is already on version 5.

Oh, but we live with a lot of consequences of bad decisions, some of which have been made thousands of years ago :) A decade or two is nothing compared to it.

Re: Today I learned that bash has hashmaps (2024)

#136
post #13

It’s amazing how much of a superpower merely reading the manual is nowadays. https://www.gnu.org/software/bash/manual/bash.html#Arrays >

Bash is low on the list of things to learn, especially as many greybeards suggest keeping on POSIX compatibility and/or using a "proper" language (Python, older: Perl) for anything longer than a few lines.

I write a lot of shell and my advice is don't use plain POSIX shell. Write bash.

It is 2025. bash is present almost everywhere. If, by chance, your script is run somewhere that doesn't have bash then guess what?

Your POSIX script probably won't work anyway. It will be a different system, with different utilities and conventions.

Line count is not a good reason to choose or avoid bash. Bash is quite reliably the lowest common denominator.

I dare say it is even the best choice when your goal is accomplished by just running a bunch of commands.

All that said, bash is gross. I wish we had something as pervasive that wasn't so yucky.

Re: Today I learned that bash has hashmaps (2024)

#137

Earlier quoted context omitted.

I’ve been a sysadmin for nearly a decade, a frontend web designer for much longer (I still have a book on all the exciting changes in HTML4), and while I can very easily learn, compose, and use many markup and scripting languages, I have always struggled with full-on programming languages, and I’m not exactly sure why. Part of it, I think, is that most tutorials and online learning resources are focused on novices wh…

One of the differences between "general programming" and the kinds of coding that you have done is the /approach/. I'm not sure if that's even the right word, but there's a different set of concerns that are important. My guess is that you can easily learn the syntax and that you have the logical and analytical skills, but the part you have to learn is how to THINK about programming and how to DESIGN a program. If yo…

This was honestly extremely helpful. I very much appreciate the advice. I think you’re probably correct in that my intuition and prior knowledge is not being particularly helpful with shifting my paradigmatic perspectives, and while I may not need the novice lessons to learn the vocabulary or practical concepts, I probably do need a better formal introduction to theory. I am largely self-taught, aside from 2-years in an electronics engineering program that included embedded programming, and lessons in logic and Boolean algebra, My bachelor’s was in media studies and film production. In my experience, practical knowledge can be obtained through hands-on exercise and observing others—but theory and philosophy usually requires a teacher (or maybe months of meditation in a cabin in the woods, but as much as I admire Henry David Thoreau as an author, he wasn’t a great software engineer), and it sounds like that’s what I am missing here. Community college classes it is.

Thanks again!

Post reply on HN