[Nice-commit] Nice/web safety.xml,1.8,1.9
Brought to you by:
bonniot
From: <bo...@pr...> - 2004-01-22 23:28:29
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9714 Modified Files: safety.xml Log Message: Make it easier to do automatic syntax highlighting by using CDATA instead of character entities. Fixed the foreach example, which was incorrect. Index: safety.xml =================================================================== RCS file: /cvsroot/nice/Nice/web/safety.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** safety.xml 16 Jan 2004 16:48:55 -0000 1.8 --- safety.xml 22 Jan 2004 23:27:37 -0000 1.9 *************** *** 175,179 **** st.push(new Object()); // invalid code, but not detected ... ! String s = (String) st.pop(); // throws a <javaexn name="ClassCastException"/> </programlisting> </para> --- 175,179 ---- st.push(new Object()); // invalid code, but not detected ... ! String s = (String) st.pop(); // throws a ClassCastException </programlisting> </para> *************** *** 204,209 **** <para> ! <programlisting lang="nice"> ! interface Stack<T> { void push(T element); --- 204,209 ---- <para> ! <programlisting lang="nice"><![CDATA[ ! interface Stack<T> { void push(T element); *************** *** 211,220 **** } ! Stack<String> st = new StackImpl(); st.push("Element A"); //st.push(new Object()); // type error ... String s = st.pop(); // no cast needed ! </programlisting> </para> --- 211,220 ---- } ! Stack<String> st = new StackImpl(); st.push("Element A"); //st.push(new Object()); // type error ... String s = st.pop(); // no cast needed ! ]]></programlisting> </para> *************** *** 240,244 **** <para> ! <programlisting lang="java"> class Person { --- 240,244 ---- <para> ! <programlisting lang="java"><![CDATA[ class Person { *************** *** 248,259 **** boolean equals(Object that) { ! if(!(that instanceof Person)) return false; return name.equals(((Person) that).name) ! && age==((Person) that).age; } } ! </programlisting> </para> --- 248,260 ---- boolean equals(Object that) { ! if (!(that instanceof Person)) return false; + return name.equals(((Person) that).name) ! && age == ((Person) that).age; } } ! ]]></programlisting> </para> *************** *** 272,276 **** <para> ! <programlisting lang="nice"> class Person { --- 273,277 ---- <para> ! <programlisting lang="nice"><![CDATA[ class Person { *************** *** 281,289 **** { return ! this.name.equals(that.name) ! && this.age == that.age; } } ! </programlisting> </para> </section> --- 282,290 ---- { return ! name.equals(that.name) ! && age == that.age; } } ! ]]></programlisting> </para> </section> *************** *** 326,344 **** <para> ! <programlisting lang="nice"> ! private ?List<Component> children(Component); children(Component c) = null; children(ContainerComponent c) = c.getChildren(); ! </programlisting> </para> <para> We can now write our example with only: ! <programlisting lang="nice"> Component c = ...; ! ?List<Component> children = children(c); ! </programlisting> </para> --- 327,345 ---- <para> ! <programlisting lang="nice"><![CDATA[ ! private ?List<Component> children(Component); children(Component c) = null; children(ContainerComponent c) = c.getChildren(); ! ]]></programlisting> </para> <para> We can now write our example with only: ! <programlisting lang="nice"><![CDATA[ Component c = ...; ! ?List<Component> children = children(c); ! ]]></programlisting> </para> *************** *** 360,372 **** useless; there is no reason to ask the programmer to write it. Therefore, it is perfectly legal in &nice; to write: ! <programlisting lang="nice"> Component c = ...; ! ?List<Component> children; if (c instanceof ContainerComponent) children = c.getChildren(); else children = null; ! </programlisting> </para> --- 361,373 ---- useless; there is no reason to ask the programmer to write it. Therefore, it is perfectly legal in &nice; to write: ! <programlisting lang="nice"><![CDATA[ Component c = ...; ! ?List<Component> children; if (c instanceof ContainerComponent) children = c.getChildren(); else children = null; ! ]]></programlisting> </para> *************** *** 494,510 **** tasks on arrays, and more generally collections. For instance, a simple iteration on the elements ! <programlisting lang="java"> ! for (int i = 0; i < a.length; i++) ! doSomething; ! </programlisting> can also be written in &nice; <programlisting lang="nice"> ! a.foreach( int i => doSomething ); </programlisting> ! Using these functions makes the code somewhat clearer by avoiding the repetition of the loop code over and over. Moreover, it removes the risks of wrong indexes, forgetting to increment the index, ... ! Even if a custom looping function is needed, it only has to be checked only ! once and for all. </para> </section> --- 495,514 ---- tasks on arrays, and more generally collections. For instance, a simple iteration on the elements ! <programlisting lang="java"><![CDATA[ ! for (int i = 0; i < a.length; i++) ! doSomething(a[i]); ! ]]></programlisting> can also be written in &nice; <programlisting lang="nice"> ! a.foreach(doSomething); </programlisting> ! Using methods like <literal>foreach</literal> makes the code clearer by ! avoiding the repetition of the loop code over and over. Moreover, it removes the risks of wrong indexes, forgetting to increment the index, ... ! It is important to note that <literal>foreach</literal> is not a built-in ! operator but a normal method defined in the standard library. ! Therefore, given a user-defined data structure, a new looping function ! can be written and only has to be checked once. </para> </section> |