In C/java there's difference between = and ==. First one is assignment operrator, and == is equality operator.
In SQL Select query:
select * from table_a where col1 = 'abc';
here = is used to check for equality. that's weird!
Wednesday, August 19, 2009
for loop vs while loop
Which loop to choose, for or while:
1. If we know that we must loop a max of x no of times, then for loop. for loop takes index of how many times to loop.
2. We can use index with while loop too, but it seems more unnatural. eg i++ needs to go inside statements, but in for loop, it goes in for structure.
3. Moreover if we need to break for loop based on some condition, we need to use break statement; a little unnatural again.
1. If we know that we must loop a max of x no of times, then for loop. for loop takes index of how many times to loop.
2. We can use index with while loop too, but it seems more unnatural. eg i++ needs to go inside statements, but in for loop, it goes in for structure.
3. Moreover if we need to break for loop based on some condition, we need to use break statement; a little unnatural again.
Standad input output in Java vs C
ANSI C library implements a model of text input and output. Standard input and standard output is by default attached to keyboard or file or another program.
eg getchar(void) will get characters fom keyboard; prog < infile will input infile contents in prog program; Using Pipes: otherprog | prog channels otherprog output into prog; putchar(int) to send to output stream; prog > outfile; prog | anotherprog.
Question to myself: Does this look easy and helpful to use; and if it is, why does Java not provide this model?
Java has System.out, System.err, System.in. hummm. So we use a lot of System.out in java; we can similarly use System.err, OK. But System.in? When did I use it, don't remember. My memory is failing me or I have really never seen it used?
But certainly Java does not have < as input redirection, or | as pipe mechanism. Or am I ignorant?
eg getchar(void) will get characters fom keyboard; prog < infile will input infile contents in prog program; Using Pipes: otherprog | prog channels otherprog output into prog; putchar(int) to send to output stream; prog > outfile; prog | anotherprog.
Question to myself: Does this look easy and helpful to use; and if it is, why does Java not provide this model?
Java has System.out, System.err, System.in. hummm. So we use a lot of System.out in java; we can similarly use System.err, OK. But System.in? When did I use it, don't remember. My memory is failing me or I have really never seen it used?
But certainly Java does not have < as input redirection, or | as pipe mechanism. Or am I ignorant?
Monday, August 3, 2009
Objective C Part 2
What are Protocols?
For the uninitiated, Protocols can be considered to be similar to Interfaces. Protocols are used for multiple inheritance of specifications.
There are two kinds of protocols: informal and formal.
Informal protocol is list of methods a class CAN implement. The compiler does not know about it. These are optional methods a delegate of a class MIGHT implement. At runtime, the class figures out whether any delegate implements these methods or not.
Formal protocols are set of methods a class declares it WILL implement(eg Interface). The compiler then makes sure that the class implements these methods.
Objectice C suports dynamic typing?
This means that most type checking, eg whether int is really coming in the parameter of a method(?), is done at compile time. So there's more chances of runtime errors. Unit testing becomes more important in dynamic type languages.
Forwarding in ObjectiveC?
As we know Objective C objects accept messages. And mostly it's up to object to do anything with that message or not. One other thing an object can do is to forward this message to another object. This is supported by forward() kindof method in base Object class. The class must define this method and forward any message it seems fit.
Categories in Objective C?
What if a class is doing a lot of things(has many responsibilities). the methods get intermingled, and it's difficult to see what each method is doing. What if we could group sets of similar responsibility/functionality methods and say, kept them in different file. Then we could add these functionality oiented methods to class at runtime. Clean code. These groupings of methods are called Categories.
Garbage collection in Objective C?
Garbage collector(an optional conservative yet generational garbage collector) was introduced ObjC 2.0. But it's not part of ObjC2.0 for iPhones.
Standard libraries fo Objective C?
GNUstep on linux and Cocoa on Mac.
http://en.wikipedia.org/wiki/Objective-C
For the uninitiated, Protocols can be considered to be similar to Interfaces. Protocols are used for multiple inheritance of specifications.
There are two kinds of protocols: informal and formal.
Informal protocol is list of methods a class CAN implement. The compiler does not know about it. These are optional methods a delegate of a class MIGHT implement. At runtime, the class figures out whether any delegate implements these methods or not.
Formal protocols are set of methods a class declares it WILL implement(eg Interface). The compiler then makes sure that the class implements these methods.
Objectice C suports dynamic typing?
This means that most type checking, eg whether int is really coming in the parameter of a method(?), is done at compile time. So there's more chances of runtime errors. Unit testing becomes more important in dynamic type languages.
Forwarding in ObjectiveC?
As we know Objective C objects accept messages. And mostly it's up to object to do anything with that message or not. One other thing an object can do is to forward this message to another object. This is supported by forward() kindof method in base Object class. The class must define this method and forward any message it seems fit.
Categories in Objective C?
What if a class is doing a lot of things(has many responsibilities). the methods get intermingled, and it's difficult to see what each method is doing. What if we could group sets of similar responsibility/functionality methods and say, kept them in different file. Then we could add these functionality oiented methods to class at runtime. Clean code. These groupings of methods are called Categories.
Garbage collection in Objective C?
Garbage collector(an optional conservative yet generational garbage collector) was introduced ObjC 2.0. But it's not part of ObjC2.0 for iPhones.
Standard libraries fo Objective C?
GNUstep on linux and Cocoa on Mac.
http://en.wikipedia.org/wiki/Objective-C
Subscribe to:
Posts (Atom)