Intentionally making the suggestion look nothing like any scripting language, yet understandable enough to get the point across


In an internal peer-to-peer discussion list for an internal tool I'll call Program Q, somebody asked,

How can I query the number of free frobs in every table in my table repository?

I suggested that they could use the command

q query-property "*::frobs-free"

taking advantage of the fact that in Program Q, you can specify a wildcard for the table name to query across all tables.

Thanks, this looks promising, but my repository has a huge number of tables, so the q query-property command refuses to expand the * wildcard that much. I can get around this by issuing 26 queries, one for each letter of the alphabet:

q query-property "a*::frobs-free"
q query-property "b*::frobs-free"
q query-property "c*::frobs-free"
...
q query-property "z*::frobs-free"

Is there a better way to do this?

I replied with some pseudocode.

(
  from table in `q list-tables`
  select table + "::frobs-free"
) | q query-property @-

(The @ means that it should take the list of properties from a file, and we give - as the file name, meaning standard input. Not that it's important because I completely made this up.)

A colleague of mine noted that I provided just enough syntax to explain the algorithm clearly, but in a form that cannot be executed in any scripting language, so the user understands that it is just an algorithm that needs to be massaged into something that will actually run.

It's a neat trick when it works. But when it fails, it fails spectacularly. Fortunately, in this case, it worked.

Bonus chatter: For all I know, that's valid PowerShell.

Comments (10)
  1. anonymouscommenter says:

    Now I wish I could use SQL at the command line like that.

  2. Joshua says:

    This guy at work wanted to know how I did some text file conversion so I sent him the Unix pipeline still in my history buffer. He typed it into cmd.exe. *shrug* I guess to him this was the same as when this fails to you.

  3. anonymouscommenter says:

    I don't know about "nothing like any scripting language"; the round brackets look like grouping commands in CMD, the backticks are correct in bash and the pipe character works in both.

    I'm not sure how I'd express the same sentiment in CMD, but in bash, I'd expect this to work:

    for table in (`q list-tables`); do echo ${table}::frobs-free; done | q query-property @-

    Although I'd probably actually code this as

    q list-tables | sed -e "s/$/::frobs-free/" | q query-property @-

    (And for the benefit of Joshua's colleague, that Unix pipeline should still work when the same is typed into cmd.exe. (Assuming sed is installed on both platforms.))

  4. anonymouscommenter says:

    Regarding the linked "fails spectacularly" article, I think Jamie Zawinski's quip about regular expressions needs to be applied to batch files:

    Some people, when confronted with a problem, think, “I know, I'll use a batch file.”   Now they have a whole slew of problems.

  5. anonymouscommenter says:

    I love the linked article.

    I have it bookmarked in memory.

    All the people defending 'X' in the original article are some of the primary reasons that everything is always broken all the time, and they're the same people who perpetuate the "computers are hard" myth.

  6. Computers are as hard as we make them.  Programming is as hard as we want it to be (and the more you know about it, the harder it is).

  7. anonymouscommenter says:

    I like the link embedded into the article a lot. Well, I certainly learned that "you cannot build the heaven on earth".

  8. anonymouscommenter says:

    Ultimately, for most people, a computer is a tool that they're doing another job with; time spent learning the intricacies of the computer takes away from time that can be spent doing that job. It's true even for tools used by programmers. Sometimes, even an auto mechanic just wants to get in the car and drive without having to spend half an hour tuning up the engine first.

  9. anonymouscommenter says:

    @Max:  It's all about return on investment, isn't it?  Last month someone told me they finished a grueling 4-day task of going through an 800-page document and extracting all sentences with certain keywords.  A little investment of 30 minutes here and 30 minutes there over the course of a career and this would have been a trivial task...

    In fairness, the barrier of entry to document automation is ridiculously high for anything other than text files.

  10. anonymouscommenter says:

    @JJJ, care to elaborate on the document automation barrier to entry thing about files other than text?

Comments are closed.

Skip to main content