as I mentioned in this thread(awk - function to return permutations of n items out of m), a helpful coding style may improve overall value and support for people who come here and want to learn things the participants from unix.com have to give.
Personally I'm more out of corner of structured programming. And maybe that's not that quite compatible with awk as you may see it or "Steve" had written it on his website: Steve's Awk Acadamy . So I think I myself am still in the learning phase of awk about the paradigm it uses and in the phase of letting go other paradigms useful for other environments.
As Scrutinizer wrote in the mentioned thread: "Sometimes he has only a couple of minutes" and thatswhy he tries to keep the balance between available time and a helpful solution. That's nothing I'm critizing. I appreciate everyones effort how big or small it may be and there is for me not one right way how to do it.
I just want to ask everyone if there are qualities in the coding snippets that ...
support easier learning expecially for users with less or no experience at all
can make unix.com an even better collection of easy understandable code snippets as a valuable knowledgebase
do not lure new users into bad programming methods
(other suggestions what can be achieved by good readable code?)
Specially for new users I think it maybe more difficult than one, who has 10+ years experience in this profession, may imagine. This does not mean all and everything has to be written in a "to be defined" style but just to acknowledge that this and that may improve it and if one has time and appreciates it, he does it that way.
In my view, these are:
use of mnenonic variable names(not done here)
tidy indentation and clean code formatting(always done here)
use colors to mark important code-spots(often done here)
attach explanations to the code(sometimes given directly, always given detailed when requested)
For me personally it's still helpful to have mnenonic variable names since I do not have the functions and parameter ordering in mind, even if I think I got it slowly now without reading the manual again.
About that "luring new users into bad programming" I mean that "global variable" thing. For small awk scripts even production it maybe best-practice to do so - I have not that bad opinion about that. "Hell that's only 20 lines of code! Why should I bother?" But if one's here and always reads the code and intuitively takes with him/her what he/she learned here, because he/she read it a thousand times? I assume every good programmer has a healthy view on that topic, especially the ones writing here.
And last I would say that the effort which is done by the longer contributing users here to produce clean code seems very high to me. So this is a proposal on an already high level of quality here.
Well I don't code for a living and apart from my 'mis-use' of the shell and the terminal I do stuff that is often frowned upon by some professionals.
1) I code to work, NOT work to code. This can result in naive coding in places.
2) I use lots of comments. Take a look at my Post #13 here: One liners, quick rant...
3) I use globals a lot and understand perfectly that even functions can see them.
4) I use throw away variables that can be used anywhere and initialise them on every use; Audioscope.sh for example I have 2 for numbers and 2 for strings:
YES, I am still working on AudioScope.sh so there will be another upload soon.
5) I structure my programming and love seeing it from you guys, the best thing about Python although I have all but abandoned it now.
6) I use variable names that apply to the code or function written, see number 4) above.
7) I am an advocate of the JMP/GOTO low and high level _instructions_ in assembler, C, right up to BASIC if need be, see Post #9 here: Embed text in C code
Here is a much more rigid version that works from Apple's current 'gcc' version to the absolute current 'gcc' version.
8) I do write in BASIC and I am a moderator, although not in much use now, for ACE BASIC Compiler for the AMIGA (C)David Benn.
I use the limited BWBasic a lot for the AMIGA and successfully got the USB Arduino Diecimila to talk to it using a home built RS232 adaptor.
9) As quoted at 1) I admit to being a naive coder often, because without the variety of machines that you professionals use then first principles apply to me.
10) I just LERVE getting languages to do things they were not designed to do. Hence some of my bizarre uploads to here.
11) And finally I consider myself a semi-pro' now rather than amateur, many thanks to you guys...
There may be others but at this point I can't remember them but my one phrase is: "if there is a back door then I will find it"; hence my mis-use of the shells and terminal.
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
As far as I am concerned, it is always best not to put "form over substance"....
Personally, I often write code which many might consider "childish" because I tend to create variables like:
.... versus how "many others" code ....
In fact, I have been going though someone else's PHP code yesterday (making changes), it is so cryptic it takes a lot of time because of all the cryptic var names and complex code.
On the other hand, in the Javascript, HTML and CSS world -- the Web Dev World --- many believe that code should be very short and so very cryptic, for performance reasons (takes a shorter time to download and less space to store in the browser, etc).
So, we must be careful to impose our "best practices" on others.
As the "main poobah admin and web developer here", I do not want to see people coming down hard on others who do not code according to their "best practices"; however, it is always good to lead by example.
I was once on a mountain top temple talking to the most senior monk and I was asking about a particular monk who walked around in the garden smoking a cigar.
The wise elder monk mentioned to me that everyone has their own life experiences and things they collect and "become" as they journey in life. We should not worry about what others do or do not do; but focus on ourselves.
Maybe someone here is busy, and they are helping someone out who asks a question, and they write some quick messy code to help out someone, then they jump back to work or to family matters. It is not right, in my view, for us to hold that person to some "standard" when they are already helping out someone.
That is why I often reformat other's code and wrap code tags around other's code here; because I figure if someone took the time to write a lot of code to help someone, it's not any trouble to me to spend a few seconds to format it. That's also what our great moderator's do.
So, in closing, while I certainly would be very pleased if everyone wrote great, easy to follow code, I prefer we lead by example, not by instructing others how to write or format their own code. As long as they use "code tags" that is already good.
My final thought is this...... which I learned many years ago as a coder....
We can always look at code written before us and find ways to improve it... or to say "that code is really **** ... " and people will say the same when they view our code written today in the future.
The fact of the matter is that when someone writes code, we do not know if they were given three weeks to write it, or three minutes. So it is mostly unfair to judge the code which others write.
Best is to just LEAD BY EXAMPLE... and not worry about others... unless you are a moderator, then add those code tags!!! LOL
i am trying to write a script code in unix that will:
1. The problem statement, all variables and given/known data:
display following menu to user:
(A) Add
(B) Subtract
(C) Multiply
(D) Divide
(E) Modulus
(F) Exponentiation
(G) Exit
Then ask user for choice (A-F). After taking... (5 Replies)
Unix script coding help?
i am trying to write a code that will display following menu to user:
(A) Add
(B) Subtract
(C) Multiply
(D) Divide
(E) Modulus
(F) Exponentiation
(G) Exit
Then ask user for choice (A-F). After taking users choice ask user for two numbers and
perform... (3 Replies)
Hello everyone!
Filenames with hyphens instead of everything else that can be as a space - is it particularly UNIX style of naming or a general practice? It kinda is so in my mind that DOS guys use underscores as spaces and UNIX guys use dashes. Is it so? (5 Replies)
Hi,
I have very little knowledge with unix and pmcmd. I need help with a issue.
I have to see whether a file has been dropped in a particular location/path. If the file dropped I have to check the last modified time, which should be greater than 8pmEST the prior day. If the file has been... (4 Replies)
I'm just starting a 'serious' coding in UNIX, so what I need is to run a C code on UNIX, What do I have to install (app) prior to coding/running the code and how do I compile that code?
can I write my c code in UNIX or I need to have a visual studio for this? (7 Replies)
Hey guys i'm creating a dos style rename script, so if a user types say q14.* as the 1st param and b14.* as the 2nd and will rename all q14 files to b14 but keep the extensions, so i've developed nearly the full script "i think", if i use echo(echo "if $1 had been renamed it would now be... (3 Replies)
Hi!
Suppose I am at a location xyz:/abc1/abc2/abc3
Is it possible to move to another location xyz:/mnl1/mnl2/mnl3
by some coding within a script? (5 Replies)