How many programmers to use, I also build my own library of functions ready to be reused in multiple projects and multiple contexts. Let me change the title of this post, maybe a little 'risky but, nevertheless, as we shall see, not far from reality.
In Objective-C you can write and call C / C + +, including the assembly for that matter. This characteristic makes it a very versatile language and, in some respects, phenomenal. On the one hand, you can use and appreciate the purely syntax of Objective-C, on the other you can run faster porting code written in ANSI C (perhaps for Digital Unix or Sun) and can comfortably fit into our iPhone or iPad applications; not to mention all the BSD kernel is already available on Mac OS X!
Continued ...
I "revived" this article of mine wrote a little 'of years ago. I slightly revised, updating a little bit here and there, but I think it is still relevant and interesting.
INTRODUCTION
What is a development language? A computer, aka PC (Personal Computer), has a personal language. This language is called machine code, to mean that every machine, so any computer (PC compatible, Apple, Unix, etc ...), has a unique and proprietary. The programs that we see "run" on our PCs are mainly carried out by the mysterious object called a microprocessor. This is the heart, the intelligent module, each computer. In fact, only one application is not running but is supported by the microprocessor, so to speak, to what is called an operating system: a software layer supplied by the manufacturer of the machine (see, for example, the Apple Macintosh).
Continued ...
It seems obvious, but some escape the subtle difference between constants and variables in a programming language. The constants, from the name, do not change their value during the cycle of a program, while variables can do it! Often, however, happen to use variables instead of constants without realizing it, also because this does not impact the logic of an application. Despite this, the difference between constants and variables, and there emerges all at compile time, where the constant plays a role certainly more powerful.
Coming from C or Assembly programming knows the difference between constants and variables, especially because, in both assembly and C, constants play a role by MACRO. For MACRO meant in a "piece of code" that is labeled and replaced in the code at compile time. The compiler, in short, performs a kind of find .. replace (and is sostituitsci) in the code each time it encounters a constant.
Imagine you write in C, the following simple piece of code:
1 2 3 4
| 5 ; int a = 5; 3 ; int b = 3; int c; b ; c = a + b; |
sono indicate come variabili in questo caso. Whether a which b are shown as variables in this case. In C, in fact, the constants are defined with the keyword #define . sono state definite come int . We note immediately that a which b has been defined as int . Already here you can make a first optimization. If we know that our variable a never exceed a certain value, you should declare it properly and do not use data types at random. Some developers do not bother to declare the correct types, thinking that this does not affect the performace! Wrong! Alternatively, it is acceptable that the first draft of the code does not involve this level of detail. However, it is a good rule, during the development process, review the code and check the data types.
However, in an assembly of the Motorola family, for example, like the mythical 68000, would seize our code compiled (without optimizations) into a kind of:
1 2 3 4
| , d0 ; int a move. the # 5, d0; int , d1 ; int b move. the # 3, d1, int b d2 ; int c - foo move. the d1, d2, int c - foo l d0 , d2 ; risultato in d2 ovvero c add. the d0, d2, d2, or result in c |
or:
1 2 3
| , d0 ; int a move. the # 5, d0; int , d1 ; int b move. the # 3, d1, int b d1 ; risultato in d1... move. l d0, d1, d1 result ... |
The compiler, however clever, effort in optimizations, then write the code with the right keyword can only help to improve the compiled output. In our case, if the value 5 is a constant is not convenient to use an integer variable, because the compiler, and rightly so, considering the variable variable, in fact, an entire predisponde easy to contain the value 5, which in binary is 101, ie occupies three single bits (if anything, int is a 32bit or 53bit worst a double-precision floating point!). If we had written the code like this:
1 2 3 4 5
| 5 # define MIA_COSTANTE
3 ; int b = 3; int c; b ; c = b + MIA_COSTANTE; |
The compiler would know from the outset that MIA_COSTANTE , being constant, the value will not change so I can reserve less space to treat it. In practice the Assembly code diverebbe:
1 2 3
| d0 ; la "q" indica una istruzione "quick", cioè che tratta valori compresi tra -128 e +127 moveq # 3, d0; the "q" indicates a statement "quick", that is values between -128 and +127 , A statement "quick" takes less CPU time (4 clock cycles in this case) d0 ; anche qui uso una istruzione "quick" addq # 5, d0; here an instruction manual "quick" |
This code is very fast and takes up less bytes. What we must keep in mind is that when you declare a variable environment prepares to treat it as such, even if today's compilers can do miracles, performing a series of steps in the code before compiling (some compilers, even perform a kind of simulation program to optimize the compilation into machine code).
A good rule, therefore, is to declare the right kind for our variables, though these are. Alternatively use the constants, especially if the programming language we are using the expected (as in the case of the new Flash CS3).
Continued ...
While we're on the subject of nostalgia, here's a nice emulation of the historic 6502 microprocessor , mounted in the 80s in the console and computers as the Apple, Commodore NS and the Nintendo 64 (then at step 6510, ...). This cute little gem is written entirely in JavaScript, running on virtually all browsers (Safari Opera), with the only downside being a little slow. But worth it. On the website ( http://www.6502asm.com/ ) found some nice examples, but curious lens.
Continued ...
Latest Comments
Joseph : Hi I wanted to ask you how you can do in the post I uploaded a gallery of 50 images, for example, ...
Joseph : Council if you want to restore all thumbs plugin Regenerate Thumbnails
Joseph : Thank you! Guide very interesting.
Giovambattista Fazioli : update: WordPress has updated the documentation of this function.
Giovambattista Fazioli : @ iLeW: of course, see here