digitalmars.D - version(Main) like python's __name__ == "__main__"
- Lionello Lunesu (22/22) Nov 21 2007 I'd like to suggest a new predefined version identifier called "Main"
- Chris Miller (3/25) Nov 21 2007 That's pretty cool, I'll vote for it.
- Lars Ivar Igesund (15/45) Nov 21 2007 We tend to add such simple tests within
- Dan (3/33) Nov 21 2007 Walter implemented something better called "unittest".
- Lionello Lunesu (7/10) Nov 22 2007 I agree that it's similar, but not quite:
I'd like to suggest a new predefined version identifier called "Main" which is defined on the main module only. The definition of "main module" would be: * the first module on the command line, or * the module whose name will be used for the executable, or * the module mentioned after DMD's "-run" The two issues with this suggestion are: * vagueness of the definition of "main module" * Main version identifier is set for one module only (by definition) It's use would be similar to Python's "__main__" [1]: version(Main) { void main() { // test code } } It would allow one to write small examples/tests in each module, that can be executed immediately, but won't cause conflicts when linked against in a larger project. L. [1] http://docs.python.org/lib/module-main.html
Nov 21 2007
On Wed, 21 Nov 2007 06:38:21 -0500, Lionello Lunesu <lio lunesu.remove.com> wrote:I'd like to suggest a new predefined version identifier called "Main" which is defined on the main module only. The definition of "main module" would be: * the first module on the command line, or * the module whose name will be used for the executable, or * the module mentioned after DMD's "-run" The two issues with this suggestion are: * vagueness of the definition of "main module" * Main version identifier is set for one module only (by definition) It's use would be similar to Python's "__main__" [1]: version(Main) { void main() { // test code } } It would allow one to write small examples/tests in each module, that can be executed immediately, but won't cause conflicts when linked against in a larger project. L. [1] http://docs.python.org/lib/module-main.htmlThat's pretty cool, I'll vote for it.
Nov 21 2007
Lionello Lunesu wrote:I'd like to suggest a new predefined version identifier called "Main" which is defined on the main module only. The definition of "main module" would be: * the first module on the command line, or * the module whose name will be used for the executable, or * the module mentioned after DMD's "-run" The two issues with this suggestion are: * vagueness of the definition of "main module" * Main version identifier is set for one module only (by definition) It's use would be similar to Python's "__main__" [1]: version(Main) { void main() { // test code } } It would allow one to write small examples/tests in each module, that can be executed immediately, but won't cause conflicts when linked against in a larger project. L. [1] http://docs.python.org/lib/module-main.htmlWe tend to add such simple tests within debug (ModuleName) { void main() { blah } } then compile with dmd -debug=ModuleName I find this solution more than easy enough and possibly more flexible? There may be other usecases where such a Main version identifier would be of interest though. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Nov 21 2007
Lionello Lunesu Wrote:I'd like to suggest a new predefined version identifier called "Main" which is defined on the main module only. The definition of "main module" would be: * the first module on the command line, or * the module whose name will be used for the executable, or * the module mentioned after DMD's "-run" The two issues with this suggestion are: * vagueness of the definition of "main module" * Main version identifier is set for one module only (by definition) It's use would be similar to Python's "__main__" [1]: version(Main) { void main() { // test code } } It would allow one to write small examples/tests in each module, that can be executed immediately, but won't cause conflicts when linked against in a larger project. L. [1] http://docs.python.org/lib/module-main.htmlWalter implemented something better called "unittest". Although I wish you could execute JUST a unittest, and only for one unit...
Nov 21 2007
Dan wrote:Walter implemented something better called "unittest". Although I wish you could execute JUST a unittest, and only for one unit...I agree that it's similar, but not quite: I think it's shady for a unittest to make internet connections and such, but it would be fine for a small test app. It could use command line arguments for the URL or any file it wants to open/create. That's not something a unittest can do. L.
Nov 22 2007