8/15/2010

I have a dream

I have a dream of a new langage, which prevent programmers to write ugly things, and which give to programmers the keys to design their code in accordance of proven OO principles.

This language will be called KISS, as Keep It Smart and Simple. It will take all the advantages of the knew languages, C++, Java, Ruby and so on, and throw away what is really ugly.

It will be a very high-level language. Many keywords will disapear (goto for example). It will be strongly typed, but will allow functional programming, and the ''auto'' keyword of c++0x.

This language does not exist, and probably won't exist, but I need to talk, so I do talk. :)

Some things won't be in that language, or will be added if a real example of a real need is formuled by a programmer (template metaprogramming, preprocessor metaprogramming, reflection...).

Objectives:
1. Write some Kiss programs without launching them, in order to have a good idea of the final results, and check if the result is really as beautiful as we expected;
2. Write the Kiss Bnf grammar and write a (c++) program which serialize the Kiss code in an xml AST.
3. Write a program which reads the xml AST to a valid program. (I think I will translate it in c++)
4. Write an IDE for the Kiss language in Kiss language.

To make it worthly, the kiss language must have something really different when we use it, and it must be easily integrated with all the other languages. I may use Swig.

In the Kiss language, class will have a fixed limit of autorized lines, methods too.
Comments won't be allowed inside the methods.
Spaces must be correctly written, no tabs allowed.
Name conventions will be rules.
There will be no compilation warnings, only errors. I hate warnings.
I think there will not be any iterators, because iterators suck (use a Visitor pattern instead).
No pointers, of course. No copy operators.
I am not sure about the implicit conversions, but I think it sucks too, because it is quite hard to read.
Each class will need al least one interface class, and each interface class will generate a mock class.
No memory management, no call of a garbage collector.
It will not be possible to write a singleton pattern, no static variable.

It may look stupid at the first read, but with this, I hope I will kill the property of code. Every Kiss code will look the same. If we ask two programmers to write the same method, they may write the same code lines (!!).

To finish, I do not care about optimization or efficiency of the compiler or of the final program, but I know that if Kiss looks good, people will do that job better than me.

8/06/2008

JavaScript 3d

Hi back!

I had some fun trying the JavaScript 3d library I told you last time.

I juste wrote a code to draw a 2d square.

I tried the JS3D library from WXS.

You can download the library js3d.js.

Here is my code:

<html>
<head>
<script type="text/javascript" src="js/js3d.js"></script>
<script type="text/javascript">
var canvas;

function drawSquare(x1, y1, w, h, num, text, m) {
m = scale(20,20,100,m);
var numW = num;
var numH = num;
if( w == Math.max(w, h) )
numH = num / (w / h);
else
numW = num / (h / w );
canvas.addLine( x1 , y1 , 0, x1 + w, y1 , 0, numW, text, m );
canvas.addLine( x1 , y1 - h, 0, x1 + w, y1 - h, 0, numW, text, m );
canvas.addLine( x1 , y1 , 0, x1 , y1 - h, 0, numH, text, m );
canvas.addLine( x1 + w, y1 , 0, x1 + w, y1 - h, 0, numH, text, m );
}

function init() {
canvas = new JS3D("canvas", -20);
canvas.matrix = identity();
canvas.matrix = canvas.translate(canvas.width/2,0,-200);
drawSquare( -5, 20, 5, 2, 10, ".", identity());
canvas.paint();
}
</script>
</head>
<body onLoad="init();">
<div id="canvas" style="position:absolute;
width:500px;
height:500px;
background-color: cyan;"></div>
</body>
</html>


I regret JS3D only give 2 demo samples to show how to use their library. Their tutorial is interesting but it doesn't work. I had to show the source of their demo to make it working!

By the way, this idea is nice, but I don't think it would be used someday.
We want JavaScript to have some 3d stuff, but not by scaling and positioning text correctly in a layer..!

However I tried it because it was fun, I may continue that to write a BallBreaker if I have nothing else to do ! :)

5/07/2008

How to make your own multitouch surface

Hi,

I have been amazed when I saw this!




I did this box for fun, and here you can see a picture from my webcam, and my tiny fingers on the paper.
Now I just have to do all of the image processing work! (Will I use TouchLib?)

Just read this article:
http://cb.nowan.net/blog/2008/05/05/how-to-make-your-own-multitouch-surface/

Mac os tips!

Hi back!

Here comes some useful tricks I found on the web, while I was learning how to use my platform. :)

To begin with, if you use openVPN gui for Windows, just use TunnelBlick for Mac Os X. It uses almost the same configuration file, I just lost my dns.
=> Try to write directly an ip in Safari from your distant network and it should work directly! =)

Then, if you want to access a computer in your network but you only know its ip, use Finder, Command+K and then write :
smb://your_ip (smb for samba)

Sample:
smb://192.168.0.1


To make the Command+Click works on Safari, write these command lines in a terminal:
defaults write com.apple.Safari TargetedClicksCreateTabs -bool true


To see french accents in your terminal, write these line in your ressource file (.profile):
# To be able to see and use accentuated characters
stty cs8 -istrip -parenb
bind 'set convert-meta off'
bind 'set meta-flag on'
bind 'set output-meta on'
export LC_CTYPE="fr_FR.UTF-8"

4/08/2008

C++ boost thread, so easy!

Never though it would be that easy to deal with threads!

Try these lines:


#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>

namespace
{
void print( int x )
{
std::cout << x << std::endl;
std::cout << x << std::endl;
std::cout << x << std::endl;
std::cout << x << std::endl;
}
}

int main()
{
boost::thread_group Tg;

Tg.create_thread( boost::bind( print, 1 ) );
Tg.create_thread( boost::bind( print, 2 ) );
Tg.create_thread( boost::bind( print, 3 ) );
Tg.create_thread( boost::bind( print, 4 ) );

Tg.join_all();
std::cout << "Done! =)" << std::endl;
std::cin.get();
return 0;
}


Compile this, then launch it many times and you will see different results.

The join_all method blocks your program until all the threads finished.

I found it really very pretty! And sexy! =D

4/02/2008

Control power of a USB lamp (device)

Hi back,

Dealing with boost::bind looks like doing code obsfucation!

Nevermind, todays I was trying to control this 5V USB port on Windows!

Impossible! Explanations:

My goal was to plug some usb lamp I would have done (thanks to this video), and to control the USB power thanks to a program, whatever the language.



I tried many libraries, such as libusb-win32, or SharpUSBlib, which both works nicely. These libraries give some generic device controller : their sample programs recognized my usb mouse.
But I have some usb fan cooler too, and it could not recognize it, because it was only using the 5V power offered by the USB port, whithout sending any data.

I continued my searchs. And after reading this forum, I realised it would be hard to manage.
Then I tried to disable the driver directly with the configuration panel from Windows. Once my port disabled, I plugged my fan and the power was still delivered.

"Pwned!" as they said...

I don't care! I think I must go towards a usb controller. This paper explains it very well. But... I will read it later, I need a break! =)

Have fun!

3/29/2008

C++ boost bind, a good functor

Hi!

I had lots of fun this weekend with boost::bind! =)

boost::bind documentation

I wanted to use it as a functor.

Here comes some samples I wrote to understand how it works:


#include <iostream>
#include <boost/bind.hpp>

int g( int x )
{
return x;
}

class A
{
public:
void print()
{
std::cout << boost::bind( g, 42 )() << std::endl;
}
};

int main()
{
A a;
a.print();
return 0;
}


The same one, but we don't call a function, but a method. Please focalise on the "*this": I lost time because of that. =)


#include <iostream>
#include <boost/bind.hpp>


class A
{
public:
int g(int x)
{
return x;
}

void print()
{
std::cout << boost::bind(&A::g, *this, 51)() << std::endl;
}
};

int main()
{
A a;
a.print();
return 0;
}


An the last one, the call is outside the class, the method called is templated because I really don't want to know what is the type of boost::bind (if someone knows it, give me the answer in a comment!).
And for fun I used boost::bind as a lambda function functor. So nice.


#include <iostream>
#include <boost/bind.hpp>


class A
{
public:
int g(int x)
{
std::cout << "g() function is called" << std::endl;
return x;
}

int sum(int x, int y)
{
std::cout << "sum() function is called" << std::endl;
return x + y;
}


template< class F >
void print( F fun)
{
for( int i = 0; i < 5; ++i)
std::cout << fun( i ) << std::endl;
}
};

int main()
{
A a;
a.print( boost::bind( &A::g, a, _1 ) );
a.print( boost::bind( &A::sum, a, 69, _1 ) );
return 0;
}


Of course, all the functor work can be done without boost::bind, but I believe it is easier to read the code with boost::bind. Furthermore, it makes me write less code lines! =)

Have fun using it!