Naming convention #280
Replies: 3 comments
-
👏 Love it! |
Beta Was this translation helpful? Give feedback.
-
Discussion made in #73I here summarize the discussion made in #73. The discussion has not yet ended, so this comment will be updated as new replies are added to the original thread. @Kreyren, I intend that this is just a discussion log, so let's continue the discussion in the original thread in #73 instead of replying to this log. BackgroundThere are existing functions of Reply by @Kreyren in #73 (comment)
I don't like the naming it's designed to be and convention for the other functions is Reply by @akinomyoga in #73 (comment)
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 Reply by @Kreyren in #73 (comment)I am aware of the presented issue thus why the provided definitions are prefixed with Reply by @akinomyoga in #73 (comment)So that it can be replaced by the user-provided version of Reply by @Kreyren in #73 (comment)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 Reply by @akinomyoga in #73 (comment)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 Reply by @Kreyren in #73 (comment)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. Reply by @akinomyoga in #73 (comment)
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). Reply by @Kreyren in #73 (comment)
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. Reply by @akinomyoga in #73 (comment)
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 |
Beta Was this translation helpful? Give feedback.
-
Discussion in #268Also, there has been a shorter comment in #268. The rename from Reply by @akinomyoga in #268 (comment)Naming convention for config variables: Why
|
Beta Was this translation helpful? Give feedback.
-
Here, I'd like to summarize the discussions related to the naming convention of variables and functions used by oh-my-bash. Also, we want to manage the list of aliases already defined in oh-my-bash to avoid possible conflicts like #63 (#97). Currently, there are no certain rules for the naming convention, but we want to gradually organize them into namespaces to avoid possible name conflicts. Actually, we have already some conflicts between alias names #63 and variable names (e.g.
red
, etc. for terminal sequences vs prompt sequences).Current (tentative) suggestion (will be edited after discussions)
OMB_*
.OMB_${config^^}
OMB_${namespace^^}_${config^^}
OMB_PLUGIN_${plugin_name^^}_${config^^}
OMB_THEME_${theme_name^^}_${config^^}
_omb_*
_omb_${namespace}_${varname}
_omb_plugin_${plugin_name}_${varname}
_omb_theme_${theme_name}_${varname}
_omb_${varname}
directly put under_omb
namespace._omb_*
._omb_${namespace}_${funcname}
_omb_plugin_${plugin_name}_${funcname}
_omb_theme_${theme_name}_${funcname}
_omb_${varname}
directly put under_omb
namespace.Beta Was this translation helpful? Give feedback.
All reactions