Dojo vs jQuery

I got back to work on the side project I started awhile ago using Dojo, nodejs and mongoDB, I kept having this problem, I can’t find ready components and plugins for dojo, and the existing ones, are not doing a very good job or at least requires heavy customisation to work the way I want, while there are literally dozens of alternatives for every components or plugin in jQuery. I found myself ended up developing components that works correctly and do what I want instead of working on the actual thing. Continue reading

Recursive Search and Replace using Perl

If you’ve used Perl at all you are probably familiar with the simple oneliner to do a search and replace on a given string:

 Perl |  Copy |? 
1
perl -p -i -e 's/oldstring/newstring/g' *

This will replace all occurrences of oldstring with newstring in all of the files in your current directory. Being able to do this quickly and easily is absolutely awesome, but what if you want to do this recursively across the current directory and all directories below that? I’m sure that there are plenty of ways to do this, the one below is the method that seems the easiest:

 Perl |  Copy |? 
1
perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

If you wanted to be more precise you could replace find with grep and only perform the search and replace on files that you know already contain oldstring, like this:

 Perl |  Copy |? 
1
perl -p -i -e 's/oldstring/newstring/g' `grep -ril oldstring *`

This is one of those things that I don’t have to do very often, but when I do, this Perl oneliner is a real life saver.

How do I succeed

I don’t like to be patted on the back. this is why people fail in the first place. Because they knew when they fail they can crawl whining back to a person and say “oh,look at me, I’m bad, I’m a big failure”. and this person looks back to them and start to comfort them with words like “it’s not your fault, bla bla”, so instead of trying to get back on their feet, they start to forget everything about it and blame the circumstances or whatever float their boat forgetting all about their failure. 
So what I do each time I fail – I may sound a little crazy here- I stand in front of the mirror, and I start yelling “FUCK FUCK FUCK FUCK FUCK, I’m Mustafa Zidan god dammit, how I fail in a thing that is so easy like this?, I wont let such a thing bring me down, I’m gonna do whatever it takes to finish this”
and the lesson is each time you fail, just yell at the mirror as hard as you can like a crazy person, no seriously each time you fail just remember you are closer than you think to success.

How To: Javascript Class with optional constructor parameters.

JavaScript is one of the most popular and widely used languages in the world today. Because it is embedded in all modern browsers, it has an extraordinarily wide distribution. As a language, it is incredibly important in our daily lives, powering the websites that we go to and helping the Web to present a rich interface.

Why then do some still consider it to be a toy language, not worthy of the professional programmer? We think it is because people do not realize the full power of the language and how unique it is in the programming world today. JavaScript is a very expressive language, with some features that are uncommon to the C family of languages

In this post I’ll show a quick how to declare a Javascript Class with optional constructor parameters.

 Javascript |  Copy |? 
01
02
/**
03
 * you can use Activity model as follows
04
 * activity = new Activity('name'[,description [, start [,stop ] ] ] );
05
 */ 
06
var Activity = function() {
07
    this.name = arguments[0] ? arguments[0]:'';
08
    this.description =  arguments[1] ? arguments[1]:''; 
09
    this.start =  arguments[2] ? arguments[2]:new Date();
10
    this.stop =  arguments[3] ? arguments[3]:null;
11
};
12
 
13
Activity.prototype = {
14
    name :"",
15
    description: "",
16
    start: null,
17
    stop: null,
18
    inprogress:true
19
};
20

When control enters the execution context of a function an arguments object is created. The arguments object has an array-like structure with an indexed property for each passed argument and a length property equal to the total number of parameters supplied by the caller. Thus the length of the arguments object can be greater than, less than or equal to the number of formal parameters in the function definition (which we can get by querying the function’s length property). So I simply used arguments object to set attributes if they are supplied by the caller and set the Activity attributes accordingly .

javascript interfaces, they can be done … em faked

When I was reading an article about interfaces, a question poped up through my mind. why JavaScript has no built-in way of creating or implementing interfaces.It also lacks built-in methods for determining whether an object implements the same set of methods as another object, making it difficult to use objects interchangeably. Luckily, JavaScript is extremely flexible, making it easy to add these features.
Continue reading

HTML 5’s “Web SQL Database” API

HTML 5 has a large,new and exciting APIs that will allow web developers to create richer and more better applications.and one of the most exciting new APIs is “Web SQL Database” Web SQL Datebase is set of APIs to manipulate client-side databases using SQL.

The API is asynchronous, so authors are likely to find anonymous functions (lambdas) very useful in using this API. Here is an example of a script using this API.

 Javascript |  Copy |? 
01
function prepareDatabase(ready, error) {
02
  return openDatabase( 'documents' ,
03
     '1.0',   'Offline document storage', 5*1024*1024,
04
     function ( db ) {
05
        db.changeVersion( ' ', '1.0', function ( t ) {
06
          t.executeSql('CREATE TABLE docids (id, name)');
07
        }, error
08
        );}
09
    );
10
 } 

A function prepareDatabase() is defined. This function tries to create the database if necessary, giving it one table called “docids” with two columns (“id” and “name”).

The executeSql() method has an argument intended to allow variables to be substituted into statements without risking SQL injection vulnerabilities:

 Javascript |  Copy |? 
01
02
db.readTransaction(
03
  function (t) {
04
    t.executeSql('SELECT title, author FROM docs WHERE id=?', [id], 
05
      function (t, data) { 
06
        report( data.rows[0].title, data.rows[0].author);
07
      }
08
    );
09
  }
10
);

SEMAT and Human Factors

[...]Why this is so was primarily crystallized for me by Alistair Cockburn who explained that since people are the central element in software development, and people are inherently non-linear and unpredictable – such an effort is fundamentally doomed. 

this is what Martin Fowler said  one of his posts  when he was invited to participate in  SEMAT (Software Engineering Method and Theory); and I found his opinion quite reasonable .the idea to found software engineering  based on a solid theory, proven principles and best practices. didn’t make much sense to me Software engineering still is, I believe, strongly driven by opinion and authority, not (scientific) evidence. I don’t know much about the particular approach though.

the reason that you cannot found software engineering on scientific evidence is the human factor,the fact  that you cannot standardize people and their unpredictability, the needs of people changes through time makes them untraceable by mathematical methodologies  ,the need for people to change is  another reason why the software development process cannot be controlled by scientific methods or at least the ordinary type.

Programmer Attitude

 

Have you ever waded through a mess so grave that it took weeks to do what should have taken hours? Have you seen what should have been a one-line change, made instead in hundreds of different modules? These symptoms are all too common.
Why does this happen to code? Why does good code rot so quickly into bad code? We have lots of explanations for it. We complain that the requirements changed in ways that thwart the original design. We bemoan the schedules that were too tight to do things right. We blather about stupid managers and intolerant customers and useless marketing types and telephone sanitizers. But the fault, dear Dilbert, is not in our stars, but in ourselves. We are unprofessional.
This may be a bitter pill to swallow. How could this mess be our fault? What about the requirements? What about the schedule? What about the stupid managers and the useless marketing types? Don’t they bear some of the blame?
No. The managers and marketers look to us for the information they need to make
promises and commitments; and even when they don’t look to us, we should not be shy
about telling them what we think. The users look to us to validate the way the requirements will fit into the system. The project managers look to us to help work out the schedule. We are deeply complicit in the planning of the project and share a great deal of the responsibility for any failures; especially if those failures have to do with bad code!
“But wait!” you say. “If I don’t do what my manager says, I’ll be fired.” Probably not.
Most managers want the truth, even when they don’t act like it. Most managers want good code, even when they are obsessing about the schedule. They may defend the schedule and requirements with passion; but that’s their job. It’s your job to defend the code with equal passion.
To drive this point home, what if you were a doctor and had a patient who demanded that you stop all the silly hand-washing in preparation for surgery because it was taking too much time? Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.
So too it is unprofessional for programmers to bend to the will of managers who don’t understand the risks of making messes.

Clean Code : A Handbook of Agile Software Craftsmanship P5

Exceptions Standards

 

Introduction

There has been a great deal of confusion over the distinction between Errors and Exceptions in some cases no distinction has been made. In an attempt to clarify, the following definitions are offered:

Exception: An abnormal condition or state of execution that may be distinctly identified and dealt with (full definition click here).

Error: A condition or state of an application or utility that requires a message from the application and “actor” intervention (full definition click here).

Another distinction is that some Errors must be logged, while Exceptions do not necessarily be logged.

Typically an Exception can be caught and perhaps handled or, if not, will perhaps result in an Error.Additionally Error messages should be internationalized according to I18N standards, Exceptions do not to be internationalized.

According to the definitions above, Errors cannot result in Exceptions however, Exceptions can and often do generate Errors.

In general, errors can be thought of as unhandled or unrecoverable exceptions.

Nature of Exceptions

There are three different situations that cause exceptions to be thrown:

  • Exceptions due to programming errors: Exceptions are generated due to programming errors (e.g., NullPointerException ). The client code usually cannot do anything about programming errors.
  • Exceptions due to client code errors: Client code attempts something not allowed by the API, and thereby violates its contract. The client can take some alternative course of action, if there is useful information provided in the exception. (e.g., an exception is thrown while parsing an XML document that is not well-formed. The exception contains useful information about the location in the XML document that causes the problem. The client can use this information to fix the problem).
  • Exceptions due to resource failures: Exceptions that get generated when resources fail. (e.g., the system runs out of memory or a network connection fails). The client’s response to resource failures is context-driven. The client can retry the operation after some time or just log the resource failure and bring the application down.

Continue reading