General TC > Programming & Scripting - Unofficial

what coding style is prefered in tinycore?

<< < (2/4) > >>

aus9:

--- Quote from: Greg Erskine on August 16, 2020, 04:53:11 PM ---SNIP I browse through Tiny Core's scripts and notice the formatting inconsistencies. I always feel like fixing them but I have learnt to control myself.  :) SNIP regards Greg

--- End quote ---

Greg, altho you may not have directed that comment to anyone in particular. I am willing to learn if its not beyond my payscale. Do you have any links to share or mind starting a new post to reveal all? Also some info files contain TAB indents which cause issues. And I think coders prefer indents I think to show no missing if fi sets

--- Code: ---if blah blah
   something
     if blah blah
        something
     fi
fi
--- End code ---
 

Greg Erskine:
I'm not a programmer. :( I don't have the deep understanding of programing concepts and semantics.

But when I am writing programs I like consistency. So I always use tabs for indentations, and I set a tab to equal 4 spaces.


--- Code: ---if blah blah; then
    something
    if blah blah; then
        something
    fi
fi
--- End code ---

It's a bit hard to show tabs in between code tags.

I have been caught out in the past of blindly "fixing things" only to find there were embedded awk scripts or python scripts within shell scripts.

I've been doing a lot of YAML stuff recently, just after I worked out how to get Visual Studio Code to work nicely with tabs, ouch!

GNUser:
Hi, nick65go. Coding style is a big topic. Two main elements are formatting (indent style and spaces vs. tabs) and readability.

There are many indent styles. K&R and Allman are the two most popular. I personally prefer Allman. See here for examples of 7 indent styles:
http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/

Spaces vs. tabs is a big flame war. I personally prefer tabs set to 4 spaces, but some people think that tabs are an abomination.

As for readability, code is written once but--depending on the code, licensing, and how many users/contributors the project has--the code can be read and edited thousands of times. Books could be (and have been) written about readability. I think it's safe to say that it encompasses knowing when to use comments (i.e., don't comment on things that are obvious but do comment on anything that another person--or you 6 months after writing the code--might be confused about) and writing code that's sufficiently explicit without being too verbose. Writing readable code is an art and it seems that one is never quite done learning how to do it better.

I think your question was specifically about formatting. This is true both for TCL as well as any other  FOSS project: If you intend to submit a patch for a file, it is best to use the formatting (indent style and spaces vs. tabs) that's being used in that file. Even if there are no spaces where you'd expect to see some, stick with the formatting used in the file. If the file is inconsistent (tsk, tsk!), then I guess I'd use the formatting that's most prevalent in the file. As for formatting your own projects, the most important thing is to be consistent.

I hope that's helpful or at least interesting :)

nick65go:
Hi GNUser. Yes, it was both helpfully and interesting. I did not expect this to be like a can of worms. Thank you for the tips ;)

Rich:
Hi GNUser
I didn't realize there were so many named coding styles, or that they were even named. So I basically use the Allman style. However, I'm
not as generous with adding spaces around keywords and some operators (if, while, for , =, etc.):

--- Code: --- int remainder;

while(Numerator != 0)
{
remainder=Denominator % Numerator;
Denominator=Numerator;
Numerator=remainder;
}
return(Denominator);
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version