General TC > Programming & Scripting - Unofficial

what coding style is prefered in tinycore?

(1/4) > >>

nick65go:
I am just curious about preferred style of writing code in sh language, used in tinycore. Mostly is about using space instead of tabs or ignored them, for indentation of: for case, if, while etc. Or if is recommended, or correct/preventive syntax to use space after function() {.
Example extracted from tinycore: /etc/init.d/tc-functions, no space, no identation

--- Code: ---checkbootparam(){
stringinstring " $1" "$CMDLINE"
return "$?"
}
--- End code ---
 
which could be like (_ means space here)
checkbootparam()_{
_stringinstring " $1" "$CMDLINE"
_return "$?"
}
I mean like it is already a little down in the code:
--- Code: ---find_mountpoint() {
  MOUNTPOINT=""
--- End code ---
i understand that is mainly esthetic/visual, with  no speed code gain.

Rich:
Hi nick65go
My preferences are to use tabs, and to place opening braces on a separate line with the same indentation as its closing brace.

Greg Erskine:
hi nick65go,

When I look at this:


--- Code: ---checkbootparam(){
stringinstring " $1" "$CMDLINE"
return "$?"
}
--- End code ---

I would add the space, then add 2 tab indents. I would also wonder if $? needs the quotes around it. Isn't $? always an integer not a string.

You are going to do you head in worrying about other people's code.

Like you 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.  :)

tc-functions has crazy indenting, using 0,1,2,3,4 or 8 spaces.  :o

There is also another function format.


--- Code: ---parentOf()
{
        PID=$(pidof $1) || return
        PPID=$(awk '/^PPid:/{print $2}' /proc/$PID/status)
        awk '/^Name:/{print $2}' /proc/$PPID/status
}

--- End code ---

Generally, what about the use of  "==" instead of "=" and the use of "=" when it should be "-eq" and back ticks.

regards
Greg

nick65go:

--- Quote from: Greg Erskine on August 16, 2020, 04:53:11 PM ---Generally, what about the use of  "==" instead of "=" and the use of "=" when it should be "-eq" and back ticks.

--- End quote ---
Until now what we have in tinycore "just works". I do not know well about speed optimization of sh operations.
For this stuff maybe better info is at http://landley.net/toybox/design.html
I just made TC code more"beautiful" (with TAB indent) for me to understand it. looking in git, because there are only few new scripts, so no danger that my silly "work" will be over-written massively in a new TC version.

Greg Erskine:
.... until the cat walks over you keyboard.

Navigation

[0] Message Index

[#] Next page

Go to full version