Page 1 of 1

Contexts/namespaces naming in modules

Posted: Thu May 14, 2009 11:27 am
by Lutz
I am considering to title-case all contexts/namespaces names used in standard modules shipped with the source distribution and installers which are currently lower-case.

This has been discussed earlier, but as it may break existing code I am interested to hear the community about this again and before changint it.

The following prefixes would be affected:

canvas.lsp - cv -> Cv
crypto.lsp - crypto -> Crypto
postscript.lsp - ps -> Ps
stat.lsp - stat -> Stat
sqlite3.lsp -> sql3 -> Sql3
unix.lsp -> unix -> Unix
zlib.lsp -> zlib -> Zlib

The following prefixes would stay as they are:

cgi.lsp - CGI
ftp.lsp - FTP
gmp.lsp - GMP
indix.lsp - INFIX (or should it be Infix ?)
mysql.lsp - MySQL
pop3.lsp - POP3
postgres.lsp - PgSQL
xmlrpc-client.lsp - XMLRPC

Basically we would follow Cormullion's suggestion to title-case namespace names except for generally known abbreviations (Internet protocols, known trademarks, etc.). The documentation (newlisp_manual.html, CodePatterns.html) mostly follows this convention already and changes would be made where this is not the case.

Most third party modules listed here: http://www.newlisp.org/modules/ also follow this convention already, and it seems to be generally accepted programming practice.

What do you think? What would be the schedule of introduction?

Ps: variables holding contexts would stay lower-case. This way both cannot be confused when reading unknown code:

Code: Select all

(new Class 'Bar)

(define (foo cx a b c)
    (set 'cx:data (+ a b c))
)

(foo Bar 1 2 3)

Bar:data => 6
... it would then be obvious that 'cx' is a variable holding a context, not a context itself.

Posted: Thu May 14, 2009 11:57 am
by Jeff
You could always just duplicate the names for a few versions:

Code: Select all

(context 'canvas)
...
(context 'MAIN)
(new 'canvas 'Cv)

Posted: Thu May 14, 2009 12:13 pm
by newdep
Hi Lutz,

This is only from a visual aspect and not becoming mandatory.. right?

Because If I dislike something in particular about a programming language
then its being case sensitive.. Ieeeekksss my fingers start rejecting the keyboard already..

Norman.

Posted: Thu May 14, 2009 12:32 pm
by Lutz
Its not mandatory, only good practice and the way modules would be shipped.

Posted: Thu May 14, 2009 1:02 pm
by Lutz
Jeff:

but 'new' would also duplicate the memory used, because everything gets copied to a second context.

There is a better method using a context variable:

Code: Select all

(context 'foo)

(define (bar x y) ..._

(context MAIN)

(set 'Foo foo)

(Foo:bar 3 4) ; will call foo:bar
This technique is also described in the canvas module. The canvas and the postsrcipt module are API compatible. When I was testing the canvas module, I just plugged in the old postscript modules for testing.

Posted: Thu May 14, 2009 4:18 pm
by cormullion
My suggestion was for future modules. I'm voting against changes that break existing code.

Posted: Thu May 14, 2009 5:36 pm
by m i c h a e l
I think what cormullion is responding to here is the reason standards committees are set up to begin with. I, too, was bitten by 10, but the bites have mostly healed now. Granted, I have no modules of code floating around to continue mauling me.

It’s the ol’ ebb-and-flow between freedom and security.

As newLISP matures, changes will naturally become less frequent and drastic. Till then, we’re riding the rough Western range, where nothing is gare-on-teed.

As to the naming change, I kind of liked the idea that module names were lowercased to set them off from classes :-) But I know Lutz struggles with his decisions about every tiny detail of newLISP, so I’ll naturally defer to him.

m i c h a e l

Posted: Thu May 14, 2009 5:43 pm
by m35
I know there's been a lot of talk about contexts and possible identifier collisions recently. I've been wondering if we shouldn't start a more unique naming convention:

Code: Select all

(context 'org.newlisp.cv)
(context 'org.newlisp.crypto)
(context 'org.newlisp.ps)
(context 'org.newlisp.stat)
(context 'org.newlisp.sql3)
(context 'org.newlisp.unix)
(context 'org.newlisp.zlib)
Referring to these long identifiers might be annoying, but you can always make an alias.

Code: Select all

(setq Sql3 org.newlisp.sql3)
Of course this Java-like pattern is only one style. We have nearly all characters available to do whatever we want.