Programming trick

from Wikipedia, the free encyclopedia

A programming trick is an approach to programming in which, by not envisaged by exploiting characteristics of the programming language or the software and hardware that would require larger in textbook excessive programming effort environment effects are achieved or not at all would be possible. The line between "conventional" programming and programming trick is fluid. The general term for such procedures is called a hack .

Programming tricks are used for a variety of purposes:

  • Faster program flow ( performance )
  • Less memory consumption
  • Avoidance of software and hardware errors ( bugs )
  • Circumvention of restrictions in the software and hardware environment
  • Obfuscation of program functions (e.g. to implement copy protection )
  • More compact source code (saving typing)

The use of programming tricks is particularly widespread in the demo scene , especially when it comes to exhausting the capabilities of older computer systems ( C64 , Amiga ) or mobile devices (e.g. PDA ). Due to the many disadvantages, u. a. Badly understandable code, restricted portability and the risk of compatibility problems , the use of tricks in "normal" programs should be avoided if possible.

Examples

The XOR trick
The x86 - assembly language instruction "XOR EAX, EAX" leads ostensibly an XOR operation of the EAX register (other registers are available) to itself from the contents of the register will be set to 0 (zero). This command is therefore equivalent to "MOV EAX, 0", but saves 4 bytes of storage space.
Illegal orders
Older processor architectures, e.g. For example, the 6502 family could execute commands that were not in the specification of the CPU. By using these commands, memory space and clock cycles could often be saved, but there was a risk that the code would no longer work on other versions of the same processor.
Self-modifying machine code
This trick is not used in modern processors to increase performance (in fact it actually leads to a massive slowdown), but is suitable for obfuscation mechanisms.
Hacker folklore
In a well-known story published on Usenet ( The Story of Mel ) about the archetypal "real programmer" Mel Kaye, he uses a. a. an overflow to control a loop.

Web links