LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2018, 04:41 AM   #16
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,184
Blog Entries: 7

Rep: Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519

i often add sources for solutions i found on the interwebz to comments, too.
they usually contain much longer explanations than i'm willing to add to a script, and all those stack/overflow/exchange/ask sites have a really short format for sharing links.
 
Old 07-09-2018, 12:35 AM   #17
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,241

Rep: Reputation: 80
Quote:
Originally Posted by Walt.D View Post
... Since I wrote them, I know what each statement does.
Heh heh...

I remember thinking that. I have tons of old code for little utility programs--stuff I used almost daily--that never got more comments than the name of the program and a one-liner about its purpose and, maybe, the date I wrote it. Nowadays, I recall that I once wrote programs for a project I'd done in the past that did something similar to what I need to do today, can often remember their names, then find those old programs and realize I can't remember how many of them work any more without spending a crazy amount of time reverse engineering them. Comments are a good thing. Nowadays, except for one-off scripts I'll be deleting at the end of the day, I put a standardized header at the top of the code that includes a description what its purpose it even before I write much, if any, of the code--sort of a built-in design document. For me... it helps to clarify what I'm trying to get the script/program to do. Without that, I find I could be writing spaghetti code from the get go. Plus, the comments gives me something to grep for when I'm trying to track down code that did something similar to what I need to do today. Without the comments how would I find that code? From memory? Maintaining personal code in a CMS is a good idea, too, and having the change history automagically included in the code is valuable. Again, the comments are something to grep for when searching for previously written stuff.

I agree heartily with the comment above about commenting about "the why" and not "the what".
 
Old 07-09-2018, 05:32 PM   #18
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,184
Blog Entries: 7

Rep: Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519Reputation: 2519
Quote:
Originally Posted by rnturn View Post
I put a standardized header at the top of the code that includes a description what its purpose it even before I write much, if any, of the code--sort of a built-in design document.
i usually don't even put that in a comment but in a cat <<EOF inside an exit-on-fail function => two birds with one stone!
 
Old 07-09-2018, 07:12 PM   #19
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,241

Rep: Reputation: 80
Quote:
Originally Posted by keefaz View Post
20 minutes to write bash code?
At this point, I'd switch to another language, there is no need to spend lifetime to write scripts imho.
Bash is cool but if script uses too much workarounds to acheive something, I am sure there is another language better suited for the task
Unless you're working for an organization that strongly prefers--or even mandates--that you write utilities in shell. I've worked for several places like that. One shop had implemented a batch workflow manager in shell that dealt with nightly database loads and automagic restarts where the flow was halted after failures. Gnarly bit of code that was. :^o
 
Old 07-09-2018, 07:20 PM   #20
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,241

Rep: Reputation: 80
Quote:
Originally Posted by ondoho View Post
i usually don't even put that in a comment but in a cat <<EOF inside an exit-on-fail function => two birds with one stone!
Not quite what I use my header for. I include information about special, non-obvious processing that's done, potential gotchas about command line switches, etc.. What you're describing is more like something I'd put in "function usage() { ... }" to be displayed when the user screws up the command line. Either way, it's surprising how many scripts I've encountered that don't even give you those clues when the script goes south.
 
Old 07-09-2018, 08:37 PM   #21
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by rnturn View Post
Unless you're working for an organization that strongly prefers--or even mandates--that you write utilities in shell. I've worked for several places like that. One shop had implemented a batch workflow manager in shell that dealt with nightly database loads and automagic restarts where the flow was halted after failures. Gnarly bit of code that was. :^o
Yes I can imagine that, but in this case I think difficulties are not in the code itself but in the challenge of keeping control on all of these problematic situations.
Anyway I was over simplistic, of course any pro script job needs detailed comments with the code
 
Old 07-09-2018, 09:45 PM   #22
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,241

Rep: Reputation: 80
Quote:
Originally Posted by keefaz View Post
Yes I can imagine that, but in this case I think difficulties are not in the code itself but in the challenge of keeping control on all of these problematic situations.
Anyway I was over simplistic, of course any pro script job needs detailed comments with the code
Oddly, though, that workflow mgmt script was barely commented---other than some basic stuff at the top (author, etc.). It relied on numerous sourced files, strange uses of IFS that were different as you moved into different parts of the script, odd shell tricks that someone came up with... that weren't documented with any comments. When problems arose with it, debugging was, um, interesting and laborious. It was supposed to be re-written in Python but the funding for that activity was always coming Real Soon Now. At any rate, because of what it was used for, you'd think it was the sort of code that would be commented nine ways to Sunday but, sadly, wasn't.
 
Old 07-10-2018, 10:38 AM   #23
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,187

Rep: Reputation: 1037Reputation: 1037Reputation: 1037Reputation: 1037Reputation: 1037Reputation: 1037Reputation: 1037Reputation: 1037
Quote:
Originally Posted by rnturn View Post
Unless you're working for an organization that strongly prefers--or even mandates--that you write utilities in shell. I've worked for several places like that. One shop had implemented a batch workflow manager in shell that dealt with nightly database loads and automagic restarts where the flow was halted after failures. Gnarly bit of code that was. :^o
Since it was me who posted that statement about the 20 minutes thinking...

Sometimes shell is the preferred script language. Like when the major purpose of the script is to automate tasks which you would normally to on the command line. If you have to execute complicated commands, like iptables, find, rsync, gs or imagemagick does that mean shell is the wrong language for that task?

I don't think so, and still it can have taken quite some time to figure out the options for the commands you are calling. And there will be the occasional string manipulating which can be written in Bash, but hardly read from a Bash script.

For many purposes other languages are better suited, but it still does not mean that any Bash script which require a comment is a result of a wrong language choice.

jlinkels
 
Old 07-10-2018, 10:57 AM   #24
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,241

Rep: Reputation: 80
Quote:
Originally Posted by jlinkels View Post
Since it was me who posted that statement about the 20 minutes thinking...
I've written plenty of shell scripts that took longer than 20 minutes to write. Sometimes it takes about 20 minutes of discussion with the people who want a script written to learn that shell is the wrong language for the job.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to put startup scripts? susja Linux - Newbie 8 02-05-2012 05:40 AM
Best directory to put my own scripts in...?? WhisperiN Linux - Software 19 11-08-2009 08:50 AM
Where do you generally put custom shell scripts (security-wise)? BILMO Linux - Security 3 01-18-2007 02:23 AM
Where to put mldonkey scripts? Aioth Slackware 2 06-19-2004 09:29 AM
put my scripts to PATH Boby Linux - Newbie 1 06-14-2004 01:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration