Re: Compile time vs run time -- what is the difference?
On Wednesday, 28 December 2022 at 12:42:24 UTC, thebluepandabear wrote: Before even running the code I get an IDE warning (IntelliJ). Does IntelliJ compile the code in the background? It will NOT compile successfully unless you do one of these things: (1) ensure the result of the 'static assert' is true. (2) comment out the static assert. Once you do either of (1) or (2) above, it will compile to an executable format. When you execute it, the runtime will catch the 'assert' failure (ie. assertion == false), and the runtime will bring your program to an immediate halt. This was just meant to be an example of differentiating compile time from runtime, as per you question. With static assert, your logic testing is traversed during compilation, and your compilation will come to a stop when the assertion is found to be false, whereas your asserts are traversed during program execution, and if they are found to be false, your program comes to a stop. https://dlang.org/spec/version.html#static-assert https://tour.dlang.org/tour/en/gems/contract-programming
Re: Compile time vs run time -- what is the difference?
On 12/28/22 08:04, Ali Çehreli wrote: > I don't think any of them can run the program though because > the program can be in a state that could harm its environment > like deleting unwanted files. I was too eager there. Likely no IDE goes that far. All they need is to understand the code enough to give help. They must stop at some point in the following steps of compilation: - preprocessing (does not exist for D) - lexical analysis - parsing - semantic analysis I copied those items from Wikipedia: https://en.wikipedia.org/wiki/Compiler It lists the later stages of compilation as - intermediate representation - code optimization - code generation Ali
Re: Compile time vs run time -- what is the difference?
On 12/27/22 18:31, thebluepandabear wrote: > What I do understand is that compile time and run time are the two > processes that your code goes through to be executed natively. There is a confusion: Compile time ends when the compiler generates the executable program, one that will be executed natively. Run time is each time when the user starts the executable program by typing its name followed by the Enter key, double clicking on it, etc. For a program that was extremely simple, bug-free, lucky, etc. there may be as few as a single compilation and infinite number of executions (run times). On the other hand, for a program that could never be compiled successfully, there may be infinite number of compilations and zero run times. > In Java and some other languages, during compile time the code gets > executed into Java bytecode. This also happens for C#. I don't know if > there is an equivalent 'intermediate' language for D that your code gets > translated to. No, D does not use that model. Copying a comment of yours: > Before even running the code I get an IDE warning > (IntelliJ). Does IntelliJ compile the code in the background? Yes, many IDEs continuously compile the code as you type the source code to understand it to give you such help. I don't think any of them can run the program though because the program can be in a state that could harm its environment like deleting unwanted files. Ali
Re: Compile time vs run time -- what is the difference?
On Wednesday, 28 December 2022 at 09:10:38 UTC, areYouSureAboutThat wrote: On Wednesday, 28 December 2022 at 02:31:45 UTC, thebluepandabear wrote: .. Other errors are only able to be spotted during run time such as exceptions, dividing by zero, assert blocks. With regards to the 'assert blocks' you mention, D (like C++) has both static assert and runtime assert. // --- module test; @safe: import std; void main() { string val = "some string"; static assert(is(typeof(x) : int)); // assertion fails at compile time. assert(val == "some other string"); // assertion fails at runtime. } // --- Before even running the code I get an IDE warning (IntelliJ). Does IntelliJ compile the code in the background?
Re: Compile time vs run time -- what is the difference?
On Wednesday, 28 December 2022 at 02:31:45 UTC, thebluepandabear wrote: .. Other errors are only able to be spotted during run time such as exceptions, dividing by zero, assert blocks. With regards to the 'assert blocks' you mention, D (like C++) has both static assert and runtime assert. // --- module test; @safe: import std; void main() { string val = "some string"; static assert(is(typeof(x) : int)); // assertion fails at compile time. assert(val == "some other string"); // assertion fails at runtime. } // ---