Live data from Hacker News

Today I learned that bash has hashmaps (2024)

xeiaso.net

91–100 of 137 posts

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

#91
Got burned on this on an interview question before.

In a related question I said something about switching to a language like Python when a script started to get "complicated"

Then the interviewer explained how his favorite language was bash, how he uses it for everything...

I did not get the job. Ironically my next job I did a bunch of Perl to Bash conversion.

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

#92

Nice that these exist—but does anyone else absolutely abhor shell programming? The syntax is impossible to memorize, it’s incredibly easy to make mistakes, and debugging is a pain. I hate it more than C++ and AppleScript.

Have you tried plan9's rc? easy to memorize syntax thing. It's still easy to make mistakes though and nobody uses it.

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

#94
post #38
post #33

Earlier quoted context omitted.

That is certainly true - associative arrays in c++ (std::map) for example, are implemented as red-black trees.

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.

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

#95
post #57

Earlier quoted context omitted.

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.

They suggest that based on their experience. Error handling in bash is awful so I advice against using it for anything complex.

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'

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

#96
post #18

I love shell, I think it's killer feature are pipes and whoever figured out how to design so you can pipe in and out of control structures(Doug Mcilroy?) is a goddamn genius. however, after writing one to many overly clever shell scripts, I have a very clearly delineated point in which the script has become too complex and it is time to rewrite in a language better suited for the task. and that point is when I need a…

Control structures? Do you mean something like '{ cmd1 || cmd2; } | cmd3', where the control structures are the braces?

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

#97
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.

Give bash some credit - it's actually amazing for even very large, complex systems (of which there are many -- quietly doing their jobs for decades.)

With xargs or GNU parallel, you can have multi-processing, too. Combining with curl or ffmpeg, you can literally build a production-grade web scraper or video transcoding pipeline in a couple of minutes and a few dozen lines of code.

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

#98
post #57

Earlier quoted context omitted.

They suggest that based on their experience. Error handling in bash is awful so I advice against using it for anything complex.

Anything complex should be written in a competent language like Java. Script languages (like Bash and Python) are for short (a few lines long) scripts. Using the tool outside the scope of what it was designed for is not a good idea.

When my scripts outgrow bash, they almost always wind up in Python.

That said, Sonnet 3.5 had gotten me much further in bash than was possible before - and it's all really maintainable too. I highly suggest consulting with Sonnet on your longer scripts, even just asking it "what would you suggest to improve".

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

#100
post #70
post #62

Earlier quoted context omitted.

Tell me you have never seriously used Python without telling me you have never seriously used Python. I mean, viewing Python strictly as a scripting language? I am honestly lost for words. There are many huge and major applications and web sites written in Python, without people regretting it after the fact. And yet here you are dismissing it out of hand without a single argument.

Meanwhile most of the time topics like this come up and people hate on shell scripts, those of us that like them see those criticisms the same way you're looking at this comment about python: So far out there it's almost not worth responding. I think that's why GGP and GGGP think "greybeards" don't think it's worthwhile based on experience - it's actually not worth arguing against misinformed comments so newer people…

> …not worth arguing against misinformed comments …

Yeah, I have these same response patterns. Shell works really well for some use cases. I generally don’t respond to the comments that list the various “footguns” of shell, or that complain about security holes, etc. My use cases are not sensitive to these concerns, and even besides this, I find the concerns overstated.

Post reply on HN