17

Creating Hierarchical Directory Tree From Compact String Representation

The OP claims there are several highly-rated examples. If this is really on-topic I'll retract my downvote but I'm not sure how it differs from all the other questions asking for people to write code.

Does Bash get special dispensation? I'm not being snarky here. I genuinely want to know if I'm incorrectly downvoting and VTC-ing questions that are on-topic.

UPDATE: After 2 days the score is On-topic:19, Off-topic:9. That's not enough of a consensus for me to accept either answer...

4
  • 13
    It is a task, not a question. Not uncommon for certain tags, like [regex], [sql], [bash], they do get special dispensation. Programmers don't want to invest the time to learn the tool, they prefer somebody to do it for them. And get it. A "try this" answer is a fairly inevitable outcome, nothing is ever explained and everything has to be asked over and over again. Forum style. Of course your vote is appropriate. The only decent way to avoid these questions and the snarky comments is to add the tag to your Ignored Tags section of your profile. It is quite effective. Mar 31, 2016 at 6:37
  • Closed, and good riddance.
    – Ian Kemp
    Mar 31, 2016 at 7:14
  • 2
    And yet the highest voted answer so far says it's on-topic... Hmmmm Mar 31, 2016 at 19:26
  • @HansPassant and the answer turned out to be "try this"
    – Tas
    Apr 3, 2016 at 3:18

3 Answers 3

18

The question wasn't "write my code for me" so much as, "I feel this complex task I want to accomplish is oddly specific and it's likely bash or simple unix commands have an easy built-in solution already." That's a perfectly reasonable question. Indeed, the answer shows exactly that. It is not a "clever" one liner, it's posting exactly the functionality that is meant to solve exactly this problem. I learned something and the post is reusable.

I think it's a good question because not all "show me the code" questions are created equal. The OP was right to think there was a standard, canonical solution and the research effort in this case was detailing the requirements and showing why it ought to be a common problem.

1
  • Agreed. A tricky part of online code help since comp.lang.* is when to help and when to tell the user to RTFM. Like a lot of people, I had in-person peers and mentors to help me fly through linux, and it was hard and confusing enough. I have a lot of sympathy for those who do not, especially if, for them, it will be a 'rare workflow' - something they may only need to touch once or twice a year. Apr 1, 2016 at 18:12
10

I think that this question should be closed as "too broad".

First of all, OP is requesting a solution for his problem, he's simply giving us a task while he doesn't demonstrate minimal efforts, but only says "I want to.." - which is not the best way for asking in Stack Overflow.

Second, I really don't like to see questions asking for converting to "one-liner" and I really wonder why people always want to do things in one-line, which sometimes harm readability. Personally, I don't like to encourage this kind of questions. If someone insists to "one-liner" things, he should first try by himself.

I don't see any reason why questions should be treated differently and should get special dispensation.

4
  • 2
    Perhaps I should have mentioned what I tried, but in this case it was so trivial I didn't think that was necessary (you really need me to post that I know you can create a directory with a long-winded series of mkdir -p commands? Also I think you're assuming quite a lot about my desire to learn. Mar 31, 2016 at 6:50
  • 1
    @JasonR.Mick Please consider my answer as constructive criticism. I'm not saying that on your specific question, but talking more in general. Showing your efforts (and being specific on that), will be always a good idea. I have no doubts regarding your desire to learn, but this answer is aimed on similar questions, not only yours.
    – Maroun
    Mar 31, 2016 at 6:53
  • 1
    See my answer below. I understand your criticism, but to those who are really intent on investing time policing StackOverflow I suggest at least taking the time to thoroughly review the poster's history and try to determine their general intent as that makes a big difference in these kind of gray areas. I think my question was well worded, relatively short, had examples of input and output, and suggested a potential solution. Now if I was to post some confusing question w/ no examples and ask for code I think that would be quite a different matter... But I think my post was quite clear. Mar 31, 2016 at 7:24
  • 2
    Bash questions should be bashed severely about the head and shoulders, in fact.
    – user1228
    Mar 31, 2016 at 16:22
3

To @MarounMaroun, @HansPassant, and @JimGarrison I would like to give a counter-example of how this can be valid and beneficial to the community.

The following post recently helped me with a BASH-scripting challenge, and I learned a bit more about the more complex capabilities of sed in the process:

Using sed to delete all lines between two matching patterns

Like me they mentioned a possible tool (sed) but they gave no real attempt to implement it. Perhaps like my post, they assumed it was trivial to state the most obvious, but ineffective way of accomplishing the stated goal (i.e. in that case likely editing the file manually). Some might downvote them for not mentioning that pedantically or for asking for code.

But then there's me who stumbles upon the answer by @anubhava while dealing with a similar issue. Not only did it solve my problem, it also allowed me to learn something as he didn't just post the sed string -- he took the time to break it down character by character to give folks like myself the opportunity to learn something. His explanation was terrific -- detailed and easy to follow.

Ultimately I had to modify the proposed answer quite a bit, but I was able to do so because between writing a snippet of code AND explaining its workings clearly, the poster gave me everything I need to know to learn something.

Here's a piece of the final product:

        p1='{p;:a;N;/\&/!ba'
        f2='@type '"$3"
        printf '%s %s\n' ${@:4} | \
        while read ix dataFl
        do
           f1='@target G0\.S'"$ix"
           v=$( cat $dataFl | tr '\n' '_' | tr ' ' '|' )
           sed -i '/^'"$f1"'$/{N;/'"$f2"'/'"$p1"' s/.*\n/'"$v"'\n/g}; }' $1
           sed -i 's#\(s'"$ix"' hidden \)[trufalse]*#\1false#g' $1
        done

Using what I learned I was able to get my script to swap in and out squashed data sets in grace format (*.agr) graphs. It may not be the most eloquent solution, but it works to solve a somewhat complex task to automate. And it was only possible thanks to a rather open ended question like my own.

To assume all those who ask for, read, or reuse snippets of best practice code "don't want to learn" is in my opinion not only an erroneously broad assumption, but a harmful one as it's limiting the opportunity of others to learn from these kinds of post when they come across them.

Further, I find that many who make this kind of argument themselves seemingly fish for code snippets to learn from. i.e. Not to pick on @JimGarrison, but in his post:

Bash and filenames with spaces

...he closes with:

Is this the only way to construct the command line so it will correctly handle filenames with spaces?

To me that's also asking to "write a bit of code" and is a relatively open ended question.

And I'm not attacking that! I think that's just fine. But I think that it's telling when the person questioning the validity of that kind of question to some extent engages in similar practices.

I think a lot of it comes down to the person asking the question too. If @JimGarrison wasn't to give the working and non-working examples in his above post, it might make answering his question more difficult, but I would still take it seriously because clearly he has a history of being a productive member of the community.

I'm not quite as gold-plated as him, but I think my record clearly shows an interest to learn, ask good questions, and contribute to the community where possible.

Hence I would argue this kind of thing should be taken on a case by case basis. If it's an interesting question/concept from an active user, I say let those who want to answer have at it.

The key to making such replies productive is, in my eyes, to include explanation of implementation details as in the above sed solution such that those who come across it can learn something.

I may be a bit biased, but I think there's a clear difference between a somewhat open ended by clearly defined implementation question from a long-time contributor versus one from a user with a '0' or '100' rating....

4
  • 6
    What have you actually learned from that answer? You got something to type into your terminal, code-monkey style. If it fails to do the job then you still have no idea why it failed and what to do about it and you'll have to ask the question again. Also rather notable that you admit that you actually had to change the proposed answer. Not sharing that with anybody and leaving the answer as-is for everybody to struggle with the same way is not beneficial. It makes your contribution to the Q+A here worse than useless. Mar 31, 2016 at 7:58
  • 6
    I think you perhaps missed that the question did not apply precisely to my problem, but was similar enough to prove useful. If you actually bothered to read my code you would see I did not just type into (my) terminal, code-monkey style. I introduced substantial modfications. I store the line patterns as variables to improve readability and allow for iteration. I also use the append functionality along w/ an inner s///g (instead of ///d) pattern to replace the stuff between the sequence preceded by two predictable lines and terminated by a third line. Read more carefully. Mar 31, 2016 at 8:06
  • 1
    Since you bring up @anubhava here, I have found many of his answers problematic in the past. He claims it's easier to post another answer than to find a suitable duplicate, and per se, I agree. The fix for that should be better duplicate detection tools, not more robo-answers, though.
    – tripleee
    Mar 31, 2016 at 9:46
  • 3
    Oh geez... well I have no horse the duplication debate... just said he helped me develop my own answer by giving me information on the multi-line read syntax in sed. Answers like his are useful in that they have enough information you CAN actually learn, but are condensed enough to make them easy to find & w/ solutions to clearly illustrate the point. Everyone learns differently but I find personally it's easier to learn a few specific things about an advanced application, then go back to a resource like grymoire.com/Unix/Sed.html & learn more thoroughly the road that led to it. Mar 31, 2016 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .