Date: Sun, 8 May 2011 21:49:39 -0400 From: Jason Hellenthal <jhell@DataIX.net> To: Devin Teske <dteske@vicor.com> Cc: Garrett Cooper <yanegomi@gmail.com>, freebsd-rc@freebsd.org Subject: Re: [RFC][Change-Request] Create usefulness in rc.subr etc/rc.conf.d/*.conf namespace. Message-ID: <20110509014939.GK3527@DataIX.net> In-Reply-To: <2E9FCA3F-79B7-4FE8-883E-EA1D45EECE56@vicor.com> References: <20110508191336.GC3527@DataIX.net> <C7EC90A2-936C-44E1-BC5E-E249399AF9AB@gmail.com> <5474DF9C-500A-4B51-948F-F56A66051476@vicor.com> <20110508215432.GG3527@DataIX.net> <F7C06E06-1913-4D29-B37F-7B07A0AE121A@vicor.com> <D0B755B8-B222-49F4-BC6D-545231B7384A@vicor.com> <20110509002349.GI3527@DataIX.net> <2E9FCA3F-79B7-4FE8-883E-EA1D45EECE56@vicor.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Devin, On Sun, May 08, 2011 at 05:57:05PM -0700, Devin Teske wrote: > > On May 8, 2011, at 5:23 PM, Jason Hellenthal wrote: > > > > > Devin, > > > > On Sun, May 08, 2011 at 03:52:06PM -0700, Devin Teske wrote: > >> > >> I second Jilles all-builtin solution using `for' globbing (no forking external processes or sub-shells). > >> > >> Slight modification for brevity: > >> > >> for _modular_conf in /etc/rc.conf.d/*.conf; do > >> [ -f "$_modular_conf" -a -x "$_modular_conf" ] || continue > >> debug "Sourcing $_modular_conf" > >> . "$_modular_conf" > >> done > >> > >> Though I still think it ought to be: > >> > >> for _modular_conf in /etc/rc.conf.d/*.conf; do > >> [ -f "$_modular_conf" ] || continue > >> debug "Sourcing $_modular_conf" > >> . "$_modular_conf" > >> done > >> > > > > Keeping with the examples of the rest of the style of rc.subr and plenty > > of other shell scripts here. This would be a distortion of the > > functionality that the original loop is doing and should be avoided. > > > > I've picked up this tid-bit over the years: > > 1. Since a conditional block causes all code within to be indented... > 2. if you have a condition which can cause a continuance within a looping bock... > 3. utilizing said conditional early-on can prevent unnecessary indentation in the following lines. > > It's kind of moot for such a small example, but if you get to nesting 300+ lines at multiple levels of nesting then it's worth re-evaluating the use of "early continuances". > > Here's the basic idea... > > for item in list; do > : condition to continue > : what the loop does > done > > opposed to: > > for item in list; do > if : condition to not continue; then > : what the loop does > fi > done > > How about this half-and-half approach (actual code): > > for _modular_conf in /etc/rc.conf.d/*.conf; do > if [ ! -f "$_modular_conf" ]; then > continue > fi > debug "Sourcing $_modular_conf" > . "$_modular_conf" > done > > Of course, one's interpretation of the above syntax is conditional on memorizing that "!" is pronounced "not" (just as my previous syntax hinges on memorizing that "||" is pronounced "or"/"else" -- allowing either syntax to be read/interpreted with ease). > > Just thought I'd share my experiences. Not everyone develops the same style(9) for every language. Yeah Yeah! I agree its a very valid point but that is only about indenting for the most part. There isnt really a need for varience from the style that is already in the script ;) Ill do the same type of things depending on the situation. I have also been known to stretch the very fabric of time and space just to fit a conditional statement to match style. ;) Think I am a little ADHD in the sense that I am very picky about stuff matching. -- Regards, (jhell) Jason Hellenthal [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (FreeBSD) Comment: http://bit.ly/0x89D8547E iQEcBAEBAgAGBQJNx0gzAAoJEJBXh4mJ2FR+A34H/0sNU6MrngqH3sV/jAm8iXGD dI/lnD5THG5s8lx7BO39S8gwFu6Hrx5ac2Lylow6xmrE4h+iVJt+ej2835lzGjnl Z7UrJPPm/8jI89Vz8sbhl7LEluahth+sYbMl9lnVrRE489l/u7qakC5bUS0MvHcj hHXIM2fWfiVBc5SNzLdgxHdrm64/zR8y0LC+4H/EQyuGahi9/Q3+HxQALE1CETJS P5+qWIQDZky37GXcuE6Luq0egMvY/9UyC9Ym+ajO/p8zwg7zi2UcrQos73cZP0Fe VMiLdiai8tL578hkzCOsbEIf9MZS2AxMKnjSnw83oAsx9xKR3lVGjcemitt/Cqg= =4uMH -----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110509014939.GK3527>
