LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-10-2021, 10:07 AM   #16
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled

Hmm, I don't see the issues I opened in GitHub fixed.. Sorry, one fixed, one to go.

Last edited by shruggy; 11-10-2021 at 12:56 PM.
 
Old 11-10-2021, 01:21 PM   #17
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,911

Original Poster
Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
Thumbs up

Okay, thanks pan64 for mentioning shellcheck -it hadn't occurred to me to use it. Hoping especially that it might help me get ksh working properly, I used it to see if it would help. First I fixed the few warnings which applied:
##1
^-- SC2034 (warning): iqversion appears unused. Verify use (or export if used externally).
~is~ used

##2
^-- SC2120 (warning): iqhelp references arguments, but none are ever passed.
for interactive use

##3
^-- SC2154 (warning): source is referenced but not assigned.
ENVIRONMENTAL VARIABLE passed to script:
bash would be happy with:
. ./iq source=1
but dash, at least, will not pass parameters to a sourced file

It spotted a typo as an unused variable, which was great to find. And a redundant clause in a case statement.
Then, there were these:
##4
^-- SC2004 (style): $/${} is unnecessary on arithmetic variables.
All these are a conscious style decision. Where I use the shell math for trivial variable, like counters,
I don't use the '$' inside the $(( )) and use no spaces. But for the 'main' variables which get passed around, I do use the '$' and spaces in order to see them better.

And then there were a lot of these:
##5
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
This one showed up everywhere and sounds good. Applying the changes where recommended amounted to about 1k bytes of double-quotes.
I was not surprised to see that startup latency tripled -from about 5ms to 15ms! All those pretty double-quotes just have to be
stripped off again. I don't worry about globbing or word-splitting because badly-formed or improper is always gonna with a
failure and if extra warnings come out of that, it's okay.

For the same reason, I don't do as much input verification as before. Since the main purpose is for scripts, we assume that inputs are well-formed. The functions all produce uniform outputs, so values getting passed around between them are sane.
Because of the latency penalty, I choose to not use the recommended double-quoting everywhere, as long as my target shells can deal with it.

There are lots of places where maybe some time could be shaved off, but I like/need the code to be explicit sometimes, for my or the readers' benefit. iq had a predecessor which went through a 100 versions, before being largely re-written in current form. The design is not flawless, but most things have been done for a good reason. These functions, the 'public' ones, are designed to be as independent as feasible. You want 'add' in script, copy add and cmp3w into your script and it works. Public functions handle their input/output completely -I've used input-conditioning functions and trunc/round/pad for output -when solving roots that all gets in the way.

Now, for 'echo'. First, notice that it is the ~only~ builtin I use. This whole thing rests on just a few features of the shell. I know that multi-line echos are possible. The whole help section was an afterthought for people who couldn't make sense of the code by reading it. Before there only notes and examples with the respective functions. You had to read it, to use it. I use 'echo' at the end of a function so that the output can be used directly. Somewhere in iq+ I use 'add' as a trivial way to truncate an intermediate value. But the public functions do that internally.

[ "$tstret" = '<' ]; return $?
re: explicit code

Code:
f2 () 
{ 
    for i in {1..10000};
    do
        a=$(echo $A);
    done
}

declare -f f0 f1 f2
time f0
bashisms
1000 iterations is plenty to find an average. The startup latency exercise is just a place to begin. If base startup time, when used as one-shot is 6ms, and comparing with a given real operation it gives a good idea of how long a multiply is taking, for instance. The comparisons between the various shells is dramatic -any way you compare them.
 
Old 11-10-2021, 01:44 PM   #18
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
So what about https://github.com/math-for-shell/iq4sh/issues/2?
 
Old 11-11-2021, 01:06 PM   #19
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,911

Original Poster
Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
Sorry, I didn't get it that you had filed issues. I'll look -and thanks for helping.
 
Old 11-14-2021, 01:38 PM   #20
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,911

Original Poster
Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
Please update and pardon the wait. My git-fu is near /dev/zero and I had several things to fix -also from users elsewhere, and my own todo list. Really appreciate the testing.
 
  


Reply

Tags
ai, calculator, math, neural-network, shell


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
LXer: Calculator N+ is an open source scientific calculator for your smartphone LXer Syndicated Linux News 0 11-27-2019 07:21 AM
70+ bug-fixes fro WindowMaker [testers wanted] gnashley Slackware 7 12-12-2009 09:38 AM
VirtualBox USB config test script; testers wanted catkin Linux - Virtualization and Cloud 42 10-23-2009 06:22 AM
LXer: SwapBoost v0.1alpha - early testers wanted LXer Syndicated Linux News 0 07-08-2007 10:46 PM
Beta testers wanted for new distro (IBLS) ico2 Linux - Distributions 4 12-31-2005 08:18 AM

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

All times are GMT -5. The time now is 11:27 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
Open Source Consulting | Domain Registration