Penguin

Differences between current version and predecessor to the previous major change of LanguageNi.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 11 Last edited on Saturday, July 23, 2005 11:35:27 am by PerryLorier
Older page: version 10 Last edited on Saturday, September 13, 2003 2:00:52 pm by GerwinVanDeSteeg Revert
@@ -1,58 +1 @@
-NiTypes  
-  
-NiStructures  
-  
-NiExpressions  
-  
-NiIdentifiers  
-  
-NiCallBackExample  
-  
-NiOptimisations  
-  
-(So what is this Ni then? A compiled [Python ]?  
-If so, do you know about [Pyrex|http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/]? --GlynWebster)  
-  
-Partially, Ni also has a few other goals. One of the major ones is that programmers introduce bugs, usually at a constant rate per line of code written. By reducing the amount of programming a programmer has to do, and using the compiler to try and detect bugs earlier, more reliable programs can be written. Ni attempts to do this by:  
-  
-!!Using pre and post conditions  
-Functions have pre and post conditions which can be specified by the programmer. The compiler will also look at the pre and post conditions of statements and generate it's own pre and post conditions and try and validate them, warning if they are violated. Thus code like:  
-  
- def foo(int i):  
- return 5/i  
-  
-would automatically have the precondition added that i!=. Thus, if a call is made to foo() where i may be "", a warning will be generated at compile time. The compiler can also use this information to optimise the program. For instance, foo() above has no side effects, and depends on no other information other than i, therefore it's result can be cached, precomputed, and/or hoisted out of a loop.[1]  
-  
-Much of this came about after looking at programs which contained comments like:  
- /* ptr cannot be null here, because ... */  
- assert(NULL != ptr);  
-Looking at the code generated by the compiler, it was unable to make use of these comments/assertions for optimisation, nor was it able to warn me if I called this function with a constant NULL.[1] Another example in all the m_*.c files in ircu, there is a short note mentioning that in the m_* functions, sptr==cptr. The compiler is unable to make use of this hint and will reload all the elements of the structures these point to when the other one changes, not realising that they can be optimised and only loaded once.  
-  
-!!Datastructure operations are determined by the compiler.  
-A lot of programming is spent maintaining various datastructures (hash tables, linked lists etc). Even in langauges which have runtime libraries which provide redblack tree's, hashtables, and the like the programmer still has to decide which of these to use. Many programmers don't know when a redblack tree would be an appropraite datastructure to use. Part of what "Ni" provides built into the language is a "dictionary" structure similar to [PHP]'s array's. These are ordered associative maps. The compiler can look at which operations are used on them and use the most efficient implementation, or, in some cases, more than one implementation, for example:  
-  
- array [[] of string data;  
-  
- for i in range(,10):  
- data.append(read_string())  
-  
- data.sort()  
-  
- for i in data:  
- print data[[i]  
-  
-First of all the compiler can tell that the data isn't inspected after it's been inserted into the array and before the sort() method call, so it can use a sorted datastructure for the underlying implementation, making the call to sort() a noop and changing the append() into a insertSorted(). The compiler can tell that the data is read out in consequative order, and is never used after that so it can garbage collect data during the for loop, thus reducing the second for loop to:  
- for i in data:  
- print data.pop()  
-Now, the only used methods are insertSorted() and data.pop(), so the "best" implementation of this would be a PriorityQueue, the memory ca n be statically allocated at 10 items, since we know at compile time that that is the maximum size of the heap.  
-  
-This leaves the programmer free from having to think about datastructures and just thinking about the "business logic" of their program.  
-  
-----  
-  
-[1] [Splint|http://www.splint.org/] will check a [C] program against special [annotations|http://www.splint.org/manual/html/appC.html] placed in its comments. It would give you the warning you wanted. It can't help the C compiler use this information for optimisation, though, so I see the point in building this sort of thing into the language. --GlynWebster  
-  
-Yeah. I've looked at them. We use "assert(3)" in ircu a lot to try and catch bugs like these. I've considered annotating using something like splint, but I'm pondering if I really want to try and maintain all those comments, especially in a large collaberative open source project .  
-  
------  
-CategoryProgrammingLanguages  
+Describe [LanguageNi ] here.