JavaScript open my eyes (1) digg delicious su

Posted by tiendung
on Wednesday, October 10

Don’t be fool by the title, it’s used to attract readers like you. This series is about programming in general. But wait, I’ll talk about JavaScript later because it’s true that JavaScript is cool and it has changed my programming point of view.

Before know JavaScript, I lived in the world of produce and object-oriented language like Pascal, C/C++ and never know what programming is. In high school, I was taught algorithms before programming languages, just used languages as tools to implement algorithms. Fist and second years in university, I was taught a lot of math before knowing that math is the most important foundation of programming. I wondered why I had to learn math, I were there to be a developer (and I forgot math very soon). Two years later, they taught me about software engineering, database, AI … without showing me how programs actually implemented and run in a computer. As time go by, I write more and more programs and still don’t know about programming. May be this the reason why Vietnam do not have talent programmers. Singapore is better. I found some interesting programming courses at NUS like

CS1101S: Programming Methodology (with Scheme)

CS2104: Programming Language Concepts

CS3212: Programming Languages

CS4212: Compiler Design

But most of other courses related to Java and some courses force student using Java (or not encourage using other languages) to do assignments. For most students in NUS, Java is their language of choice. May be I’m lucky that I know only C and little C++ when I came to NUS and I hated Java at the first sight because it dismisses the main() function and force me to write a class, then create an object just to write a pure object-oriented “hello world” program (I used Java once to do assignments).

Then I tried some dynamic programming languages: Python, Ruby (on Rails) and JavaScript. I didn’t plan to learn JavaScript in order to create web apps because I thought I can do sexy Ajax things via RJS in Rails. But everything is not as expected. In my first project, I have to generate DOM elements from data in JSON format and RJS didn’t help much. I had to use JavaScript and started to learn the language. Ok, it’s just another languages, just learn the syntax and done. My first book is Pro JavaScript by John Resig (the creator of jQuery). He taught me how different JavaScript is from traditional object-oriented programming languages and the private and privileged techniques of Crockford to make object-oriented JavaScript more powerful. These techniques looked very strange, I never saw them before. I stopped reading and try to implement it in my first project, I also used jQuery to handle Ajax calls, DOM … (John mentioned jQuery in his book, of course). Then Crockford JavaScript videos keep my eyes opening (wider and wider) ...

just a point of view digg delicious su

Posted by tiendung
on Friday, August 17

People always make mistakes. We are all wrong 99% of the time. The winner is the one who realize self-mistakes sooner and fix them faster than others.

So don’t be too proud of yourself, be realistic:

  • admit that you can make mistakes
  • don’t afraid of making mistakes
  • welcome mistakes come soon (through experiments)
  • don’t blame others’ mistakes
  • fix them as soon as possible

Tien Dung.

fun with JavaScript Chainability digg delicious su

Posted by tiendung
on Friday, August 10

want to show all string properties of an object in JavaScript?


function showAllStringPropertiesOf( object ) {
  for (var property in object) {
    if (typeof object[property] == "string") {
       console.log(property, ":", object[property]);
    }
  }
}

var object1 = {
      name: "Spiragram",
      address: "87 Beach Road",
      vision: "Spiragram will liberate, lead and inspire programmers to realize their full potential ..." 
    },
    object2 = {
      name: "Tien Dung",
      age: 26,
      saySomething: function () { alert("hello from " + this.name); }
     };

showAllStringPropertiesOf(object1);
showAllStringPropertiesOf(object2);

is it nice if we do not have to duplicate the function name? We can write:


forEach([object1, object2], showAllStringPropertiesOf );
 

where forEach is a funtion:


function forEach( a, fn ) {
  var i, l = a.length;
  for (var i = 0; i < l; i++)
    fn(a[i]);
};

is there a better way (because we have only two objects)? The answer is making the function chainable by adding a return itself command to the end of the function.


function showAllStringPropertiesOf ( ... ) {
  ...
  ...
  return arguments.callee;
}

now we can call:

showAllStringPropertiesOf( object1 )( object2 )

still want to make it more readable? Let make more fun with “and” keyword.

showAllStringPropertiesOf( object1 ).and ( object2 );

by adding some code below

function showAllStringPropertiesOf ( ... ) {
  ...
  ...
  return addAndMagicTo(arguments.callee);
}

function addAndMagicTo( fn ) {
  fn.and = fn;
  return fn;
}

Tien Dung

My first task at Spiragram digg delicious su

Posted by tiendung
on Tuesday, August 07
T1) Setting a server
T2) Implement a simple feature
T3) Adding data to a website
T4) Reading xxx pages of the Top Secret Methodology Book

Which Tx == true ?
Anybody can guest ?
.
.
.
.
.
The correct answer is:

(T1 || T2 || T3 || T4 == false)

Let me tell you my first task is get used to a brand new MacBook :)))

Actually, my first task (I assign to myself) is to understand and catch up with other team members as soon as possible. Working at Spiragram is like a dream, everyday working with people who share the same vision, read the same books and ... at the same toilet too :) I will try my best to keep this dream last forever.

Tien Dung