* Need advice for naming practice for namespaces in Elisp.
@ 2013-02-05 20:44 Oleksandr Gavenko
2013-02-06 6:42 ` Drew Adams
2013-02-06 18:59 ` Stefan Monnier
0 siblings, 2 replies; 4+ messages in thread
From: Oleksandr Gavenko @ 2013-02-05 20:44 UTC (permalink / raw)
To: help-gnu-emacs
I read very small amount of elisp code and found practice to put '->' in the
name of elisp var/func:
./emacs-bzr/emacs-24/lisp/info-look.el:107:(defsubst info-lookup->topic-value (topic)
./emacs-bzr/emacs-24/lisp/info-look.el:110:(defsubst info-lookup->mode-value (topic mode)
./emacs-bzr/emacs-24/lisp/info-look.el:113:(defsubst info-lookup->regexp (topic mode)
Also I search for dot in names:
./emacs-bzr/trunk/lisp/erc/erc-backend.el:928: (setf (erc-response.sender msg)
./emacs-bzr/trunk/lisp/erc/erc-backend.el:933: (setf (erc-response.command msg)
and for colon:
./emacs-bzr/emacs-24/lisp/org/org-agenda.el:5666: (maxgap (org-hh:mm-string-to-minutes
./emacs-bzr/emacs-24/lisp/org/org-agenda.el:5703: (org-minutes-to-hh:mm-string
Seems that official sources don't often use special marker to separate package
name and command and some times uses '->', ':' and '.'
I want to choose good marker for package to simplify reading my code and make
it more syntactically structured. I am feeling good with dot:
blog4y-chunk.write
blog4y-chunk.read
blog4y-blog-selection.select
blog4y-blog-selection.buffer-name
blog4y-blog-selection.regex
but would be glad to hear any suggestion and coding practices... My be some
syntax agreement come from CL or other languages or have some historical
background...
--
Best regards!
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Need advice for naming practice for namespaces in Elisp.
2013-02-05 20:44 Need advice for naming practice for namespaces in Elisp Oleksandr Gavenko
@ 2013-02-06 6:42 ` Drew Adams
2013-02-06 18:59 ` Stefan Monnier
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2013-02-06 6:42 UTC (permalink / raw)
To: 'Oleksandr Gavenko', help-gnu-emacs
> I read very small amount of elisp code and found practice to
> put '->' in the name of elisp var/func:
>
> Also I search for dot in names:
> and for colon:
>
> Seems that official sources don't often use special marker to
> separate package name and command and some times uses '->',
> ':' and '.'
>
> I want to choose good marker for package to simplify reading
> my code and make it more syntactically structured. I am
> feeling good with dot:
>
> but would be glad to hear any suggestion and coding
> practices...
I say use whatever you like.
The Elisp manual suggests using a hyphen (`-'). See (elisp) `Coding
Conventions':
,----
|* You should choose a short word to distinguish your program from
| other Lisp programs. The names of all global variables,
| constants, and functions in your program should begin with that
| chosen prefix. Separate the prefix from the rest of the name with
| a hyphen, `-'. This practice helps avoid name conflicts, since
| all global variables in Emacs Lisp share the same name space, and
| all functions share another name space(1).
|
| Occasionally, for a command name intended for users to use, it is
| more convenient if some words come before the package's name
| prefix. And constructs that define functions, variables, etc.,
| work better if they start with `defun' or `defvar', so put the
| name prefix later on in the name.
|
| This recommendation applies even to names for traditional Lisp
| primitives that are not primitives in Emacs Lisp--such as
| `copy-list'. Believe it or not, there is more than one plausible
| way to define `copy-list'. Play it safe; append your name prefix
| to produce a name like `foo-copy-list' or `mylib-copy-list'
| instead.
|
| If you write a function that you think ought to be added to Emacs
| under a certain name, such as `twiddle-files', don't call it by
| that name in your program. Call it `mylib-twiddle-files' in your
| program, and send mail to `bug-gnu-emacs@gnu.org' suggesting we add
| it to Emacs. If and when we do, we can change the name easily
| enough.
|
| If one prefix is insufficient, your package can use two or three
| alternative common prefixes, so long as they make sense.
`----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Need advice for naming practice for namespaces in Elisp.
2013-02-05 20:44 Need advice for naming practice for namespaces in Elisp Oleksandr Gavenko
2013-02-06 6:42 ` Drew Adams
@ 2013-02-06 18:59 ` Stefan Monnier
2013-02-07 19:04 ` Oleksandr Gavenko
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2013-02-06 18:59 UTC (permalink / raw)
To: help-gnu-emacs
> I read very small amount of elisp code and found practice to put '->'
> in the name of elisp var/func:
I use -> sometimes, typically for access to a struct's fields.
This comes from my learning lispy languages via Scheme.
> Also I search for dot in names:
I (strongly) recommend against the use of "." in symbols.
"(erc-response.sender)" could also be interpreted as "(erc-response
. sender)" and historically Elisp has not been very good at resolving
this ambiguity in a reliable way.
> and for colon:
Colon is typically used in a Common-Lisp way, to separate the "module
name" from the specific definition.
> Seems that official sources don't often use special marker to separate
> package name and command and some times uses '->', ':' and '.'
Common usage is to use "-".
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Need advice for naming practice for namespaces in Elisp.
2013-02-06 18:59 ` Stefan Monnier
@ 2013-02-07 19:04 ` Oleksandr Gavenko
0 siblings, 0 replies; 4+ messages in thread
From: Oleksandr Gavenko @ 2013-02-07 19:04 UTC (permalink / raw)
To: help-gnu-emacs
On 2013-02-06, Stefan Monnier wrote:
>> I read very small amount of elisp code and found practice to put '->'
>> in the name of elisp var/func:
>
> I use -> sometimes, typically for access to a struct's fields.
> This comes from my learning lispy languages via Scheme.
>
Thanks for interesting answer!
>> Also I search for dot in names:
>
> I (strongly) recommend against the use of "." in symbols.
> "(erc-response.sender)" could also be interpreted as "(erc-response
> . sender)" and historically Elisp has not been very good at resolving
> this ambiguity in a reliable way.
>
OK. Thanks for advice.
I start from dot as separator to mimic OOP language syntax... And found that
evaluation of:
(defun foo.?bar () ())
by C-x C-e produce:
foo\.bar
in message buffer. Same for 'foo?bar' name. Why '\.' or '\?' was printed?
(info "(elisp)Symbol Type") have:
A symbol name can contain any characters whatever. Most symbol names
are written with letters, digits, and the punctuation characters
`-+=*/'. Such names require no special punctuation; the characters of
the name suffice as long as the name does not look like a number. (If
it does, write a `\' at the beginning of the name to force
interpretation as a symbol.) The characters `_~!@$%^&:<>{}?' are less
often used but also require no special punctuation. Any other
characters may be included in a symbol's name by escaping them with a
backslash.
>> and for colon:
>
> Colon is typically used in a Common-Lisp way, to separate the "module
> name" from the specific definition.
>
>> Seems that official sources don't often use special marker to separate
>> package name and command and some times uses '->', ':' and '.'
>
> Common usage is to use "-".
>
I complete agree.
Also I forget to mention about '/' char:
./cedet/ede/ede-locate.el:307: (cedet-idutils-create/update-database root))
./cedet/ede/ede-locate.el:347: (cedet-cscope-create/update-database root))
And become understand that really have another question...
I write code which have distinct parts, so use prefixes:
blog4y
blog4y-chuck
blog4y-serv
I want be able to recognise them from each other, so instead of:
blog4y-init ; blog4y
blog4y-chunk-write ; blog4y-chunk
blog4y-serv-show ; blog4y-serv
use something like:
blog4y-init ; blog4y
blog4y-chunk:write ; blog4y-chunk
blog4y-serv:show ; blog4y-serv
But this code is ugly:
blog4y-serv:mode
blog4y-serv:mode-map
blog4y-serv:font-lock-keywords
and break elisp conventions... So what I really need is to make prefix visible
and distinct from rest part of name, like:
blog4y-init ; blog4y
blog4y*chunk-write ; blog4y*chunk
blog4y*serv-show ; blog4y*serv
or use any other `-+=*/_~!@$%^&:<>{}?' allowed non-usual symbol.
Seems that any personal choice will be good...
Again thanks all for replays!
--
Best regards!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-02-07 19:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-05 20:44 Need advice for naming practice for namespaces in Elisp Oleksandr Gavenko
2013-02-06 6:42 ` Drew Adams
2013-02-06 18:59 ` Stefan Monnier
2013-02-07 19:04 ` Oleksandr Gavenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).