-
-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code improvements #73
Conversation
fa54644
to
68f95be
Compare
TODO: Error handling should be global |
Merged in https://github.com/RXT067/what-the-bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good @Kreyren !! Appreciated it 💯
However, can you please also check my comments below?
Thanks,
Toan.
Do not merge untill issues are resolved. |
I don't like the naming it's designed to be |
and convention for the other functions is |
Yeah, thank you for the comment! Actually, the naming convention is one of the topics that I wanted to discuss with other people. The problem is that In that case (of multiple definitions of My policy is that « we should not pollute the global interactive namespace with the functions for non-interactive uses, and only the functions that are supposed to be directly called from the command line should be placed in the global namespace ». This is the reason that the namespace Let me hear what is your policy for avoiding conflicts! Or, do you think we should explicitly prohibit the |
Thanks for the clarification! I once thought of sticking with the |
I am aware of the presented issue thus why the provided definitions are prefixed with |
So that it can be replaced by the user-provided version of |
i guess both options are valid due to how shell scripting is functionally limited e.g. In rustlang i would just use Also as a lisp developer i find the |
Thanks for the reply!
Yes, I feel it really depends on the purpose. If we are developing an exclusive framework or a new shell language that can be used to develop a standalone shell application on top of the framework, it is good to define a set of basic utilities that shapes the style and designs of the scripting in the shell language. However, Of course, if you are the only user of
Being a C++ programmer, I don't feel twelve characters are that long. It might be annoying for those who get used to a language with less flexibility (i.e. with many reserved names in the global namespace), but "super annoying" just hears like an exaggeration because recent strict languages tend to have longer fully-qualified (i.e. unaliased) names for outputting texts/logs, such as I think we might think of renaming them to a bit shorter names |
I also work with C++ and saying that lisp is less flexible is hilarious.. The point of flexibility in terms of naming identifiers is to make them quick to write while not creating conflicts with naming convention that clutter the code that infringes on readability, maintenance and file size where C/C++ are usually very guilty of doing that.. So i prefer identifiers to be at around 5 characters, but I am not too opposed to use C/C++-like naming here. example of GNU Guile code for comparison: #!/usr/local/bin/guile \
-l fact -e main -s
!#
;; define is used to define variables and functions
(define (choose n m)
(/ (fact m) (* (fact (- m n)) (fact n))))
(define (main args)
(let ((n (string->number (cadr args)))
(m (string->number (caddr args))))
(display (choose n m))
(newline))) $ ./choose 0 4
1
$ ./choose 1 4
4
$ ./choose 2 4
6
$ ./choose 3 4
4
$ ./choose 4 4
1
$ ./choose 50 100
100891344545564193334812497256 From https://www.gnu.org/software/guile/manual/html_node/Scripting-Examples.html That said GNU Guile is extensible and functional language so it can't be compared to C/C++/Rust as they are different usecases e.g. I would use GNU Guile to build C++ if i was tasked to do something with C++, but i wouldn't use C++ to build GNU Guile. |
Yeah, I think it was too hilarious. I haven't intended to say lisp is less flexible compared to C++ as a language, but I was specifically talking about the namespace or the identifiers that users can define in the global scope. For example, if the language or its standard library provides a global name
Are you talking about the identifiers in a local/limited scope? Isn't that the same with most languages that we can define short local identitiers? The example you have provided can be naturally translated to C++/Bash/etc. (though we might discuss the levels of optimizations in different languages). Anyway, I have been discussing the global names that are exposed to the users from the libraries (that are designed for the general users). |
I do agree that: die() { printf "FATAL: %s\\n" "$2"; exit 1 ;} Is a bad practice thus why i am using: command -v die >/dev/null || die() { printf "FATAL: %s\\n" "$2"; exit 1 ;} Meaning: Which allows the user to set up their own handling of fatal errors in their # ~/.bashrc
die() { printf "Something terrible happened: %s\\n" "$2"; exit 1 ;}
yes
yes it would be more appropriate to provide this in a different language to also enable translations as those are really painful to do in shell: command -v die >/dev/null || die() {
case "$LANG" in
# Czech
cs-*) printf "FATÁLNÍ" %s\\n" "$2" ;;
# Default
*) printf "FATAL: %s\\n" "$2"
esac
exit 1
} In general shell should just be used as shell manager meaning to manage
Also don't think of shell as a C++ it has a very similar syntax, but it's more like very limited functional programming e.g. nixlang so it should be treated as such so defining
To clarify: command -v die >/dev/null || die() { ... ;} Is NOT being exported outside of omb, but it's affected by definition outside of omb. |
I don't understand. This doesn't solve anything. It seems like you have not yet understood what is the problem. As I have already written in the first reply to your question on
How do you ensure that the existing |
But, the file |
Hmm, maybe I misunderstood the reason why you have provided the example of I was not talking about the translations of the general programs, for which I agree with you that the general program (which has a certain level of complexity) should not be written in shell scripts. I was talking about the specific program of |
Could you describe it in more detail? It appears to be the opposite for me. If there is a standardized way of importing libraries for the language, we expect from the language the standardized namespacing /scoping / module system, so we can define the identifiers in a namespace, etc. with short identifiers. However, if there is no standardized way of importing libraries, everything will be placed in the same namespace. In such a case, if every library defines functions of the same name but with different behavior, things will clutter. The only way of solving the situation is to protect ourselves by introducing effective namespaces by ourselves using the namespace prefixes to the identifiers. Actually, you haven't answered the question in my first reply to your comment on
In case you didn't understand my question correctly, let me explain it again: If |
Yes, that's the problem, or isn't that a problem that OMB is unexpectedly affected by the codes outside of OMB? I mean it is fine if the user intentionally changes the behavior of OMB by defining It is more explicit, unambiguous, and readable that the user defines |
I dropped the commits related to these logging functions and merged the changes of this PR. I'm closing the PR now. We discuss the dropped commits for the logging functions at #290. |
Fixing spellcheck and code quality