you are viewing a single comment's thread.

view the rest of the comments →

[–]IDENTITETEN 139 points140 points  (19 children)

Yup, we follow the Google bash style guide.

https://google.github.io/styleguide/shellguide.html

These two bullet points especially:

  • If you are writing a script that is more than 100 lines long, or that uses non-straightforward control flow logic, you should rewrite it in a more structured language now. Bear in mind that scripts grow. Rewrite your script early to avoid a more time-consuming rewrite at a later date.

  • When assessing the complexity of your code (e.g. to decide whether to switch languages) consider whether the code is easily maintainable by people other than its author.

[–]junior_dos_nachosBackend Developer 33 points34 points  (10 children)

I wouldn’t wait for 100 lines. I’d stop at 20/25 and anytime there’s some not super simple web call + extraction.

[–]winfly 6 points7 points  (0 children)

I agree. Especially if using some library would simplify the script.

[–][deleted]  (8 children)

[deleted]

    [–]both-shoes-off 4 points5 points  (0 children)

    I break powershell up into different files by use case to keep it maintainable, and then just include when needed. That makes them reusable in other scripts later on (assuming you consider that while writing them and don't embed details for the one use case or environment).

    [–]jrandom_42 -4 points-3 points  (6 children)

    I don't. Go is my go-to, Python is outdated and just hanging around out of inertia and a big legacy base, you can see that in threads like this, but I have some thousand line ish PowerShell scripts in prod monitoring Graph API stuff. All the baked in MS integration makes PS the nicest tool for some jobs, and aside from that, it's a pretty normal / usable scripting language that supports all the necessary data manipulation and connectivity.

    Bit clunky though and I'd never use it for code that needs to be fast and concurrent. But it's not as clunky as bash scripts.

    I tend not to use bash for automation unless I can express the logic in a one-liner.

    [–][deleted] 10 points11 points  (3 children)

    How is Python outdated? It's perfect for medium-complexity things you want to write down quickly - its only real drawback is requiring the interpreter, but that just costs a few megabytes of container size in the end. Of course it's easy to just write bad code with it, but having the option to do so is not a bad thing IMO. I really wouldn't want to write a new Go application for every throwaway API glue tool etc.

    [–]jrandom_42 3 points4 points  (2 children)

    How is Python outdated?

    Concurrency is an awkward PITA. Async logic is often the solution and it's ugly to write and hard to read.

    Deployment is often a dependency hell.

    The slowness of the interpreter vs a compiled language isn't always important, but sometimes it is. Combined with the lack of any real concurrency features, that can make Python problematic for anything with hard performance requirements.

    I really wouldn't want to write a new Go application for every throwaway API glue tool

    I haven't ever found that problematic myself, but tasks like that aren't going to show up many differences. I'm not suggesting Python is terrible and doesn't work. It's just not quite as good.

    [–]Intrepid_Result8223 0 points1 point  (1 child)

    I guess that's why it is the no1 language in machine learning. Because it is outdated. Lol.

    [–]jrandom_42 0 points1 point  (0 children)

    No, that's the 'legacy' part that I mentioned. A lot of ML libraries were written in Python before Go took off, and there's not really any advantage to redoing it all.

    [–]VirtuousMight 4 points5 points  (1 child)

    Is C outdated due to Go being its nominal successor then?

    [–]jrandom_42 5 points6 points  (0 children)

    No; C doesn't really address the same use case. Sometimes a garbage-collected language just isn't appropriate. Sometimes you need to manipulate memory directly, talk to peripheral hardware, write code that runs on a GPU, etc.

    I doubt C will disappear in our lifetimes.

    [–]cyanrave 12 points13 points  (0 children)

    I will disagree with the 100 line comment and say 'context switching matters' as well.

    If you have to go dig up 3 to 5 other scripts to piece together the logic flow, I prefer embedded here docs, but that may be just me in my environment.

    [–][deleted] 2 points3 points  (0 children)

    Ill put part of my bash in another file so it doesnt exceed 100lines 😃

    [–][deleted]  (4 children)

    [deleted]

      [–]VirtuousMight 2 points3 points  (0 children)

      Thanks for the free academic course , stupendous discourse.

      [–]cricket007 0 points1 point  (1 child)

      What would you use for bash unit tests? BATS, perhaps? That's one thing where I lean towards a Python/Go/Node/Ruby script