4 ms·
Yes, but then people are conflating notions of type-system/runtime/vm/etc. with the notion of script vs. program. The key distinction is this: In a programming
by jballanc 18y ago
Yes, but then people are conflating notions of type-system/runtime/vm/etc. with the notion of script vs. program. The key distinction is this: In a programming language you can only have one entry point (the "main()" function), regardless of how the individual files are linked. In a scripting language the entry point depends on which file the interpreter starts with, and the execution model can change depending on how the script is invoked.
For example, the Ruby community uses this trick quite often so that one file can be a library if included by another source file, but can be an executable if invoked by the interpreter directly. See: http://gist.github.com/51337 http://gist.github.com/51337. If you run "ruby a.rb" you'll get something different than if your run "ruby b.rb", even though both are the result of "linking" a.rb and b.rb together.
...let's see you do that with C! ;-)
- bioengineer 18y agoIf I am understanding you correctly, I believe that it is possible in C, using macros. If you include the following in each file: #ifndef MAIN_ALREADY_DEFINED__ #define MAIN_ALREADY_DEFINED__ int main(){ /* file specific stuff */ } #endif Disclaimer: I wouldn't actually do this in practice...
- kragen 18y agoThis is a different distinction than the one the other poster reported that Matz proposes, but it's not useful either. You can do it in C, even without using the preprocessor; see http://gist.github.com/51416 http://gist.github.com/51416, which does it with weak symbols. Worse, whether C is a "scripting language" or not depends only on the presence or absence of such trivial features. Your distinction would make Java a "scripting language," because every class can have its own main function, and still leaves x86 assembly as a "scripting language", and now it makes GNU C a "scripting language" too; and given the nondeterministic invocation order of the constructors of static objects, it makes any particular C++ implementation a "scripting language" too.
- jballanc 18y agoSo, I think you're focusing too much on the specific example and not enough on the runtime distinction. The C runtime looks for "main()". If you trick it into looking in different places for it, that's a trick. Ruby (and other scripting languages) goes through the source file sequentially, executing statements and definitions as it goes. There isn't a specific symbol for it to look for. (Well, there is, but that just complicates matters.) The point I'm trying to make is that the distinction between scripting language and programming language shouldn't rely on how it's used, but rather on how it's formatted. ...and by the way, I would consider x86 assembly a scripting language. You're just scripting out the processor's actions...
- kragen 18y agoI can't prevent you from using that definition of "scripting language" but I don't think it has much in common with the usual meaning of the term.