Live data from Hacker News

Shell Style Guide

google.github.io

311–320 of 336 posts

Re: Shell Style Guide

#311
post #297

Earlier quoted context omitted.

^ this! Bash is the best stitching together language you'll get. Sure it sucks at scripting.. So stitch a script in there for God's sake!

Fish shell?

Not portable enough. The point of bash (well, really sh if we want to be pedantic) is that it's a stitching tool available on just about every conceivable platform.

Re: Shell Style Guide

#312
post #90
post #49

Earlier quoted context omitted.

This document agrees with you. - If you find you need to use arrays for anything more than assignment of ${PIPESTATUS}, you should use Python. - If you are writing a script that is more than 100 lines long, you should probably be writing it in Python instead. Bear in mind that scripts grow. Rewrite your script in another language early to avoid a time-consuming rewrite at a later date.

I'm one of those people who finds perverse pleasure in writing portable Bourne shell, and doing so correctly. I know I spend far more brain cycles on it than I should; once it gets past a certain complexity limit, I should just switch to Python. But I always say "It's just a little bit more code, there must be a good way to do this," and there generally is, but only after passing over several bad ways to do it first.…

> One of the constraints I impose is that spaces in pathnames should always be handled correctly;

I tend to do the exact opposite. If a filename has spaces in it, i like my script to fail spectacularly while insulting the user (who is typically me....)

Filenames are variable names. It makes no sense to allow spaces in them.

Re: Shell Style Guide

#313

# Not this: if [[ "${my_var}X" = "some_stringX" ]]; then do_something fi Why would anybody write this?

They learned that $null = test is bad, that $a = $b is bad, but didn't learn that you do either x$null = xtest or "$a" = "$b", not both.

Re: Shell Style Guide

#314
post #294
post #96

Earlier quoted context omitted.

It is, but don't forget it's a guide for Google engineers on the Google machines. People who share code for the world to use should use: - `#!/usr/bin/env bash` - or `#!/bin/sh` for POSIX shell scripting

Doesn't explain why Google wouldn't use env unless there's a good reason to avoid env.

Top of my head:

- it works

- it's simple

- they know that bash is in /bin

- maybe it avoids a needless call to env, resulting in better startup time (see e.g. https://news.ycombinator.com/item?id=16978932 for a similar situation with python)

Re: Shell Style Guide

#315

Earlier quoted context omitted.

You don't know true terror. I've seen an "ETL" solution (minus the "T") written entirely in SQL but using XML instead of tables and columns. After traveling through multiple servers via OpenQuery it eventually gets loaded into a domain-specific piece. That piece passes the data into a frontend that can only run in quirks mode. That frontend has 60-80 separate projects that all parse out basically the same data but fr…

They should have fired the author/s of this abomination much earlier instead of allowing that thing to evolve up to that size.

> They should have fired the author/s of this abomination much earlier instead of allowing that thing to evolve up to that size.

The main author of the SQL side and original author of the frontend has been promoted to the top because the system is critical to the business needs, and since everyone else struggles to work with this monstrosity they must be a pretty great developer. Can't afford to lose them.

The frontend team have threatened to quit several times unless things get better. They've been demanding version control, CI, automated deployments, a shared library, and to not use the domain-specific editor piece that prevents all this.

Management (including (or because of?) the OG author) is convinced that they're pushing for these things because of job security and refuse to let them overcomplicate things. But every time they they threaten to quit they get pretty substantial raises because no one else is willing/able to deal with the mess they were left with.

If you ask me, no amount of money is worth that environment, but all parties involved still work there...

Re: Shell Style Guide

#316

I don’t understand all the hate for bash or python in this thread. These are programming languages. Like all programming languages one must understand how to deploy them and use them properly. Yes bash has faults absolutely. It can be very arcane and esoteric and I think this due to the fact that it’s creators are very much of the old 1970s and 1980s Unix mindset and largely bash tools still feel like they work the w…

It's because so many here on hn are the compsci theoritical programmer, sysadmins are dying devops is everything, kind of people who don't actually support production systems other than maybe their particular depts single page webapp, etc... Hn has a problem with people living in the SV filter bubble seeing everything through that lens... in the real world, bash is still a king. When your devs shit out some bad code…

You make an awful lot of assumptions about population of the site where you can be practically anonymous to other users.

Re: Shell Style Guide

#317
post #17
post #8

Earlier quoted context omitted.

Sure, but not as terrifying as people rewriting shell one-liners in python or (gasp) java.

Then a lot of people don’t understand the limits of what they’re doing. For instance piping though commands works fine until one character sequence is interpreted as EOF. The fun part is it will work most of the time, and when it fails nobody will understand why (“we didn’t touch anything”), and rewriting the thing will be a political nightmare (“it was working before and was only 3 lines, why you need so much time t…

If you can do it as a one-liner in Bash, then you're not using the JVM. The benefit of using Apache Groovy for scripting is access to the JVM (and of course defining Gradle builds). If you don't need the JVM, then do it in Python or Ruby.

Re: Shell Style Guide

#318

Earlier quoted context omitted.

That is mind blowing for me in a couple ways. * You have (at least) seven tiered support structures. * You have only one 'competent' shell programmer in your 'reachable' project scope. No wonder these types of language policies are in place.

It's been decades since "writing a 1000 line script" was best done in shell, if there ever was a time. Someone with that much experience ought to be a very senior engineer.

I have shell libraries that generate code via here documents and other templating that are > 500 lines. That is about as far as I reasonably go. Note that these are function (and scope specific variables (with hopefully unique namespaces)) only code bases with copious comments and references to underlying tools.

Re: Shell Style Guide

#319
post #197

Earlier quoted context omitted.

> This is nonsense [...] You're off your rocker. Come on Drew, you know better than to do this here, regardless of how wrong someone is. If senior users set this kind of example how can we tell new ones not to? https://news.ycombinator.com/newsguidelines.html

You're right, I'm sorry.

Don't apologize to trash. The guy moderates comments for a "living". Don't grovel before useless trash. You offered technical points (though they were wrong).

Re: Shell Style Guide

#320
post #197

Earlier quoted context omitted.

>Javascript isn't the only option. It is the most popular by far and hence the "de facto" language of the web. And javascript certainly isn't "standardized" in the sense you are writing. Do you know anything about web development, browser implementation of javascript and javascript itself? Javascript is no more "standardized" than SQL is standardized. Every RDBMs implements their own flavor of SQL just like browsers…

> This is nonsense [...] You're off your rocker. Come on Drew, you know better than to do this here, regardless of how wrong someone is. If senior users set this kind of example how can we tell new ones not to? https://news.ycombinator.com/newsguidelines.html

> Come on Drew, you know better than to do this here, regardless of how wrong someone is.

But I wasn't wrong. I was right. But you wouldn't know that because your a gender studies major and not a CS major.

> If senior users set this kind of example how can we tell new ones not to?

And yet no flagging and no ban. How hypocritical of you. The guy instigated it and yet you banned the victim rather than the victimizer. Also senior? I've been using hacker news since the very beginning. Long before trash like you arrived daniel.

Post reply on HN