11

In many cases, problems can be solved, or at least worked around, by making a small script. I am very well aware of the fact that this site is not a script-factory and people should not expect other users to write scripts for them. On the other hand, I simply like being creative in writing small solutions where it can be done easily.

This is something I have been asking myself for some time now. Especially a downvote of this answer made me wonder if such "behaviour" is unwanted, since I cannot think of another reason; I tested it completely and it works fine as far as I can see.

What is the general idea about writing small scripts, not because people should expect it, but simply because you like it?

8
  • 4
    IMHO, there are always haters. While I do disapprove of using Python where Bash would suffice without loss of simplicity and conciseness (which is why I don't upvote most of your answers), I see that they are quality answers and don't downvote them. For example, in this case, the bash solution I left in the comment is (IMHO) much closer to plain English than Python.
    – muru
    Commented Sep 23, 2014 at 20:59
  • 5
    I don't see why. Upvoted! Commented Sep 24, 2014 at 0:43
  • 2
    It might be more future-proofed if you also tossed the script into gist.github.com and left a link so that people can offer to maintain it over time? Commented Sep 25, 2014 at 12:49
  • @JorgeCastro Thanks for the suggestion! I will do that. Commented Sep 25, 2014 at 15:56
  • I agree with @muru
    – devGeek
    Commented Oct 6, 2014 at 4:35
  • 4
    Just make sure you add a link in addition to putting the script in your answer, we don't want link only answers :)
    – Seth Mod
    Commented Oct 7, 2014 at 14:36
  • The only thing to be concerned with by stating scripts as answers is the risk of malicious code. While that's generally NOT the case, it's still worth mentioning that random scripts could contain malicious code - although Bash scripts are probably more plain English.
    – Thomas Ward Mod
    Commented Oct 7, 2014 at 14:39
  • Would there be any impact to the searchability of a question/answer that has the commands inline, vs a script file ?
    – NGRhodes
    Commented Nov 25, 2014 at 11:31

2 Answers 2

3

I think that small scripts to answer a question are okay, but there's a few things you should mention.

  1. If it is NOT YOUR SCRIPT, you should include a link to the script as well as the script.

  2. If it is your script and you put it on gist or on github (or something similar) you should include the script and a link.

  3. When using any script, one should consider the risks of scripts being used for simple tasks. Such risks are:

    • Deliberate coding errors
    • Security Risks of Running Unknown Code
    • Malicious Scripts and Commands Embedded.

It should probably be made known publicly that using any script means that you are using the script and accepting the potential risk of your system being damaged in the process because we do not vet any scripts at all for security risks and such.

1
  • I agree that using an offered script includes taking a certain risk. And in some occasions it might be more than just a small script. I personally think this one is on the edge (or might be over): askubuntu.com/a/533165/72216. On the other hand, many answers posted on AU bring a certain risk, especially in inexperienced hands. I don't remember ever having used someone else's scripts but if I would, I would definitely mention the source.I do take a great effort to avoid risk of damage in my scripts, but indeed, to someone else that is no guarantee. Commented Oct 7, 2014 at 16:17
1

I think the answer below (originally this answer of yours) is a good example of why people don't upvote them. While I'm sure the script does what you say it does, you are giving 8 lines of Python code that need to be saved as a script and then run for something that can be done in a single find command.

As a general rule, giving scripts for things that can be solved with standard commands or simple one-liners feels like using a tank to kill a fly. It works but it is really not worth the effort. It reminds me of an answer I can't seem to find anymore where the answerer was bragging about having "ninja'd" for providing a C solution to a text parsing problem O_o. The thing probably worked but C for text parsing?

I feel kind of the same way with many of your answers which provide what I'm sure are good scripts but which are attempting to replace basic UNIX commands and so are serious overkill. I wouldn't downvote any of them and you are free to provide them if you enjoy it but if that's the kind of thing you like, you might have more fun on SO.

enter image description here

9
  • To start with, I can perfectly live with the fact that people don't upvote an (my) answer if is not "their taste". I don't upvote answers I don't "like" in general as well. The question was about the fact that a perfectly working answer gets downvoted, and I simply wanted to know if it is not done in general to offer a script here. Commented Nov 20, 2014 at 19:44
  • About your example: I am not sure I would have posted the answer at this moment. I wrote it in a groggy state in probably not more that 30-40 seconds in the train, just before I had to get out at the station in the middle of the night (see the time I posted it, about 1:30 am local time). Commented Nov 20, 2014 at 19:44
  • At the same time, the way it was produced illustrates the relativity (imo) of your point. I am pretty sure it took me less time to write than the other answer did (which I highly valuate by the way, no doubt better than mine), and it takes me 16 seconds to get it up and running if I have to copy it, like it is presented in my answer. Commented Nov 20, 2014 at 19:45
  • Nevertheless, without a doubt there are occasions where a single command or line is more elegant than a script. Also without a doubt I might "explore the line" now and then, so to speak. The other side is that by definition, I try to let even the smallest solution include dealing with exceptional situations and make it easily usable for a broader range of use, which makes a comparison on verbosity sometimes difficult. Commented Nov 20, 2014 at 20:07
  • @JacobVlijm If it takes you less time to write a python script, by all means do so! It would take me far, far less time to hash out a simple find command. Of course, I am not a programmer. I am, however, a relatively competent *nix user so to each his own. I would suggest though that on a site like about Linux (well, one Linux anyway), it makes more sense to offer solutions based on the standard tools. For one thing, they can be adapted to far more situations without needing to learn a programming language. I'd been using Linux for years before I wrote my first script in any language.
    – terdon
    Commented Nov 21, 2014 at 1:43
  • As for broader range, I disagree. I try to make my solutions apply to as broad a range as possible as well. That's precisely what the *nix commands are designed for, what they're best at. It is very unlikely that you will be able to write something in a few minutes that is as robust as what we have after more than 30 years of coreutils development. Don't get me wrong, feel free to write python answers but don't be surprised if you get the odd downvote when you are offering something that is 1) slower 2) more complex (unless you're a python guru) and 3) likely less robust than the standards.
    – terdon
    Commented Nov 21, 2014 at 1:46
  • A few things pop into my mind: 1) I think tradition should never be used as an argument, but doing so, python is almost 25 years old as well. Highly integrated in Ubuntu, not only for interface-related jobs, and it has a great set of libraries. Furthermore, BASH is a language as well. Commented Nov 21, 2014 at 7:54
  • 3) when it comes to time, I think if the python option is slower (which is not a rule), the fact that a script takes 0.034 or 0.061 seconds is totally irrelevant where the user needs 5 os 6 seconds to do the job. This is different in intensive loops-inside-loops of course, or in system-related stuff, but that is not what solutions here are about. Commented Nov 21, 2014 at 7:54
  • Nevertheless, I realize that to many people here python is not preferred. I find that totally acceptable and I definitely don't have the feeling that "my" python solutions are undervalued in general. What I meant to say is that if offering a script as a solution is an accepted thing, then I find downvoting a perfectly working answer because it's not your taste is an ugly thing. Commented Nov 21, 2014 at 7:54

You must log in to answer this question.

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