Search This Blog

Monday, August 6, 2012

Javascript solutions to day2's questions

Today i would discuss about the solutions i came up with for the 3 problems i discussed in previous blog,
Crashing a browser:
The first idea i got is to write a simple recursion and crash the browser. This technique works great for C programs. But it never worked for me in crashing browsers. May be the javascript engines were too clever to avoid crashing!
Then i tried infinite loop .. which worked well in crashing the browser. In case of firefox the browser crashed, whereas in chrome only the tab running the code crashed. Other tabs were working fine. This is because chrome uses different threads for each tab.
However both firefox and chrome gave me the option to stop the script running as it is crashing the browser !!

Pattern:
Animation using sprites ! I have coded that already and that seemed a perfect answer for pattern problem. In addition to that i tried working with ‘canvas’ which is a new functionality added in html5.
It allows you to draw beautiful patterns.
What i decided to do was allow the user to draw his own pattern in the canvas.I used event handlers to find the mouse position and then draw line tracing the pointer. Event handling is an area which has many cross browser compatibility issues. It took some time to find suitable functions that worked well both in chrome and firefox.
Finally i put the animation and this canvas on the same page and did little coding which makes the animation to stop whenever the user draws and resumes when user stops drawing and comes out of canvas.

My own programming language:
It turned out to be my most favorite question after i finished it. I decided to create a language similar to assembly language. Remember x86 language? which uses instructions like mov,add,sub etc...
I used js object which allows you to store key-value pairs for storing variables and their values.
I consciously put effort to improve code-reusability and modularity. But then realised that without conscious efforts too, i would have done the same refactoring. I still firmly believe designing code is all about the programmers instincts. Good programmers do it in a better way !
will upload codes in a separate post.
See you in next post !

No comments:

Post a Comment