Thursday, April 30, 2009

Explaining MoisUnn

MoisUnn is a groundbreaking programming language that has just recently been launched. So not many people know about it. It is very similar to Java/C++ in some of its syntax and borrows some from Python.

The main features of MoisUnn are the ability to do concurrent assignments, powerfull list operations and multiple returns.

Concurrent Assignments:
Originally to get some thing like:
int a=5; int b=0;
int a_old=a;
a= a+5; b=a_old;
//a=10, b=5

In this better way:
int a=5; int b=0;
a,b=a+5,a;
//a=10, b=5

So the ability to write less code that is more powerful becomes evident.

List Operations:
There are some math operations you should be familiar with: +,-,/,*,%. MoisUnn introduces ^ as the exponent operator.
You can apply a single arithmetic operation on a list, or use a list to do math on another list.
EX:
to add 1 to every element in a list:
int list=[1,2,3,4,5];
for(int i=0; i less than list.size(); i++)
list[i]=list[i] +1;
//list=[2,3,4,5,6]
But in MoisUnn, it is:
array of int x: [1,2,3,4,5];
x=x+1;
//x=[2,3,4,5,6]
Also to use a list on a list:
array of int x: [1,2,3] +[4,5,6];
//x=[5,7,9]

This can be applied to doubles/floats.

Boolean Operators can be applied as well (<,<=, ==,!=,=>,>)
array of boolean x: [1,2,3,4,5] less than 3;
//x=[true,true,false, false,false]

And logical operators can be applied as well (!, &&, )
array of boolean x: [true,false,true] && [false,true,true]
//x = [false, false, true].

Now the fun stuff with lists begins:
The operator ".:" will append an element to the beginning of a list. The operator "`" will pop off the first element of a list. The operator ":." will append an element to the end of a list. The operator "++" will combine two lists. The operator $ returns the size of a list.
EX:
array of int x: [1,2,3,4]; int y;
y=`x;
//y=1, x=[2,3,4]
x=x :. y;
//y=1, x=[2,3,4,1]
x= 5 .: x;
//x=[5,2,3,4,1]
x= x ++ [34,4];
//x= [5,2,3,4,1,34,4]
int b= $x;
//b=7

You can also access individual elements of a list and get values from it or put values in it.
It also allows list operations like in python.
array of int x: [1,2,3,4,5]
array of int y: x[0:2]
//y=[1,2]

There are no lists of Chars available in MoisUnn because then that would be a string. And a list of chars is just stupid in general.

Also the operator "in" can be applied to lists or strings like in python to see if something is in a list or a string.

Multiple Returns:

Normally do find the min and max of two elements you would have to do:
int max(int x, int y)
{ if (x greater than y) return x;
return y;
}

int min(int x, int y)
{ if (x less than y) return x;
return y;
}

int mi=min(5,2);
int ma=max(5,2);
//mi=2, ma=5

In MoisUnn:
int, int MM(int x , int y)
{ if (x greater than y)
return x,y;
return y,x;
}
int max, min;
max,min=MM(5,2);
//max=5,min = 2

Of course, multiple returns can make code far more powerfull and far more complex.
int ba()
int, int, fool(int x, int)
int,bool foo()
float, bool, int, int foo2(int, bool, int, int)

And then :
foo2(foo(),fool(ba(),5))

Is completely runnable.

So far that's all that has been accomplished with MoisUnn in the past few weeks. It is set to rapidly expand with it's usability and flexibility and revolutionize(hopefully) programming languages.



MoisUnn is copyrighted by Stephen Moist and Varun Unnikrishnan.

Thursday, April 23, 2009

DON'T DO THIS

SERIOUSLY DONT.

When you write unit tests don't ever use loops to check things.  EVER.
As an example:

for (int i=0; i is less than 512; i++)
{
ASSERT(something);
}

Why?  Because when one of the asserts fail, then what happens is that you get the line number of the assert failing.  Which is in the example above, 3.  Which is completely useless.  It won't tell you on which iteration it failed.  And if you are using an ASSERT_FAIL, then it is even more useless.   This is horrible.  This should never be used unless your unit tests test the ability of a generator to test whether or not it can consistently generate good values.  See the example of how to do this that isn't retarded.
A better version to do is:
int numberofFailures=0;

for (int i=0; i is less than 512; i++)
{
if( the same logic of the assert)
else:
numberofFailures++;
}
AssertEquals(numberofFailures, 512);

Another thing:
Don't have output that you have to check manually.  This really is bad.  And I don't mean printing out some number and then checking by hand if that number is the right output.  What I mean is printing out :
-----------------------------------
Test 21: Passed: Good values of tacos.
-----------------------------------
***************************
Test 22: Failed: Too much tacos.
***************************

This is not helpful since you are not using asserts which can then print standardly out to a file which then can be easily parsed and integrated in a report for all the unit tests ran. 

I am not against printing things out, but USE ASSERTS not prints and if's instead.

Also:
If you use a counter to keep track of the current test case being ran, this is stupid.  Use fixed numbers.  It makes things very hard to figure out which test is being ran when everything looks the same!

Thursday, April 9, 2009

Making my Own Unit Test Suite

Yea I'm going to do that.

I hope to do something more flexible than Python's unit testing framework where if something fails it stops everything.  I won't be using asserts to do this because I don't wanting it to stop stuff, I want it to continue on!  It will will probably be an object.  I hope for it to somehow be compatible with the google app engine and also independent of it.  So I hope to let the user specify if they want it to be part of the google app or just write the output directly to the terminal.

Yea, it's gonna have to be an object for that to work.  So far I've come up with the methods that you can use:

Unit.assertTrue(boolean value)
Unit.assertFalse(boolean)
Unit.assertTrueFAIL(boolean)
Unit.assertFalseFAIL(boolean)
Unit.assertEqual(thing 1, thing 2)
Unit.assertNotEqual(thing 1, thing 2)
Unit.assertEqualFAIL(thing 1, thing2)
Unit.assertNotEqualFAIL(thing 1, thing 2)

The functions with "FAIL" in them will instead of using a nice if statement they will use an assert, so if the assert fails, it will stop everything. This allows things to where the code after it is absolutely DEPENDENT on the code above working correctly.  This is great for when if something should stop at that point could perhaps, say, delete your whole database or enter a profoundly awesome loop that will not end.

If I have enough time, I will add to it:
Unit.assertTrueGIVE(boolean) 
where the GIVE will return the value of what happened.  So if you make a function call in it, it will return that function call's return value.
So it will be possible to do:
x=Unit.assertEqualGIVE(5,65) and will set x = to 5.

So theoretically, there will be no statements other than unit test calls in the unit test file.  Nifty eh?

Any comments or feedback would be nice.

Wednesday, April 1, 2009

Selenium Part 2

So hopefully by now you have gotten adjusted to Selenium or completely abandoned it.  A quick note on how Selenium works.  It works by looking for a field and when it finds that field, it will insert text into it or selected it.  So if you name your phone number field in TA "phone" and then change it, Selenium won't find it.  But if you move it around on the page, or change the validators and code that gets run from it, Selenium will run it fine.  So keep that in mind if you start changing the names of fields.

So open up the IDE.  Load in a test and then click the tab called "Source" on the window bar (or where ever) under "Options" go to "Format" and then "Python".  It will take your nice GUI test and convert it all to python code.  More specifically, a unit test built around the Selenium framework.  And the best part is that it is easily runnable, you just copy and paste it into a new file.py and then run it from python.  You can easily link many together.   So if you have multiple tests, just make a "UIUnitTest.py" file, copy all of one into it and then just grab the "def test_new(self):   " part and paste it in.   Python will run it all as one big unit test automatically.  Isn't it wonderfull!

However......   For this to run, you must install the Selenium RC package (it is on the same download page).   And you must use Unix, Linux or the terminal in OS X.   So download it,  unzip it and shove it into a directory.  The next part you need to visit here  on how to set environment variables and point Selenium to the right spot.   So go into the folder selenium-remote-control-1.0-beta-2/ and then into selenium-server-1.0-beta-2   .   Now run the jar there by java -jar selenium-server.jar  .   This must be running for you to remote execute things.  Make a new terminal and put your UIUnitTest.py file under the one python branch in the selenium-remote-control-1.0-beta-2 folder and then run it.   It will automatically launch firefox (remember to have X windows on...) and then run it.  And please make sure that it runs correctly before doing this!

Now the great part about running it in the RC version is that you can inject Python code into the unit test file.  So if you need to create tables for a database, you can easily do that.  Run some script?  Go ahead!  What ever Python can do, you can put it in and then automate it.

So if you think Selenium will help you in whatever, use it.  If not, don't.   Oh and remember, the documentation for Selenium is horrible.  So if you have a question, ask here I may be able to help.