Penguin

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

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

Newer page: version 9 Last edited on Monday, November 11, 2002 7:26:13 pm by PerryLorier Revert
Older page: version 6 Last edited on Monday, November 11, 2002 5:58:20 pm by PerryLorier Revert
@@ -1,5 +1,5 @@
-NiTypesin  
+NiTypes  
  
 NiStructures 
  
 NiExpressions 
@@ -9,10 +9,10 @@
 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) 
+(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 
@@ -20,14 +20,14 @@
  
  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. 
+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. 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. 
+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: 
  
@@ -46,4 +46,10 @@
  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.